From patchwork Mon Mar 11 16:20:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 13589005 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 613454D9E4; Mon, 11 Mar 2024 16:20:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174036; cv=none; b=fNeZuJox0Qaxmk408UCrOgz+jSu0vqfr69O5TMlPpHbOX1VPOlsYA7GO9PnNR4q8IhH6vvaRCsXLju+loKLXnV05cK+kisa6L24jG5zPSzRJM0tDJRpqAxfH8absM/mcC22BW4yARBeWBZXUHMHT1EQekt8A7BiGR6dd5k55FHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174036; c=relaxed/simple; bh=wTf71Ms5kA2VbK3Ba4HKR/5dJ1JQif9cQASBJtfB/Bs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gz08rSuXRuU0tzI8Nav9u3x8rYbEcAlIDNdU/2lVwPyfNayZ5iC7+KEwGDtxUEAy+uRKxKnE71IXTNXnqpSdik2UvbBq135NvO+i9oY1EsJ/zrSyHhnL0f9NXMzeUErklmgktJLEfqh4KNdKY5bBmoCcnOlYgoweP2EpFjpDo2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SQoZrvOi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SQoZrvOi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9908C43390; Mon, 11 Mar 2024 16:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710174036; bh=wTf71Ms5kA2VbK3Ba4HKR/5dJ1JQif9cQASBJtfB/Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SQoZrvOivWf5ZSF9/zGSoG3Xi4gq17S7w0ENLwKYFk6aTnSA6EKZctPbR5ffp7Q/l ucshRSmpEDqQ0oyBTtmB6mC4yM9AnzNh8/OwsLXn93jWUfwbf1x0M51UmMN4zA2M8I DoG8Y/tFOdHLwpEFCIInOwooAeYL0PQ8fWJldrjM1Zo9OtiS/BStecyN1vMvmhypHE fsNhY/H3M3BkU0JZVLdHc6gBqZs30CgDfEzb3uV0nkFock3vZT+mN7s+rPYqmNkqag Q7o4PyGBt2wVQB37MeNWJuquWdJTZ8Bof5e2bOZXApDizE7nxWJqm8+ucANluEjfXk WJiUetmQ0qByw== From: Zorro Lang To: fstests@vger.kernel.org Cc: io-uring@vger.kernel.org Subject: [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly Date: Tue, 12 Mar 2024 00:20:27 +0800 Message-ID: <20240311162029.1102849-2-zlang@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162029.1102849-1-zlang@kernel.org> References: <20240311162029.1102849-1-zlang@kernel.org> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Darrick J. Wong Reviewed-by: Jeff Moyer --- 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++) From patchwork Mon Mar 11 16:20:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 13589006 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 544954D9E4; Mon, 11 Mar 2024 16:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174038; cv=none; b=SDBI0N0o/e2ahf1lZjQH+2nZMG9UNeIltp/n7OWCWbWNjxB6XiNp6WD/aQABmLdnqj38wf3C9QmjJGf8kHq8bbCxzjiZS6GWtfCDuz1VVdCBHZumDDFo+/YTb2W/CAvAvTbAo7YVJhPhij++qMabVtSzcWkvqy4n0FPhCiNy80s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174038; c=relaxed/simple; bh=pD+JXNYfVc2XwYZgA8tF77QEryy7OGA3MWHG9Y3kxYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kbj4d7HtiJnE9xjHOWUIMxLamqDaS7JdwSall/PlHBvxO0o9rSWxjLJl4sHqUd0u2awt6EdMPMUW8m/8l/3CtDwOOUEdvL6imWbRrCuWiEhomecemftroTVBuzhgxJVMMQJ/DrTDDPZly+SL5SMLMjCTOmToi8gUtIuOlArqt0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PoCYwnlK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PoCYwnlK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8426DC43399; Mon, 11 Mar 2024 16:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710174037; bh=pD+JXNYfVc2XwYZgA8tF77QEryy7OGA3MWHG9Y3kxYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PoCYwnlKlfnRZ1t10cA5IvTFslv/ZTFdV6Ey9lEx32jy04ZnyTolJJn3//cWQq10O e9hc8Aw2j2sGaVfFuNdCCOm2z2lHUCHZCXIka0IhLYAMu702/5RnSBRehfmEuHFUyv GP3CgbkvFXsZAJVM8q5dQ2OjkJenI3VIrIzqDbNLwmlYUpQiH5ac/SBX8eq3ifvcgf Z2tXVyHPGSaeXWLHcMWu0JzLPj3vjbvwRy71KXwLsiRio7kboGUuMYygVY/TbtBowR wopmFNof3Zvsl9ahdj1phNGHZbJrhbeqLkv9NYiPwF3pt7/9SB0QKpUtUF4jERS9lF soMGrfotz7i5Q== From: Zorro Lang To: fstests@vger.kernel.org Cc: io-uring@vger.kernel.org Subject: [PATCH v2 2/3] fsstress: bypass io_uring testing if io_uring_queue_init returns EPERM Date: Tue, 12 Mar 2024 00:20:28 +0800 Message-ID: <20240311162029.1102849-3-zlang@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162029.1102849-1-zlang@kernel.org> References: <20240311162029.1102849-1-zlang@kernel.org> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Darrick J. Wong Reviewed-by: Jeff Moyer --- 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 From patchwork Mon Mar 11 16:20:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 13589007 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01DF356445; Mon, 11 Mar 2024 16:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174040; cv=none; b=uYa5U8Yfxc0W+Go0l4L4DEshG8G9O93ZTz6y71KwDF/nBPNDYLOmL2BpTTbMMqbh2TEMSjsHotbLZQafdG+9lIp9jT7qsc33y9tNQ5c4pLxBlYSsjjecIj4b/mjUwHePLmW/X12ErycWjjnOtzdE+/N7E2W7rDpGJ89hBmdYuGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174040; c=relaxed/simple; bh=wd8neVZpk/GvLCTO+77Ndomdio0+UKtd1+l8xOPggWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b+GmhYaUXWGfjhULOiILX2HeuAsGk9PQaRsVnA8IORG1hk/Ou4CZgHn7Jp847FbVoksJ6N0NC4+2Szgrg8iT6wYDggHuwD2dRz/uj/ZYIexadndOpq9ikoGbcr3ZGH4q7I6gXVuST772cmNZTWVTrBV8DjX6LzUr7EN+uTmei80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qwaRu8PO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qwaRu8PO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73F62C433F1; Mon, 11 Mar 2024 16:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710174039; bh=wd8neVZpk/GvLCTO+77Ndomdio0+UKtd1+l8xOPggWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwaRu8POPENlEeaB26XFdLLRycRZZv5WkTlFYWoJfcwUgieDLO/qAKXpbmTTMnMGy WcQfa0k6kAMQe3HCXi8Ayj6xQTyRdA36t2vChiKpwFTbkyGBX+6za9jZMGyx0irco0 9BnS34mB+nr0fTdQ3nynNQNE/rwHhtOXINXgzZWVPtMi0YuNe0FMuQBUGBGG32TQkf NbghaloNQamSmg2u2CGEFMcq3z+V9Twy+N9egLR0kb5FE1DFG2uRhFCtspxraU9uj8 k8+JR07Yl5+ryCPgOuCZQpqrtLRY5yVFl0fMYCm7WqFt+xx5eqDOZGR+SjsCK3oJ11 R0UnEPWUGgoNg== From: Zorro Lang To: fstests@vger.kernel.org Cc: io-uring@vger.kernel.org Subject: [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl Date: Tue, 12 Mar 2024 00:20:29 +0800 Message-ID: <20240311162029.1102849-4-zlang@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162029.1102849-1-zlang@kernel.org> References: <20240311162029.1102849-1-zlang@kernel.org> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Darrick J. Wong --- 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;