From patchwork Fri Dec 6 15:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 13897281 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 C825CE7717B for ; Fri, 6 Dec 2024 15:20:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CD8A6B0274; Fri, 6 Dec 2024 10:20:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 191066B026C; Fri, 6 Dec 2024 10:20:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEC8A6B0274; Fri, 6 Dec 2024 10:20:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AAD7E6B026C for ; Fri, 6 Dec 2024 10:20:43 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 59D7316172F for ; Fri, 6 Dec 2024 15:20:43 +0000 (UTC) X-FDA: 82864896156.28.A88F964 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf28.hostedemail.com (Postfix) with ESMTP id 6003FC001E for ; Fri, 6 Dec 2024 15:20:21 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eDGm9GBt; spf=pass (imf28.hostedemail.com: domain of 3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com designates 209.85.160.202 as permitted sender) smtp.mailfrom=3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.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=1733498423; 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=8zF6cyo4V+yV1OddWsDU7llWFhEXM57i4QvxWba9u5g=; b=cZDMaMwxB3bARDjFu5U5KDFL1DTttUyuTjcc3HVwBgIcwIJ+JrVZuqrPtV3T80bgxN60xd ukB07dRFEWMlY+1gvsQ8dfx9aIWPYhFSFMeoougX43zoXtAG2A835kPLaqfCphH4gRQrgK JGRbo0Vxhmq0NF5DE7xifyGKtiu1/zc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eDGm9GBt; spf=pass (imf28.hostedemail.com: domain of 3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com designates 209.85.160.202 as permitted sender) smtp.mailfrom=3SBZTZwcKCAMejhiirqjrrjoh.frpolqx0-ppnydfn.ruj@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733498423; a=rsa-sha256; cv=none; b=Z5K3J6XDu1uWwL43Yt4hfEwv2YgDHY3C1LnfVZTArB7m68nTNY/cK9FiJc+sbxkG9Yfr1C wa6nA4LCuJ9fo8JsudrzE99GGqDD1sKT1NTUZzwLqegqZ8hiHy1R6/nGIrakFAP1nQu4xS obiX0xUwm5OG1hOBizIkOXseydWuNFE= Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-4669bf7cef7so44183511cf.1 for ; Fri, 06 Dec 2024 07:20:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733498440; x=1734103240; 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=8zF6cyo4V+yV1OddWsDU7llWFhEXM57i4QvxWba9u5g=; b=eDGm9GBtPi0zuNA0u0CyZUB/U/MgOsjVMgF/s2am7NhfcgmVFZb4kMOz1kU7hM5dDi IqxrYuLwF1WyqVxaTkK7MqXLaEGJuZq1cgDu7K57sxwaPeylVuGbX7DfxDt81I90uSOw fF6ZjxsiGzi1gq5Nyei/Oi06BGj5TF9TeGrQb4ErPRDK9GtK6HzP4vc0uTq0S257IYho Zyj/+VRUmhrFC1R+gMDjvaWJEKyBxbAUbUBSBMqABcCQFJvJOz4R2Qqfe4sM9Bdk57R1 I428Dj84YaRvecOGeO7APINYfiI5Qvd21Er15XI4X1PojsXDLKquj/f6IYREfDpI7VTq FtQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733498440; x=1734103240; 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=8zF6cyo4V+yV1OddWsDU7llWFhEXM57i4QvxWba9u5g=; b=a29fYqo38tSyQBdvqcmyjiMowcsZD4tuH4xrvEfL3bIjB4eGj4oxC9Gt6EA42CZC1A CwEDXwZ8BSTy8xH8HIe9kg1D0VZi7+/++0mSgx7zzOP3kNeWHumt0WzBynDiGN7eHf2R oeZUqNmG1bnjOOyBUUaZ58HZUfcaMVqyydVsny/oqiNRwP1gT9rHtoairC5Z18KxQbcZ XFNvK7DeDZstz7A2NuXVi6mY1zrg2w/kLpfpjM3FQjTr4pDgoBtqBO5qQAepg4NKq3nE HjGkJjOkx9s6S5Feya9xxp34yitnamOj79bXwLhlAb2s+wCyetuB+EZRwVFb+v1ifBIM bNBw== X-Gm-Message-State: AOJu0YzrMbX2ocjChbAwmWG+oLybt8hKMs8FRRb3M1eCmXhJoYz/uTck VQ08zOb6cC/umbrmoL0apgt9C2ghOp9QD6PQpYP1SGHbtJphc6fIHWhMt228WPXxBP9xamWaAIo yaUwOEg== X-Google-Smtp-Source: AGHT+IGb3dyB+1mIM9uaJ8shaiN2smOAw7d48MDhvLaY9VwvHL+JlNyqB1itmzCSQbeXEMb+r4xoquxqxwdB X-Received: from qtcw37.prod.google.com ([2002:a05:622a:1925:b0:462:ac63:5263]) (user=bgeffon job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:57cb:0:b0:467:1f3c:4d22 with SMTP id d75a77b69052e-46734e26188mr80292871cf.52.1733498440618; Fri, 06 Dec 2024 07:20:40 -0800 (PST) Date: Fri, 6 Dec 2024 10:20:32 -0500 In-Reply-To: <20241206152032.1222067-1-bgeffon@google.com> Mime-Version: 1.0 References: <20241206152032.1222067-1-bgeffon@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241206152032.1222067-3-bgeffon@google.com> Subject: [PATCH 2/2] selftests: mm: Add a new MREMAP_DONTUNMAP self test From: Brian Geffon To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Brian Geffon X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6003FC001E X-Rspam-User: X-Stat-Signature: fwdzede1o8kojacwj64oiiwbwhcsmgmi X-HE-Tag: 1733498421-957763 X-HE-Meta: U2FsdGVkX1+PqdHeTepmduEusvW12XxxikakKwDQRk02zbT5VPj3v0YQdJHBZa/57UHyTpsazCnhZTRkHjUFUnd3scvgJYOX7biQ6/W5kH59c8NR7LHjCbTFxwX2hSLmNsnvO6jtB539lXaVeRQKz7HKNcRWCRM6wjPZb4yIWfYx0/N/pgDL8q8av854icF7Ufw5cKLM6E17ezsSHzlzCdT41DyEynOlNMYRFsnRlA8d2opbChepDeYNGaUDGwRubg2+V41vV/KiOAiLZ0SMM5qNnFPtmoN3u/QaQ/zSksucm++n3B9gg8WnqWXxocBc7S+qH70iLPmZUGn88lNStP7z4RkOc4BBZkO7mMivau+bNjmz38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rJx8ai+rMLbdg5FAR1SDP2hdE2A8FrpjnbRc/4Hpb2BTbZVGquQC9P+3u7V3BZ0eQazFryDDtGQfSam1fz/lrv0/YROGWGFUnPKJ7tRBXAPvr0nTa/C55DC/I8HGWk/N/5eEtYJolel6navT78INu9jpSGV+fgNMh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000790, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a new selftest which validates that a new_addr as a hint behaves in the same way as mmap. Signed-off-by: Brian Geffon --- tools/testing/selftests/mm/mremap_dontunmap.c | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_dontunmap.c b/tools/testing/selftests/mm/mremap_dontunmap.c index 1d75084b9ca5..ccce97c68019 100644 --- a/tools/testing/selftests/mm/mremap_dontunmap.c +++ b/tools/testing/selftests/mm/mremap_dontunmap.c @@ -224,6 +224,44 @@ static void mremap_dontunmap_simple_fixed() ksft_test_result_pass("%s\n", __func__); } +// This test validates MREMAP_DONTUNMAP using a newaddr hint without +// MREMAP_FIXED. +static void mremap_dontunmap_simple_newaddr_hint() +{ + unsigned long num_pages = 5; + + // This dest hint is intentionally not aligned. + void *new_addr_hint = (void*)0x999900010; + + void *source_mapping = + mmap(NULL, num_pages * page_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + BUG_ON(source_mapping == MAP_FAILED, "mmap"); + memset(source_mapping, 'a', num_pages * page_size); + + void *remapped_mapping = + mremap(source_mapping, num_pages * page_size, num_pages * page_size, + MREMAP_DONTUNMAP | MREMAP_MAYMOVE, + new_addr_hint); + BUG_ON(remapped_mapping == MAP_FAILED, "mremap"); + + // And the source mapping will have had its ptes dropped. + BUG_ON(check_region_contains_byte + (source_mapping, num_pages * page_size, 0) != 0, + "source should have no ptes"); + + // And the remapped area will be filled with 'a's. + BUG_ON(check_region_contains_byte + (remapped_mapping, num_pages * page_size, 'a') != 0, + "dest should have remapped content"); + + BUG_ON(munmap(source_mapping, num_pages * page_size) == -1, + "unable to unmap source mapping"); + BUG_ON(munmap(remapped_mapping, num_pages * page_size) == -1, + "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); +} + // This test validates that we can MREMAP_DONTUNMAP for a portion of an // existing mapping. static void mremap_dontunmap_partial_mapping() @@ -348,7 +386,7 @@ int main(void) ksft_finished(); } - ksft_set_plan(5); + ksft_set_plan(6); // Keep a page sized buffer around for when we need it. page_buffer = @@ -359,6 +397,7 @@ int main(void) mremap_dontunmap_simple(); mremap_dontunmap_simple_shmem(); mremap_dontunmap_simple_fixed(); + mremap_dontunmap_simple_newaddr_hint(); mremap_dontunmap_partial_mapping(); mremap_dontunmap_partial_mapping_overwrite();