From patchwork Mon Apr 1 17:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13612919 Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC1864D5A1 for ; Mon, 1 Apr 2024 17:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711993993; cv=none; b=K1hb5ENb8wrZugAuhOBipYXjwmxnwWXYDPKt2INaHodKx+xOcH/T+KkmjVZppmsVEJXGpxt7W/ICOEKfTsI2X+ah/Jsa8gUvH3T+TEgACnO2QS9V1sRgOvi5+siNJZMEWe5iKSJ+/YvHBm4Si4K/OTYQg5PlRO49oUIfS0/T19U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711993993; c=relaxed/simple; bh=QMcG4jx1tBIDBQBqjiX5YjBseHoAec8UDDjX9cHOu+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sS+AF31Dvg4H3jbxe5BCPteQzeMZiiA1HMzcg8QNiVYX7xPy289SGuw+ep/EBgR+Aw3c0DDi+MHITH0IJIHdZEcq1j5rSI6v22G7iTT/xtGJHyhfarIxlJVeRfgyeBVzrLKecPPQy8pkQz49CLtV3A6AHAYxWItxCUM9ytFANI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=usjril7F; arc=none smtp.client-ip=209.85.166.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="usjril7F" Received: by mail-io1-f44.google.com with SMTP id ca18e2360f4ac-7d0772bb5ffso85891139f.0 for ; Mon, 01 Apr 2024 10:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711993990; x=1712598790; darn=vger.kernel.org; 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=r1LVcHg6RD6pOvGDHs5bk1+ZbPdnQyvBrliIb9jmOn4=; b=usjril7FFA2Vlj+bcHuufGxCsiimIVohh/UPmoTWCWW8GGRKbEmNdHDscoPG7QL9XP BghVasoK9Dv/xcB2SiICX0inxgbTvZdfxB+6v754V43654iFgMtMCTUERpkiOADzuE/P HbN7HAyoDyUovds1RoW77QRad30rW7vbSW0oI7wtDRzEFqN3XGvbhNKhpWZoxe6zyPJa rx27+1/2Hpycfdlp/XddM6SwJPHTM5m4FNo9h6V2pcPxBUTnxkYNwlYFktpWilcU+TKs X+mZ3X/KHjH9/YRtEpQ8u2ttCnHJahC+HYItqYCtb0tywevJBrYriVQm0euqMAEQfs9b lAgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711993990; x=1712598790; 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=r1LVcHg6RD6pOvGDHs5bk1+ZbPdnQyvBrliIb9jmOn4=; b=GfXUk/s4jqQS7nmVfla2Jh2ohiTN0UU20I6nLbhpX4bURsWfZfHwBHTJr9nbXkFNbU GiJ6cZsiQy/6KliAmCzZCp3V4l4ynIg164/VmWX8jpa9fPyqDG3P02aEcdNtNQ0oE/FZ zegdvPailDM03KudJf5F/FtVyiS4txooSFl6GjHi6tYc1kDaCGLghPHr5Mcu0fkeP2CR rVDpkxH1XGAWoDabcJ37gaZMjCV0JBmweIsJY66cxXwFXL9fiQ3mejeWvC91aiFEyBmv 9TuZlE5cUPAng8LHYxZfGqEbv20LptSvN5+mhlZVKDhSuFQ8K9Y2RUSAJJRDduEnNvtQ 6JHQ== X-Gm-Message-State: AOJu0YztM0M0lQ6qzYXiL5Ygf7y58LRtTT8AZOQXxgwBBmTyvZQcfJg/ HMGsFk7fkbLQaqpr8zx7rGliXD227gD4nagroGj+8urMrLA8xFOCrjWK9RGqLcvUkbjt2Dtjw3I 9 X-Google-Smtp-Source: AGHT+IFdi5QSuH9n05fGrgfGEbwql/F+8F+UVYT6gjOh/L3/sEdcGMV+OGZD6GOm2/y6Y+StSk2jYA== X-Received: by 2002:a05:6e02:221a:b0:368:b52b:b449 with SMTP id j26-20020a056e02221a00b00368b52bb449mr13044392ilf.0.1711993990480; Mon, 01 Apr 2024 10:53:10 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gm14-20020a0566382b8e00b004773d7a010dsm2663829jab.76.2024.04.01.10.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 10:53:08 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe , stable@vger.kernel.org Subject: [PATCH 1/2] io_uring/rw: don't allow multishot reads without NOWAIT support Date: Mon, 1 Apr 2024 11:49:15 -0600 Message-ID: <20240401175306.1051122-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240401175306.1051122-1-axboe@kernel.dk> References: <20240401175306.1051122-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Supporting multishot reads requires support for NOWAIT, as the alternative would be always having io-wq execute the work item whenever the poll readiness triggered. Any fast file type will have NOWAIT support (eg it understands both O_NONBLOCK and IOCB_NOWAIT). If the given file type does not, then simply resort to single shot execution. Cc: stable@vger.kernel.org Fixes: fc68fcda04910 ("io_uring/rw: add support for IORING_OP_READ_MULTISHOT") Signed-off-by: Jens Axboe --- io_uring/rw.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index 0585ebcc9773..c8d48287439e 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -936,6 +936,13 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags) ret = __io_read(req, issue_flags); + /* + * If the file doesn't support proper NOWAIT, then disable multishot + * and stay in single shot mode. + */ + if (!io_file_supports_nowait(req)) + req->flags &= ~REQ_F_APOLL_MULTISHOT; + /* * If we get -EAGAIN, recycle our buffer and just let normal poll * handling arm it. @@ -955,7 +962,7 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags) /* * Any successful return value will keep the multishot read armed. */ - if (ret > 0) { + if (ret > 0 && req->flags & REQ_F_APOLL_MULTISHOT) { /* * Put our buffer and post a CQE. If we fail to post a CQE, then * jump to the termination path. This request is then done. From patchwork Mon Apr 1 17:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13612920 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 765B54D59E for ; Mon, 1 Apr 2024 17:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711993994; cv=none; b=DscLrI2062D833uymDf3pjJzr/mqwLmbNqMPDUJUt5iceKt/pmQrwv39HnjJBDDHZRNg9+W8WYyve0hGLGQ9+ll27N8LZBxpr/my+rM3c32CC2cNnyUMFSZMgyIzwJsbTPBkFGtfgKEpK72cHPs7+r+n5HWHj5k/pYs7OpHi/7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711993994; c=relaxed/simple; bh=6eg0n59KBs0zRUKBf6SOF/jApkG2l9N6XA2aasOeg+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PtHO6sm1SbcbFyboHkfaEh2Bv3dShNCO6Ll2WEEFeYOxFUf42HaxlimqCl42rMo1WzC3sIYbvFOIvLZlmOe+9odIv62BMCX6/HlDxJuAAnDgXjwiTQOEWIg8gZ+WQMHhrv2jPHSoa8YV03v+r6rc7UNhu+6BSgJOzgdn3YN/Z3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=tzDeCbPU; arc=none smtp.client-ip=209.85.166.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="tzDeCbPU" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3688dcc5055so1645885ab.1 for ; Mon, 01 Apr 2024 10:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711993992; x=1712598792; darn=vger.kernel.org; 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=T8W3ugZY2UxWd610/Dfdbazi+rTB2V6f48BemOSZe18=; b=tzDeCbPUpU2iTXqs+sjR0S16Rj57eDA4pM0UKcTeKBq9itVhBS0eBCoJTvhmqB3FlK EE2C266gTqOfPA9ZA0fZ1tOE1tVEyZRLfGgiSBN0PUAx+Sn2bUmspX4Ss3WZMaakvQSw EzFHXYAoIWREcQ01QLF2X6kkzEISL1QuM84wX+ZgELyjv0PdXgje2PL2e0UTBLNnkWj4 it/vY0njyKvhG0Ak17hLcoGmy/qWTkygxz2nFQjXiubsX51sB6yray26ajBXfWrqiSWa JRJq5oiYor7CqgqTPKgN3EzZPBsKBgGyoZwp2MgkT4gz80wAXq+K8wDwkyxaQvkIzSzX BdAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711993992; x=1712598792; 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=T8W3ugZY2UxWd610/Dfdbazi+rTB2V6f48BemOSZe18=; b=NpT+sgHoLDaB0NOjBHFwslQ+xNosMvJvwhaJ+ym3b8frUJWCa0szC40SA6t07EgOzh jbab+VYNsm1p7vPqKCCWC0WMkFXgC6q5Nm7uvrEXoZCInd8qGnMEMjdcsUhjYxZyK9VZ jPehfPO1aS8Ka9yy/BbsXLxR8/rHSiFxR+Y0RM1iPZhN41bOjj5iR+zFnDP9IYuPlviz moWP4NynVUgtxfelsfoGC+j+/Fjfcz7jBP3Trq6rcT135IRu6wacPazK0zNy7rnAEWrB GKXADwgg7v4x6IhRF34lzzDzKP2mnJtRBNDmvtakK9eraQlu/Qzp8SR9i7cu/kK4OyGu SsCg== X-Gm-Message-State: AOJu0YwB3PKCisfabocA19mqwMe+DkPez0Ij9LU9/NhDKxTR8/FF49lw huW4ulZiZiWKYIlnEOCaAw7+AjPyxDMX3ObIhgq3AweCNUmmIcGVLB1A2dgbVhuN8WtyoRlApqn M X-Google-Smtp-Source: AGHT+IHS+PG6hIvtQRPJ9iRsByiCDr4J6r5jhTZPO8kgLm1EJHahQtiOqlIXUZ7gcNZIXIzUO6SPTg== X-Received: by 2002:a6b:f118:0:b0:7d0:c4db:39f2 with SMTP id e24-20020a6bf118000000b007d0c4db39f2mr3860239iog.2.1711993992249; Mon, 01 Apr 2024 10:53:12 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gm14-20020a0566382b8e00b004773d7a010dsm2663829jab.76.2024.04.01.10.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 10:53:10 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe , stable@vger.kernel.org Subject: [PATCH 2/2] io_uring: disable io-wq execution of multishot NOWAIT requests Date: Mon, 1 Apr 2024 11:49:16 -0600 Message-ID: <20240401175306.1051122-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240401175306.1051122-1-axboe@kernel.dk> References: <20240401175306.1051122-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do the same check for direct io-wq execution for multishot requests that commit 2a975d426c82 did for the inline execution, and disable multishot mode (and revert to single shot) if the file type doesn't support NOWAIT, and isn't opened in O_NONBLOCK mode. For multishot to work properly, it's a requirement that nonblocking read attempts can be done. Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5d4b448fdc50..8baf8afb79c2 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1982,10 +1982,15 @@ void io_wq_submit_work(struct io_wq_work *work) err = -EBADFD; if (!io_file_can_poll(req)) goto fail; - err = -ECANCELED; - if (io_arm_poll_handler(req, issue_flags) != IO_APOLL_OK) - goto fail; - return; + if (req->file->f_flags & O_NONBLOCK || + req->file->f_mode & FMODE_NOWAIT) { + err = -ECANCELED; + if (io_arm_poll_handler(req, issue_flags) != IO_APOLL_OK) + goto fail; + return; + } else { + req->flags &= ~REQ_F_APOLL_MULTISHOT; + } } if (req->flags & REQ_F_FORCE_ASYNC) {