linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
To: Hannes Reinecke <hare@suse.de>, Jens Axboe <axboe@kernel.dk>
Cc: "hch@infradead.org" <hch@infradead.org>,
	linux-block <linux-block@vger.kernel.org>,
	Damien Le Moal <Damien.LeMoal@wdc.com>,
	Keith Busch <kbusch@kernel.org>,
	"linux-scsi @ vger . kernel . org" <linux-scsi@vger.kernel.org>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	"linux-fsdevel @ vger . kernel . org"
	<linux-fsdevel@vger.kernel.org>, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH v9 08/11] scsi: sd_zbc: emulate ZONE_APPEND commands
Date: Tue, 28 Apr 2020 12:09:25 +0000	[thread overview]
Message-ID: <SN4PR0401MB35985B7C08A21C15DBD515299BAC0@SN4PR0401MB3598.namprd04.prod.outlook.com> (raw)
In-Reply-To: 92524364-fdd2-c386-9ac4-e4cbb73751f0@suse.de

On 28/04/2020 13:42, Hannes Reinecke wrote:
[...]
>> diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
>> index 50fff0bf8c8e..6009311105ef 100644
>> --- a/drivers/scsi/sd.h
>> +++ b/drivers/scsi/sd.h
>> @@ -79,6 +79,12 @@ struct scsi_disk {
>>    	u32		zones_optimal_open;
>>    	u32		zones_optimal_nonseq;
>>    	u32		zones_max_open;
>> +	u32		*zones_wp_ofst;
>> +	spinlock_t	zones_wp_ofst_lock;
>> +	u32		*rev_wp_ofst;
>> +	struct mutex	rev_mutex;
>> +	struct work_struct zone_wp_ofst_work;
>> +	char		*zone_wp_update_buf;
>>    #endif
>>    	atomic_t	openers;
>>    	sector_t	capacity;	/* size in logical blocks */
> 
> 'zones_wp_ofst' ?
> 
> Please replace the cryptic 'ofst' with 'offset'; those three additional
> characters don't really make a difference ...

'zones_wp_ofst' was good to maintain the 80 chars limit and not end up 
with broken up lines, because we crossed the limit. I'll have a look if 
we can make it 'zones_wp_offset' without uglifying the code.

[...]

>> @@ -396,11 +633,67 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
>>    	return 0;
>>    }
>>    
>> +static void sd_zbc_revalidate_zones_cb(struct gendisk *disk)
>> +{
>> +	struct scsi_disk *sdkp = scsi_disk(disk);
>> +
>> +	swap(sdkp->zones_wp_ofst, sdkp->rev_wp_ofst);
>> +}
>> +
>> +static int sd_zbc_revalidate_zones(struct scsi_disk *sdkp,
>> +				   u32 zone_blocks,
>> +				   unsigned int nr_zones)
>> +{
>> +	struct gendisk *disk = sdkp->disk;
>> +	int ret = 0;
>> +
>> +	/*
>> +	 * Make sure revalidate zones are serialized to ensure exclusive
>> +	 * updates of the scsi disk data.
>> +	 */
>> +	mutex_lock(&sdkp->rev_mutex);
>> +
>> +	/*
>> +	 * Revalidate the disk zones to update the device request queue zone
>> +	 * bitmaps and the zone write pointer offset array. Do this only once
>> +	 * the device capacity is set on the second revalidate execution for
>> +	 * disk scan or if something changed when executing a normal revalidate.
>> +	 */
>> +	if (sdkp->first_scan) {
>> +		sdkp->zone_blocks = zone_blocks;
>> +		sdkp->nr_zones = nr_zones;
>> +		goto unlock;
>> +	}
>> +
>> +	if (sdkp->zone_blocks == zone_blocks &&
>> +	    sdkp->nr_zones == nr_zones &&
>> +	    disk->queue->nr_zones == nr_zones)
>> +		goto unlock;
>> +
>> +	sdkp->rev_wp_ofst = kvcalloc(nr_zones, sizeof(u32), GFP_NOIO);
>> +	if (!sdkp->rev_wp_ofst) {
>> +		ret = -ENOMEM;
>> +		goto unlock;
>> +	}
>> +
>> +	ret = blk_revalidate_disk_zones(disk, sd_zbc_revalidate_zones_cb);
>> +
>> +	kvfree(sdkp->rev_wp_ofst);
>> +	sdkp->rev_wp_ofst = NULL;
>> +
>> +unlock:
>> +	mutex_unlock(&sdkp->rev_mutex);
> 
> I don't really understand this.
> Passing a callback is fine if things happen asynchronously, and you
> wouldn't know from the calling context when that happened. Ok.
> But the above code definitely assumes that blk_revalidate_disk_zones()
> will be completed upon return, otherwise we'll get a nice crash in the
> callback function as the 'rev' pointer is invalid.
> But _if_ blk_revalidata_disk_zones() has completed upon return we might
> as well kill the callback, have the ->rev_wp_ofst a local variable ans
> simply the whole thing.

Sorry but I don't understand your comment. If in 
blk_revalidate_disk_zones() returns an error, all that happens is that 
we free the rev_wp_ofst pointer and return the error to the caller.

And looking at blk_revalidate_disk_zones() itself, I can't see a code 
path that calls the callback if something went wrong:

noio_flag = memalloc_noio_save(); 
 

ret = disk->fops->report_zones(disk, 0, UINT_MAX, 
 

                                blk_revalidate_zone_cb, &args); 
 

memalloc_noio_restore(noio_flag); 
 

 
 

/*
  * Install the new bitmaps and update nr_zones only once the queue is 
 

  * stopped and all I/Os are completed (i.e. a scheduler is not 
 

  * referencing the bitmaps).
  */
blk_mq_freeze_queue(q); 
 

if (ret >= 0) { 
 

         blk_queue_chunk_sectors(q, args.zone_sectors); 
 

         q->nr_zones = args.nr_zones; 
 

         swap(q->seq_zones_wlock, args.seq_zones_wlock); 
 

         swap(q->conv_zones_bitmap, args.conv_zones_bitmap); 
 

         if (update_driver_data)
                 update_driver_data(disk); 
 

         ret = 0; 
 

} else {
         pr_warn("%s: failed to revalidate zones\n", disk->disk_name); 
 

         blk_queue_free_zone_bitmaps(q);
}
blk_mq_unfreeze_queue(q);

And even *iff* the callback would be executed, we would have:
static void sd_zbc_revalidate_zones_cb(struct gendisk *disk)
{
         struct scsi_disk *sdkp = scsi_disk(disk); 
 


         swap(sdkp->zones_wp_ofst, sdkp->rev_wp_ofst);
}

I.e. we exchange some pointers. I can't see a possible crash here, we're 
not accessing anything.

Byte,
	Johannes

  reply	other threads:[~2020-04-28 12:09 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28 10:45 [PATCH v9 00/11] Introduce Zone Append for writing to zoned block devices Johannes Thumshirn
2020-04-28 10:45 ` [PATCH v9 01/11] scsi: free sgtables in case command setup fails Johannes Thumshirn
2020-04-29 12:48   ` Johannes Thumshirn
2020-04-28 10:45 ` [PATCH v9 02/11] block: provide fallbacks for blk_queue_zone_is_seq and blk_queue_zone_no Johannes Thumshirn
2020-05-06  2:51   ` Martin K. Petersen
2020-04-28 10:45 ` [PATCH v9 03/11] block: rename __bio_add_pc_page to bio_add_hw_page Johannes Thumshirn
2020-05-06  2:52   ` Martin K. Petersen
2020-04-28 10:45 ` [PATCH v9 04/11] block: Introduce REQ_OP_ZONE_APPEND Johannes Thumshirn
2020-05-06  2:56   ` Martin K. Petersen
2020-04-28 10:45 ` [PATCH v9 05/11] block: introduce blk_req_zone_write_trylock Johannes Thumshirn
2020-05-06  2:57   ` Martin K. Petersen
2020-04-28 10:46 ` [PATCH v9 06/11] block: Modify revalidate zones Johannes Thumshirn
2020-05-06  2:57   ` Martin K. Petersen
2020-04-28 10:46 ` [PATCH v9 07/11] scsi: sd_zbc: factor out sanity checks for zoned commands Johannes Thumshirn
2020-05-06  2:58   ` Martin K. Petersen
2020-04-28 10:46 ` [PATCH v9 08/11] scsi: sd_zbc: emulate ZONE_APPEND commands Johannes Thumshirn
2020-04-28 11:42   ` Hannes Reinecke
2020-04-28 12:09     ` Johannes Thumshirn [this message]
2020-04-28 14:50       ` Douglas Gilbert
2020-05-06  3:21   ` Martin K. Petersen
2020-04-28 10:46 ` [PATCH v9 09/11] null_blk: Support REQ_OP_ZONE_APPEND Johannes Thumshirn
2020-04-28 11:43   ` Hannes Reinecke
2020-05-06  3:22   ` Martin K. Petersen
2020-04-28 10:46 ` [PATCH v9 10/11] block: export bio_release_pages and bio_iov_iter_get_pages Johannes Thumshirn
2020-04-28 11:43   ` Hannes Reinecke
2020-05-06  3:23   ` Martin K. Petersen
2020-04-28 10:46 ` [PATCH v9 11/11] zonefs: use REQ_OP_ZONE_APPEND for sync DIO Johannes Thumshirn
2020-04-30  2:18 ` [PATCH v9 00/11] Introduce Zone Append for writing to zoned block devices Martin K. Petersen
2020-05-05 19:01   ` Johannes Thumshirn

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=SN4PR0401MB35985B7C08A21C15DBD515299BAC0@SN4PR0401MB3598.namprd04.prod.outlook.com \
    --to=johannes.thumshirn@wdc.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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).