public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH v2 0/3] fstests: fix io_uring testing
@ 2024-03-11 16:20 Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly Zorro Lang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zorro Lang @ 2024-03-11 16:20 UTC (permalink / raw)
  To: fstests; +Cc: io-uring

[PATCH 1/3]
According to the manual of io_uring_queue_init, it doesn't set errno
but return the -errno on failure. So we should check the return value
of io_uring_queue_init, to make sure if the io_uring is supported by
kernel. We've left this problem in xfstests/ltp/fsstress.c long time.

V2 replace "if()...else..." with "switch()..."

[PATCH 2/3]
And besides kernel build without CONFIG_IO_URING, a system can disable
the io_uring supporting manually, by set sysctl kernel.io_uring_disabled=2.
The former cause io_uring_queue_init return ENOSYS, but the latter will
return EPERM. So I let fsstress to deal with both situations.

V2 follows the "switch()..." format of patch 1/3

[PATCH 3/3]
This patch is re-written totally, and no any RVB.
This v2 decides to notrun if sysctl kernel.io_uring_disabled is 2. Then
change README to clarify how to make sure io_uring testing to be run.

Thanks,
Zorro


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

* [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly
  2024-03-11 16:20 [PATCH v2 0/3] fstests: fix io_uring testing Zorro Lang
@ 2024-03-11 16:20 ` Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 2/3] fsstress: bypass io_uring testing if io_uring_queue_init returns EPERM Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl Zorro Lang
  2 siblings, 0 replies; 5+ messages in thread
From: Zorro Lang @ 2024-03-11 16:20 UTC (permalink / raw)
  To: fstests; +Cc: io-uring

As the manual of io_uring_queue_init says "io_uring_queue_init(3)
returns 0 on success and -errno on failure". We should check if the
return value is -ENOSYS, not the errno.

Fixes: d15b1721f284 ("ltp/fsstress: don't fail on io_uring ENOSYS")
Signed-off-by: Zorro Lang <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Reviewed-by: Jeff Moyer <[email protected]>
---
 ltp/fsstress.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index 63c75767..4fc50efb 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -763,13 +763,17 @@ int main(int argc, char **argv)
 #ifdef URING
 			have_io_uring = true;
 			/* If ENOSYS, just ignore uring, other errors are fatal. */
-			if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
-				if (errno == ENOSYS) {
-					have_io_uring = false;
-				} else {
-					fprintf(stderr, "io_uring_queue_init failed\n");
-					exit(1);
-				}
+			c = io_uring_queue_init(URING_ENTRIES, &ring, 0);
+			switch(c){
+			case 0:
+				have_io_uring = true;
+				break;
+			case -ENOSYS:
+				have_io_uring = false;
+				break;
+			default:
+				fprintf(stderr, "io_uring_queue_init failed\n");
+				exit(1);
 			}
 #endif
 			for (i = 0; keep_looping(i, loops); i++)
-- 
2.43.0


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

* [PATCH v2 2/3] fsstress: bypass io_uring testing if io_uring_queue_init returns EPERM
  2024-03-11 16:20 [PATCH v2 0/3] fstests: fix io_uring testing Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly Zorro Lang
@ 2024-03-11 16:20 ` Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl Zorro Lang
  2 siblings, 0 replies; 5+ messages in thread
From: Zorro Lang @ 2024-03-11 16:20 UTC (permalink / raw)
  To: fstests; +Cc: io-uring

I found the io_uring testing still fails as:
  io_uring_queue_init failed
even if kernel supports io_uring feature.

That because of the /proc/sys/kernel/io_uring_disabled isn't 0.

Different value means:
  0 All processes can create io_uring instances as normal.
  1 io_uring creation is disabled (io_uring_setup() will fail with
    -EPERM) for unprivileged processes not in the io_uring_group
    group. Existing io_uring instances can still be used.  See the
    documentation for io_uring_group for more information.
  2 io_uring creation is disabled for all processes. io_uring_setup()
    always fails with -EPERM. Existing io_uring instances can still
    be used.

So besides the CONFIG_IO_URING kernel config, there's another switch
can on or off the io_uring supporting. And the "2" or "1" might be
the default on some systems.

On this situation the io_uring_queue_init returns -EPERM, so I change
the fsstress to ignore io_uring testing if io_uring_queue_init returns
-ENOSYS or -EPERM. And print different verbose message for debug.

Signed-off-by: Zorro Lang <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Reviewed-by: Jeff Moyer <[email protected]>
---
 ltp/fsstress.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index 4fc50efb..9d2631f7 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -762,7 +762,12 @@ int main(int argc, char **argv)
 #endif
 #ifdef URING
 			have_io_uring = true;
-			/* If ENOSYS, just ignore uring, other errors are fatal. */
+			/*
+			 * If ENOSYS, just ignore uring, due to kernel doesn't support it.
+			 * If EPERM, maybe due to sysctl kernel.io_uring_disabled isn't 0,
+			 *           or some selinux policies, etc.
+			 * Other errors are fatal.
+			 */
 			c = io_uring_queue_init(URING_ENTRIES, &ring, 0);
 			switch(c){
 			case 0:
@@ -770,9 +775,16 @@ int main(int argc, char **argv)
 				break;
 			case -ENOSYS:
 				have_io_uring = false;
+				if (verbose)
+					printf("io_uring isn't supported by kernel\n");
+				break;
+			case -EPERM:
+				have_io_uring = false;
+				if (verbose)
+					printf("io_uring isn't allowed, check io_uring_disabled sysctl or selinux policy\n");
 				break;
 			default:
-				fprintf(stderr, "io_uring_queue_init failed\n");
+				fprintf(stderr, "io_uring_queue_init failed, errno=%d\n", -c);
 				exit(1);
 			}
 #endif
-- 
2.43.0


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

* [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl
  2024-03-11 16:20 [PATCH v2 0/3] fstests: fix io_uring testing Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly Zorro Lang
  2024-03-11 16:20 ` [PATCH v2 2/3] fsstress: bypass io_uring testing if io_uring_queue_init returns EPERM Zorro Lang
@ 2024-03-11 16:20 ` Zorro Lang
  2024-03-11 16:29   ` Darrick J. Wong
  2 siblings, 1 reply; 5+ messages in thread
From: Zorro Lang @ 2024-03-11 16:20 UTC (permalink / raw)
  To: fstests; +Cc: io-uring

If kernel supports io_uring, userspace still can/might disable that
supporting by set /proc/sys/kernel/io_uring_disabled=2. Let's notrun
if io_uring is disabled by that way.

Signed-off-by: Zorro Lang <[email protected]>
---
 README        |  6 ++++++
 common/rc     | 10 ++++++++++
 src/feature.c | 19 ++++++++++++-------
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/README b/README
index c46690c4..477136de 100644
--- a/README
+++ b/README
@@ -142,6 +142,12 @@ Setup Environment
    https://www.lscdweb.com/registered/udf_verifier.html, then copy the udf_test
    binary to xfstests/src/.
 
+8. (optional) To do io_uring related testing, please make sure below 3 things:
+     1) kernel is built with CONFIG_IO_URING=y
+     2) sysctl -w kernel.io_uring_disabled=0 (or set it to 2 to disable io_uring
+        testing dynamically if kernel supports)
+     3) install liburing development package contains liburing.h before building
+        fstests
 
 For example, to run the tests with loopback partitions:
 
diff --git a/common/rc b/common/rc
index 50dde313..1406d8d9 100644
--- a/common/rc
+++ b/common/rc
@@ -2317,6 +2317,8 @@ _require_aiodio()
 # this test requires that the kernel supports IO_URING
 _require_io_uring()
 {
+	local n
+
 	$here/src/feature -R
 	case $? in
 	0)
@@ -2324,6 +2326,14 @@ _require_io_uring()
 	1)
 		_notrun "kernel does not support IO_URING"
 		;;
+	2)
+		n=$(sysctl -n kernel.io_uring_disabled 2>/dev/null)
+		if [ "$n" != "0" ];then
+			_notrun "io_uring isn't enabled totally by admin"
+		else
+			_fail "unexpected EPERM error, please check selinux or something else"
+		fi
+		;;
 	*)
 		_fail "unexpected error testing for IO_URING support"
 		;;
diff --git a/src/feature.c b/src/feature.c
index 941f96fb..7e474ce5 100644
--- a/src/feature.c
+++ b/src/feature.c
@@ -232,15 +232,20 @@ check_uring_support(void)
 	int err;
 
 	err = io_uring_queue_init(1, &ring, 0);
-	if (err == 0)
+	switch (err) {
+	case 0:
 		return 0;
-
-	if (err == -ENOSYS) /* CONFIG_IO_URING=n */
+	case -ENOSYS:
+		/* CONFIG_IO_URING=n */
 		return 1;
-
-	fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
-		strerror(-err));
-	return 2;
+	case -EPERM:
+		/* Might be due to sysctl io_uring_disabled isn't 0 */
+		return 2;
+	default:
+		fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
+			strerror(-err));
+		return 100;
+	}
 #else
 	/* liburing is unavailable, assume IO_URING is unsupported */
 	return 1;
-- 
2.43.0


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

* Re: [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl
  2024-03-11 16:20 ` [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl Zorro Lang
@ 2024-03-11 16:29   ` Darrick J. Wong
  0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2024-03-11 16:29 UTC (permalink / raw)
  To: Zorro Lang; +Cc: fstests, io-uring

On Tue, Mar 12, 2024 at 12:20:29AM +0800, Zorro Lang wrote:
> If kernel supports io_uring, userspace still can/might disable that
> supporting by set /proc/sys/kernel/io_uring_disabled=2. Let's notrun
> if io_uring is disabled by that way.
> 
> Signed-off-by: Zorro Lang <[email protected]>

Looks fine to me,
Reviewed-by: Darrick J. Wong <[email protected]>

--D

> ---
>  README        |  6 ++++++
>  common/rc     | 10 ++++++++++
>  src/feature.c | 19 ++++++++++++-------
>  3 files changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/README b/README
> index c46690c4..477136de 100644
> --- a/README
> +++ b/README
> @@ -142,6 +142,12 @@ Setup Environment
>     https://www.lscdweb.com/registered/udf_verifier.html, then copy the udf_test
>     binary to xfstests/src/.
>  
> +8. (optional) To do io_uring related testing, please make sure below 3 things:
> +     1) kernel is built with CONFIG_IO_URING=y
> +     2) sysctl -w kernel.io_uring_disabled=0 (or set it to 2 to disable io_uring
> +        testing dynamically if kernel supports)
> +     3) install liburing development package contains liburing.h before building
> +        fstests
>  
>  For example, to run the tests with loopback partitions:
>  
> diff --git a/common/rc b/common/rc
> index 50dde313..1406d8d9 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -2317,6 +2317,8 @@ _require_aiodio()
>  # this test requires that the kernel supports IO_URING
>  _require_io_uring()
>  {
> +	local n
> +
>  	$here/src/feature -R
>  	case $? in
>  	0)
> @@ -2324,6 +2326,14 @@ _require_io_uring()
>  	1)
>  		_notrun "kernel does not support IO_URING"
>  		;;
> +	2)
> +		n=$(sysctl -n kernel.io_uring_disabled 2>/dev/null)
> +		if [ "$n" != "0" ];then
> +			_notrun "io_uring isn't enabled totally by admin"
> +		else
> +			_fail "unexpected EPERM error, please check selinux or something else"
> +		fi
> +		;;
>  	*)
>  		_fail "unexpected error testing for IO_URING support"
>  		;;
> diff --git a/src/feature.c b/src/feature.c
> index 941f96fb..7e474ce5 100644
> --- a/src/feature.c
> +++ b/src/feature.c
> @@ -232,15 +232,20 @@ check_uring_support(void)
>  	int err;
>  
>  	err = io_uring_queue_init(1, &ring, 0);
> -	if (err == 0)
> +	switch (err) {
> +	case 0:
>  		return 0;
> -
> -	if (err == -ENOSYS) /* CONFIG_IO_URING=n */
> +	case -ENOSYS:
> +		/* CONFIG_IO_URING=n */
>  		return 1;
> -
> -	fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
> -		strerror(-err));
> -	return 2;
> +	case -EPERM:
> +		/* Might be due to sysctl io_uring_disabled isn't 0 */
> +		return 2;
> +	default:
> +		fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
> +			strerror(-err));
> +		return 100;
> +	}
>  #else
>  	/* liburing is unavailable, assume IO_URING is unsupported */
>  	return 1;
> -- 
> 2.43.0
> 
> 

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

end of thread, other threads:[~2024-03-11 16:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-11 16:20 [PATCH v2 0/3] fstests: fix io_uring testing Zorro Lang
2024-03-11 16:20 ` [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly Zorro Lang
2024-03-11 16:20 ` [PATCH v2 2/3] fsstress: bypass io_uring testing if io_uring_queue_init returns EPERM Zorro Lang
2024-03-11 16:20 ` [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl Zorro Lang
2024-03-11 16:29   ` Darrick J. Wong

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