From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 77E2E24C06A for ; Thu, 17 Sep 2026 00:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789604358; cv=none; b=mszGqCzXIjRYjySwdMLKpmIQjykTd9Pydx52fqOQ5uBSuIvHWgakcIqLc2Vui1/dcr9yswAaspu3gUh+B7rfE6zHZ4Qn95MGmy/JkLhgmm3fXcRaXgOijpnc+jVTfJMnf7y4FsGmiBIA273ovMgmSaWGT9cB/oL/6TSSPfUIw3k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789604358; c=relaxed/simple; bh=Ynrhgbzgg/N43dmKM6reM1zDzpXqhi0nH2T+soNekh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B7slxCHVYL554dEoBUOaTj0g4giAGmodAjBJzFIS1D64DZAkVy/+DZXRV2R+50fGuOWwbh0o6U1ux94uxnuc8bMKDqEJEgGVyINmnEUTsurI7tKAXA2jTRL8HuwWnIPOsMuzqNaF9cP3YKV3f1wgAqGdFfGkwSlkUgDyUIl/IrY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z2njGPB5; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z2njGPB5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A41F11F000FF; Thu, 17 Sep 2026 00:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789604357; bh=IYkLUPWYtWirbpgV1TCRhEF8IFG1jJIH7M2urieSIjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Z2njGPB5SmyoVMUlr9h9Ud/xhqoGnp3RhjWHWP8ypgQvmKg2La5Loq4HsnPoZKDkl cyiCkUs4NbCt+UppvWaJPxo7KKQCZC85nJC58/F/skwkhPE80W1+lTNczHNYBoQFIK czFOLKp60ZU52ZhThIFwA7bFGRiJzy7N/3l0N/N/cJvnX2HCNSFYfW9nYrMpgNIw6M Vw7alNGOy4SPLBReaizuBas3/4qBn+i3DHJga+vNj7KF86gPCgoCye5HD2y4ADYmcV 4Z8q0YRr2enAo2S0CCdsMDQAHU7c/FfnlzkPc4yP9QdhJe8YoGoC7sYA5AlaR9t6mg 1D33eeBSWpg3g== From: Sasha Levin To: stable@vger.kernel.org Cc: Jens Axboe , syzbot+2eb3d983669d3e49d4fa@syzkaller.appspotmail.com, Sasha Levin Subject: [PATCH 6.1.y] io_uring/rw: end write accounting from ->ki_complete Date: Wed, 16 Sep 2026 20:19:15 -0400 Message-ID: <20260917001915.3360921-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026091625-maturing-defog-33c9@gregkh> References: <2026091625-maturing-defog-33c9@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Jens Axboe [ Upstream commit 796aa0547557e63338657ed1c487906f9fac4c73 ] Commit b000145e9907 moved both the fsnotify calls and the write accounting out of the kiocb completion handler and into the io_req_rw_complete() task_work. However, only the fsnotify part actually needed to move as it may sleep. Ending the write accounting is just a percpu_up_read() on the superblock writers sem. Deferring it is a problem, because it makes dropping SB_FREEZE_WRITE protection depend on the ring owner getting to running task_work. But the task may be blocked in freeze_super(), causing it to never get to that: task io-wq worker -------------------------------------------------------------- io_write() io_kiocb_start_write() (takes sb_writers, hidden from lockdep by __sb_writers_release) write_iter() -> -EIOCBQUEUED ioctl(FS_IOC_SHUTDOWN) bdev_freeze() freeze_super() percpu_down_write() <- waits for the reader above io_write() kiocb_start_write() percpu_down_read() <- queued behind the writer io_complete_rw() queues io_req_rw_complete() <- never runs, task is in D state End the write from io_complete_rw() instead, and leave only the fsnotify calls in task_work. Reported-by: syzbot+2eb3d983669d3e49d4fa@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Fixes: b000145e9907 ("io_uring/rw: defer fsnotify calls to task context") Signed-off-by: Jens Axboe [ replaced upstream’s separate notification helper with an end_write Boolean parameter in io_req_io_end() ] Signed-off-by: Sasha Levin --- io_uring/rw.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index cbd3ee9a9373a..bf66ffef7e434 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -235,14 +235,15 @@ static void io_req_end_write(struct io_kiocb *req) /* * Trigger the notifications after having done some IO, and finish the write - * accounting, if any. + * accounting for inline completions. */ -static void io_req_io_end(struct io_kiocb *req) +static void io_req_io_end(struct io_kiocb *req, bool end_write) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); if (rw->kiocb.ki_flags & IOCB_WRITE) { - io_req_end_write(req); + if (end_write) + io_req_end_write(req); fsnotify_modify(req->file); } else { fsnotify_access(req->file); @@ -255,10 +256,10 @@ static bool __io_complete_rw_common(struct io_kiocb *req, long res) if ((res == -EAGAIN || res == -EOPNOTSUPP) && io_rw_should_reissue(req)) { /* - * Reissue will start accounting again, finish the - * current cycle. + * Write accounting is already finished by + * io_complete_rw(). */ - io_req_io_end(req); + io_req_io_end(req, false); req->flags |= REQ_F_REISSUE | REQ_F_PARTIAL_IO; return true; } @@ -284,7 +285,7 @@ static inline int io_fixup_rw_res(struct io_kiocb *req, long res) static void io_req_rw_complete(struct io_kiocb *req, bool *locked) { - io_req_io_end(req); + io_req_io_end(req, false); io_req_task_complete(req, locked); } @@ -293,6 +294,10 @@ static void io_complete_rw(struct kiocb *kiocb, long res) struct io_rw *rw = container_of(kiocb, struct io_rw, kiocb); struct io_kiocb *req = cmd_to_io_kiocb(rw); + /* ring owner may block in freeze_super() before task_work runs */ + if (kiocb->ki_flags & IOCB_WRITE) + io_req_end_write(req); + if (__io_complete_rw_common(req, res)) return; io_req_set_res(req, io_fixup_rw_res(req, res), 0); @@ -333,7 +338,7 @@ static int kiocb_done(struct io_kiocb *req, ssize_t ret, * Safe to call io_end from here as we're inline * from the submission path. */ - io_req_io_end(req); + io_req_io_end(req, true); io_req_set_res(req, final_ret, io_put_kbuf(req, issue_flags)); return IOU_OK; -- 2.53.0