From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 2/4] nvme: fix the check for duplicate unique identifiers
Date: Thu, 24 Feb 2022 20:28:43 +0100 [thread overview]
Message-ID: <20220224192845.1097602-3-hch@lst.de> (raw)
In-Reply-To: <20220224192845.1097602-1-hch@lst.de>
nvme_subsys_check_duplicate_ids should needs to return an error if any of
the identifiers matches, not just if all of them match. But it does not
need to and should not look at the CSI value for this sanity check.
Rewrite the logic to be separate from nvme_ns_ids_equal and optimize it
by reducing duplicate checks for non-present identifiers.
Fixes: ed754e5deeb1 ("nvme: track shared namespaces")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/core.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 076a03b801b7e..3e6ac985b24f6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1716,13 +1716,6 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
}
-static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
-{
- return !uuid_is_null(&ids->uuid) ||
- memchr_inv(ids->nguid, 0, sizeof(ids->nguid)) ||
- memchr_inv(ids->eui64, 0, sizeof(ids->eui64));
-}
-
static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
{
return uuid_equal(&a->uuid, &b->uuid) &&
@@ -3676,12 +3669,21 @@ static struct nvme_ns_head *nvme_find_ns_head(struct nvme_subsystem *subsys,
static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys,
struct nvme_ns_ids *ids)
{
+ bool has_uuid = !uuid_is_null(&ids->uuid);
+ bool has_nguid = memchr_inv(ids->nguid, 0, sizeof(ids->nguid));
+ bool has_eui64 = memchr_inv(ids->eui64, 0, sizeof(ids->eui64));
struct nvme_ns_head *h;
lockdep_assert_held(&subsys->lock);
list_for_each_entry(h, &subsys->nsheads, entry) {
- if (nvme_ns_ids_valid(ids) && nvme_ns_ids_equal(ids, &h->ids))
+ if (has_uuid && uuid_equal(&ids->uuid, &h->ids.uuid))
+ return -EINVAL;
+ if (has_nguid &&
+ memcmp(&ids->nguid, &h->ids.nguid, sizeof(ids->nguid)) == 0)
+ return -EINVAL;
+ if (has_eui64 &&
+ memcmp(&ids->eui64, &h->ids.eui64, sizeof(ids->eui64)) == 0)
return -EINVAL;
}
--
2.30.2
next prev parent reply other threads:[~2022-02-24 19:29 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-24 19:28 properly validate the nvme uniqueue identifiers are unique v2 Christoph Hellwig
2022-02-24 19:28 ` [PATCH 1/4] nvme: cleanup __nvme_check_ids Christoph Hellwig
2022-02-24 22:50 ` Chaitanya Kulkarni
2022-02-24 19:28 ` Christoph Hellwig [this message]
2022-02-24 22:51 ` [PATCH 2/4] nvme: fix the check for duplicate unique identifiers Chaitanya Kulkarni
2022-02-24 19:28 ` [PATCH 3/4] nvme: check for duplicate identifiers earlier Christoph Hellwig
2022-02-24 22:52 ` Chaitanya Kulkarni
2022-02-24 19:28 ` [PATCH 4/4] nvme: check that EUI/GUID/UUID are globally unique Christoph Hellwig
2022-02-24 22:54 ` Chaitanya Kulkarni
2022-04-08 1:04 ` Luis Chamberlain
2022-04-08 5:29 ` Christoph Hellwig
2022-04-08 7:19 ` Klaus Jensen
2022-04-08 16:10 ` Christoph Hellwig
2022-04-08 17:46 ` Luis Chamberlain
2022-04-11 5:05 ` Christoph Hellwig
2022-04-11 5:54 ` Christoph Hellwig
2022-04-11 6:01 ` Klaus Jensen
2022-04-11 6:09 ` Christoph Hellwig
2022-04-11 6:11 ` Klaus Jensen
2022-04-12 18:46 ` Luis Chamberlain
2022-04-18 23:30 ` Alan Adamson
2022-04-20 7:36 ` Christoph Hellwig
2022-06-06 20:35 ` Alan Adamson
2022-06-06 21:38 ` Keith Busch
2022-06-06 21:51 ` Alan Adamson
2022-06-06 21:58 ` Keith Busch
2022-06-06 23:11 ` Alan Adamson
2022-06-07 19:01 ` Keith Busch
2022-06-08 7:48 ` Christoph Hellwig
2022-06-08 7:52 ` Christoph Hellwig
2022-06-08 18:11 ` Alan Adamson
2022-06-08 19:04 ` Keith Busch
2022-06-09 0:30 ` Chaitanya Kulkarni
2022-06-09 15:11 ` Alan Adamson
2022-06-09 3:53 ` Christoph Hellwig
2022-06-10 0:27 ` Alan Adamson
2022-06-10 14:12 ` Keith Busch
2022-06-15 20:15 ` Alan Adamson
2022-06-17 9:01 ` Christoph Hellwig
2022-06-21 18:40 ` Alan Adamson
2022-06-21 19:11 ` Keith Busch
2022-06-21 20:39 ` Alan Adamson
2022-06-22 11:00 ` Christoph Hellwig
2022-06-22 15:45 ` Alan Adamson
2022-02-24 19:38 ` properly validate the nvme uniqueue identifiers are unique v2 Keith Busch
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=20220224192845.1097602-3-hch@lst.de \
--to=hch@lst.de \
--cc=kbusch@kernel.org \
--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