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 69218C83F17 for ; Wed, 16 Jul 2025 03:06:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 689536B009B; Tue, 15 Jul 2025 23:06:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 662146B009C; Tue, 15 Jul 2025 23:06:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 578416B009D; Tue, 15 Jul 2025 23:06:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 43A4A6B009B for ; Tue, 15 Jul 2025 23:06:10 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 02A8D16025E for ; Wed, 16 Jul 2025 03:06:09 +0000 (UTC) X-FDA: 83668638900.22.589DE36 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf09.hostedemail.com (Postfix) with ESMTP id 38A24140005 for ; Wed, 16 Jul 2025 03:06:08 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AYt6slY1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3Hhd3aAYKCHMjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3Hhd3aAYKCHMjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752635168; a=rsa-sha256; cv=none; b=YRu9uDiRBpMH0fswjGZU7C3SpZ2KO32SJkAvYK8g8U1ZwhgggPau/clvZuTNyfug6YjeUX OGrk/xfsiAhd6YT8JERrNEDGBjcY4BASNhNdrS1bStBRJQUMV5RTRaAtFivLoKhRSVs70k AptJrlAJ07odGZybes70PsBjcNkVmEU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AYt6slY1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3Hhd3aAYKCHMjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3Hhd3aAYKCHMjliVeSXffXcV.TfdcZelo-ddbmRTb.fiX@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752635168; 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=E5I/8nq9VjjojkVVQOAcYIsIM51QjKrtMe0yEnKvPYr5dLtAjPk4DZ7k/5VrCZPKtj8C0N Nn2UntJ9CHyt5gedYHidBi3e6KDV2KgjX0W705uelZX2h3sGdFlE1YuEOlwXR02hdu32GI hdwwAhlnMMg0eyBA1NDkKpwMxBRZ83c= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74ad608d60aso5328180b3a.1 for ; Tue, 15 Jul 2025 20:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752635167; x=1753239967; 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=AYt6slY1zrUJVGBg2ju8u4dwvxUjpK32DkhiaK57YN8oksUPQmKT1x00iW3TwFEroR UvKkK+JWxJ9xJuVU0K1wkQk+Xg34b0YH4QaiYExEtgCDxae0Bim5nvyJyN6ODcYMEkYd CK+vlNomGy0aGrgWl64YgnLcPBnC+XFYTf1XLInBA4hL/tldl0mHnBOGPbbKHDbhQD4h SfS6DEHDIsH+QUXjX/YjP6Vcg/X9NAy+NKr4fLMxzFzgw7O5Kb3ABN4f8gQQjObJi8CZ zWt1fEVKaxvfjY3dCNWmGyoLjqrT1kVCs6nQ90pEQCKF3reGs9NC6EJcetPY0cT41dIl lwXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752635167; x=1753239967; 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=fkogvDj5HmB8tIjburjQlw7xO9MKkVHFBZkkpmBnzarNMNOG8q4s7vEYrsptVPjs8N nyaFY9fTL6SxCITzA3dWEbhwL3VMABdHAZtj/G5+ys/yEJa5I1daCTJyN/AfL9BZaC0W ymXziawLpPKS7/TnNsw9eOJKIdNb7exrFlFqRJGZyLgiH7k6T1Kw0gLJDc7vXGWWn8pw kbZ70wD4IWqDlQ/u0EiQJjla6vFuv9KVDp5ayKNQtq2PL1q//IknuKT2CDKCKNcE+O2l wE+YNB7oUKHXZlqQIH2bShqIm1jS1El+J2E+H/X9tHkBD4dfNYp3t+qHcyfyA9XMB47U dUAQ== X-Forwarded-Encrypted: i=1; AJvYcCWAwWkQk7mqz3DjROhZ+OlroyJme44vg3F3xoFQoUW7xxfmMta1rG+FeaUaxbd9jyfvuQraVUjGWQ==@kvack.org X-Gm-Message-State: AOJu0YysQMcL10wVH3k1ju89zrHJ6UK1TwNfsay4ro9KZrAZ/YC3jmzy PcaeI4gKG75StphobspoghIjJfGEfxHF8zh0xJoapsHAgENw0m8oBVnWmjsH3ny1v8uPKvgZ5j9 BDw3QlQ== X-Google-Smtp-Source: AGHT+IHN4KjxRUYFy2gmozTCR7TK1ofpV5QP2mqF+y0rY8P1k6j/G7f8VA9mG0zvAsbo/1BgyAC1yTm//HE= X-Received: from pfvb10.prod.google.com ([2002:a05:6a00:cca:b0:748:f270:c438]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:982:b0:74e:c917:3b1a with SMTP id d2e1a72fcca58-75724c805c8mr1488713b3a.24.1752635166933; Tue, 15 Jul 2025 20:06:06 -0700 (PDT) Date: Tue, 15 Jul 2025 20:05:52 -0700 In-Reply-To: <20250716030557.1547501-1-surenb@google.com> Mime-Version: 1.0 References: <20250716030557.1547501-1-surenb@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250716030557.1547501-4-surenb@google.com> Subject: [PATCH v7 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, 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 38A24140005 X-Stat-Signature: kfyfqdd3bus5nky4srr1fri45ceihsyj X-HE-Tag: 1752635168-175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5tM11klhvc1M68/6sK7S3VDhmQC7l3llwq5HCkpqXCaRwkp8EXDcbKcgSk9GvYh0S/cFkpekFeTIvJ73z/0RQVBhKE5dyIBzcL4rVSJDwy17HNit8DeXKT5fkRSHoewFmPBgP+tRHTPa8vTO4UwJn0sm0wqXyNtP+osr3og6WdmUAMuyPN0A5dyoq9iRpBmeFVLqw1i+tCp723EfN8GQSgK46uE9A/irdlHWOA/xhFh/O0Gl4AaDke6rH1xNACmP/EwDKqZ/FH1TMZ2i2l6t+JGuz1LuhG5UrwNfKIarGtkHsgbMQmZkWs0ZNk6YkIOg1giW+Nmfdjzy0gLjBI6xcZhOYynUHg1kahfcpBqz/XWh3FjMigRFpKRW0KfCL4cK6brbC4hvbCZGksGSzbvNGu2YIQsQsk6cF37IN5zhr8DWZo9rq2uG9XN8ATxFRTiVX8mNQjRBZpfWl2rlPROj4aw 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