All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Ming Lei <ming.lei@redhat.com>
Cc: linux-block@vger.kernel.org,
	Caleb Sander Mateos <csander@purestorage.com>,
	Uday Shankar <ushankar@purestorage.com>
Subject: Re: [PATCH V2] ublk: fix deadlock when reading partition table
Date: Tue, 16 Dec 2025 10:57:25 -0700	[thread overview]
Message-ID: <5e2038e1-efcf-4313-8a14-565b970370f2@kernel.dk> (raw)
In-Reply-To: <6d40e8a0-14e9-45f4-bbea-360678524767@kernel.dk>

On 12/16/25 8:03 AM, Jens Axboe wrote:
>> The issue for ublk is actually triggered by something abnormal: submit AIO
>> & close(ublk disk) in client application, then fput() is called when the
>> submitted AIO is done, it will cause deferred fput handler to wq for any block
>> IO completed from irq handler.
> 
> My suggested logic is something ala this in bdev_release():
> 
> 	if (current->flags & PF_KTHREAD) {
> 		mutex_lock(&disk->open_mutex);
> 	} else {
> 		if (!mutex_trylock(&disk->open_mutex)) {
> 			deferred_put(file);
> 			return;
> 		}
> 	}
> 
> and that's about it.

I took a look at the bug report, and now it makes more sense to me -
this is an aio only issue, as it does fput() from ->bi_end_io() context.
That's pretty nasty, as you don't really know what context that might
be, both in terms of irq/bh state, but also in terms of locks. The
former fput() does work around.

Why isn't the fix something as simple as the below, with your comment
added on top? I'm not aware of anyone else that would do fput off
->bi_end_io, so we migt as well treat the source of the issue rather
than work around it in ublk. THAT makes a lot more sense to me.

diff --git a/fs/aio.c b/fs/aio.c
index 0a23a8c0717f..d34ae02c61c1 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1104,8 +1104,13 @@ static inline void iocb_destroy(struct aio_kiocb *iocb)
 {
 	if (iocb->ki_eventfd)
 		eventfd_ctx_put(iocb->ki_eventfd);
-	if (iocb->ki_filp)
+	if (iocb->ki_filp) {
+		unsigned long flags;
+
+		local_irq_save(flags);
 		fput(iocb->ki_filp);
+		local_irq_restore(flags);
+	}
 	percpu_ref_put(&iocb->ki_ctx->reqs);
 	kmem_cache_free(kiocb_cachep, iocb);
 }

-- 
Jens Axboe

  reply	other threads:[~2025-12-16 17:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-12 14:34 [PATCH V2] ublk: fix deadlock when reading partition table Ming Lei
2025-12-12 16:57 ` Caleb Sander Mateos
2025-12-12 19:49 ` Jens Axboe
2025-12-13  2:28   ` Ming Lei
2025-12-14  6:41     ` Jens Axboe
2025-12-16  8:56       ` Ming Lei
2025-12-16 15:03         ` Jens Axboe
2025-12-16 17:57           ` Jens Axboe [this message]
2025-12-17  3:09             ` Ming Lei
2025-12-17  3:19               ` Jens Axboe
2025-12-17  3:33                 ` Ming Lei
2025-12-18  2:37                   ` Jens Axboe
2025-12-18  2:41 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e2038e1-efcf-4313-8a14-565b970370f2@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=ushankar@purestorage.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.