From patchwork Wed Aug 7 20:37:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Falcato X-Patchwork-Id: 817829 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 733792A1D1; Wed, 7 Aug 2024 20:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723063058; cv=none; b=tDj0tXxgeBeGb0u6rxENGlts0vYVmiOjUgh4AA/8STEOtT0zLoag+4izxZG+blawAgL714EVIBLIYT0gCf8CSE6yjJjCL+Z8GWFM8LCZQJ2JD/SStYeyYCsDNiK7+IPFd0abieUujCrUL1lbWjBBUIziRLscnvrK9YYhCujZH2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723063058; c=relaxed/simple; bh=XppvwH6P+YroeBc9mNU+12vhKV+A3Jx4a4pnvsbgqfs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j2d9TTo/rAbwWuzBb8DXgWJWQZDsRmVn2TBec0bG7tUH/EcMB3whSFqFk5MFPRzch9djrxasEHwjnCif3E6FombfvrOF1aJhCqKv88BMLnEn2SxdcxSRDDg7zxpIJkDaEYcVcW6YuSa68ZrISTvLLptyf3Iti9KQv+3KrHV8tVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KjeZ3v7i; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KjeZ3v7i" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-368380828d6so126507f8f.1; Wed, 07 Aug 2024 13:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723063055; x=1723667855; darn=vger.kernel.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=2MmaFumpYxx53X7+tTMs8NnH+I8o6dRYOWw21OJtXhs=; b=KjeZ3v7i+QZaYAk6R8XcuKJ6Bm6EJAPNPanFI5mSaN/7uIkf/vM7pMv0hvOj9IMaTg kghRJIcJl7d+5Ps0kLxOGNw74byei+sk1qb1JCjpRFBOAL9ggZqaqkysKi0NypG/XmJg uytHBgiqbQIq1lUQeTLqARUJdYLZ9XgdSHj55nplqQ0PW1jyZ7mx//BYEtaiwA3fbf1q dM02WQgbGLOoNN0ZUOUQwWlmxcE/EI5/nijtltezlk40vW4FOX8Xkt4MNtWGqefkzZh2 ySKLoJ+V1qe1rR63mE1e0b1GADz255mmF4DiP7Tmc0fcdaYu7UAFAQYbBuhPMaRlbHv6 PXiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723063055; x=1723667855; 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=2MmaFumpYxx53X7+tTMs8NnH+I8o6dRYOWw21OJtXhs=; b=pgGFh6Y11PD5/F4Ll9phcNe+I+HE8677jvoUivh/XAr0fyMuwSgUP4oAtZBZ/I50ia ZRjg752nuRnky0wY+HvE9V9AiS2g74i9p7TArUfO6XOjC2CavTO3xobNA6rdf2GNBWx9 ZcxTj2TpAKkpKnP/i1MvX+DZCpFRD/5RqZPAN1OI2Jdfl2nhEsBRNUP16xW7S2HqnwvX mhqtO+5Dec852PSQYr0rLeLfejQvlbL7u+ZixE2FH7gOlKE+aEGDEawX/rX0OEYebSPG 4hjzDM6WOPeQANcDp2L7y0zasxPt8UuZ0m5Ynlw2ir8+lmIOWt2szTek6EUSZEMrFp2p lP1Q== X-Forwarded-Encrypted: i=1; AJvYcCX+oDUVCBGoE+tQIw5jQDIMoQh9LmcFfjYSQh+IqWVjCj4RYEL09GjQ4rMQN8asZvjSk0hwpHe/QXCqGmLREYZNmbSKRwib10iTg35G18k5Th63waU2jJ7Rdu3/GVx0JNWgtXrjQmqpvqfhwnjb X-Gm-Message-State: AOJu0Yw+TA12Dn0vZnJ9sZVEqaQlpSnr/MaIAviZjaQPE/0RkPwa+CEe c00sJ8rBTRxNkbqP+mcf9Jd8BflRhhtn1EWv4MF13Br7gfUWx8yz X-Google-Smtp-Source: AGHT+IE61kFXwqm9Rh8xnuvCuNL8UJuGX36F/y+p9CbI7arO4EcDSFiG1ZFM90I06yh52+467O3GJg== X-Received: by 2002:a5d:4e90:0:b0:367:434f:ca9a with SMTP id ffacd0b85a97d-36bbbffe12emr13325706f8f.0.1723063054378; Wed, 07 Aug 2024 13:37:34 -0700 (PDT) Received: from PC-PEDRO-ARCH.lan ([2001:818:e92f:6400:96b:aa92:afc0:2d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4290598e236sm44492585e9.22.2024.08.07.13.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 13:37:34 -0700 (PDT) From: Pedro Falcato To: pedro.falcato@gmail.com, akpm@linux-foundation.org Cc: Liam.Howlett@oracle.com, jeffxu@chromium.org, kees@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, shuah@kernel.org Subject: [PATCH] fixup! selftests/mm: Add mseal test for no-discard madvise Date: Wed, 7 Aug 2024 21:37:24 +0100 Message-ID: <20240807203724.2686144-1-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240807173336.2523757-3-pedro.falcato@gmail.com> References: <20240807173336.2523757-3-pedro.falcato@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adjust the mseal test's plan. Signed-off-by: Pedro Falcato --- Andrew, please squash this small fix into "selftests/mm: Add mseal test for no-discard madvise". Thank you! tools/testing/selftests/mm/mseal_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index 2dcda7440eb..7eec3f0152e 100644 --- a/tools/testing/selftests/mm/mseal_test.c +++ b/tools/testing/selftests/mm/mseal_test.c @@ -1775,7 +1775,7 @@ int main(int argc, char **argv) if (!pkey_supported()) ksft_print_msg("PKEY not supported\n"); - ksft_set_plan(80); + ksft_set_plan(82); test_seal_addseal(); test_seal_unmapped_start(); From patchwork Wed Aug 7 17:33:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Falcato X-Patchwork-Id: 817841 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 423D313D53F; Wed, 7 Aug 2024 17:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723052081; cv=none; b=i+AQLDto8+9ivkoPm231At5SMuwWR4AeWgIxDKOJop8nOxRoIr4IslCF75nyGe3xd8LKzCrIBcyvf840ItI4cYD9irwGgH29x3gNuwDVGLEz7RhCQ0iOJ5LaXeMdoaI/oRzThZdfNsx8bu09p/AKOF0NMPlR43bFCmP3E+oTj5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723052081; c=relaxed/simple; bh=PrxRm/D+gH6hP8WNQ6u//nRouzN6ryRD5SwlsPZ1JAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mPWnFRGyB8jCSQXYW6W56IqIqQbsHgDp7n6fTW+37FG2yGIh4CG046rrXQ56bgvEHFy+hMDgcI5BG4Ooim6A7VBBtNrzGBKkQmIrKxJAAoH8SNITzvxBJQtzEqefMSMmfCIEBT5WcBsW3mV1VY3MjfyEwZtlYV+QcClNpeKDJdw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T940ysed; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T940ysed" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2f035ae1083so510961fa.3; Wed, 07 Aug 2024 10:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723052078; x=1723656878; darn=vger.kernel.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=fkbLPlxft252tCcvtQQOAioY0nhUSIetGhYQZRnuOjM=; b=T940ysedopRuEfFbaTROs+Haub9qKO0ElkICqA3wvrmKZYeRMrmt24OMRATCtZB3V1 vxBbAqgSGusaGBixFy8DdrLeglQpa4lJwCIX/RHTRwB5xcLdVMNHGRLaEGKVtdJocngh yR8w5x1PCy2HQV8A/xSLq1oQqk55Bmp716vzatWCT6shAnBkqNAA+MuXQK5vY9fX3wsW tAXvUftn+L2raRcEGAaJ3Xq5hvn8OLEHMU9k+AqYRljPc3a1SP/tH06LhSnfVLf/MHVE 4QgGDKFOzp+V5IP5Dpa/WeZ6HOSmiiyb5A/IjGlWXj9IcuueZlEfJ+STsc0ei48o3FbE jKKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723052078; x=1723656878; 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=fkbLPlxft252tCcvtQQOAioY0nhUSIetGhYQZRnuOjM=; b=l0GMnW1k0FhgD7vTmWbvVSSUuJeXLdObybJDix+g7nwHoxTtHAOab2gG7Iij/TIPP9 GYY1ls2BsQhHb6DUdo1JXYnp6LG4i6gcp+qk5JMjWuytoHag1prmnRBM3j16lfSSGuXf r0U61PCqru+WR2SiHQAL0G6qTjeBb8qfQMzPonpxn1hjYq1vWULJ4suN39IQG+8LhUSe vGwQCCRn/SsrLTFjquhj9j0IxEuftjiGEZHKtqgJV0oV+qrWzgtY8alc6KLUyutwyUsO z5Q+ZDq21/mSsTTTzk/FeAi3muJE8lXI/9fVO3hOwYUDWNhUxut+Rjc/VDTroqyGQBp/ usHA== X-Forwarded-Encrypted: i=1; AJvYcCU+emgO82Sd1XAZl+HPxl4ySFa56vInSwcCDFzdYYZh+in6QRWrab4KEGudiFiezP6IN67aKcFtATkGmjCuv7D2azdU9+JMsSDyQOMuaWJ3 X-Gm-Message-State: AOJu0YwmWtLDCPSmJFPhNDr1aZ6vQl8MUvXRBfLqgnQ4KlRf4N1XBIys A9hx6rZeKgla3KAEEdr69rIlCqzHvragiDaw6SICA+t0asWw8ZlA X-Google-Smtp-Source: AGHT+IHIIJqMOzpEvAkMj1C5BnPy4mssOYul/wmg3Y4s/jeLUk3lFc/ZevqzIKcixd25dALAJ8jRxg== X-Received: by 2002:a05:651c:a0a:b0:2f1:5c89:c875 with SMTP id 38308e7fff4ca-2f15c89ca6amr155201391fa.26.1723052077831; Wed, 07 Aug 2024 10:34:37 -0700 (PDT) Received: from PC-PEDRO-ARCH.lan ([2001:818:e92f:6400:96b:aa92:afc0:2d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42905801f5bsm40335185e9.29.2024.08.07.10.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 10:34:37 -0700 (PDT) From: Pedro Falcato To: Andrew Morton , Shuah Khan , "Liam R. Howlett" , Jeff Xu , Kees Cook , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Pedro Falcato Subject: [PATCH 2/2] selftests/mm: Add mseal test for no-discard madvise Date: Wed, 7 Aug 2024 18:33:36 +0100 Message-ID: <20240807173336.2523757-3-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240807173336.2523757-1-pedro.falcato@gmail.com> References: <20240807173336.2523757-1-pedro.falcato@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add an mseal test for madvise() operations that aren't considered "discard" (e.g purely advisory ops such as MADV_RANDOM). Signed-off-by: Pedro Falcato --- tools/testing/selftests/mm/mseal_test.c | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index a818f010de4..2dcda7440eb 100644 --- a/tools/testing/selftests/mm/mseal_test.c +++ b/tools/testing/selftests/mm/mseal_test.c @@ -1731,6 +1731,38 @@ static void test_seal_discard_ro_anon(bool seal) REPORT_TEST_PASS(); } +static void test_seal_madvise_nodiscard(bool seal) +{ + void *ptr; + unsigned long page_size = getpagesize(); + unsigned long size = 4 * page_size; + int ret; + + setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + + if (seal) { + ret = seal_single_address(ptr, size); + FAIL_TEST_IF_FALSE(!ret); + } + + /* + * Test a random madvise flag like MADV_RANDOM that does not touch page + * contents (and thus should work for msealed VMAs). RANDOM also happens to + * share bits with other discard-ish flags like REMOVE. + */ + ret = sys_madvise(ptr, size, MADV_RANDOM); + FAIL_TEST_IF_FALSE(!ret); + + ret = sys_munmap(ptr, size); + if (seal) + FAIL_TEST_IF_FALSE(ret < 0); + else + FAIL_TEST_IF_FALSE(!ret); + + REPORT_TEST_PASS(); +} + int main(int argc, char **argv) { bool test_seal = seal_support(); @@ -1822,6 +1854,8 @@ int main(int argc, char **argv) test_seal_mremap_move_fixed_zero(true); test_seal_mremap_move_dontunmap_anyaddr(false); test_seal_mremap_move_dontunmap_anyaddr(true); + test_seal_madvise_nodiscard(false); + test_seal_madvise_nodiscard(true); test_seal_discard_ro_anon(false); test_seal_discard_ro_anon(true); test_seal_discard_ro_anon_on_rw(false);