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 92A87C5B552 for ; Wed, 4 Jun 2025 23:12:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 714926B00AA; Wed, 4 Jun 2025 19:12:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C5B66B0176; Wed, 4 Jun 2025 19:12:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58CF66B0286; Wed, 4 Jun 2025 19:12:06 -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 339486B00AA for ; Wed, 4 Jun 2025 19:12:06 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D543C140BB4 for ; Wed, 4 Jun 2025 23:12:05 +0000 (UTC) X-FDA: 83519268210.07.9CFCF0E Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf08.hostedemail.com (Postfix) with ESMTP id 3FCA3160011 for ; Wed, 4 Jun 2025 23:12:04 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4dnbErC6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3w9JAaAYKCLQmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3w9JAaAYKCLQmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749078724; a=rsa-sha256; cv=none; b=6mUcQOuU5Fs0DuvqZuBQlghYNQ9Pi1fu7gPBNuaB1sm0LOmYYpSbJQjMx/qPGRQWt1Q0pW PjMBpZutpH6RJHgGLzeMZMfz3m9cp7gI+8LHR5/yLM4o6HEmjOdN36VHchSYJzP2t5Nfpt YQJpP3tq+/baKru7+0e418bHPm4m/4E= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4dnbErC6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3w9JAaAYKCLQmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3w9JAaAYKCLQmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749078724; 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=Yn1CuoL7GOnivK1jg6V+q/afAc7Csel1kqBamqmGWos=; b=x2eJO+TKneS9F+GMngZ6sTzvjaEyiYoqYwONOK2AE3WXKG3/452paJAezjTZ+iWPWI/5HR XoOLeGqlrEZk1B9QJ0/2NzyzHQC+3T4G5XQhBwlN2aKonMHgI3CQDBaIxGsxqu2igB4/Hn WQQb4tHB7yU+FzyokmhkrNM5XegB9Ns= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-742c03c0272so593669b3a.1 for ; Wed, 04 Jun 2025 16:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749078723; x=1749683523; 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=Yn1CuoL7GOnivK1jg6V+q/afAc7Csel1kqBamqmGWos=; b=4dnbErC6j9c8MpGm3VrSqlAEpNDMYeA194vQFP+Ejhavhll/1UskBcEq2cjWC1PHFj HoTiKIvoSM5dfOl/t/bRJqe0pnal9/RZKr+QjUXgigX0EHJLfLOp2x4vuQZYYbHxtVSf 2AR21fVZfmnAtRS/0pS44n85uisTs6fgCOUEwHUmKVSxBZzbl9w9I7/o+ayv53zehhWM JMjoKoQRbY8z87U+1/oVL80TfOApEeCOrlF2HIHn6U0yUnrVoB962oYVWH3K3AGkvawS m6vF/7P8mKPkY36UWbz0RsR5I9kmMT6r2mE9pnpYLewU18fGaTndW9uPyS+mQ1iGyp6i rSHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749078723; x=1749683523; 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=Yn1CuoL7GOnivK1jg6V+q/afAc7Csel1kqBamqmGWos=; b=ZW0TL0JgTwzJexBtcV04O6LeFP0UlVnaE5z2pcUp7R5W1SO6isRiiKxfLHDmaPdpdF 6S9KWs6lRwkWPc0jRuw5xQPy27mM6ZBPlSrCeW3pcGd1QZiN8ccH7W6V2WAM5h8s8E5e SGx1TulOTKv2V/xSfN95aXafCrBZAB6Z0OLlfEmjZIhPr8QAaSUTw/UyO5xspbk3A28g /cNGFPQMS7kaSplpNHhjLTWNY2kAi/lM1G6CPP1bg7XVRhDdbOVWBwOxF9BYugvJknYX bIE6jO8cM48Nq6qKYSTHQwmmgrTz39N3XBYZJ7wxEn2LeWyZdO5fND1/BkzpVWdxHeHd wCwQ== X-Forwarded-Encrypted: i=1; AJvYcCV+lJKU/kCdffUYn6sXc1yCvV9XFmoIY8O3THEedQ+30aJcQVHDymTboXIWbIGPOJYDjfuHK9wjgA==@kvack.org X-Gm-Message-State: AOJu0YzXrUnsd3Lwl9iAsu1igszOuHMLM3RxCTJF3gqGktqHF9BTBRuM Xy/M1J+C3DJ8dY6mQ1RQ8H5xMVS+TtzCIDwP3axf6qEfgR9/ZHUwOjdzV9lU2fx9ioFX/ZWytIm EQ0Uung== X-Google-Smtp-Source: AGHT+IGP+DfdXdLpP6/QarYMevGBa3Y0zZIyyxRVm7jNq4fA+66yl/00aXVcKUbDun5QpuD+I3S+pPim8k0= X-Received: from pfdc11.prod.google.com ([2002:aa7:8c0b:0:b0:746:257b:1d37]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:339f:b0:215:fb74:2dc2 with SMTP id adf61e73a8af0-21d22ba385amr7389771637.11.1749078723086; Wed, 04 Jun 2025 16:12:03 -0700 (PDT) Date: Wed, 4 Jun 2025 16:11:46 -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-3-surenb@google.com> Subject: [PATCH v4 2/7] selftests/proc: extend /proc/pid/maps tearing test to include vma resizing 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: rspam08 X-Rspamd-Queue-Id: 3FCA3160011 X-Stat-Signature: qjy6mw743hitr4rhxhbsdqjjthqh1xas X-Rspam-User: X-HE-Tag: 1749078724-999218 X-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vOtXGCdjHMw4tD4co8goU6dQXQZwF4rzwXcQrR2bm5PT62Wos+S7cQyQqwifKLGB+zNuD3YKsSXjmGgP1xNUbOvR1fYlKHJBcXpht53ZXGEcKZA0sjBeyLGiu3hil/M6kkFJmjwdEO8aUUJezYefcUgK9W+NTkyg21cFae1mDwZZ6 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 a vma at the edge of the page is being concurrently remapped. This remapping results in the vma shrinking and expanding from under the reader. We should always see either shrunk or expanded (original) version of the vma. Signed-off-by: Suren Baghdasaryan --- tools/testing/selftests/proc/proc-pid-vm.c | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tools/testing/selftests/proc/proc-pid-vm.c b/tools/testing/selftests/proc/proc-pid-vm.c index 6e3f06376a1f..39842e4ec45f 100644 --- a/tools/testing/selftests/proc/proc-pid-vm.c +++ b/tools/testing/selftests/proc/proc-pid-vm.c @@ -583,6 +583,86 @@ static void test_maps_tearing_from_split(int maps_fd, signal_state(mod_info, TEST_DONE); } +static inline void shrink_vma(const struct vma_modifier_info *mod_info) +{ + assert(mremap(mod_info->addr, page_size * 3, page_size, 0) != MAP_FAILED); +} + +static inline void expand_vma(const struct vma_modifier_info *mod_info) +{ + assert(mremap(mod_info->addr, page_size, page_size * 3, 0) != MAP_FAILED); +} + +static inline void check_shrink_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 only the last vma of the first page is 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_resize(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 shrunk_last_line; + struct line_content shrunk_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 = shrink_vma; + mod_info->vma_restore = expand_vma; + mod_info->vma_mod_check = check_shrink_result; + + capture_mod_pattern(maps_fd, mod_info, page1, page2, last_line, first_line, + &shrunk_last_line, &shrunk_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 shrinking it */ + if (!strcmp(new_last_line.text, shrunk_last_line.text)) { + /* + * The vmas should be consistent with shrunk results, + * however if the vma was concurrently restored, it + * can be reported twice (first as shrunk 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, shrunk_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; @@ -674,6 +754,9 @@ static int test_maps_tearing(void) test_maps_tearing_from_split(maps_fd, mod_info, &page1, &page2, &last_line, &first_line); + test_maps_tearing_from_resize(maps_fd, mod_info, &page1, &page2, + &last_line, &first_line); + stop_vma_modifier(mod_info); free(page2.data); -- 2.49.0.1266.g31b7d2e469-goog