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 4780EC5B549 for ; Wed, 4 Jun 2025 23:12:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCB5F8D0053; Wed, 4 Jun 2025 19:12:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D54738D0007; Wed, 4 Jun 2025 19:12:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1F238D0053; Wed, 4 Jun 2025 19:12:12 -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 9D1938D0007 for ; Wed, 4 Jun 2025 19:12:12 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 60E1E140BB4 for ; Wed, 4 Jun 2025 23:12:12 +0000 (UTC) X-FDA: 83519268504.01.03C8EE4 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf03.hostedemail.com (Postfix) with ESMTP id 909CC20003 for ; Wed, 4 Jun 2025 23:12:10 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QWTNQnVb; spf=pass (imf03.hostedemail.com: domain of 3ydJAaAYKCLoxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3ydJAaAYKCLoxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@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=1749078730; 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=0FA9HEfGx7V1U+x/ZxWl25F47mbSYtvHNegG6DkQ3X0=; b=Tp67qBZ2m6GtmzakuARimnIAcw7LD8q3IPLGX14vX3fE8+OtPozZ9l7Lp1X0lmgntfQKWN 9a0Q3kuHJ/EtVux9umLPY6RFiVW8/owPg+BhGckh3i8lhOKRd+FZIhH9djSNG2zbsqDkA2 XlCStvoIvFOzAyFrihgb2JVyGsnGy7Q= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QWTNQnVb; spf=pass (imf03.hostedemail.com: domain of 3ydJAaAYKCLoxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3ydJAaAYKCLoxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749078730; a=rsa-sha256; cv=none; b=pPyr/4/pXlzDIxldu3dKs2hzHZL1b5YocCX1dE8BuaUcKeATOz0GsD2PsrUvVbg5ZTCFzN RbsqB6XEwUy3i5lnVunLVsr1LVcpTvoAOeEv0LLVrDuX+6jrdubM9zp7tXxRvn/2G8HqsC hOEgOKo3b8s+3vaMa2vAvJd0WDlPs5w= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-234aceaf591so1952415ad.1 for ; Wed, 04 Jun 2025 16:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749078729; x=1749683529; 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=0FA9HEfGx7V1U+x/ZxWl25F47mbSYtvHNegG6DkQ3X0=; b=QWTNQnVbFjeWsV0XQJJbg3onWI/zfJcm++J9SWzGjQrhiaWxMj7s08BXG39REuQVxt zGiihvGm6OAp2nYV8rNvWqOE8PWYN1RvghmQ4bZaHRYJBVQliobwNBGeTrO2ycMcHltQ MVL+2bas29NDF3JjoJCzHiKjK+KE1+kb8Bw9Ft+JVI+lkbxxNc2kU8xuXkbMDf2KIzEs ieYAXV7uo85mE2+H434qY/VPL+onYX4ph9K4F0OwiKdvuyw0mMoUyu65ntjBpyk7V6mw MAzxND4moctgqVl88XXbhWMtKCIAASXt8yBsCB3PUlkWKq4Kbt2RdoNGQzdMGe9aN6vh JCOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749078729; x=1749683529; 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=0FA9HEfGx7V1U+x/ZxWl25F47mbSYtvHNegG6DkQ3X0=; b=RYBY5V1Nh/KrIjhwCFrNH8hrwJIfpQYJX92UgNDKF5FoZmw+50ynB9/B+bhJSJnJUH jLDqTNVagl8ixdZ9h5qyhhc6Lbgso1bZMIAbLwniiDCDPBD0uzHZOQRTh3GA4+K7U0N9 y0YwTfbfs8Q5oY1dK0GXjuox2yXhR3uDgZsJLy8pUBdvBCOxKdzCCK4n1C5gqKFEcJcH Ph4GaNxrTKymhAPLfr/lJ9MTlwPMLsZ8uG6Z3zXTFCxCDGe/KtxLn3+nTi7XV5w+qAs3 9lniZKgJEpIKRCZe3G4ypGzv6+skTGy4vUj2IJ7YgdDk3vFgARgvn6vLgMh/gx5IGdgG eT/A== X-Forwarded-Encrypted: i=1; AJvYcCVljdX6J3USD+DJQQTIzGJ8sxkWiYfBdBmzPDZOipCxKsWhhV7H3GB+Y6H4lFGFLmPHaW3PHk5aJg==@kvack.org X-Gm-Message-State: AOJu0YzeL5ou4wL83rtzYM6Z0EZdvfOcA7I2lVDNWo2tG9gYZNUNfP49 Pnca8yt+ywOIvLuE9uQxmCPKMWCudHY9a1i7lJQZtxGb8Fo07hR826514xqxn25FDWtB6jZnnpp FC+Z9bw== X-Google-Smtp-Source: AGHT+IHKTW0FyMFXnbv+r0+NsbH4HZxFH9qcykRJPxlisC0t/nE0casNv64qhrGUdh0QFtZ3/VwVrTXk6rU= X-Received: from plmt12.prod.google.com ([2002:a17:903:3d4c:b0:234:593c:eb5]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b45:b0:234:c5c1:9b63 with SMTP id d9443c01a7336-235e1124bcemr58010975ad.18.1749078729438; Wed, 04 Jun 2025 16:12:09 -0700 (PDT) Date: Wed, 4 Jun 2025 16:11:47 -0700 In-Reply-To: <20250604231151.799834-1-surenb@google.com> Mime-Version: 1.0 References: <20250604231151.799834-1-surenb@google.com> X-Mailer: git-send-email 2.49.0.1266.g31b7d2e469-goog Message-ID: <20250604231151.799834-4-surenb@google.com> Subject: [PATCH v4 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: 909CC20003 X-Stat-Signature: 14wczd4d858dg3dq1x84747188ttbi8m X-Rspam-User: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GjhTYrsOiEkeyDD1f6RVS82QBnZky5VyTm6639O6OzA1tVfAhsz92GxlMEyv+I+JGeZuaf5KEMFKWE5lJEh7VIm+gMqPYmQ5fAlQ/LfHLWpLcuzy5qRNAPD13eQviHTODfuAykyQr1KgDKJg88ZljCJLMHamgLZDUQmlwdr8Ig9bmVV5B9p+Ht5Yt90qeQG1hooLNdzPNEVoMPMu8p13Fw9uluKPmxqqRGg8XmhX038Dcr0vGOqcA+8kGkUk6OtqNxtHMMJCk54XXqt9F20WqlT37jfeP7T5uNqLBpULkLpgEifwPjIfKms30c6v4iMn5QivCpRvbOcU6SYihvJ9Oc+sXUZhd66Ufif9emG0lETVLm/Gfk/6ZJkgnJNDyEiAE1HFONyqHlULmW/T5OUszbOZI0WIUpWulVdDXvkwsxDeVyNzZciG0BK1vFGhiZR8GD7yP2OJUWBWk6N0XCuA2QGJcnN886W5/orH0hcTn8PY= 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.1266.g31b7d2e469-goog