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 E7141C369CA for ; Fri, 18 Apr 2025 17:50:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4B806B02AA; Fri, 18 Apr 2025 13:50:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB1D26B02A9; Fri, 18 Apr 2025 13:50:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8B146B02AA; Fri, 18 Apr 2025 13:50:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 866C86B02A7 for ; Fri, 18 Apr 2025 13:50:11 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D650F1C929C for ; Fri, 18 Apr 2025 17:50:12 +0000 (UTC) X-FDA: 83347903464.16.3BCE83F Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf08.hostedemail.com (Postfix) with ESMTP id 09B6A16000B for ; Fri, 18 Apr 2025 17:50:10 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1ixFDRbb; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 30ZACaAYKCEQy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=30ZACaAYKCEQy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744998611; a=rsa-sha256; cv=none; b=ExUjbbS507on+J0YlFom5/OZlTUwlCImzQWOPIcqaFjc5uV1/n1pJ7is/qUHGWMd0HIPnJ /oadKNAFpbNVGbnZaslyRJCo/D73uvsl+uiYUCXr9RhIlIXKwbzfQJh56tCrXD6hIs247D xvGimCt1HugjgyKjb6/ALnHO8PFeM2U= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1ixFDRbb; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 30ZACaAYKCEQy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=30ZACaAYKCEQy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744998611; 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=9QDrVpMHVQI58rYUIwLQJvrC+l7tIXNhALhARIzYV3A=; b=N8UN8wBFewGTJqRk0f7rx26TUYjs0w5hZ7rrg03ScSvAU7wknB6Werdbn5WA867Y3jddv1 iGP6oNHcmWNnqh2Q7no0Le8zGRZNqtH7nBUXa9qz9V7abVO9e2QWb0uDpgmnRyaJfoEmvE Lll6C4XEeHbhSJdb6lTT4ljp4kBZbGM= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30872785c3cso2566588a91.1 for ; Fri, 18 Apr 2025 10:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744998610; x=1745603410; 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=9QDrVpMHVQI58rYUIwLQJvrC+l7tIXNhALhARIzYV3A=; b=1ixFDRbbR1sCFwV6p4RncQS01UuTevHqnd7D+Mp0YDwiDDPquLnHs9JZM3m7/EtJxF +50UykzfnZ7VPmI1XK6tjISF8263dSZnvTCcFg/Xjdi+tQ3BnS3NdD2juTwpy3H5+Wh4 aKZJFof7cuQibQtXmmFZrICnZe0b2opk+iKMksTJfPZqiqkLdRqnc5uqKSW52h5ZrtlB FhAnev8eIiAgC2johFchpH1qxp+S9w0aDtuBnN0BYZNin4UYplvwAhosH/ajEzo7RaVE dgQ7cbKN/7YRWPFu+Na71QEq5BG41dou0wpFPyQVy71wHbzB9ReCXV4QFSXMF54TLxI9 G5eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744998610; x=1745603410; 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=9QDrVpMHVQI58rYUIwLQJvrC+l7tIXNhALhARIzYV3A=; b=Y6JWaOqutBDqm4tLV5SdbNbOAP7W8hVRi3jrsb+AcHjDSXoQ6jtCUojRsSxMcV3ihW NUk7iFT82RmFiqn33DfRHeZ9QmJKCPUULezVhPHKsu+1HY6B1WeI9nS5moh4wt0+46QY mwhtphE0kAGNHRR+hlwHalz1jCGYG985xOx58Tu4MDrAVI4xPIuUotC6aij0xgy3eKQT 3aEkz+upKhfFpUPjeyEQThi7Fj1Wsve8BsDGjI6k7sRusJH8UYNFPI9OXIZLb/23RjCR RuhBE1J1wqbAPUvFSnXPbfx8LoM7u67a2nZddGMnLS7aFBcwexdB3gh8BkoUNhwOfMD1 8RxA== X-Forwarded-Encrypted: i=1; AJvYcCUaKl3RUOMGp1gcp8H9KIguSqG9wLKFSMiI2oezRVa7K9XcW33N429Jfm9ulaXRfzaGlMbRSvgL2Q==@kvack.org X-Gm-Message-State: AOJu0YwLVDrTfZqF5bALTYBEBv5E/7I8HaVycQE5UIyCZDX8NCWDdN/r jlKHYhS3r3Y+SeI4SfNl0NTk9AqUE9myWL/7xWp5Zlyz102paKCOCJXbggb+mlHmpm8D4QhWwFy JPA== X-Google-Smtp-Source: AGHT+IE7iTtCIpLL5pKA5lwf7kKMbjD35Kmet76OppQlPi+RQQiOVcZRsAZLaU2DHrZErhMdfWGzeuof8yo= X-Received: from pjqq6.prod.google.com ([2002:a17:90b:5846:b0:2fc:3022:36b8]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4ed0:b0:2fe:8c22:48b0 with SMTP id 98e67ed59e1d1-3087bb6d159mr5887502a91.15.1744998609934; Fri, 18 Apr 2025 10:50:09 -0700 (PDT) Date: Fri, 18 Apr 2025 10:49:54 -0700 In-Reply-To: <20250418174959.1431962-1-surenb@google.com> Mime-Version: 1.0 References: <20250418174959.1431962-1-surenb@google.com> X-Mailer: git-send-email 2.49.0.805.g082f7c87e0-goog Message-ID: <20250418174959.1431962-4-surenb@google.com> Subject: [PATCH v3 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, 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-Queue-Id: 09B6A16000B X-Stat-Signature: 8tahsjgar747zx78e4pxfkinwxck1wky X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1744998610-280203 X-HE-Meta: U2FsdGVkX1/JJ4kw9dARTpeUVZOzQV05UZ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2TRUzlQTIfBjLUGigTM3tw2OhGG2fThGTpqPG77q5399U8ahsxBYhAfHamFaUAA6bJf8KMyRZoH37PMse7Fg+/55da2zr495hJRKXx7tZhJLpHsIld3CBU+lYydUH7SDX46klO71Nz6U4LecFx/dQNE/K3Y1KBtjzScjCN22RzQmK34ZORChBVLACgaTXJPhcMubeHlaDvnnReGwezJzrkTyyIsgjWyxlcFgmOKV1D8i52yUhkmtUP0RsKIozzmwM9CizevfjH7Zd6C0e4G2O23aYpfaDpufOOSVSlzGotecQ/+SWoLX0R4NvIX3J7E1O3rrQx5InEGerxKoweln6XoxqH+VZJqh1ZB6/lLiMfvuQEShZfvxZvuPUEedmQvz4PYLpF94AlYkJzj92g/A1yRwwfZfgf8OG/icPuWCPdRKKraoHM3U= 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.49.0.805.g082f7c87e0-goog