From patchwork Tue May 9 15:19:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13235878 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 3D171C7EE23 for ; Tue, 9 May 2023 15:19:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235188AbjEIPTR (ORCPT ); Tue, 9 May 2023 11:19:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjEIPTQ (ORCPT ); Tue, 9 May 2023 11:19:16 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B534A40CE for ; Tue, 9 May 2023 08:19:15 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-760dff4b701so37603639f.0 for ; Tue, 09 May 2023 08:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1683645555; x=1686237555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5dgWRc5/LSrLk2Jc/BvYuBNSBxWtzvDa1580QK6qMmU=; b=4xi4UZAsDeZFH2vLjBFdwNzUsZtprOD9/RBP6wxtqxg2m2X0Pjlt0wGUNsQsC4YjDC prvSHWRI031SawHeC7XDrXt2NCWtp22mGMWbkt4ze/0RNLPQZ96qCJP54CPLe/oYA2V4 +OeMBSOhB88waZ+p2FXolrirI5HHe0yBzxhV3nwWRR9lo8gOqDc9LXXC0VxS5WNACLTz bu7Ig3MeIqOObDGvZn85n+CTT6M86yMgbNblAoLWF1IceccPHnwapfS4y+tUKqP1tNHB HDP9nG7JtLG26waYqnPKg6JByAGiL2yYvHdkKCBOhLxXog21b0CvwGVgPq6EfL586PT1 m/vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683645555; x=1686237555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5dgWRc5/LSrLk2Jc/BvYuBNSBxWtzvDa1580QK6qMmU=; b=RBY6WTdK1XuuMC/sNL3kh5taflHYJHFqdOFShdnBsY/4aDx2TTCYBcfzO3WIhWkMOO CR/MMC54KK289qEbm0w6fAGj+RvMFk3RWAgxYP5MxjSY+RotCLRLtHmx5J7ppPWFqvbr /8qGPNMvoLs1OKO3JbF79/6DE2ZMK+bXds/v3ACK8/uHtQ7s/ZiRKHcEh8YvlOsS4OZm mFvtDxV2iBMBQSxvxNfjp+ImUbj6KBUhVLJSKKA+Nq1B8Ze5CGigKooeFjm33gPxY7AX ME2nkuGVk5xF3iO1PMgsTZKnIhWEZ/EP3HhcqGTPPCGICDiu91PPA/73PVdb0CqFSsxL yZgw== X-Gm-Message-State: AC+VfDxpSDtIBQiWEDr+KNx4TQZfoEP1m0sindxqyBleMi/GaXO3UWZc HjxXSi5hA4jrqk0nXTIPj17AtN0hiCksLmaE3+g= X-Google-Smtp-Source: ACHHUZ5Dj4Z1JapNi5FTM3anXVp9Zd6k/R11Xiek3v5eBUYl2hIPAtlM36jdfz24NtBjXzjui/oOSw== X-Received: by 2002:a05:6602:2d51:b0:763:6aab:9f3e with SMTP id d17-20020a0566022d5100b007636aab9f3emr11367715iow.1.1683645554843; Tue, 09 May 2023 08:19:14 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id z1-20020a056638240100b0041659b1e2afsm677390jat.14.2023.05.09.08.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 08:19:14 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: torvalds@linux-foundation.org, Jens Axboe , "David S. Miller" , Eric Dumazet , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH 1/3] net: set FMODE_NOWAIT for sockets Date: Tue, 9 May 2023 09:19:08 -0600 Message-Id: <20230509151910.183637-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230509151910.183637-1-axboe@kernel.dk> References: <20230509151910.183637-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The socket read/write functions deal with O_NONBLOCK and IOCB_NOWAIT just fine, so we can flag them as being FMODE_NOWAIT compliant. With this, we can remove socket special casing in io_uring when checking if a file type is sane for nonblocking IO, and it's also the defined way to flag file types as such in the kernel. Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: netdev@vger.kernel.org Signed-off-by: Jens Axboe Reviewed-by: Paolo Abeni --- net/socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/socket.c b/net/socket.c index a7b4b37d86df..6861dbbfadb6 100644 --- a/net/socket.c +++ b/net/socket.c @@ -471,6 +471,7 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) return file; } + file->f_mode |= FMODE_NOWAIT; sock->file = file; file->private_data = sock; stream_open(SOCK_INODE(sock), file); From patchwork Tue May 9 15:19:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13235879 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 58E64C7EE24 for ; Tue, 9 May 2023 15:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235732AbjEIPTT (ORCPT ); Tue, 9 May 2023 11:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235638AbjEIPTS (ORCPT ); Tue, 9 May 2023 11:19:18 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55C6640CE for ; Tue, 9 May 2023 08:19:17 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-760b6765f36so21049939f.0 for ; Tue, 09 May 2023 08:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1683645556; x=1686237556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r/jkxiCP4JthB71tD2UnyEZpZa4CleF0O3E0hHUUj2s=; b=J6MxwIbuqm1FKPUVMo9wqx01RiXxThePQKhHVy9j81JKUdegB1fL4DBWREmXRH+rZ4 qZv7P7RINWlFaZ9Cz2qLfTP+9QGOotFhAcP7QnL/KU4QbjumB5po5OqR0GoygqKGuKwI RoKETRjpu8bcVE3sGs+IFxNkdLn7MCCl0Tr8Nvhdl+zLaxgboAdYFeozzfYSosKLTwd+ /3rbddUSD0rRtgtrW9G+Rzh1nKJOIgE3BVmWzJnTXWrrNtj2Na2rkwJhm3kYupLgJWyB 5RdTqpFXpXCg0swOFL0t3sOa7xXLTcFEUV/F43oTl/uTDNmqYjL8NLdBl4re/AS8bXL9 vR1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683645556; x=1686237556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r/jkxiCP4JthB71tD2UnyEZpZa4CleF0O3E0hHUUj2s=; b=bfkwW9dLnVWDdDqMyqd58AcXN6M7V9Ubh53I/A9RMmce1Ibf5CzodhiaSAu0rrk+45 QsXpMHG5fslYdn8h1LF980RuIeD5j8p6RwTbonjmqMndmmq0MZODPDCayyNz85mTBbIP V7b5qnLPO84FCtI4XxQb7ZDpejYfhKdWPhuQG1bqawu8N2CsZREtDGmrAHCK6VMQN3jH O+wTv+OBl8XpXWPuo6NMlHCVo31bbGokdRcOynt0ZrYK6J3lUdVcIORM5qeEpb9GAmcq xBPvKBo/hLm2l3iEtajdRoMEYN87TROA5nvzw8yhVrE2cC7qzeI2NDHQD71QQOqheIGl MnLQ== X-Gm-Message-State: AC+VfDxn+YEaA6J4VJD6uyQaRqBej5HjNFdgmpDuqGU/mKWv8bO10JPp 7iboAMYjI4cTrCt6El9E3fsTeNBso1EujDsK4Xg= X-Google-Smtp-Source: ACHHUZ42L5EZpZexHnQ9E+vXfaofOXLtZIeIku+36oDtyPUueapg5a63UVr1ieq5fEbsZx2fBD0DhQ== X-Received: by 2002:a6b:5f09:0:b0:760:f7e4:7941 with SMTP id t9-20020a6b5f09000000b00760f7e47941mr6891056iob.0.1683645556246; Tue, 09 May 2023 08:19:16 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id z1-20020a056638240100b0041659b1e2afsm677390jat.14.2023.05.09.08.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 08:19:15 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: torvalds@linux-foundation.org, Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH 2/3] block: mark bdev files as FMODE_NOWAIT if underlying device supports it Date: Tue, 9 May 2023 09:19:09 -0600 Message-Id: <20230509151910.183637-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230509151910.183637-1-axboe@kernel.dk> References: <20230509151910.183637-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org We set this unconditionally, but it really should be dependent on if the underlying device is nowait compliant. Cc: linux-block@vger.kernel.org Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig Signed-off-by: Christoph Hellwig Signed-off-by: Christoph Hellwig --- block/fops.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c..ab750e8a040f 100644 --- a/block/fops.c +++ b/block/fops.c @@ -481,7 +481,7 @@ static int blkdev_open(struct inode *inode, struct file *filp) * during an unstable branch. */ filp->f_flags |= O_LARGEFILE; - filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC; + filp->f_mode |= FMODE_BUF_RASYNC; if (filp->f_flags & O_NDELAY) filp->f_mode |= FMODE_NDELAY; @@ -494,6 +494,9 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (IS_ERR(bdev)) return PTR_ERR(bdev); + if (bdev_nowait(bdev)) + filp->f_mode |= FMODE_NOWAIT; + filp->private_data = bdev; filp->f_mapping = bdev->bd_inode->i_mapping; filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); From patchwork Tue May 9 15:19:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13235880 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 AAB31C7EE22 for ; Tue, 9 May 2023 15:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235749AbjEIPTU (ORCPT ); Tue, 9 May 2023 11:19:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235638AbjEIPTT (ORCPT ); Tue, 9 May 2023 11:19:19 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9963E49EA for ; Tue, 9 May 2023 08:19:18 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-760f040ecccso37630539f.1 for ; Tue, 09 May 2023 08:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1683645557; x=1686237557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YfjEIUkXnk7S+bBGuGh6z945jc8ADPHYNzGQJKoLLE4=; b=xtm+JSG+yQ7NVMIxUCcrzb9fqk6Pt8FnmmqYDMw5U7xs0/iGr4fHsdvWZZWRMP+Gtn Dde4/TsSgfHkwecQvvjSFsFXKzvZswFsCF4a2sWJlopmC70o8Jaew1S8wXExfuiBeRtX HnjzTHlpSalIrsFou2sutxX0Zug6r+pk/s6PcbksQWYBbu1Z583/E7ZOmreqA0QxoaHG mYXYtNIV0DWnrtyomR0vS5Y9Nw8hBYjf5BW55YG4TzbJYkSG28vHhcHHnUkJXcldgvQy g0IERh5yFFJCwUADWmIYYk0Rf59kt15CUykef6/R1AfSdJpLLA19a8zhI7xTRV5F9OrT pQBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683645557; x=1686237557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YfjEIUkXnk7S+bBGuGh6z945jc8ADPHYNzGQJKoLLE4=; b=RY0d5CLQLT62MpyY4FAkHmFSQDKbs/8S8JLl4st3IfCJKNH027+hQcyxAyGNIMfsUQ +LbPuioFzJTjvEzQIHpBTlgBnB5bNrp5cQt4t371CqLDET18MgO90V7HSnrmD3dZFnDi 0LIovqzzkcU+dxFuJYuTvtQu4lrW2GChkuNICYU1uSZx/KuKqThDrSmDVU/4CnWKNik5 CD3br6C4+/tCGVEh80bYAjaPPqB2ycVGZ+zAyriS5Vy1DtKc1JMbiL4zvV/x+nX2bu3A aSjf5KwFLKOxyAEbhy/2W0HlynzRn+Sa322nEnqpVfoSGkGBOqJc3z5I0RNdzFSTATqx GUOg== X-Gm-Message-State: AC+VfDx2Oy/Ex8Z2hKckmXdH+Dmk4s+oBuYe63RSQUeiNYWnvEzhkiYN NY9TJF5ZeyH6/IN3ljlI2wp3TuASu5AlKQRgehw= X-Google-Smtp-Source: ACHHUZ6OED0m3ebTV2zlg2XqKcDnD2rsB/yN4+mpqkX2/PX3Q+BpQogGknlPJLzvWafRYsBnEa2giQ== X-Received: by 2002:a05:6602:2c81:b0:763:86b1:6111 with SMTP id i1-20020a0566022c8100b0076386b16111mr10151559iow.2.1683645557484; Tue, 09 May 2023 08:19:17 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id z1-20020a056638240100b0041659b1e2afsm677390jat.14.2023.05.09.08.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 08:19:16 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: torvalds@linux-foundation.org, Jens Axboe Subject: [PATCH 3/3] io_uring: rely solely on FMODE_NOWAIT Date: Tue, 9 May 2023 09:19:10 -0600 Message-Id: <20230509151910.183637-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230509151910.183637-1-axboe@kernel.dk> References: <20230509151910.183637-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Now that we have both sockets and block devices setting FMODE_NOWAIT appropriately, we can get rid of all the odd special casing in __io_file_supports_nowait() and rely soley on FMODE_NOWAIT and O_NONBLOCK rather than special case sockets and (in particular) bdevs. Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3bca7a79efda..7c426584e35a 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1758,11 +1758,6 @@ static void io_iopoll_req_issued(struct io_kiocb *req, unsigned int issue_flags) } } -static bool io_bdev_nowait(struct block_device *bdev) -{ - return !bdev || bdev_nowait(bdev); -} - /* * 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 @@ -1770,22 +1765,6 @@ static bool io_bdev_nowait(struct block_device *bdev) */ static bool __io_file_supports_nowait(struct file *file, umode_t mode) { - if (S_ISBLK(mode)) { - if (IS_ENABLED(CONFIG_BLOCK) && - io_bdev_nowait(I_BDEV(file->f_mapping->host))) - return true; - return false; - } - if (S_ISSOCK(mode)) - return true; - if (S_ISREG(mode)) { - if (IS_ENABLED(CONFIG_BLOCK) && - io_bdev_nowait(file->f_inode->i_sb->s_bdev) && - !io_is_uring_fops(file)) - return true; - return false; - } - /* any ->read/write should understand O_NONBLOCK */ if (file->f_flags & O_NONBLOCK) return true;