From: Christoph Hellwig <hch@lst.de> To: axboe@kernel.dk, martin.petersen@oracle.com Cc: Lihong Kou <koulihong@huawei.com>, kbusch@kernel.org, sagi@grimberg.me, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 2/3] block: flush the integrity workqueue in blk_integrity_unregister Date: Tue, 14 Sep 2021 09:06:56 +0200 [thread overview] Message-ID: <20210914070657.87677-3-hch@lst.de> (raw) In-Reply-To: <20210914070657.87677-1-hch@lst.de> 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
WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de> To: axboe@kernel.dk, martin.petersen@oracle.com Cc: Lihong Kou <koulihong@huawei.com>, kbusch@kernel.org, sagi@grimberg.me, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 2/3] block: flush the integrity workqueue in blk_integrity_unregister Date: Tue, 14 Sep 2021 09:06:56 +0200 [thread overview] Message-ID: <20210914070657.87677-3-hch@lst.de> (raw) In-Reply-To: <20210914070657.87677-1-hch@lst.de> 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
next prev parent reply other threads:[~2021-09-14 7:11 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-14 7:06 fix an integrity profile unregistration race Christoph Hellwig 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 2021-09-14 7:06 ` Christoph Hellwig 2021-09-14 7:10 ` Sagi Grimberg 2021-09-14 7:10 ` Sagi Grimberg 2021-09-14 7:06 ` Christoph Hellwig [this message] 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: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:06 ` Christoph Hellwig 2021-09-14 7:19 ` Sagi Grimberg 2021-09-14 7:19 ` Sagi Grimberg 2021-09-15 2:03 ` fix an integrity profile unregistration race Jens Axboe 2021-09-15 2:03 ` Jens Axboe
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=20210914070657.87677-3-hch@lst.de \ --to=hch@lst.de \ --cc=axboe@kernel.dk \ --cc=kbusch@kernel.org \ --cc=koulihong@huawei.com \ --cc=linux-block@vger.kernel.org \ --cc=linux-nvme@lists.infradead.org \ --cc=martin.petersen@oracle.com \ --cc=sagi@grimberg.me \ /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: linkBe 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.