nvmet: add missing locks around nvmet_ns_revalidate
Subsystems (2)
PATCH v2 1/1 nvmet: add missing locks around nvmet_ns_revalidate
nvmet_ns_changed states via lockdep that the ns->subsys->lock must be held. The only caller of nvmet_ns_changed which does not acquire that lock is nvmet_ns_revalidate. The only 2 callers of nvmet_ns_revalidate which do not acquire that lock are nvmet_execute_identify_cns_cs_ns and nvmet_execute_identify_ns. Add a lock for around the call to nvmet_ns_revalidate in those 2 functions.
Both of those identify functions are called from a common function nvmet_execute_identify, which itself is called indirectly via the req->execute function pointer.
This issue was found using a static type-based analyser and manually verified.
---
Changes in v2:
- added sentence about how the issue was found.
- added missing &
drivers/nvme/target/admin-cmd.c | 2 ++ drivers/nvme/target/zns.c | 3 +++ 2 files changed, 5 insertions(+)
drivers/nvme/target/admin-cmd.c +2 -0
@@ -511,7 +511,9 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req) goto done; } +mutex_lock (&req->ns->subsys->lock);nvmet_ns_revalidate (req->ns); +mutex_unlock (&req->ns->subsys->lock);/* * nuse = ncap = nsze isn't always true, but we have no way to find
drivers/nvme/target/zns.c +3 -0
@@ -123,7 +123,10 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req) goto done; } +mutex_lock (&req->ns->subsys->lock);nvmet_ns_revalidate (req->ns); +mutex_unlock (&req->ns->subsys->lock); + zsze = (bdev_zone_sectors (req->ns->bdev) <<9 ) >> req->ns->blksize_shift; id_zns->lbafe[0 ].zsze =cpu_to_le64 (zsze);
Signature · 1 line
2.35.1
Quoted 14 lines · Niels Dossche
nvmet_ns_changedstates via lockdep that thens->subsys->lockmust be held. The only caller ofnvmet_ns_changedwhich does not acquire that lock isnvmet_ns_revalidate. The only 2 callers ofnvmet_ns_revalidatewhich do not acquire that lock arenvmet_execute_identify_cns_cs_nsandnvmet_execute_identify_ns. Add a lock for around the call tonvmet_ns_revalidatein those 2 functions.Both of those identify functions are called from a common function
nvmet_execute_identify, which itself is called indirectly via thereq->executefunction pointer.This issue was found using a static type-based analyser and manually verified.
Quoted 7 lines
Signed-off-by Niels Dossche <[email protected]>---
Changes in v2:
- added sentence about how the issue was found.
- added missing &
Thanks, looks good.
-ck
Christoph Hellwig
maintainerQuoted 3 lines · Niels Dossche
nvmet_ns_changedstates via lockdep that thens->subsys->lockmust be held. The only caller ofnvmet_ns_changedwhich does not acquire that lock isnvmet_ns_revalidate.
So acquire it in nvmet_ns_revalidate only when we actually call nvmet_ns_changed. Otherwise we take a subsystem-wide lock for every Identify Namespace all.
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Niels Dossche
nvmet_ns_changedstates via lockdep that thens->subsys->lockmust be held. The only caller ofnvmet_ns_changedwhich does not acquire that lock isnvmet_ns_revalidate.So acquire it in
nvmet_ns_revalidateonly when we actually callnvmet_ns_changed. Otherwise we take a subsystem-wide lock for every Identify Namespace all.
There are 3 callers of nvmet_ns_revalidate, of which 2 do not acquire the lock and 1 does.
I'll send a v3 patch which does the locking locally inside that if check by adding an additional argument to indicate whether the lock should be acquired or not. Thanks.