Skip to contentSkip to conversation

fix an integrity profile unregistration race

PATCH In review Christoph Hellwig 3 participants 8 messages Sep 14, 2021 – Sep 15, 2021

Subsystems (2)
lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH 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
index 69a12177dfb62..48bfb53aa8571 100644
@@ -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
author maintainer
#3 lore raw

PATCH 2/3 block: flush the integrity workqueue in blk_integrity_unregister

In reply to Christoph Hellwig

From: 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.

[hch: split up and shortened the changelog]
---
 block/blk-integrity.c | 3 +++
 1 file changed, 3 insertions(+)
block/blk-integrity.c +3 -0
index 48bfb53aa8571..16d5d5338392a 100644
@@ -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
author maintainer
#5 lore raw

PATCH 3/3 nvme: remove the call to nvme_update_disk_info in nvme_ns_remove

In reply to Christoph Hellwig

There 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
index 97f8211cf92c1..6600e138945e2 100644
@@ -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
maintainer Applied
#7 lore raw
In reply to Christoph Hellwig
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