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 66564C83F09 for ; Fri, 4 Jul 2025 06:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 115786B8006; Fri, 4 Jul 2025 02:07:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09F0F6B00F1; Fri, 4 Jul 2025 02:07:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E82106B8006; Fri, 4 Jul 2025 02:07:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D43C46B00EE for ; Fri, 4 Jul 2025 02:07:39 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AA57F1CF750 for ; Fri, 4 Jul 2025 06:07:39 +0000 (UTC) X-FDA: 83625550638.19.6A17CE1 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf01.hostedemail.com (Postfix) with ESMTP id D50D640005 for ; Fri, 4 Jul 2025 06:07:37 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=sUG1M5Nt; spf=pass (imf01.hostedemail.com: domain of 3qG9naAYKCG8fheRaOTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3qG9naAYKCG8fheRaOTbbTYR.PbZYVahk-ZZXiNPX.beT@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=1751609257; 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=Li63ssKppcLITl1ITfej/YujyWpoLXNJQdKFDqdnOTk=; b=BespyBE7KLMqlLx9Rhn0xoNK+zjmek8WHunF7nLBEUWUNsTWJUxCoscazpQJF2f7K6TUE5 cUezgANm2RvkQIqOi3BG41FIHVxRpxl/UNqeGNpOeBz4PzYDAsQ6N76Oi4XR2q+6IkSebA tL/2q0WyiNG6jdssFjU9N4BMpwAWMBA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=sUG1M5Nt; spf=pass (imf01.hostedemail.com: domain of 3qG9naAYKCG8fheRaOTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3qG9naAYKCG8fheRaOTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751609257; a=rsa-sha256; cv=none; b=LJsh/rSKSP24/yLLnH+6S/pbXEtzLRyeu0TzAawQF8GhAPB9W00pEN0GC1wIwea1joV0L6 JBGaQlmyohgQK6g7iEE41LMkxzhLZGx3P4tAIi2r58gl5vursT6QBtwqQNZPqk2PhP2C/w MV69ypIxF5FXvxsMgPe4BaEdNdB3ge4= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74b29ee4f8bso528407b3a.2 for ; Thu, 03 Jul 2025 23:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751609257; x=1752214057; 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=Li63ssKppcLITl1ITfej/YujyWpoLXNJQdKFDqdnOTk=; b=sUG1M5NtqqgRM/PmqF4kltk3puboXj0ERmf/CGknrkRfCpaVKEFH6/dYG4jIjqRCCb +qeZy7zCLk6XHApmJhjhfj5vxETJWdEUzptu8/FS9013ZuXo8IAW46LzX0A5fVpG2DcQ 9qv19WOZt9BaNMT/IXIG/kKnuFgRdXF6sX+bgK4PhARDaqA1GhJEsFlQ5LdzWPfq/9N4 vYnbb6B6Yr4scPO2x3ckBAbdM2wOYFz2TScD3GFUFhuZWJE6FEjznPuxprviDIVUh3tx hjCJU/F2W/beB4fMiybyCnUO6fTjwp+m/5JmSFBdWM67HM3sRiTCqxs4KoxPl9/xphvs djaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751609257; x=1752214057; 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=Li63ssKppcLITl1ITfej/YujyWpoLXNJQdKFDqdnOTk=; b=v2MmrfTEMk1s5Ha9cp8FkSp07R/TbMgs61sGyabUhO28yhawdU/E9djyGs7mECJ/1e qgod5NFIh6PokVLTkuuNjDzUzH6svE8HBkMG1JXuOOxejVHLZx7ouvGBrJCGX7+A/Fx8 Nghh25/NfxkQ56Mgk2h+XWh9wNqoTUmow63okLeewtq2xzt4w037cEjfwPUuiwIrEJRr WUc35NnLY6WP/7+5l4IlyDYtv88uJwfjxMKeAAGkRrqxwL1FqP4nct/U3ip0Uq6zwhEM fIGptQNqrWixoaKhUcKu8SoSYVuVpKvYK3j8YvGSvzfWYvzw9DWUy0g9wYCgbToTAz76 0m8w== X-Forwarded-Encrypted: i=1; AJvYcCWEya/GMLBszXWKxFFVtqgk1tastbkQw2v08hDJOEusM7uIjuTqldh2gQmIXNATvQ1Zg+cqCz8dZA==@kvack.org X-Gm-Message-State: AOJu0Yywy48p5NcPbwncxFa+vNm0C0ddsUkJXRA+GTjg9717t/9fRd3w BoEn0cC5syjD3IuIvM9+KCpgJoNfNwVBlND/XhfVTvXZ39DyHLrEW4FdGF9g7hVlMAe8CKgbYiP EJXKu/A== X-Google-Smtp-Source: AGHT+IFg2kF2IsphyTUD4Tvtt+9uGgwrJfxzBAwNyZq9idmvq78iXfjYjXpbgDrlsnLunNcFZOzQ5AK3W2w= X-Received: from pgji5.prod.google.com ([2002:a63:d445:0:b0:b11:3ba:92e4]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:e90:b0:222:d817:2f4a with SMTP id adf61e73a8af0-22609a8977dmr1043637637.17.1751609256747; Thu, 03 Jul 2025 23:07:36 -0700 (PDT) Date: Thu, 3 Jul 2025 23:07:21 -0700 In-Reply-To: <20250704060727.724817-1-surenb@google.com> Mime-Version: 1.0 References: <20250704060727.724817-1-surenb@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250704060727.724817-4-surenb@google.com> Subject: [PATCH v6 3/8] 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, aha310510@gmail.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-Stat-Signature: n6gq9oqx1tt66dznk45quacmkramsmh3 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D50D640005 X-HE-Tag: 1751609257-122857 X-HE-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SIN/HbyUJPMmuL0/1jaTEj5sxO8AfF2PLyMRo15GBRA2uxR8ETLHz9gwDbXjuEiBwAAvQ3dAQLpgckN4OQJ1ihSm0AugnBl54yi8pWNIj67tdJjkMzccpK9rrNnTNn94jJkM2gF9dbrMeSnmnHl3HmFRos5igeTP79byyhsNw8F2ZqpQn2QcWVqnO2msrlOvhoyf7cuUPxDg8VTuF0JGO1AVNUpR9yeFZE5cYFZO9yFvn6QUmQqfAL98orzo5mkEjPpIUNg9jfy3QXYXy+llHc1kdaRO6G1PuPYW5QteDDoWdllngHvWMH3hZwcW5oGin6d5kZhj2LfJctNOeqt9HDyYpUTHi0coY2jipSwKy0d+6SvxV5A8ZMI39/iJBdiBCj1bDtinXCknJImI4L60NT/stXxjD0roDn1C97Md6Q64MKk2plXRkECxK7rq4DfuTLLOefJf6mnRpf 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-maps-race.c | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tools/testing/selftests/proc/proc-maps-race.c b/tools/testing/selftests/proc/proc-maps-race.c index 10365b4e68e1..764821ffd63d 100644 --- a/tools/testing/selftests/proc/proc-maps-race.c +++ b/tools/testing/selftests/proc/proc-maps-race.c @@ -416,6 +416,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); +} + int usage(void) { fprintf(stderr, "Userland /proc/pid/{s}maps race test cases\n"); @@ -527,6 +616,9 @@ int main(int argc, char **argv) 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.727.gbf7dc18ff4-goog