linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/testing/selftests: fix guard region test tmpfs assumption
@ 2025-04-25 16:24 Lorenzo Stoakes
  2025-04-28 10:23 ` Ryan Roberts
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Stoakes @ 2025-04-25 16:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Ryan Roberts, Liam R . Howlett, Vlastimil Babka,
	Suren Baghdasaryan, linux-mm, linux-kernel

The current implementation of the guard region tests assume that /tmp is
mounted as tmpfs, that is shmem.

This isn't always the case, and at least one instance of a spurious test
failure has been reported as a result.

This assumption is unsafe, rushed and silly - and easily remedied by simply
using memfd, so do so.

We also have to fixup the readonly_file test to explicitly only be
applicable to file-backed cases.

Reported-by: Ryan Roberts <ryan.roberts@arm.com>
Closes: https://lore.kernel.org/linux-mm/a2d2766b-0ab4-437b-951a-8595a7506fe9@arm.com/
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 tools/testing/selftests/mm/guard-regions.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
index c39dd26c47a3..0cd9d236649d 100644
--- a/tools/testing/selftests/mm/guard-regions.c
+++ b/tools/testing/selftests/mm/guard-regions.c
@@ -272,12 +272,16 @@ FIXTURE_SETUP(guard_regions)
 	self->page_size = (unsigned long)sysconf(_SC_PAGESIZE);
 	setup_sighandler();
 
-	if (variant->backing == ANON_BACKED)
+	switch (variant->backing) {
+	case ANON_BACKED:
 		return;
-
-	self->fd = open_file(
-		variant->backing == SHMEM_BACKED ? "/tmp/" : "",
-		self->path);
+	case LOCAL_FILE_BACKED:
+		self->fd = open_file("", self->path);
+		break;
+	case SHMEM_BACKED:
+		self->fd = memfd_create(self->path, 0);
+		break;
+	}
 
 	/* We truncate file to at least 100 pages, tests can modify as needed. */
 	ASSERT_EQ(ftruncate(self->fd, 100 * self->page_size), 0);
@@ -1697,7 +1701,7 @@ TEST_F(guard_regions, readonly_file)
 	char *ptr;
 	int i;
 
-	if (variant->backing == ANON_BACKED)
+	if (variant->backing != LOCAL_FILE_BACKED)
 		SKIP(return, "Read-only test specific to file-backed");
 
 	/* Map shared so we can populate with pattern, populate it, unmap. */
-- 
2.49.0



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

* Re: [PATCH] tools/testing/selftests: fix guard region test tmpfs assumption
  2025-04-25 16:24 [PATCH] tools/testing/selftests: fix guard region test tmpfs assumption Lorenzo Stoakes
@ 2025-04-28 10:23 ` Ryan Roberts
  0 siblings, 0 replies; 2+ messages in thread
From: Ryan Roberts @ 2025-04-28 10:23 UTC (permalink / raw)
  To: Lorenzo Stoakes, Andrew Morton
  Cc: Liam R . Howlett, Vlastimil Babka, Suren Baghdasaryan, linux-mm,
	linux-kernel

On 25/04/2025 17:24, Lorenzo Stoakes wrote:
> The current implementation of the guard region tests assume that /tmp is
> mounted as tmpfs, that is shmem.
> 
> This isn't always the case, and at least one instance of a spurious test
> failure has been reported as a result.
> 
> This assumption is unsafe, rushed and silly - and easily remedied by simply
> using memfd, so do so.
> 
> We also have to fixup the readonly_file test to explicitly only be
> applicable to file-backed cases.
> 
> Reported-by: Ryan Roberts <ryan.roberts@arm.com>
> Closes: https://lore.kernel.org/linux-mm/a2d2766b-0ab4-437b-951a-8595a7506fe9@arm.com/
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> ---
>  tools/testing/selftests/mm/guard-regions.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
> index c39dd26c47a3..0cd9d236649d 100644
> --- a/tools/testing/selftests/mm/guard-regions.c
> +++ b/tools/testing/selftests/mm/guard-regions.c
> @@ -272,12 +272,16 @@ FIXTURE_SETUP(guard_regions)
>  	self->page_size = (unsigned long)sysconf(_SC_PAGESIZE);
>  	setup_sighandler();
>  
> -	if (variant->backing == ANON_BACKED)
> +	switch (variant->backing) {
> +	case ANON_BACKED:
>  		return;
> -
> -	self->fd = open_file(
> -		variant->backing == SHMEM_BACKED ? "/tmp/" : "",
> -		self->path);
> +	case LOCAL_FILE_BACKED:
> +		self->fd = open_file("", self->path);
> +		break;
> +	case SHMEM_BACKED:
> +		self->fd = memfd_create(self->path, 0);
> +		break;
> +	}
>  
>  	/* We truncate file to at least 100 pages, tests can modify as needed. */
>  	ASSERT_EQ(ftruncate(self->fd, 100 * self->page_size), 0);
> @@ -1697,7 +1701,7 @@ TEST_F(guard_regions, readonly_file)
>  	char *ptr;
>  	int i;
>  
> -	if (variant->backing == ANON_BACKED)
> +	if (variant->backing != LOCAL_FILE_BACKED)
>  		SKIP(return, "Read-only test specific to file-backed");
>  
>  	/* Map shared so we can populate with pattern, populate it, unmap. */



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

end of thread, other threads:[~2025-04-28 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-25 16:24 [PATCH] tools/testing/selftests: fix guard region test tmpfs assumption Lorenzo Stoakes
2025-04-28 10:23 ` Ryan Roberts

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