linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: secretmem: Floor the memory size to the multiple of page_size
@ 2023-12-14 10:19 Muhammad Usama Anjum
  2023-12-14 19:40 ` Andrew Morton
  2023-12-15 10:59 ` Mike Rapoport
  0 siblings, 2 replies; 5+ messages in thread
From: Muhammad Usama Anjum @ 2023-12-14 10:19 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan, Mike Rapoport, James Bottomley
  Cc: Muhammad Usama Anjum, kernel, kernelci.org bot, linux-mm,
	linux-kselftest, linux-kernel

The "locked-in-memory size" limit per process can be non-multiple of
page_size. The mmap() fails if we try to allocate locked-in-memory
with same size as the allowed limit if it isn't multiple of the
page_size because mmap() rounds off the memory size to be allocated
to next multiple of page_size.

Fix this by flooring the length to be allocated with mmap() to the
previous multiple of the page_size.

Fixes: 76fe17ef588a ("secretmem: test: add basic selftest for memfd_secret(2)")
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 tools/testing/selftests/mm/memfd_secret.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/mm/memfd_secret.c b/tools/testing/selftests/mm/memfd_secret.c
index 957b9e18c729..9b298f6a04b3 100644
--- a/tools/testing/selftests/mm/memfd_secret.c
+++ b/tools/testing/selftests/mm/memfd_secret.c
@@ -62,6 +62,9 @@ static void test_mlock_limit(int fd)
 	char *mem;
 
 	len = mlock_limit_cur;
+	if (len % page_size != 0)
+		len = (len/page_size) * page_size;
+
 	mem = mmap(NULL, len, prot, mode, fd, 0);
 	if (mem == MAP_FAILED) {
 		fail("unable to mmap secret memory\n");
-- 
2.42.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-15 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-14 10:19 [PATCH] selftests: secretmem: Floor the memory size to the multiple of page_size Muhammad Usama Anjum
2023-12-14 19:40 ` Andrew Morton
2023-12-15  7:56   ` Muhammad Usama Anjum
2023-12-15 10:59 ` Mike Rapoport
2023-12-15 13:26   ` Muhammad Usama Anjum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox