Linux cgroups development
 help / color / mirror / Atom feed
* [PATCH] selftests: cgroup: fix test_zswap error path and meaningless check
@ 2023-09-12  8:38 Domenico Cerasuolo
       [not found] ` <20230912083800.57435-1-cerasuolodomenico-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Domenico Cerasuolo @ 2023-09-12  8:38 UTC (permalink / raw)
  To: dan.carpenter, akpm, kernel-team, linux-kernel, cgroups,
	linux-kselftest
  Cc: Domenico Cerasuolo

Replace destruction paths with simple returns before the test cgroup is
created, there is nothing to free or destroy at that point.

Remove pointless check, stored_pages is a size_t and cannot be < 0.

Fixes: a549f9f31561 ("selftests: cgroup: add test_zswap with no kmem bypass test")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
---
 tools/testing/selftests/cgroup/test_zswap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c
index 49def87a909b..5257106776d5 100644
--- a/tools/testing/selftests/cgroup/test_zswap.c
+++ b/tools/testing/selftests/cgroup/test_zswap.c
@@ -178,10 +178,10 @@ static int test_no_kmem_bypass(const char *root)
 
 	/* Set up test memcg */
 	if (cg_write(root, "cgroup.subtree_control", "+memory"))
-		goto out;
+		return KSFT_FAIL;
 	test_group = cg_name(root, "kmem_bypass_test");
 	if (!test_group)
-		goto out;
+		return KSFT_FAIL;
 
 	/* Spawn memcg child and wait for it to allocate */
 	set_min_free_kb(min_free_kb_low);
@@ -208,8 +208,6 @@ static int test_no_kmem_bypass(const char *root)
 		free(trigger_allocation);
 		if (get_zswap_stored_pages(&stored_pages))
 			break;
-		if (stored_pages < 0)
-			break;
 		/* If memory was pushed to zswap, verify it belongs to memcg */
 		if (stored_pages > stored_pages_threshold) {
 			int zswapped = cg_read_key_long(test_group, "memory.stat", "zswapped ");
-- 
2.34.1


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

* Re: [PATCH] selftests: cgroup: fix test_zswap error path and meaningless check
       [not found] ` <20230912083800.57435-1-cerasuolodomenico-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2023-09-12 17:18   ` Andrew Morton
  2023-09-13  7:17     ` Domenico Cerasuolo
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2023-09-12 17:18 UTC (permalink / raw)
  To: Domenico Cerasuolo
  Cc: dan.carpenter-QSEj5FYQhm4dnm+yROfE0A, kernel-team-M8Ki61LpUEw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kselftest-u79uwXL29TY76Z2rM5mHXA

On Tue, 12 Sep 2023 10:38:00 +0200 Domenico Cerasuolo <cerasuolodomenico-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> Replace destruction paths with simple returns before the test cgroup is
> created, there is nothing to free or destroy at that point.
> 
> Remove pointless check, stored_pages is a size_t and cannot be < 0.
> 
> ...
>
> @@ -208,8 +208,6 @@ static int test_no_kmem_bypass(const char *root)
>  		free(trigger_allocation);
>  		if (get_zswap_stored_pages(&stored_pages))
>  			break;
> -		if (stored_pages < 0)
> -			break;
>  		/* If memory was pushed to zswap, verify it belongs to memcg */
>  		if (stored_pages > stored_pages_threshold) {
>  			int zswapped = cg_read_key_long(test_group, "memory.stat", "zswapped ");

stored_pages will be set to -1 on error.  It would be better to cast
stored_pages to ssize_t in the check, rather than simply ignoring
errors?

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

* Re: [PATCH] selftests: cgroup: fix test_zswap error path and meaningless check
  2023-09-12 17:18   ` Andrew Morton
@ 2023-09-13  7:17     ` Domenico Cerasuolo
  0 siblings, 0 replies; 3+ messages in thread
From: Domenico Cerasuolo @ 2023-09-13  7:17 UTC (permalink / raw)
  To: Andrew Morton
  Cc: dan.carpenter, kernel-team, linux-kernel, cgroups,
	linux-kselftest

On Tue, Sep 12, 2023 at 7:18 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Tue, 12 Sep 2023 10:38:00 +0200 Domenico Cerasuolo <cerasuolodomenico@gmail.com> wrote:
>
> > Replace destruction paths with simple returns before the test cgroup is
> > created, there is nothing to free or destroy at that point.
> >
> > Remove pointless check, stored_pages is a size_t and cannot be < 0.
> >
> > ...
> >
> > @@ -208,8 +208,6 @@ static int test_no_kmem_bypass(const char *root)
> >               free(trigger_allocation);
> >               if (get_zswap_stored_pages(&stored_pages))
> >                       break;
> > -             if (stored_pages < 0)
> > -                     break;
> >               /* If memory was pushed to zswap, verify it belongs to memcg */
> >               if (stored_pages > stored_pages_threshold) {
> >                       int zswapped = cg_read_key_long(test_group, "memory.stat", "zswapped ");
>
> stored_pages will be set to -1 on error.  It would be better to cast
> stored_pages to ssize_t in the check, rather than simply ignoring
> errors?

I'm not sure I understood, isn't it safe to just rely on the return value of
get_zswap_stored_pages a few lines above? In that case we break the loop and
the value of stored_pages is not used.

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

end of thread, other threads:[~2023-09-13  7:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12  8:38 [PATCH] selftests: cgroup: fix test_zswap error path and meaningless check Domenico Cerasuolo
     [not found] ` <20230912083800.57435-1-cerasuolodomenico-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-09-12 17:18   ` Andrew Morton
2023-09-13  7:17     ` Domenico Cerasuolo

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