From patchwork Fri Aug 30 18:02:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13785415 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 B66BBCA0EFD for ; Fri, 30 Aug 2024 18:02:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 012A46B01F7; Fri, 30 Aug 2024 14:02:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EDD756B01F9; Fri, 30 Aug 2024 14:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D56736B01F8; Fri, 30 Aug 2024 14:02:48 -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 9F94B6B01F6 for ; Fri, 30 Aug 2024 14:02:48 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3A8541A02E4 for ; Fri, 30 Aug 2024 18:02:48 +0000 (UTC) X-FDA: 82509682416.18.DCCCC32 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf20.hostedemail.com (Postfix) with ESMTP id 4D9E41C0022 for ; Fri, 30 Aug 2024 18:02:46 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="NhJO/LsI"; spf=pass (imf20.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.216.44 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725040921; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iKGNPxNsYKipWJTu2FnzfGVLgyBodzOHMPjLCFGxD/E=; b=D8hv8uuvDleQ7ZwCuawIDFad7tIU0TXTgJ1mXGEYDRaqBqdlsPqTA5w9afxrT3TVtM0Ixf KX7HLsdj2TcDS+0XHdEe+SyghsRqn+rVmuOTI84/7BsdN/CH+v5MDR/bq0/2xg++hsSjzD xtvb7T9nH4/oxTA1aXsXXlrlAEwQPU4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="NhJO/LsI"; spf=pass (imf20.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.216.44 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725040921; a=rsa-sha256; cv=none; b=qi1wkUZ6AxejJWeoWro4ECncr4nk2otV9/f9O4/V4z4XGqvJ7B5S+GILubB0XPiuEIatU9 RLgN9ZJ3l5UNFJPrHsdV9unQt80T17bOqu5amQ3WnoWmLMSGbcvf3SNCJ3wNcQOIAz7sq6 mldKmBY14Z/cpK3FvARbXOWEQctVCqo= Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2d88ec20283so18664a91.0 for ; Fri, 30 Aug 2024 11:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725040965; x=1725645765; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iKGNPxNsYKipWJTu2FnzfGVLgyBodzOHMPjLCFGxD/E=; b=NhJO/LsIw/A8j8jhLuS1Rcdr95ptds/mFiHLUa8HNFYIsCWC2Gsy3YWIsyEnoEyXY0 W06ka7sitsaaEhmweiPeOxc+UlM/9u4AiftPAfCaAoVr9p9FWqJvn6LRvaxnpT0ZtgHt sup1Rx51wcVFBVsctsvHS+9VYgh+2DwF4ranQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725040965; x=1725645765; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iKGNPxNsYKipWJTu2FnzfGVLgyBodzOHMPjLCFGxD/E=; b=eV+E//PXmGsZ1XBaPcDsi/6QlcBEtMFOjXzkI30OcOPmFjyVd7vGmX6trMi5qutR4I XSEh5KSFy8lBCjl1/vPN1dhFiI5JQMNCsbj0p46+su5R377vnZk98PhRkV4Kkz5eDCy1 Xk5D6W5zvTAkFDInSsOGmqr27NFdzF5si76eo5ZDfZPZbNv9MtGRqd0vnVewN3f8at3/ U2SFBArqMnd/GVP9GamxjJEkUNf2LPqteCi8bpHmC+H464k2bC1Bktgem+Br7xWrDGll E9EneZsgbBEEeDDy+ZpTtqPT1k7cpo03sHFh8WyevAlUTAgT9PHNLCVjwwCqHo1AYJNF icBQ== X-Forwarded-Encrypted: i=1; AJvYcCVdYZq0fJlQN8Gg99/MZJsnmdKyz8IoCK0UYdpozFmRVXQ3clRqk3PN6Eoe+VZrrjoHslLQV1NqWw==@kvack.org X-Gm-Message-State: AOJu0Yz5k09jqpkpAR0p3q3fQ/SzJSZsxETSuqwleiEkeVg1BKM3S9jo BsPPrCxaKC9Switeo/bQhh58EAL8Tb0Uq7fVHqgUdKxJqNUOxFjsom6Q1zEMmg== X-Google-Smtp-Source: AGHT+IEihnCD63EfKi0DOVXqIMhOWH4VJANKaavsJJCvNs5Q8uboJudceTAmj4oEGAUcSNs9tNCDsA== X-Received: by 2002:a17:90a:d904:b0:2d3:da94:171 with SMTP id 98e67ed59e1d1-2d86b8c3a42mr1724919a91.5.1725040964619; Fri, 30 Aug 2024 11:02:44 -0700 (PDT) Received: from localhost (150.12.83.34.bc.googleusercontent.com. [34.83.12.150]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2d8445d5bb0sm6770604a91.1.2024.08.30.11.02.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Aug 2024 11:02:44 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org Cc: linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, pedro.falcato@gmail.com, willy@infradead.org, lorenzo.stoakes@oracle.com, broonie@kernel.org, vbabka@suse.cz, Liam.Howlett@oracle.com, rientjes@google.com, keescook@chromium.org, Jeff Xu Subject: [PATCH v3 3/5] selftests/mseal: munmap across multiple vma ranges. Date: Fri, 30 Aug 2024 18:02:35 +0000 Message-ID: <20240830180237.1220027-4-jeffxu@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240830180237.1220027-1-jeffxu@chromium.org> References: <20240830180237.1220027-1-jeffxu@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 4D9E41C0022 X-Stat-Signature: h8yfrkatixbrm7mf4i15eqd3gzbeqqsz X-HE-Tag: 1725040966-777953 X-HE-Meta: U2FsdGVkX19IgoOLMij0BBN2MKfCeSOosD4rwakDGjAQy+xE0+dcyg9e0IYFK694ss7w/3aRaU9xK5B+vnm0hUNbaklVxyIcJmVlJy2R1HkYnB3L6N34bLi77+3bXrlIOebabj/O2rsFf0N2Q5Ca5cYzEcNiIPJr7p7cLoyooPr8UGHpvfHgaguyTKJ8rno+YOVtKJ0hKgIcLqNbbwk3lSlvC0qDBQWdD0FBP4IzL+1YqkT6jE8ZADATzlaCkOVkogJ28ChpjSE/hLJSKh6GH/nIUkHKya+S1SB9V9FX6lzu6FDXYee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1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Jeff Xu Add a test to munmap across multiple vma ranges. Signed-off-by: Jeff Xu --- tools/testing/selftests/mm/mseal_test.c | 80 ++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index 6d77dc9b5442..e855c8ccefc3 100644 --- a/tools/testing/selftests/mm/mseal_test.c +++ b/tools/testing/selftests/mm/mseal_test.c @@ -2147,6 +2147,81 @@ static void test_seal_discard_madvise_advice(void) REPORT_TEST_PASS(); } +static void test_munmap_free_multiple_ranges(bool seal) +{ + void *ptr; + unsigned long page_size = getpagesize(); + unsigned long size = 8 * page_size; + int ret; + int prot; + + setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + + /* unmap one page from beginning. */ + ret = sys_munmap(ptr, page_size); + FAIL_TEST_IF_FALSE(!ret); + + /* unmap one page from middle. */ + ret = sys_munmap(ptr + 4 * page_size, page_size); + FAIL_TEST_IF_FALSE(!ret); + + size = get_vma_size(ptr + page_size, &prot); + FAIL_TEST_IF_FALSE(size == 3 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + + size = get_vma_size(ptr + 5 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 3 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + + + /* seal the last page */ + if (seal) { + ret = sys_mseal(ptr + 7 * page_size, page_size); + FAIL_TEST_IF_FALSE(!ret); + + size = get_vma_size(ptr + 1 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 3 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + + size = get_vma_size(ptr + 5 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 2 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + + size = get_vma_size(ptr + 7 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 1 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + } + + /* munmap all 8 pages from beginning */ + ret = sys_munmap(ptr, 8 * page_size); + if (seal) { + FAIL_TEST_IF_FALSE(ret); + + /* verify mapping are not changed */ + size = get_vma_size(ptr + 1 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 3 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + + size = get_vma_size(ptr + 5 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 2 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + + size = get_vma_size(ptr + 7 * page_size, &prot); + FAIL_TEST_IF_FALSE(size == 1 * page_size); + FAIL_TEST_IF_FALSE(prot == 4); + } else { + FAIL_TEST_IF_FALSE(!ret); + + for (int i = 0; i < 8; i++) { + size = get_vma_size(ptr, &prot); + FAIL_TEST_IF_FALSE(size == 0); + } + } + + REPORT_TEST_PASS(); +} + int main(int argc, char **argv) { bool test_seal = seal_support(); @@ -2168,7 +2243,7 @@ int main(int argc, char **argv) if (!get_vma_size_supported()) ksft_exit_skip("get_vma_size not supported\n"); - ksft_set_plan(89); + ksft_set_plan(91); test_seal_addseal(); test_seal_unmapped_start(); @@ -2279,5 +2354,8 @@ int main(int argc, char **argv) test_seal_discard_madvise_advice(); + test_munmap_free_multiple_ranges(false); + test_munmap_free_multiple_ranges(true); + ksft_finished(); }