From patchwork Tue Jun 20 11:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 198B6EB64D7 for ; Tue, 20 Jun 2023 11:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231737AbjFTLcp (ORCPT ); Tue, 20 Jun 2023 07:32:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjFTLco (ORCPT ); Tue, 20 Jun 2023 07:32:44 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB50FE for ; Tue, 20 Jun 2023 04:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=U3ainyF2UXZak0+VVSWzlG5U4kg4C6crs3+ZoOul5Yc=; b=M270kmmTvd7BS1b0N7t00WyHB+ OzG8lvOI5IEQwigpkn7Qhc5vQzIPIjXjumADM0ZpsUayJg4N89fDIlpgbe+7S+DHprWBLeeW86knJ rHFJIbLTp2V2hp+F4hh1jDnVWtTUQDgO8sVlrNhuj0fcKy2skfwcRC04zCdZfmiZIPihvc1/ErfF0 NdJ2H/zMSc0Q8mhi3BWndb0Kp78fBJukIWk5Etg+o9Liyjjt58AbgVwVfxp8C090kiWWij6mnUuwP 6j1eL3UYirIySohWLr1OyNB/JJjE9cT1VD+HArrcVTPl6AGTge5pl03LWQwWvEOMY62BqnO/VZjDb gPDpIxRg==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbG-00B8Wu-2Q; Tue, 20 Jun 2023 11:32:43 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 1/8] io_uring: remove __io_file_supports_nowait Date: Tue, 20 Jun 2023 13:32:28 +0200 Message-Id: <20230620113235.920399-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Now that this only checks O_NONBLOCK and FMODE_NOWAIT, the helper is complete overkilļ, and the comments are confusing bordering to wrong. Just inline the check into the caller. Signed-off-by: Christoph Hellwig --- io_uring/io_uring.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index f181876e415b9a..7e735724940f7f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1766,19 +1766,6 @@ static void io_iopoll_req_issued(struct io_kiocb *req, unsigned int issue_flags) } } -/* - * If we tracked the file through the SCM inflight mechanism, we could support - * any file. For now, just ensure that anything potentially problematic is done - * inline. - */ -static bool __io_file_supports_nowait(struct file *file, umode_t mode) -{ - /* any ->read/write should understand O_NONBLOCK */ - if (file->f_flags & O_NONBLOCK) - return true; - return file->f_mode & FMODE_NOWAIT; -} - /* * If we tracked the file through the SCM inflight mechanism, we could support * any file. For now, just ensure that anything potentially problematic is done @@ -1791,7 +1778,7 @@ unsigned int io_file_get_flags(struct file *file) if (S_ISREG(mode)) res |= FFS_ISREG; - if (__io_file_supports_nowait(file, mode)) + if ((file->f_flags & O_NONBLOCK) || (file->f_mode & FMODE_NOWAIT)) res |= FFS_NOWAIT; return res; } From patchwork Tue Jun 20 11:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285722 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80BF1EB64D7 for ; Tue, 20 Jun 2023 11:32:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbjFTLct (ORCPT ); Tue, 20 Jun 2023 07:32:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjFTLcs (ORCPT ); Tue, 20 Jun 2023 07:32:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B0A3FE for ; Tue, 20 Jun 2023 04:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kx0rflILjnefGz1AIFHCumAr85yYTSMNWuTiLbGBzC0=; b=EJ/+GyohnmQW+q4JsMk65ssfOS rj6CbYRk938XsQ9m6dXvFknNAMmybnAW9VuVchJU7PhNz2iMKd+iLJpuybClbsPn9U30QNIqkvxKI oIQRT6x6ThyT8NT+OqnHswhMUu6ePi8/VRDQXUEVrEcHx8foII6BMR3sJuIHy+evOc3XR9KB8Yf4k fLa9SXHHDztUCV7q7r4FyXTBVwXpUDdtX9mFwCqMgOoNje3pUvG1H1hmUING6dhLZORPaK536NWMg UOoBALBwaXngMgod4PxtMJTKwNVBhzR7X1Dd8ZCFa0UHMKlzlmlanFEco0rK8CJI4ROpyp8giVT56 CisInTAQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbK-00B8Xf-0l; Tue, 20 Jun 2023 11:32:46 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 2/8] io_uring: remove the mode variable in io_file_get_flags Date: Tue, 20 Jun 2023 13:32:29 +0200 Message-Id: <20230620113235.920399-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The variable is only once now, so don't bother with it. Signed-off-by: Christoph Hellwig --- io_uring/io_uring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 7e735724940f7f..2d13f636de93c7 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1773,10 +1773,9 @@ static void io_iopoll_req_issued(struct io_kiocb *req, unsigned int issue_flags) */ unsigned int io_file_get_flags(struct file *file) { - umode_t mode = file_inode(file)->i_mode; unsigned int res = 0; - if (S_ISREG(mode)) + if (S_ISREG(file_inode(file)->i_mode)) res |= FFS_ISREG; if ((file->f_flags & O_NONBLOCK) || (file->f_mode & FMODE_NOWAIT)) res |= FFS_NOWAIT; From patchwork Tue Jun 20 11:32:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32F7BEB64D7 for ; Tue, 20 Jun 2023 11:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbjFTLcw (ORCPT ); Tue, 20 Jun 2023 07:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbjFTLcv (ORCPT ); Tue, 20 Jun 2023 07:32:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B010A10F3 for ; Tue, 20 Jun 2023 04:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=TUSVxYaytrTe3oUKDr6xrBrOzikkQ3pHL+E+pAfVEjM=; b=yLeVZ4Xn6aGauUb0aua5GXYmri VOT7k8A9FChh4F2lTcbYkVZAEBn9EbDPJ1Am0SNJdsmiDS49FxMcMEz7XC3sdZnJA3Y/m9kB1UoDf 32iVmPEpYWwCZS7xohMh71iHhNUuulocj2p1k6J/LSYU+MG4k6e3dJkTou9Ae6ucvalSvAvk5IANr apauzTom31F1/SMwYza4MEQvsmmzMk/wSBbyjNkFGiWlnZ+1Y89Rrqu7kbksZhgGdauh89vDkDcmg 1WCfAcynxY6wvOQbE0lDnhsny0IrinjfX4dsMMW+4ZAyxH8T7wMsOauTnaWV8naOfvLZRkfSXP0EN 2D1ag6wQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbN-00B8Ye-1R; Tue, 20 Jun 2023 11:32:49 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 3/8] io_uring: remove a confusing comment above io_file_get_flags Date: Tue, 20 Jun 2023 13:32:30 +0200 Message-Id: <20230620113235.920399-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The SCM inflight mechanism has nothing to do with the fact that a file might be a regular file or not and if it supports non-blocking operations. Signed-off-by: Christoph Hellwig --- io_uring/io_uring.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 2d13f636de93c7..79f3cabec5b934 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1766,11 +1766,6 @@ static void io_iopoll_req_issued(struct io_kiocb *req, unsigned int issue_flags) } } -/* - * If we tracked the file through the SCM inflight mechanism, we could support - * any file. For now, just ensure that anything potentially problematic is done - * inline. - */ unsigned int io_file_get_flags(struct file *file) { unsigned int res = 0; From patchwork Tue Jun 20 11:32:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285724 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06C83EB64D7 for ; Tue, 20 Jun 2023 11:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232133AbjFTLcz (ORCPT ); Tue, 20 Jun 2023 07:32:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbjFTLcy (ORCPT ); Tue, 20 Jun 2023 07:32:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3796130 for ; Tue, 20 Jun 2023 04:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kRnpR4PaG/N3bQJf2yFh83PhIdYSL1lX09KSmTqGqW0=; b=MzQiFXKU9kUCDllA3kcVBpNxGg SlFOwfJO5dY634peO7cmL99qjCHwHbWZSsjWKOI8z9FB0nqGmnB/Pn3Eu2iIKmI6vWmaMSQDa9fI0 rdxLaFRTUiTwe+AZIQn17LkaZdbolHi3qJQzzIClql6iaK1l0GOq4XK+xs6KJnpVqlH+ruwiL8fsa 9vMDmzAMeiqC1wPtQ3S7gnFjO23c7PlZisRMeedlI+zqbp28aXR4NHBJm0gSmGda3JbGwn3R4jmlv VHARIK6i2WX4F/NeD/yzYs/jOIvhFeYUBXlXKWH+2uX5Mmy6goIMP8C8vxn7xJ61yT8+REJ+Rema0 T5G0VyDA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbQ-00B8ZK-1g; Tue, 20 Jun 2023 11:32:53 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 4/8] io_uring: remove io_req_ffs_set Date: Tue, 20 Jun 2023 13:32:31 +0200 Message-Id: <20230620113235.920399-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Just checking the flag directly makes it a lot more obvious what is going on here. Signed-off-by: Christoph Hellwig --- io_uring/io_uring.c | 2 +- io_uring/io_uring.h | 5 ----- io_uring/rw.c | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 79f3cabec5b934..0e0bdb6ac9a202 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -424,7 +424,7 @@ static void io_prep_async_work(struct io_kiocb *req) if (req->flags & REQ_F_FORCE_ASYNC) req->work.flags |= IO_WQ_WORK_CONCURRENT; - if (req->file && !io_req_ffs_set(req)) + if (req->file && !(req->flags & REQ_F_FIXED_FILE)) req->flags |= io_file_get_flags(req->file) << REQ_F_SUPPORT_NOWAIT_BIT; if (req->file && (req->flags & REQ_F_ISREG)) { diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index a937b4b75aee98..9718897133db59 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -57,11 +57,6 @@ struct file *io_file_get_normal(struct io_kiocb *req, int fd); struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags); -static inline bool io_req_ffs_set(struct io_kiocb *req) -{ - return req->flags & REQ_F_FIXED_FILE; -} - void __io_req_task_work_add(struct io_kiocb *req, unsigned flags); bool io_is_uring_fops(struct file *file); bool io_alloc_async_data(struct io_kiocb *req); diff --git a/io_uring/rw.c b/io_uring/rw.c index c23d8baf028769..1cf5742f2ae9cb 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -666,7 +666,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) if (unlikely(!file || !(file->f_mode & mode))) return -EBADF; - if (!io_req_ffs_set(req)) + if (!(req->flags & REQ_F_FIXED_FILE)) req->flags |= io_file_get_flags(file) << REQ_F_SUPPORT_NOWAIT_BIT; kiocb->ki_flags = file->f_iocb_flags; From patchwork Tue Jun 20 11:32:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E05CEB64D7 for ; Tue, 20 Jun 2023 11:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231893AbjFTLc6 (ORCPT ); Tue, 20 Jun 2023 07:32:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbjFTLc5 (ORCPT ); Tue, 20 Jun 2023 07:32:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A365FE for ; Tue, 20 Jun 2023 04:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=cA+Tgvvo+DnJVVkgrzEmjRYhFDG0B2ufcY5cUFFTsds=; b=4g+fMwp6W+wAFYIu9QLAKk7hMo T4915HjYhJaR3pXD+C0jjuH0D0W8N6JHTtlzFqonglclMkuXCCjl4Sxq+QkN0jafLRIQ5gMRYICkj pKVxjmG/pITs5v1lqmFJkOsBP8/zLR7Twzs05QcWDvrZ3Rs4STTZIcHei+BwSzS+LcRfPrcbBEfAB xdWEdBBjaHayWb6uF7SqnjWhG8Ur2BZ+XlXeTlkJByZp/A0asUVngA0mMCwNaOZvnWtVfBsJvgyrU 9Nj3/QCH4PjJLAam/Wtm4SrZi0yvufO+3KML4rf+RB0byuIV6ic1ry6hm+fGcBXs0bVvWL+193/ya /claJz4Q==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbT-00B8a6-2u; Tue, 20 Jun 2023 11:32:56 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 5/8] io_uring: return REQ_F_ flags from io_file_get_flags Date: Tue, 20 Jun 2023 13:32:32 +0200 Message-Id: <20230620113235.920399-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Two of the three callers want them, so return the more usual format, and shift into the FFS_ form only for the fixed file table. Signed-off-by: Christoph Hellwig --- io_uring/filetable.h | 6 ++---- io_uring/io_uring.c | 6 +++--- io_uring/rw.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/io_uring/filetable.h b/io_uring/filetable.h index 351111ff888274..697cb68adc8169 100644 --- a/io_uring/filetable.h +++ b/io_uring/filetable.h @@ -54,10 +54,8 @@ static inline struct file *io_file_from_index(struct io_file_table *table, static inline void io_fixed_file_set(struct io_fixed_file *file_slot, struct file *file) { - unsigned long file_ptr = (unsigned long) file; - - file_ptr |= io_file_get_flags(file); - file_slot->file_ptr = file_ptr; + file_slot->file_ptr = (unsigned long)file | + (io_file_get_flags(file) >> REQ_F_SUPPORT_NOWAIT_BIT); } static inline void io_reset_alloc_hint(struct io_ring_ctx *ctx) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 0e0bdb6ac9a202..1f348753694bfe 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -425,7 +425,7 @@ static void io_prep_async_work(struct io_kiocb *req) req->work.flags |= IO_WQ_WORK_CONCURRENT; if (req->file && !(req->flags & REQ_F_FIXED_FILE)) - req->flags |= io_file_get_flags(req->file) << REQ_F_SUPPORT_NOWAIT_BIT; + req->flags |= io_file_get_flags(req->file); if (req->file && (req->flags & REQ_F_ISREG)) { bool should_hash = def->hash_reg_file; @@ -1771,9 +1771,9 @@ unsigned int io_file_get_flags(struct file *file) unsigned int res = 0; if (S_ISREG(file_inode(file)->i_mode)) - res |= FFS_ISREG; + res |= REQ_F_ISREG; if ((file->f_flags & O_NONBLOCK) || (file->f_mode & FMODE_NOWAIT)) - res |= FFS_NOWAIT; + res |= REQ_F_SUPPORT_NOWAIT; return res; } diff --git a/io_uring/rw.c b/io_uring/rw.c index 1cf5742f2ae9cb..1bce2208b65c4f 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -667,7 +667,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) return -EBADF; if (!(req->flags & REQ_F_FIXED_FILE)) - req->flags |= io_file_get_flags(file) << REQ_F_SUPPORT_NOWAIT_BIT; + req->flags |= io_file_get_flags(file); kiocb->ki_flags = file->f_iocb_flags; ret = kiocb_set_rw_flags(kiocb, rw->flags); From patchwork Tue Jun 20 11:32:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 465D3EB64D7 for ; Tue, 20 Jun 2023 11:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232335AbjFTLdE (ORCPT ); Tue, 20 Jun 2023 07:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbjFTLdC (ORCPT ); Tue, 20 Jun 2023 07:33:02 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7205E130 for ; Tue, 20 Jun 2023 04:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Q88bOLkv1vZXWuiPW58K2AE3L23Zp9g+dU/2Q7O5Q9k=; b=r0J4tlO3/n1id2C2BVg1lwHzXr AA6l5TojjS+gRarIc0H0RqngeqohICuoqVwCIwTZijFVRKzl0nly5hcaTHgTtp16aoMyRlY9LlRvK G7BqRTVNLXRVYBoN4wc2RngHm+NZMUvdjBGsC9wXbltN8YSj0ctAo14DbaMsBKKZofyqDpiebm1IT KedXjx0Myl9Aq/hAeCcB6OUmvbvguMFK6wdt6BlEj8zafMnM5bLKijD1WHdgaO/g+Eb+qBWwyNfrk SP3QPgnKdV145jzOkLO5LaA2wpLdkicOeaGu+OOYrz1g3XT1DqotJBInodYgRAqngaRfSrmdkBYFd vNrBnuQg==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbX-00B8ap-0S; Tue, 20 Jun 2023 11:32:59 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 6/8] io_uring: use io_file_from_index in __io_sync_cancel Date: Tue, 20 Jun 2023 13:32:33 +0200 Message-Id: <20230620113235.920399-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Use io_file_from_index instead of open coding it. Signed-off-by: Christoph Hellwig --- io_uring/cancel.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index b4f5dfacc0c31d..58c46c852bdd9a 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -216,13 +216,10 @@ static int __io_sync_cancel(struct io_uring_task *tctx, /* fixed must be grabbed every time since we drop the uring_lock */ if ((cd->flags & IORING_ASYNC_CANCEL_FD) && (cd->flags & IORING_ASYNC_CANCEL_FD_FIXED)) { - unsigned long file_ptr; - if (unlikely(fd >= ctx->nr_user_files)) return -EBADF; fd = array_index_nospec(fd, ctx->nr_user_files); - file_ptr = io_fixed_file_slot(&ctx->file_table, fd)->file_ptr; - cd->file = (struct file *) (file_ptr & FFS_MASK); + cd->file = io_file_from_index(&ctx->file_table, fd); if (!cd->file) return -EBADF; } From patchwork Tue Jun 20 11:32:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 490BEEB64D7 for ; Tue, 20 Jun 2023 11:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231753AbjFTLdK (ORCPT ); Tue, 20 Jun 2023 07:33:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232677AbjFTLdH (ORCPT ); Tue, 20 Jun 2023 07:33:07 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D91710F8 for ; Tue, 20 Jun 2023 04:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Ui9RC+SDnLSFPQtKGL043gFzJwOrRieWjY/b9vsqTNM=; b=Pqq+ur9s55XMkaeb/G707/lxbv VrdZTsXkDAlbUMQ4OfK9/ktjVnT2JQCPWatdWj1040CXA3wLG4BCU4tp9T0M0UZIRVIsW049F0pTL lobancWhU231lY7yQON9NDw1AlZZKifYpZPlsHLHe/SZgnH6hujldnWnYUVU40h/RZkvj8wMMDmsJ qqpA55ZayUs5I3IOEIWdHp64IpQhntNN1jPNx6pBsk0b9EjtpIYnIqAb2ipgGEI9LOJ1ejKHmW90V Mqv6MyRhOoP8KAleNXT2dVgoHzrT9t7h1QkmremIdWwbiKrJN0NfEli0gjQPTkcel1WeuwkrgPpEO wnPM52HQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZba-00B8bl-1S; Tue, 20 Jun 2023 11:33:02 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 7/8] io_uring: use io_file_from_index in io_msg_grab_file Date: Tue, 20 Jun 2023 13:32:34 +0200 Message-Id: <20230620113235.920399-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Use io_file_from_index instead of open coding it. Signed-off-by: Christoph Hellwig --- io_uring/msg_ring.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index 85fd7ce5f05b85..cd6dcf634ba3cd 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -162,14 +162,12 @@ static struct file *io_msg_grab_file(struct io_kiocb *req, unsigned int issue_fl struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); struct io_ring_ctx *ctx = req->ctx; struct file *file = NULL; - unsigned long file_ptr; int idx = msg->src_fd; io_ring_submit_lock(ctx, issue_flags); if (likely(idx < ctx->nr_user_files)) { idx = array_index_nospec(idx, ctx->nr_user_files); - file_ptr = io_fixed_file_slot(&ctx->file_table, idx)->file_ptr; - file = (struct file *) (file_ptr & FFS_MASK); + file = io_file_from_index(&ctx->file_table, idx); if (file) get_file(file); } From patchwork Tue Jun 20 11:32:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13285728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDB0DEB64DB for ; Tue, 20 Jun 2023 11:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbjFTLdL (ORCPT ); Tue, 20 Jun 2023 07:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231886AbjFTLdI (ORCPT ); Tue, 20 Jun 2023 07:33:08 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3D2D10E2 for ; Tue, 20 Jun 2023 04:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=HEPUBv3V9+ZWs9gYEpLcOWvdWubsLh0s75fklAsOQg0=; b=trISI0otxVkr1X6MzYr/vrX1oz PNzYtet2vLp004Mb1HwU/EtWpW7bvIlkBUGaGd5ZR1ZGIaR6kZgMer9CRRsCEvtlxsBHQTixqlJoj mCa4ktt09F4Ycg9jY5ZJQpHD5j+nXZz2GRyPVxr/aEG/q0xWoLHUYZFsxFvHZQ5WIlxr59N7+JcV0 4/G6Jgim+Tj0/AgeRqcJOUO74M6wOMSjueZmAZQrBR5pdxYO/dvVx1cRzLAP/MGzMYmDex/q4irex zHLxzGmNIOQJckeXrRtVO0yCxiYZx4JtBxTLwOtCnkb6Edpb6YSe1sf2ApszXhLUiyHlkmUpGItQ3 BpUUsxMQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qBZbd-00B8cN-1g; Tue, 20 Jun 2023 11:33:06 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org Subject: [PATCH 8/8] io_uring: add helpers to decode the fixed file file_ptr Date: Tue, 20 Jun 2023 13:32:35 +0200 Message-Id: <20230620113235.920399-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620113235.920399-1-hch@lst.de> References: <20230620113235.920399-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Remove all the open coded magic on slot->file_ptr by introducing two helpers that return the file pointer and the flags instead. Signed-off-by: Christoph Hellwig --- io_uring/filetable.c | 11 ++++------- io_uring/filetable.h | 22 +++++++++++++++------- io_uring/io_uring.c | 10 ++++------ io_uring/rsrc.c | 8 ++++---- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/io_uring/filetable.c b/io_uring/filetable.c index 0f6fa791a47de6..e7d749991de426 100644 --- a/io_uring/filetable.c +++ b/io_uring/filetable.c @@ -78,10 +78,8 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file, file_slot = io_fixed_file_slot(&ctx->file_table, slot_index); if (file_slot->file_ptr) { - struct file *old_file; - - old_file = (struct file *)(file_slot->file_ptr & FFS_MASK); - ret = io_queue_rsrc_removal(ctx->file_data, slot_index, old_file); + ret = io_queue_rsrc_removal(ctx->file_data, slot_index, + io_slot_file(file_slot)); if (ret) return ret; @@ -140,7 +138,6 @@ int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags, int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset) { struct io_fixed_file *file_slot; - struct file *file; int ret; if (unlikely(!ctx->file_data)) @@ -153,8 +150,8 @@ int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset) if (!file_slot->file_ptr) return -EBADF; - file = (struct file *)(file_slot->file_ptr & FFS_MASK); - ret = io_queue_rsrc_removal(ctx->file_data, offset, file); + ret = io_queue_rsrc_removal(ctx->file_data, offset, + io_slot_file(file_slot)); if (ret) return ret; diff --git a/io_uring/filetable.h b/io_uring/filetable.h index 697cb68adc8169..b47adf170c314d 100644 --- a/io_uring/filetable.h +++ b/io_uring/filetable.h @@ -5,10 +5,6 @@ #include #include -#define FFS_NOWAIT 0x1UL -#define FFS_ISREG 0x2UL -#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG) - bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files); void io_free_file_tables(struct io_file_table *table); @@ -43,12 +39,24 @@ io_fixed_file_slot(struct io_file_table *table, unsigned i) return &table->files[i]; } +#define FFS_NOWAIT 0x1UL +#define FFS_ISREG 0x2UL +#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG) + +static inline unsigned int io_slot_flags(struct io_fixed_file *slot) +{ + return (slot->file_ptr & ~FFS_MASK) << REQ_F_SUPPORT_NOWAIT_BIT; +} + +static inline struct file *io_slot_file(struct io_fixed_file *slot) +{ + return (struct file *)(slot->file_ptr & FFS_MASK); +} + static inline struct file *io_file_from_index(struct io_file_table *table, int index) { - struct io_fixed_file *slot = io_fixed_file_slot(table, index); - - return (struct file *) (slot->file_ptr & FFS_MASK); + return io_slot_file(io_fixed_file_slot(table, index)); } static inline void io_fixed_file_set(struct io_fixed_file *file_slot, diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 1f348753694bfe..ae4cb3c4e73034 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2028,19 +2028,17 @@ inline struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned int issue_flags) { struct io_ring_ctx *ctx = req->ctx; + struct io_fixed_file *slot; struct file *file = NULL; - unsigned long file_ptr; io_ring_submit_lock(ctx, issue_flags); if (unlikely((unsigned int)fd >= ctx->nr_user_files)) goto out; fd = array_index_nospec(fd, ctx->nr_user_files); - file_ptr = io_fixed_file_slot(&ctx->file_table, fd)->file_ptr; - file = (struct file *) (file_ptr & FFS_MASK); - file_ptr &= ~FFS_MASK; - /* mask in overlapping REQ_F and FFS bits */ - req->flags |= (file_ptr << REQ_F_SUPPORT_NOWAIT_BIT); + slot = io_fixed_file_slot(&ctx->file_table, fd); + file = io_slot_file(slot); + req->flags |= io_slot_flags(slot); io_req_set_rsrc_node(req, ctx, 0); out: io_ring_submit_unlock(ctx, issue_flags); diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index d46f72a5ef7323..a2dce7ef3a7877 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -354,7 +354,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, __s32 __user *fds = u64_to_user_ptr(up->data); struct io_rsrc_data *data = ctx->file_data; struct io_fixed_file *file_slot; - struct file *file; int fd, i, err = 0; unsigned int done; @@ -382,15 +381,16 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, file_slot = io_fixed_file_slot(&ctx->file_table, i); if (file_slot->file_ptr) { - file = (struct file *)(file_slot->file_ptr & FFS_MASK); - err = io_queue_rsrc_removal(data, i, file); + err = io_queue_rsrc_removal(data, i, + io_slot_file(file_slot)); if (err) break; file_slot->file_ptr = 0; io_file_bitmap_clear(&ctx->file_table, i); } if (fd != -1) { - file = fget(fd); + struct file *file = fget(fd); + if (!file) { err = -EBADF; break;