All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Damien Le Moal <Damien.LeMoal@wdc.com>
Cc: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Subject: Re: [bug report] scsi: sd_zbc: emulate ZONE_APPEND commands
Date: Wed, 17 Feb 2021 10:32:38 +0100	[thread overview]
Message-ID: <YCzitgO+D7NBS5Sw@dhcp22.suse.cz> (raw)
In-Reply-To: <BL0PR04MB651453A8B57118B3C1818ECDE7869@BL0PR04MB6514.namprd04.prod.outlook.com>

On Wed 17-02-21 09:13:57, Damien Le Moal wrote:
> On 2021/02/17 17:03, Michal Hocko wrote:
> > On Wed 17-02-21 06:42:37, Johannes Thumshirn wrote:
> >> On 17/02/2021 00:33, Damien Le Moal wrote:
> >>> On 2021/02/17 4:42, Dan Carpenter wrote:
> >>>> Hello Johannes Thumshirn,
> >>>>
> >>>> The patch 5795eb443060: "scsi: sd_zbc: emulate ZONE_APPEND commands"
> >>>> from May 12, 2020, leads to the following static checker warning:
> >>>>
> >>>> 	drivers/scsi/sd_zbc.c:741 sd_zbc_revalidate_zones()
> >>>> 	error: kvmalloc() only makes sense with GFP_KERNEL
> >>>>
> >>>> drivers/scsi/sd_zbc.c
> >>>>    721          /*
> >>>>    722           * There is nothing to do for regular disks, including host-aware disks
> >>>>    723           * that have partitions.
> >>>>    724           */
> >>>>    725          if (!blk_queue_is_zoned(q))
> >>>>    726                  return 0;
> >>>>    727  
> >>>>    728          /*
> >>>>    729           * Make sure revalidate zones are serialized to ensure exclusive
> >>>>    730           * updates of the scsi disk data.
> >>>>    731           */
> >>>>    732          mutex_lock(&sdkp->rev_mutex);
> >>>>    733  
> >>>>    734          if (sdkp->zone_blocks == zone_blocks &&
> >>>>    735              sdkp->nr_zones == nr_zones &&
> >>>>    736              disk->queue->nr_zones == nr_zones)
> >>>>    737                  goto unlock;
> >>>>    738  
> >>>>    739          sdkp->zone_blocks = zone_blocks;
> >>>>    740          sdkp->nr_zones = nr_zones;
> >>>>    741          sdkp->rev_wp_offset = kvcalloc(nr_zones, sizeof(u32), GFP_NOIO);
> >>>>                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>>> We're passing GFP_NOIO here so it just defaults to kcalloc() and will
> >>>> not vmalloc() the memory.
> >>>
> >>> Indeed... And the allocation can get a little too big for kmalloc().
> >>>
> >>> Johannes, I think we need to move that allocation before the rev_mutex locking,
> >>> using a local var for the allocated address, and then using GFP_KERNEL should be
> >>> safe... But not entirely sure. Using kmalloc would be simpler but on large SMR
> >>> drives, that allocation will soon need to be 400K or so (i.e. 100,000 zones or
> >>> even more), too large for kmalloc to succeed reliably.
> >>>
> >>
> >>
> >> No I don't think so. A mutex isn't a spinlock so we can sleep on the allocation.
> >> We can't use GFP_KERNEL as we're about to do I/O. blk_revalidate_disk_zones() called
> >> a few line below also does the memalloc_noio_{save,restore}() dance.
> > 
> > You should be extending noio scope then if this allocation falls into
> > the same category. Ideally the scope should start at the recursion place
> > and end where the scope really ened.
> 
> But it does not look like __vmalloc_node() (fallback in kvmalloc_node() if
> kmalloc() fails) cares about the context allocation flags... I can't see
> if/where the context allocation flags are taken into account. It looks like only
> the gfp_mask argument is used. Am I missing something ?

current_gfp_context in the page allocator. vmalloc doesn't do any
reclaim on its own. It relies on the page allocator for that.
-- 
Michal Hocko
SUSE Labs

      parent reply	other threads:[~2021-02-17  9:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16 19:39 [bug report] scsi: sd_zbc: emulate ZONE_APPEND commands Dan Carpenter
2021-02-16 23:33 ` Damien Le Moal
2021-02-17  6:42   ` Johannes Thumshirn
2021-02-17  8:00     ` Damien Le Moal
2021-02-17  8:03     ` Michal Hocko
2021-02-17  9:08       ` Johannes Thumshirn
2021-02-17  9:36         ` Michal Hocko
2021-02-17  9:41           ` Johannes Thumshirn
2021-02-17 10:05             ` Michal Hocko
2021-02-17  9:13       ` Damien Le Moal
2021-02-17  9:18         ` Johannes Thumshirn
2021-02-17 11:16           ` Dan Carpenter
2021-02-17 11:18             ` Johannes Thumshirn
2021-02-17  9:32         ` Michal Hocko [this message]

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=YCzitgO+D7NBS5Sw@dhcp22.suse.cz \
    --to=mhocko@suse.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-scsi@vger.kernel.org \
    /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.