* [PATCH] block: mark GFP_NOIO around sysfs ->store()
@ 2025-01-13 1:58 Ming Lei
2025-01-13 5:47 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Ming Lei @ 2025-01-13 1:58 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei, Thomas Hellström, stable
sysfs ->store is called with queue freezed, meantime we have several
->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
memory with GFP_KERNEL which may run into direct reclaim code path,
then potential deadlock can be caused.
Fix the issue by marking NOIO around sysfs ->store()
Reported-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-sysfs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index e828be777206..e09b455874bf 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -681,6 +681,7 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
struct queue_sysfs_entry *entry = to_queue(attr);
struct gendisk *disk = container_of(kobj, struct gendisk, queue_kobj);
struct request_queue *q = disk->queue;
+ unsigned int noio_flag;
ssize_t res;
if (!entry->store_limit && !entry->store)
@@ -711,7 +712,9 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
mutex_lock(&q->sysfs_lock);
blk_mq_freeze_queue(q);
+ noio_flag = memalloc_noio_save();
res = entry->store(disk, page, length);
+ memalloc_noio_restore(noio_flag);
blk_mq_unfreeze_queue(q);
mutex_unlock(&q->sysfs_lock);
return res;
--
2.44.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] block: mark GFP_NOIO around sysfs ->store()
2025-01-13 1:58 [PATCH] block: mark GFP_NOIO around sysfs ->store() Ming Lei
@ 2025-01-13 5:47 ` Christoph Hellwig
2025-01-13 8:23 ` John Garry
2025-01-13 14:46 ` Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2025-01-13 5:47 UTC (permalink / raw)
To: Ming Lei; +Cc: Jens Axboe, linux-block, Ming Lei, Thomas Hellström, stable
On Mon, Jan 13, 2025 at 09:58:33AM +0800, Ming Lei wrote:
> sysfs ->store is called with queue freezed, meantime we have several
> ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
> memory with GFP_KERNEL which may run into direct reclaim code path,
> then potential deadlock can be caused.
>
> Fix the issue by marking NOIO around sysfs ->store()
Yes, that's a good thing, and we should aim for more of that for
block layer code that requires NOIO:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: mark GFP_NOIO around sysfs ->store()
2025-01-13 1:58 [PATCH] block: mark GFP_NOIO around sysfs ->store() Ming Lei
2025-01-13 5:47 ` Christoph Hellwig
@ 2025-01-13 8:23 ` John Garry
2025-01-13 8:29 ` Ming Lei
2025-01-13 14:46 ` Jens Axboe
2 siblings, 1 reply; 7+ messages in thread
From: John Garry @ 2025-01-13 8:23 UTC (permalink / raw)
To: Ming Lei, Jens Axboe, linux-block; +Cc: Ming Lei, Thomas Hellström, stable
On 13/01/2025 01:58, Ming Lei wrote:
> sysfs ->store is called with queue freezed, meantime we have several
> ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
> memory with GFP_KERNEL which may run into direct reclaim code path,
> then potential deadlock can be caused.
>
> Fix the issue by marking NOIO around sysfs ->store()
>
> Reported-by: Thomas Hellström<thomas.hellstrom@linux.intel.com>
> Cc:stable@vger.kernel.org
> Signed-off-by: Ming Lei<ming.lei@redhat.com>
I guess that you should be including a link to
https://lore.kernel.org/linux-block/Z4RkemI9f6N5zoEF@fedora/T/#mc774c65eeca5c024d29695f9ac6152b87763f305
Regardless, FWIW:
Reviewed-by: John Garry <john.g.garry@oracle.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: mark GFP_NOIO around sysfs ->store()
2025-01-13 8:23 ` John Garry
@ 2025-01-13 8:29 ` Ming Lei
0 siblings, 0 replies; 7+ messages in thread
From: Ming Lei @ 2025-01-13 8:29 UTC (permalink / raw)
To: John Garry
Cc: Ming Lei, Jens Axboe, linux-block, Thomas Hellström, stable
On Mon, Jan 13, 2025 at 08:23:19AM +0000, John Garry wrote:
> On 13/01/2025 01:58, Ming Lei wrote:
> > sysfs ->store is called with queue freezed, meantime we have several
> > ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
> > memory with GFP_KERNEL which may run into direct reclaim code path,
> > then potential deadlock can be caused.
> >
> > Fix the issue by marking NOIO around sysfs ->store()
> >
> > Reported-by: Thomas Hellström<thomas.hellstrom@linux.intel.com>
> > Cc:stable@vger.kernel.org
> > Signed-off-by: Ming Lei<ming.lei@redhat.com>
>
> I guess that you should be including a link to https://lore.kernel.org/linux-block/Z4RkemI9f6N5zoEF@fedora/T/#mc774c65eeca5c024d29695f9ac6152b87763f305
>
Indeed, I will add a Closes tag in V2.
> Regardless, FWIW:
> Reviewed-by: John Garry <john.g.garry@oracle.com>
Thanks,
--
Ming
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: mark GFP_NOIO around sysfs ->store()
2025-01-13 1:58 [PATCH] block: mark GFP_NOIO around sysfs ->store() Ming Lei
2025-01-13 5:47 ` Christoph Hellwig
2025-01-13 8:23 ` John Garry
@ 2025-01-13 14:46 ` Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2025-01-13 14:46 UTC (permalink / raw)
To: linux-block, Ming Lei; +Cc: Ming Lei, Thomas Hellström, stable
On Mon, 13 Jan 2025 09:58:33 +0800, Ming Lei wrote:
> sysfs ->store is called with queue freezed, meantime we have several
> ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
> memory with GFP_KERNEL which may run into direct reclaim code path,
> then potential deadlock can be caused.
>
> Fix the issue by marking NOIO around sysfs ->store()
>
> [...]
Applied, thanks!
[1/1] block: mark GFP_NOIO around sysfs ->store()
commit: 7c0be4ead1f8f5f8be0803f347de0de81e3b8e1c
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: mark GFP_NOIO around sysfs ->store()
@ 2025-08-06 2:50 xu.xin16
2025-08-06 7:27 ` Ming Lei
0 siblings, 1 reply; 7+ messages in thread
From: xu.xin16 @ 2025-08-06 2:50 UTC (permalink / raw)
To: tom.leiming, thomas.hellstrom
Cc: linux-block, zhang.anmeng, yang.tao172, axboe
> sysfs ->store is called with queue freezed, meantime we have several
> ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
> memory with GFP_KERNEL which may run into direct reclaim code path,
> then potential deadlock can be caused.
>
> Fix the issue by marking NOIO around sysfs ->store()
>
> Reported-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> block/blk-sysfs.c | 3 +++
> 1 file changed, 3 insertions(+)
Excuse me, does the issue to fix comes from f1be1788a32e ("block: model freeze &
enter queue as lock for supporting lockdep") ?
Thanks.
>
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index e828be777206..e09b455874bf 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -681,6 +681,7 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
> struct queue_sysfs_entry *entry = to_queue(attr);
> struct gendisk *disk = container_of(kobj, struct gendisk, queue_kobj);
> struct request_queue *q = disk->queue;
> + unsigned int noio_flag;
> ssize_t res;
>
> if (!entry->store_limit && !entry->store)
> @@ -711,7 +712,9 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
>
> mutex_lock(&q->sysfs_lock);
> blk_mq_freeze_queue(q);
> + noio_flag = memalloc_noio_save();
> res = entry->store(disk, page, length);
> + memalloc_noio_restore(noio_flag);
> blk_mq_unfreeze_queue(q);
> mutex_unlock(&q->sysfs_lock);
> return res;
> --
> 2.44.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] block: mark GFP_NOIO around sysfs ->store()
2025-08-06 2:50 xu.xin16
@ 2025-08-06 7:27 ` Ming Lei
0 siblings, 0 replies; 7+ messages in thread
From: Ming Lei @ 2025-08-06 7:27 UTC (permalink / raw)
To: xu.xin16
Cc: tom.leiming, thomas.hellstrom, linux-block, zhang.anmeng,
yang.tao172, axboe
On Wed, Aug 06, 2025 at 10:50:49AM +0800, xu.xin16@zte.com.cn wrote:
> > sysfs ->store is called with queue freezed, meantime we have several
> > ->store() callbacks(update_nr_requests, wbt, scheduler) to allocate
> > memory with GFP_KERNEL which may run into direct reclaim code path,
> > then potential deadlock can be caused.
> >
> > Fix the issue by marking NOIO around sysfs ->store()
> >
> > Reported-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > ---
> > block/blk-sysfs.c | 3 +++
> > 1 file changed, 3 insertions(+)
>
> Excuse me, does the issue to fix comes from f1be1788a32e ("block: model freeze &
> enter queue as lock for supporting lockdep") ?
The above commit just starts to show the potential deadlock risk, which exists for
long time.
And now it becomes not necessary because blk_mq_freeze_queue() includes
memalloc_noio_save().
Thanks,
Ming
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-06 7:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-13 1:58 [PATCH] block: mark GFP_NOIO around sysfs ->store() Ming Lei
2025-01-13 5:47 ` Christoph Hellwig
2025-01-13 8:23 ` John Garry
2025-01-13 8:29 ` Ming Lei
2025-01-13 14:46 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2025-08-06 2:50 xu.xin16
2025-08-06 7:27 ` Ming Lei
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).