* fix an integrity profile unregistration race
@ 2021-09-14 7:06 Christoph Hellwig
2021-09-14 7:06 ` [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-14 7:06 UTC (permalink / raw)
To: axboe, martin.petersen; +Cc: Lihong Kou, kbusch, sagi, linux-block, linux-nvme
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.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister
2021-09-14 7:06 fix an integrity profile unregistration race Christoph Hellwig
@ 2021-09-14 7:06 ` Christoph Hellwig
2021-09-14 7:10 ` Sagi Grimberg
2021-09-14 7:06 ` [PATCH 2/3] block: flush the integrity workqueue " Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-14 7:06 UTC (permalink / raw)
To: axboe, martin.petersen; +Cc: Lihong Kou, kbusch, sagi, linux-block, linux-nvme
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.
Reported-by: Lihong Kou <koulihong@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-integrity.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 69a12177dfb62..48bfb53aa8571 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -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);
--
2.30.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] block: flush the integrity workqueue in blk_integrity_unregister
2021-09-14 7:06 fix an integrity profile unregistration race Christoph Hellwig
2021-09-14 7:06 ` [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister Christoph Hellwig
@ 2021-09-14 7:06 ` Christoph Hellwig
2021-09-14 7:19 ` Sagi Grimberg
2021-09-14 7:06 ` [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove Christoph Hellwig
2021-09-15 2:03 ` fix an integrity profile unregistration race Jens Axboe
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-14 7:06 UTC (permalink / raw)
To: axboe, martin.petersen; +Cc: Lihong Kou, kbusch, sagi, linux-block, linux-nvme
From: Lihong Kou <koulihong@huawei.com>
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.
Signed-off-by: Lihong Kou <koulihong@huawei.com>
[hch: split up and shortened the changelog]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-integrity.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 48bfb53aa8571..16d5d5338392a 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -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));
}
--
2.30.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove
2021-09-14 7:06 fix an integrity profile unregistration race Christoph Hellwig
2021-09-14 7:06 ` [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister Christoph Hellwig
2021-09-14 7:06 ` [PATCH 2/3] block: flush the integrity workqueue " Christoph Hellwig
@ 2021-09-14 7:06 ` Christoph Hellwig
2021-09-14 7:19 ` Sagi Grimberg
2021-09-15 2:03 ` fix an integrity profile unregistration race Jens Axboe
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-14 7:06 UTC (permalink / raw)
To: axboe, martin.petersen; +Cc: Lihong Kou, kbusch, sagi, linux-block, linux-nvme
There is no need to explicitly unregister the integrity profile when
deleting the gendisk.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/core.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 97f8211cf92c1..6600e138945e2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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);
--
2.30.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister
2021-09-14 7:06 ` [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister Christoph Hellwig
@ 2021-09-14 7:10 ` Sagi Grimberg
0 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2021-09-14 7:10 UTC (permalink / raw)
To: Christoph Hellwig, axboe, martin.petersen
Cc: Lihong Kou, kbusch, linux-block, linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] block: flush the integrity workqueue in blk_integrity_unregister
2021-09-14 7:06 ` [PATCH 2/3] block: flush the integrity workqueue " Christoph Hellwig
@ 2021-09-14 7:19 ` Sagi Grimberg
0 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2021-09-14 7:19 UTC (permalink / raw)
To: Christoph Hellwig, axboe, martin.petersen
Cc: Lihong Kou, kbusch, linux-block, linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove
2021-09-14 7:06 ` [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove Christoph Hellwig
@ 2021-09-14 7:19 ` Sagi Grimberg
0 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2021-09-14 7:19 UTC (permalink / raw)
To: Christoph Hellwig, axboe, martin.petersen
Cc: Lihong Kou, kbusch, linux-block, linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fix an integrity profile unregistration race
2021-09-14 7:06 fix an integrity profile unregistration race Christoph Hellwig
` (2 preceding siblings ...)
2021-09-14 7:06 ` [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove Christoph Hellwig
@ 2021-09-15 2:03 ` Jens Axboe
3 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2021-09-15 2:03 UTC (permalink / raw)
To: Christoph Hellwig, martin.petersen
Cc: Lihong Kou, kbusch, sagi, linux-block, linux-nvme
On 9/14/21 1:06 AM, Christoph Hellwig wrote:
> 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.
--
Jens Axboe
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-09-15 2:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 7:06 fix an integrity profile unregistration race Christoph Hellwig
2021-09-14 7:06 ` [PATCH 1/3] block: check if a profile is actually registered in blk_integrity_unregister Christoph Hellwig
2021-09-14 7:10 ` Sagi Grimberg
2021-09-14 7:06 ` [PATCH 2/3] block: flush the integrity workqueue " Christoph Hellwig
2021-09-14 7:19 ` Sagi Grimberg
2021-09-14 7:06 ` [PATCH 3/3] nvme: remove the call to nvme_update_disk_info in nvme_ns_remove Christoph Hellwig
2021-09-14 7:19 ` Sagi Grimberg
2021-09-15 2:03 ` fix an integrity profile unregistration race Jens Axboe
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).