fix an integrity profile unregistration race
Subsystems (2)
Christoph Hellwig
maintainerHi all,
this series fixes a race when the integrity profile is unregistered on a live gendisk. This is a slight twist on a patch sent by Lihong, which I've taken over as she is out on vacation for the next two weeks.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 1/3 block: check if a profile is actually registered in blk_integrity_unregister
While clearing the profile itself is harmless, we really should not clear the stable writes flag if it wasn't set due to a registered integrity profile.
--- block/blk-integrity.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/blk-integrity.c +5 -1
@@ -426,8 +426,12 @@ EXPORT_SYMBOL(blk_integrity_register);*/ void blk_integrity_unregister (struct gendisk *disk) { +struct blk_integrity *bi = &disk->queue->integrity; + +if (!bi->profile) +return ;blk_queue_flag_clear (QUEUE_FLAG_STABLE_WRITES , disk->queue); -memset (&disk->queue->integrity,0 ,sizeof (struct blk_integrity )); +memset (bi,0 ,sizeof (*bi)); }EXPORT_SYMBOL (blk_integrity_unregister);
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister
Christoph Hellwig
maintainerPATCH 2/3 block: flush the integrity workqueue in blk_integrity_unregister
In reply to Christoph HellwigFrom: Lihong Kou <[email protected]>
When the integrity profile is unregistered there can still be integrity reads queued up which could see a NULL verify_fn as shown by the race window below:
CPU0 CPU1
process_one_work nvme_validate_ns
bio_integrity_verify_fn nvme_update_ns_info
nvme_update_disk_info
blk_integrity_unregister
---set queue->integrity as 0
bio_integrity_process
--access bi->profile->verify_fn(bi is a pointer of queue->integity)Before calling blk_integrity_unregister in nvme_update_disk_info, we must make sure that there is no work item in the kintegrityd_wq. Just call blk_flush_integrity to flush the work queue so the bug can be resolved.
--- block/blk-integrity.c | 3 +++ 1 file changed, 3 insertions(+)
block/blk-integrity.c +3 -0
@@ -430,6 +430,9 @@ void blk_integrity_unregister(struct gendisk *disk)if (!bi->profile)return ; + +/* ensure all bios are off the integrity workqueue */ +blk_flush_integrity ();blk_queue_flag_clear (QUEUE_FLAG_STABLE_WRITES , disk->queue);memset (bi,0 ,sizeof (*bi)); }
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 2/3] block: flush the integrity workqueue in blk_integrity_unregister
Christoph Hellwig
maintainerPATCH 3/3 nvme: remove the call to nvme_update_disk_info in nvme_ns_remove
In reply to Christoph HellwigThere is no need to explicitly unregister the integrity profile when deleting the gendisk.
--- drivers/nvme/host/core.c | 2 -- 1 file changed, 2 deletions(-)
drivers/nvme/host/core.c +0 -2
@@ -3862,8 +3862,6 @@ static void nvme_ns_remove(struct nvme_ns *ns)nvme_cdev_del (&ns->cdev, &ns->cdev_device);del_gendisk (ns->disk);blk_cleanup_queue (ns->queue); -if (blk_get_integrity (ns->disk)) -blk_integrity_unregister (ns->disk);down_write (&ns->ctrl->namespaces_rwsem);list_del_init (&ns->list);
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove
Quoted 5 lines · Christoph Hellwig
Hi all,
this series fixes a race when the integrity profile is unregistered on a live gendisk. This is a slight twist on a patch sent by Lihong, which I've taken over as she is out on vacation for the next two weeks.
Applied, thanks.
Signature · 1 line
Jens Axboe