From: Niels Dossche <dossche.niels@gmail.com>
To: linux-nvme@lists.infradead.org
Cc: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>,
Bart Van Assche <bvanassche@acm.org>,
Niels Dossche <dossche.niels@gmail.com>
Subject: [PATCH v2] nvmet: add missing locks around nvmet_ns_revalidate
Date: Thu, 10 Mar 2022 02:25:11 +0100 [thread overview]
Message-ID: <20220310012511.82536-1-dossche.niels@gmail.com> (raw)
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.
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---
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(+)
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 6fb24746de06..6d1f5e02d27b 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -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
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index 46bc30fe85d2..56e650a84bfa 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -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);
--
2.35.1
next reply other threads:[~2022-03-10 1:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 1:25 Niels Dossche [this message]
2022-03-10 1:50 ` [PATCH v2] nvmet: add missing locks around nvmet_ns_revalidate Chaitanya Kulkarni
2022-03-10 6:38 ` Christoph Hellwig
2022-03-10 12:46 ` Niels Dossche
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=20220310012511.82536-1-dossche.niels@gmail.com \
--to=dossche.niels@gmail.com \
--cc=bvanassche@acm.org \
--cc=hch@lst.de \
--cc=kch@nvidia.com \
--cc=linux-nvme@lists.infradead.org \
--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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox