* [PATCH] null_blk: cleanup null_init_tag_set
@ 2022-07-15 3:19 ` Ming Lei
2022-07-15 14:11 ` Vincent Fu
0 siblings, 1 reply; 4+ messages in thread
From: Ming Lei @ 2022-07-15 3:19 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Ming Lei, Vincent Fu
The passed 'nullb' can be NULL, so cause null ptr reference.
Fix the issue, meantime cleanup null_init_tag_set for avoiding to add
similar issue in future.
Cc: Vincent Fu <vincent.fu@samsung.com>
Fixes: 37ae152c7a0d ("null_blk: add configfs variables for 2 options")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/block/null_blk/main.c | 49 ++++++++++++++++++++++-------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index c955a07dba2d..a08856b121b3 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1898,31 +1898,44 @@ static int null_gendisk_register(struct nullb *nullb)
static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set)
{
+ unsigned int flags = BLK_MQ_F_SHOULD_MERGE;
+ int hw_queues, numa_node;
+ unsigned int queue_depth;
int poll_queues;
+ if (nullb) {
+ hw_queues = nullb->dev->submit_queues;
+ poll_queues = nullb->dev->poll_queues;
+ queue_depth = nullb->dev->hw_queue_depth;
+ numa_node = nullb->dev->home_node;
+ if (nullb->dev->no_sched)
+ flags |= BLK_MQ_F_NO_SCHED;
+ if (nullb->dev->shared_tag_bitmap)
+ flags |= BLK_MQ_F_TAG_HCTX_SHARED;
+ if (nullb->dev->blocking)
+ flags |= BLK_MQ_F_BLOCKING;
+ } else {
+ hw_queues = g_submit_queues;
+ poll_queues = g_poll_queues;
+ queue_depth = g_hw_queue_depth;
+ numa_node = g_home_node;
+ if (g_blocking)
+ flags |= BLK_MQ_F_BLOCKING;
+ }
+
set->ops = &null_mq_ops;
- set->nr_hw_queues = nullb ? nullb->dev->submit_queues :
- g_submit_queues;
- poll_queues = nullb ? nullb->dev->poll_queues : g_poll_queues;
- if (poll_queues)
- set->nr_hw_queues += poll_queues;
- set->queue_depth = nullb ? nullb->dev->hw_queue_depth :
- g_hw_queue_depth;
- set->numa_node = nullb ? nullb->dev->home_node : g_home_node;
set->cmd_size = sizeof(struct nullb_cmd);
- set->flags = BLK_MQ_F_SHOULD_MERGE;
- if (nullb->dev->no_sched)
- set->flags |= BLK_MQ_F_NO_SCHED;
- if (nullb->dev->shared_tag_bitmap)
- set->flags |= BLK_MQ_F_TAG_HCTX_SHARED;
+ set->flags = flags;
set->driver_data = nullb;
- if (poll_queues)
+ set->nr_hw_queues = hw_queues;
+ set->queue_depth = queue_depth;
+ set->numa_node = numa_node;
+ if (poll_queues) {
+ set->nr_hw_queues += poll_queues;
set->nr_maps = 3;
- else
+ } else {
set->nr_maps = 1;
-
- if ((nullb && nullb->dev->blocking) || g_blocking)
- set->flags |= BLK_MQ_F_BLOCKING;
+ }
return blk_mq_alloc_tag_set(set);
}
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] null_blk: cleanup null_init_tag_set
2022-07-15 3:19 ` [PATCH] null_blk: cleanup null_init_tag_set Ming Lei
@ 2022-07-15 14:11 ` Vincent Fu
2022-07-15 14:30 ` Ming Lei
0 siblings, 1 reply; 4+ messages in thread
From: Vincent Fu @ 2022-07-15 14:11 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block
> -----Original Message-----
> From: Ming Lei [mailto:ming.lei@redhat.com]
> Sent: Thursday, July 14, 2022 11:19 PM
> To: Jens Axboe <axboe@kernel.dk>
> Cc: linux-block@vger.kernel.org; Ming Lei <ming.lei@redhat.com>;
> Vincent Fu <vincent.fu@samsung.com>
> Subject: [PATCH] null_blk: cleanup null_init_tag_set
>
> The passed 'nullb' can be NULL, so cause null ptr reference.
>
> Fix the issue, meantime cleanup null_init_tag_set for avoiding to add
> similar issue in future.
>
> Cc: Vincent Fu <vincent.fu@samsung.com>
> Fixes: 37ae152c7a0d ("null_blk: add configfs variables for 2 options")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> drivers/block/null_blk/main.c | 49 ++++++++++++++++++++++-----------
> --
> 1 file changed, 31 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index c955a07dba2d..a08856b121b3 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -1898,31 +1898,44 @@ static int null_gendisk_register(struct nullb
> *nullb)
>
> static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set
> *set)
> {
> + unsigned int flags = BLK_MQ_F_SHOULD_MERGE;
> + int hw_queues, numa_node;
> + unsigned int queue_depth;
> int poll_queues;
>
> + if (nullb) {
> + hw_queues = nullb->dev->submit_queues;
> + poll_queues = nullb->dev->poll_queues;
> + queue_depth = nullb->dev->hw_queue_depth;
> + numa_node = nullb->dev->home_node;
> + if (nullb->dev->no_sched)
> + flags |= BLK_MQ_F_NO_SCHED;
> + if (nullb->dev->shared_tag_bitmap)
> + flags |= BLK_MQ_F_TAG_HCTX_SHARED;
> + if (nullb->dev->blocking)
> + flags |= BLK_MQ_F_BLOCKING;
> + } else {
> + hw_queues = g_submit_queues;
> + poll_queues = g_poll_queues;
> + queue_depth = g_hw_queue_depth;
> + numa_node = g_home_node;
> + if (g_blocking)
> + flags |= BLK_MQ_F_BLOCKING;
> + }
> +
Ming, thank you for fixing the mess I created.
I believe that even when 'nullb' is NULL we should still set the
BLK_MQ_F_NO_SCHED and BLK_MQ_F_TAG_HCTX_SHARED flags based on the values of
g_no_sched and g_shared_tag_bitmap, respectively. Is that not right?
Vincent
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: cleanup null_init_tag_set
2022-07-15 14:11 ` Vincent Fu
@ 2022-07-15 14:30 ` Ming Lei
0 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2022-07-15 14:30 UTC (permalink / raw)
To: Vincent Fu; +Cc: Jens Axboe, linux-block
On Fri, Jul 15, 2022 at 02:11:21PM +0000, Vincent Fu wrote:
> > -----Original Message-----
> > From: Ming Lei [mailto:ming.lei@redhat.com]
> > Sent: Thursday, July 14, 2022 11:19 PM
> > To: Jens Axboe <axboe@kernel.dk>
> > Cc: linux-block@vger.kernel.org; Ming Lei <ming.lei@redhat.com>;
> > Vincent Fu <vincent.fu@samsung.com>
> > Subject: [PATCH] null_blk: cleanup null_init_tag_set
> >
> > The passed 'nullb' can be NULL, so cause null ptr reference.
> >
> > Fix the issue, meantime cleanup null_init_tag_set for avoiding to add
> > similar issue in future.
> >
> > Cc: Vincent Fu <vincent.fu@samsung.com>
> > Fixes: 37ae152c7a0d ("null_blk: add configfs variables for 2 options")
> > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > ---
> > drivers/block/null_blk/main.c | 49 ++++++++++++++++++++++-----------
> > --
> > 1 file changed, 31 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> > index c955a07dba2d..a08856b121b3 100644
> > --- a/drivers/block/null_blk/main.c
> > +++ b/drivers/block/null_blk/main.c
> > @@ -1898,31 +1898,44 @@ static int null_gendisk_register(struct nullb
> > *nullb)
> >
> > static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set
> > *set)
> > {
> > + unsigned int flags = BLK_MQ_F_SHOULD_MERGE;
> > + int hw_queues, numa_node;
> > + unsigned int queue_depth;
> > int poll_queues;
> >
> > + if (nullb) {
> > + hw_queues = nullb->dev->submit_queues;
> > + poll_queues = nullb->dev->poll_queues;
> > + queue_depth = nullb->dev->hw_queue_depth;
> > + numa_node = nullb->dev->home_node;
> > + if (nullb->dev->no_sched)
> > + flags |= BLK_MQ_F_NO_SCHED;
> > + if (nullb->dev->shared_tag_bitmap)
> > + flags |= BLK_MQ_F_TAG_HCTX_SHARED;
> > + if (nullb->dev->blocking)
> > + flags |= BLK_MQ_F_BLOCKING;
> > + } else {
> > + hw_queues = g_submit_queues;
> > + poll_queues = g_poll_queues;
> > + queue_depth = g_hw_queue_depth;
> > + numa_node = g_home_node;
> > + if (g_blocking)
> > + flags |= BLK_MQ_F_BLOCKING;
> > + }
> > +
>
> Ming, thank you for fixing the mess I created.
>
> I believe that even when 'nullb' is NULL we should still set the
> BLK_MQ_F_NO_SCHED and BLK_MQ_F_TAG_HCTX_SHARED flags based on the values of
> g_no_sched and g_shared_tag_bitmap, respectively. Is that not right?
Yeah, it is right, and I have covered it in V2.
Thanks,
Ming
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: cleanup null_init_tag_set
@ 2022-07-15 13:19 Sachin Sant
0 siblings, 0 replies; 4+ messages in thread
From: Sachin Sant @ 2022-07-15 13:19 UTC (permalink / raw)
To: ming.lei; +Cc: Jens Axboe, linux-block, vincent.fu, linux-next
I ran into similar[1] issue (addressed by this patch ) while running blktests and
can confirm that this patch fixes the reported problem for me.
Tested-by: Sachin Sant <sachinp@linux.ibm.com>
Thanks
- Sachin
[1] -> https://lore.kernel.org/linux-next/20220715124158.GA25618@test-zns/T/#t
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-15 14:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20220715031940uscas1p27e74dec9ebf60d454441271aabe147de@uscas1p2.samsung.com>
2022-07-15 3:19 ` [PATCH] null_blk: cleanup null_init_tag_set Ming Lei
2022-07-15 14:11 ` Vincent Fu
2022-07-15 14:30 ` Ming Lei
2022-07-15 13:19 Sachin Sant
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.