From patchwork Tue Dec 10 21:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 13902097 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 BE3EBE7717F for ; Tue, 10 Dec 2024 21:31:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F9518D0016; Tue, 10 Dec 2024 16:31:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 981C18D000B; Tue, 10 Dec 2024 16:31:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 786D18D0016; Tue, 10 Dec 2024 16:31:06 -0500 (EST) 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 5516A8D000B for ; Tue, 10 Dec 2024 16:31:06 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0F61140B45 for ; Tue, 10 Dec 2024 21:31:05 +0000 (UTC) X-FDA: 82880344260.12.EE54E31 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf08.hostedemail.com (Postfix) with ESMTP id 4FB9F160006 for ; Tue, 10 Dec 2024 21:30:49 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=O3ZaiP7A; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3F7NYZwcKCCI9ECDDMLEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--bgeffon.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=3F7NYZwcKCCI9ECDDMLEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--bgeffon.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733866254; 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=AHT5xvY7w9zpRg3haw0I55yKDkK8+F/SSOT5JL37NS3LUQZ8MIoc0aE1xYjhZHWhWyyoXR DDSQCVnRCSZP3P5HlUv/gqfs11HidNBWDB6kLPGdjgRjLda8ci4lhk1ZhV4aAzWMEpNDCX tsPrdhMrnf8sN/4G+eX9L0bJwY635zA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733866254; a=rsa-sha256; cv=none; b=hCn+gdEJL1q3iVL4gIgfNAd9ymPtoOmnnYOuprta2hBMUWFObrdzq5FRJ67ztmutFoFzo4 NeTB7PBbP2fCwta7PfPDPXDlDU59oGV2Jg9KgB12bj3RtHhHYLfVHT7j9i+Q2n+fjwMleP armrtrlVvQPasXmWd28NZa0kbH5LZFc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=O3ZaiP7A; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3F7NYZwcKCCI9ECDDMLEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--bgeffon.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=3F7NYZwcKCCI9ECDDMLEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--bgeffon.bounces.google.com Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-4677666bb00so30268331cf.0 for ; Tue, 10 Dec 2024 13:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733866263; x=1734471063; 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=O3ZaiP7AmxooQTf1d3jmy3QWK+xFonbofUuIb1JHDF6FxTL24tP0MxuOevro4tu3+/ JUmJwX9kzTTjT1SVv/jioo0sMGpi9AUirCWopDTtQf61jBk/jfTU6h1rWIAK0D0zX5ww /6YPvcaj/cup5xoezx1ov4VOWA72Jf3D+eMNh9cl5ZY8YrjvWNXYjwYusQ+2mKgM4UIV oUUho8UynajPsx1wJRWBR0binAPfh+Ap+hMZLH5fopp2llSUVGMHziaEyhO5j1QK9f8x YwHRCRfZIUp/xHfQnFF9m0Tce8s0H1J+GOYRWjsH0ek8VktgYpwgukliLTaOzKHfCp+8 4P2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733866263; x=1734471063; 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=bFxJqGv+I6H384S57mD9bmvUafHkKftiglm6uFBBZ13C+z33HC6GnJ1eX8ccuaj55A QyeI4rvKPWqZ9QRKmjyncIyCX/7XKZQ/U7ngOx5KLXVrEsRxM2+TUq2AQ8QdR87EDa30 +1Oci2+GuxcyboE6vAcrXdUnFJLKL/TO3oLb/YzpzA0pVbhikrmpJsUHf12bgIHX3POr Lz5lHH7J3Gl8GYSyN8Jk6tlZn3V/VdKRrSgus/IFiFIlC84FMlU3ONuVmP/iRJdoESbO fJL8Pf5BDlgLmwM7ZXAsiL6uWL07NHKBpIoOPSB7Y+q8+tFVSFF74jR4gw77EsC9gkjk VuRw== X-Forwarded-Encrypted: i=1; AJvYcCVvSpqrKvIaWJ7b9/5tf9PcqPQ+IPZQjVq5fGaLvQfYv7FFHkS4n5gtec5n+S5MSp0lAYCjwAN5TA==@kvack.org X-Gm-Message-State: AOJu0YzIQwtlmFArylxR/pBe48TLaZgxtLqs3Z0IajSg0b3r9NEgnNwF 5inzzXst+zdaABdv3Q390dVtw3y3os/di7vgmVrA6ypZGUwfxJEJ9Z52zU7UzG9kTbcGdjAVoPI nD3nH1g== X-Google-Smtp-Source: AGHT+IHZ1924mCsfRh+0nxIV+XSxlFuKLxmvXW19hSqpR+438olx78Wtep6vn7HuCeERSohDHX/QpTjD62ds X-Received: from qtbcc14.prod.google.com ([2002:a05:622a:410e:b0:467:518e:d31b]) (user=bgeffon job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:58cd:0:b0:466:a3bf:41a7 with SMTP id d75a77b69052e-467893c594amr7220151cf.51.1733866263282; Tue, 10 Dec 2024 13:31:03 -0800 (PST) Date: Tue, 10 Dec 2024 16:30:49 -0500 In-Reply-To: <20241210213050.2839638-1-bgeffon@google.com> Mime-Version: 1.0 References: <20241210213050.2839638-1-bgeffon@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241210213050.2839638-5-bgeffon@google.com> Subject: [RFC PATCH 4/5] selftests: mm: Add a new MREMAP_DONTUNMAP self test From: Brian Geffon To: Andrew Morton Cc: Lorenzo Stoakes , Jann Horn , Vlastimil Babka , "Liam R. Howlett" , linux-mm@kvack.org, Marco Vanotti , linux-kernel@vger.kernel.org, Brian Geffon X-Stat-Signature: b69u4md86z76kcenkooeah43oyaky4hp X-Rspamd-Queue-Id: 4FB9F160006 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733866249-813911 X-HE-Meta: U2FsdGVkX1+3V+p/quPtv+kFKSpDI7DGZZkBaOgQtHENE1tyX7bjAkvT96CMTqEkZmduxQslVfmayXw/OpS4GIEhVfjX6/I4CQTj/Abx9MvFBT6GJLsUTAddnOzc7f3rXKHaPOmjPqXqOOnZ0HMkDuH1hwHz4hNW6D16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VbEe9mdoN49OWX1T/bSg8qMTNrngZoqufT/hazK7QqwCpULdtaWS2KExoJZQigI/OYwBdB6J916foofWuzvxHKrKQBQ7Mr8Fb0/UiPpumpM16gsU8L5nKJ/ml7KgoMkOR/LqqFRX4O3lXS51YeijWD2VzMgf1bQzXujpt8j063QxcNlF5ojncGSlvm/Pltxmo8qkRbSiRnT8okZeFfI1gkpD3pFrSUyuwadCi1T72HbuWP2CGOs5UdOuLYloxscqgfbrdPKTZXs8aBjYFWsC9u+VFfmI+tmK2zoXEMo98JMkiefu6Afezv9tlYbiVC6k4EslxgMyGeklRBRIPVSb6b7kFY9asQGkFd9oj7cP X-Bogosity: Ham, tests=bogofilter, spamicity=0.216112, 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();