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 8378B4CE677 for ; Wed, 16 Sep 2026 22:46:15 +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=1789598785; cv=none; b=FrDQOBONb/A66gbNzUTGmyus2jOJTfvPaZBOE+5zbBBpUVpGUbGKhgq+p8+Lx9HV0sxa5pdV+jFf1ln/zGiI8cg6fKYnTFRENsEShLgP4HzHNKVaRtB6I7xj9WLV3CKIQxIAxHAxdORwK2V+RkS5t7PYOkI3OYLdBrYSe629o6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789598785; c=relaxed/simple; bh=zlrGmLQrJrDCQk3JAQ3wUiy3u2OjicB3Z9SHw947c38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=maHj51UZVTC0xEnE1+QeWqbfOhXOHlkYNXwYAy14Z+9hYZF+hAgkjNch8nwPlRNzyeWiLuWGlujR98ODGijUWWkOeqazY8EmBMKiC0PYJB6AjzqzlmlopIwIGIP4gFJWe1sgcd2OhqZ4QzpqX7+e4UrYaX7qogWCkHBYVS3oy6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=karVF1DM; 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="karVF1DM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 262791F00893; Wed, 16 Sep 2026 22:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789598773; bh=DM3ePNVbGjG+WiTaJP3U53nQ/kTijLigCIr4mV9ljt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=karVF1DM+Q/ECoYhM3sStTo5LRIYeUy+VGE0OSqZ9AhRDsmOwHOqM89bpe5bJ1HJs MQ3SbicQbjikY/MZ5QXXB1jdF/6oWksvjvmXPCFaRhVvmx0PhabdkVZjOHy3soXg0M Z3zajNTZO8Bwq4Xo/GydxGA5JeJY0HaB9skXU87pjIkve7yhOPMzY+/tVmAUz3TACB IHmio0D+TRtpmCnrXEca/tJWH8YO3DAWB/Jox0zE8rg1QliSdifrDoByAnOM7Lsj6h K7s6TLlfj5tYHU2QdFjxZOJOQuebzF+Hyxsgr/pk1uqteJlWixfehxmvRReVU/pDB7 oG9JPh27aw1XA== From: Sasha Levin To: stable@vger.kernel.org Cc: Jens Axboe , syzbot+2eb3d983669d3e49d4fa@syzkaller.appspotmail.com, Sasha Levin Subject: [PATCH 6.12.y] io_uring/rw: end write accounting from ->ki_complete Date: Wed, 16 Sep 2026 18:46:11 -0400 Message-ID: <20260916224611.3195603-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026091624-arousal-carton-6a38@gregkh> References: <2026091624-arousal-carton-6a38@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 [ adapted accounting cleanup to the older completion helper’s retry early return. ] Signed-off-by: Sasha Levin --- io_uring/rw.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index a74664c4a05ef..d615c61bbbd2e 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -460,31 +460,23 @@ 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. - */ -static void io_req_io_end(struct io_kiocb *req) +/* Trigger the notifications after having done some IO. */ +static void io_req_io_notify(struct io_kiocb *req) { 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 (rw->kiocb.ki_flags & IOCB_WRITE) fsnotify_modify(req->file); - } else { + else fsnotify_access(req->file); - } } static bool __io_complete_rw_common(struct io_kiocb *req, long res) { if (unlikely(res != req->cqe.res)) { if ((res == -EOPNOTSUPP || res == -EAGAIN) && io_rw_should_reissue(req)) { - /* - * Reissue will start accounting again, finish the - * current cycle. - */ - io_req_io_end(req); + /* Reissue bypasses task_work, so notify here. */ + io_req_io_notify(req); req->flags |= REQ_F_REISSUE | REQ_F_BL_NO_RECYCLE; return true; } @@ -519,7 +511,7 @@ void io_req_rw_complete(struct io_kiocb *req, struct io_tw_state *ts) io_req_set_res(req, io_fixup_rw_res(req, res), 0); } - io_req_io_end(req); + io_req_io_notify(req); if (req->flags & (REQ_F_BUFFER_SELECTED|REQ_F_BUFFER_RING)) req->cqe.flags |= io_put_kbuf(req, req->cqe.res, NULL); @@ -533,6 +525,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 (!kiocb->dio_complete || !(kiocb->ki_flags & IOCB_DIO_CALLER_COMP)) { if (__io_complete_rw_common(req, res)) return; @@ -604,11 +600,13 @@ static int kiocb_done(struct io_kiocb *req, ssize_t ret, if (!__io_complete_rw_common(req, ret)) { u32 cflags = 0; + if (rw->kiocb.ki_flags & IOCB_WRITE) + io_req_end_write(req); /* - * Safe to call io_end from here as we're inline + * Safe to notify from here as we're inline * from the submission path. */ - io_req_io_end(req); + io_req_io_notify(req); if (sel) cflags = io_put_kbuf(req, ret, sel->buf_list); io_req_set_res(req, final_ret, cflags); -- 2.53.0