From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35204C77B7C for ; Tue, 24 Jun 2025 19:34:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 684CD6B00AF; Tue, 24 Jun 2025 15:34:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 636546B00B1; Tue, 24 Jun 2025 15:34:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FD7B6B00B3; Tue, 24 Jun 2025 15:34:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3ABFB6B00AF for ; Tue, 24 Jun 2025 15:34:12 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 027971A0F29 for ; Tue, 24 Jun 2025 19:34:11 +0000 (UTC) X-FDA: 83591295144.14.A9C7BFA Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 2652840010 for ; Tue, 24 Jun 2025 19:34:09 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QDk5kXJA; spf=pass (imf01.hostedemail.com: domain of 3sP1aaAYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3sP1aaAYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750793650; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VTpxqo9rYzmnOlbgrt5I9x/wPv8qMNQnGNX8faPUhlk=; b=0LKgMoPkEdpR7BGaBljS8nqzsOd9ANB7E2vO0LOTQPyiBcXX76GFr2R2S4zwkUjN6vqnRi 9mCpJq8FYtc7Vk3MvM46wStNDMb5dAjXR3GZfD61dSgmuJQwGOSB+mvfNM5Z+t6IZRGjv3 ihP5NrKwTD7eqHooUNhv5ig0waWKF+s= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QDk5kXJA; spf=pass (imf01.hostedemail.com: domain of 3sP1aaAYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3sP1aaAYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750793650; a=rsa-sha256; cv=none; b=sou9qbhaeF1pfH9Yrh3zsjGqIGs7jM/Z0KTDic+N4EvmyOk1/trfWabpqI/ubnx0Nz2Y7C vh8zpdwR4Ic902EL0EaNDCCVmZjwFPyqmFMj5FHf1Jo3ktKqhK3Cxx7cfaCVXsgcbB5T83 s8GRrmHl6hH1gPQxLrLC0dmrl4RWy3c= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2369dd58602so50319025ad.1 for ; Tue, 24 Jun 2025 12:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750793649; x=1751398449; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VTpxqo9rYzmnOlbgrt5I9x/wPv8qMNQnGNX8faPUhlk=; b=QDk5kXJAG1oxvTZyFH6KcnDXUab0gFDPVPilaFZzNtRZAftrqpdxtEp+eiVLsJIpZD Vy1DqsV6HsKOykwuVoDqoeT/f4iy/YYihp/xSizCJCQyFIWyIR4QY9Az9RDuWCu1R+af F/UVUzejHWG0x7x2i6GPW4+iYRP9CNG3A7bGQv1Si3VZsMOLupkmcEdBJHAvxNNQ2gDG d5PiGP8+MDqg9kPVmJjFE3wuI4Wppr+fT9X2PYJwcxog/6Vq1h4tQKKz7fQt4uYZRe+v 0ccA+HOyOEZhiAJdz2y2ejJJvtvSxonBughSm8PHIcBp2zjI5Cj5A4F8gS+JOQXvsJ8U g5Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750793649; x=1751398449; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VTpxqo9rYzmnOlbgrt5I9x/wPv8qMNQnGNX8faPUhlk=; b=v8AssGYmHYwHFNBeJuK2DKABhqr4zIJJ2O4OAjhJjX+n6gx26513X9B1+4/NiEqKq8 R8WZgLKTFdZY0PhFDURakFPgG2VMLxUw54wtTF+0Y4K3wom9VMGKmpln/YUzmfzdl0Lh w6dGMKygWtZ1Hn5GOsaowhAeYglzWZ+6TBZXYOYljKP933DbLrvQuur2+F67biprwPXS 0V4EefFyUHgRkr3Unc9LLB74q6qM2nVntD2SryohLIjq1HPMFaseqeK4H/aCsHpIDwKD 1XFIr2B4eHWhnRcElmRW2t8V3MG0+6uxZZms5F4qLprp1L1jErXTRj68JYwgLQcx2x/f uaeA== X-Forwarded-Encrypted: i=1; AJvYcCV4KHi+ZyIvhJkLTdmFAXFp84YgGZuBi1IT303rM+3ywnYUoiH8WZq36g+C+QK3nfMSxouM7OhTAQ==@kvack.org X-Gm-Message-State: AOJu0Yy5zi7+LtYJzBZe77208ZF1w5CJYWbUb/9qrlfxQW/MdI2/aARn vlLYg8phklZSjGoCA1PxkiTzn+if7Bq4Om9tc60Db0GvjMg8kkdTPbzryn5EORDVeBDz8DymKyH igFp9cg== X-Google-Smtp-Source: AGHT+IEYzVFlaafTK+NJEStVfwqaXhWigt92zShqce3bvq87pwtPR0sp6zBPOudQkJC7xdMwRNzMBfU8jZI= X-Received: from plbkk15.prod.google.com ([2002:a17:903:70f:b0:234:908f:4e22]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:8cd:b0:236:6f43:7047 with SMTP id d9443c01a7336-23823f87ed4mr8275335ad.9.1750793648973; Tue, 24 Jun 2025 12:34:08 -0700 (PDT) Date: Tue, 24 Jun 2025 12:33:55 -0700 In-Reply-To: <20250624193359.3865351-1-surenb@google.com> Mime-Version: 1.0 References: <20250624193359.3865351-1-surenb@google.com> X-Mailer: git-send-email 2.50.0.714.g196bf9f422-goog Message-ID: <20250624193359.3865351-4-surenb@google.com> Subject: [PATCH v5 3/7] selftests/proc: extend /proc/pid/maps tearing test to include vma remapping From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, david@redhat.com, vbabka@suse.cz, peterx@redhat.com, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, paulmck@kernel.org, shuah@kernel.org, adobriyan@gmail.com, brauner@kernel.org, josef@toxicpanda.com, yebin10@huawei.com, linux@weissschuh.net, willy@infradead.org, osalvador@suse.de, andrii@kernel.org, ryan.roberts@arm.com, christophe.leroy@csgroup.eu, tjmercier@google.com, kaleshsingh@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, surenb@google.com Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2652840010 X-Stat-Signature: 5eezm4tppg1srpssebwiuoc8uizpt75r X-Rsp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tGT1k3fjEo3fPyHQUeSKQitXigMliGuI6mBJDXUhGmE8t7LtEs/NgCR5iKIVsbNRi7NxvhlzCKElqs45jz3KJ+OV2MsI/x8Bf+LdF9MhgwjJPL8ycECeOlgWQYLpGUmlmDlB8h1DczVOTWeBXtXM30+Kx9X63cjV3DbzHRDdj1yBf3u2J9jH7ZOGzdJarnf+VN2tHSyJzONWNo1Em+NfLAk3mvNQV9/vXn87f6U6f0tXXmiC6EDHnQXhMugfPDRbFImeF18LhazXHPxpQgIi62qOZf0zClcXDRNR7MotalxCqj3/ge5Ktrk/qEtmjLHikpG0p3q7ru2nA+9so1GYSL+fpHZEBom8q7fEtOKWQAmZTHWftqcq1OedizGDRI9q9LiCw2slaS/OGIyktvNyxSbSMV3vG0xobmjvU30p7ASENk25ApNldjYe2URAXNHp/dgA2Ge2+09Z4zMBVEWO/BYojQbBLg6GWw0mUR3yf1SVfG X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Test that /proc/pid/maps does not report unexpected holes in the address space when we concurrently remap a part of a vma into the middle of another vma. This remapping results in the destination vma being split into three parts and the part in the middle being patched back from, all done concurrently from under the reader. We should always see either original vma or the split one with no holes. Signed-off-by: Suren Baghdasaryan --- tools/testing/selftests/proc/proc-pid-vm.c | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tools/testing/selftests/proc/proc-pid-vm.c b/tools/testing/selftests/proc/proc-pid-vm.c index 39842e4ec45f..1aef2db7e893 100644 --- a/tools/testing/selftests/proc/proc-pid-vm.c +++ b/tools/testing/selftests/proc/proc-pid-vm.c @@ -663,6 +663,95 @@ static void test_maps_tearing_from_resize(int maps_fd, signal_state(mod_info, TEST_DONE); } +static inline void remap_vma(const struct vma_modifier_info *mod_info) +{ + /* + * Remap the last page of the next vma into the middle of the vma. + * This splits the current vma and the first and middle parts (the + * parts at lower addresses) become the last vma objserved in the + * first page and the first vma observed in the last page. + */ + assert(mremap(mod_info->next_addr + page_size * 2, page_size, + page_size, MREMAP_FIXED | MREMAP_MAYMOVE | MREMAP_DONTUNMAP, + mod_info->addr + page_size) != MAP_FAILED); +} + +static inline void patch_vma(const struct vma_modifier_info *mod_info) +{ + assert(!mprotect(mod_info->addr + page_size, page_size, + mod_info->prot)); +} + +static inline void check_remap_result(struct line_content *mod_last_line, + struct line_content *mod_first_line, + struct line_content *restored_last_line, + struct line_content *restored_first_line) +{ + /* Make sure vmas at the boundaries are changing */ + assert(strcmp(mod_last_line->text, restored_last_line->text) != 0); + assert(strcmp(mod_first_line->text, restored_first_line->text) != 0); +} + +static void test_maps_tearing_from_remap(int maps_fd, + struct vma_modifier_info *mod_info, + struct page_content *page1, + struct page_content *page2, + struct line_content *last_line, + struct line_content *first_line) +{ + struct line_content remapped_last_line; + struct line_content remapped_first_line; + struct line_content restored_last_line; + struct line_content restored_first_line; + + wait_for_state(mod_info, SETUP_READY); + + /* re-read the file to avoid using stale data from previous test */ + read_boundary_lines(maps_fd, page1, page2, last_line, first_line); + + mod_info->vma_modify = remap_vma; + mod_info->vma_restore = patch_vma; + mod_info->vma_mod_check = check_remap_result; + + capture_mod_pattern(maps_fd, mod_info, page1, page2, last_line, first_line, + &remapped_last_line, &remapped_first_line, + &restored_last_line, &restored_first_line); + + /* Now start concurrent modifications for test_duration_sec */ + signal_state(mod_info, TEST_READY); + + struct line_content new_last_line; + struct line_content new_first_line; + struct timespec start_ts, end_ts; + + clock_gettime(CLOCK_MONOTONIC_COARSE, &start_ts); + do { + read_boundary_lines(maps_fd, page1, page2, &new_last_line, &new_first_line); + + /* Check if we read vmas after remapping it */ + if (!strcmp(new_last_line.text, remapped_last_line.text)) { + /* + * The vmas should be consistent with remap results, + * however if the vma was concurrently restored, it + * can be reported twice (first as split one, then + * as restored one) because we found it as the next vma + * again. In that case new first line will be the same + * as the last restored line. + */ + assert(!strcmp(new_first_line.text, remapped_first_line.text) || + !strcmp(new_first_line.text, restored_last_line.text)); + } else { + /* The vmas should be consistent with the original/resored state */ + assert(!strcmp(new_last_line.text, restored_last_line.text) && + !strcmp(new_first_line.text, restored_first_line.text)); + } + clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts); + } while (end_ts.tv_sec - start_ts.tv_sec < test_duration_sec); + + /* Signal the modifyer thread to stop and wait until it exits */ + signal_state(mod_info, TEST_DONE); +} + static int test_maps_tearing(void) { struct vma_modifier_info *mod_info; @@ -757,6 +846,9 @@ static int test_maps_tearing(void) test_maps_tearing_from_resize(maps_fd, mod_info, &page1, &page2, &last_line, &first_line); + test_maps_tearing_from_remap(maps_fd, mod_info, &page1, &page2, + &last_line, &first_line); + stop_vma_modifier(mod_info); free(page2.data); -- 2.50.0.714.g196bf9f422-goog