linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Damien Le Moal <dlemoal@kernel.org>,
	Ming Lei <ming.lei@redhat.com>,
	"Richard W.M. Jones" <rjones@redhat.com>
Cc: linux-block@vger.kernel.org, Jeff Moyer <jmoyer@redhat.com>,
	Jiri Jaburek <jjaburek@redhat.com>,
	Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bvanassche@acm.org>,
	Hannes Reinecke <hare@suse.de>,
	Chaitanya Kulkarni <kch@nvidia.com>
Subject: Re: [PATCH] block: elevator: avoid to load iosched module from this disk
Date: Sat, 7 Sep 2024 07:50:32 -0600	[thread overview]
Message-ID: <c8fd6c9b-67a7-4cc5-b4e5-c615c37f6b4e@kernel.dk> (raw)
In-Reply-To: <4d7280eb-7f26-4652-a1d4-4f82c4d99a4c@kernel.org>

On 9/7/24 3:04 AM, Damien Le Moal wrote:
> On 9/7/24 16:58, Ming Lei wrote:
>> On Sat, Sep 07, 2024 at 08:35:22AM +0100, Richard W.M. Jones wrote:
>>> On Sat, Sep 07, 2024 at 09:43:31AM +0800, Ming Lei wrote:
>>>> When switching io scheduler via sysfs, 'request_module' may be called
>>>> if the specified scheduler doesn't exist.
>>>>
>>>> This was has deadlock risk because the module may be stored on FS behind
>>>> our disk since request queue is frozen before switching its elevator.
>>>>
>>>> Fix it by returning -EDEADLK in case that the disk is claimed, which
>>>> can be thought as one signal that the disk is mounted.
>>>>
>>>> Some distributions(Fedora) simulates the original kernel command line of
>>>> 'elevator=foo' via 'echo foo > /sys/block/$DISK/queue/scheduler', and boot
>>>> hang is triggered.
>>>>
>>>> Cc: Richard Jones <rjones@redhat.com>
>>>> Cc: Jeff Moyer <jmoyer@redhat.com>
>>>> Cc: Jiri Jaburek <jjaburek@redhat.com>
>>>> Signed-off-by: Ming Lei <ming.lei@redhat.com>
>>>
>>> I'd suggest also:
>>>
>>> Bug: https://bugzilla.kernel.org/show_bug.cgi?id=219166
>>> Reported-by: Richard W.M. Jones <rjones@redhat.com>
>>> Reported-by: Jiri Jaburek <jjaburek@redhat.com>
>>> Tested-by: Richard W.M. Jones <rjones@redhat.com>
>>>
>>> So I have tested this patch and it does fix the issue, at the possible
>>> cost that now setting the scheduler can fail:
>>>
>>>   + for f in /sys/block/{h,s,ub,v}d*/queue/scheduler
>>>   + echo noop
>>>   /init: line 109: echo: write error: Resource deadlock avoided
>>>
>>> (I know I'm setting it to an impossible value here, but this could
>>> also happen when setting it to a valid one.)
>>
>> Actually in most of dist, io-schedulers are built-in, so request_module
>> is just a nop, but meta IO must be started.
>>
>>>
>>> Since almost no one checks the result of 'echo foo > /sys/...'  that
>>> would probably mean that sometimes a desired setting is silently not
>>> set.
>>
>> As I mentioned, io-schedulers are built-in for most of dist, so
>> request_module isn't called in case of one valid io-sched.
>>
>>>
>>> Also I bisected this bug yesterday and found it was caused by (or,
>>> more likely, exposed by):
>>>
>>>   commit af2814149883e2c1851866ea2afcd8eadc040f79
>>>   Author: Christoph Hellwig <hch@lst.de>
>>>   Date:   Mon Jun 17 08:04:38 2024 +0200
>>>
>>>     block: freeze the queue in queue_attr_store
>>>     
>>>     queue_attr_store updates attributes used to control generating I/O, and
>>>     can cause malformed bios if changed with I/O in flight.  Freeze the queue
>>>     in common code instead of adding it to almost every attribute.
>>>
>>> Reverting this commit on top of git head also fixes the problem.
>>>
>>> Why did this commit expose the problem?
>>
>> That is really the 1st bad commit which moves queue freezing before
>> calling request_module(), originally we won't freeze queue until
>> we have to do it.
>>
>> Another candidate fix is to revert it, or at least not do it
>> for storing elevator attribute.
> 
> I do not think that reverting is acceptable. Rather, a proper fix would simply
> be to do the request_module() before freezing the queue.
> Something like below should work (totally untested and that may be overkill).

I like this approach, but let's please call it something descriptive
like "load_module" or something like that.

-- 
Jens Axboe


  parent reply	other threads:[~2024-09-07 13:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-07  1:43 [PATCH] block: elevator: avoid to load iosched module from this disk Ming Lei
2024-09-07  7:35 ` Richard W.M. Jones
2024-09-07  7:58   ` Ming Lei
2024-09-07  9:04     ` Damien Le Moal
2024-09-07  9:48       ` Ming Lei
2024-09-07 10:02         ` Richard W.M. Jones
2024-09-07 10:07           ` Ming Lei
2024-09-07 10:36             ` Richard W.M. Jones
2024-09-07 11:01               ` Richard W.M. Jones
2024-09-07 11:02               ` Ming Lei
2024-09-07 11:14                 ` Richard W.M. Jones
2024-09-08  0:02                   ` Damien Le Moal
2024-09-09  1:00                     ` Ming Lei
2024-09-09  1:01                     ` Ming Lei
2024-09-07  9:53       ` Richard W.M. Jones
2024-09-07 13:50       ` Jens Axboe [this message]
2024-09-09  1:24         ` Ming Lei
2024-09-09  1:56           ` Damien Le Moal
2024-09-09  1:59           ` Damien Le Moal
2024-09-09  2:16             ` Ming Lei

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=c8fd6c9b-67a7-4cc5-b4e5-c615c37f6b4e@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=dlemoal@kernel.org \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jjaburek@redhat.com \
    --cc=jmoyer@redhat.com \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=rjones@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).