Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
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/3] nvme: fix the IDs equality check
Date: Thu, 24 Feb 2022 11:58:51 +0100	[thread overview]
Message-ID: <20220224105852.862715-3-hch@lst.de> (raw)
In-Reply-To: <20220224105852.862715-1-hch@lst.de>

In nvme_subsys_check_duplicate_ids we care if any of the IDs is the
same, not just if all of them match.  This also requires not comparing
the CSI, which is rather irrelevant here.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/host/core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 076a03b801b7e..ac4749f257439 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) &&
@@ -3681,7 +3674,14 @@ static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys,
 	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 (!uuid_is_null(&ids->uuid) &&
+		    uuid_equal(&ids->uuid, &h->ids.uuid))
+			return -EINVAL;
+		if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid)) &&
+		    memcmp(&ids->nguid, &h->ids.nguid, sizeof(ids->nguid)) == 0)
+			return -EINVAL;
+		if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64)) &&
+		    memcmp(&ids->eui64, &h->ids.eui64, sizeof(ids->eui64)) == 0)
 			return -EINVAL;
 	}
 
-- 
2.30.2



  parent reply	other threads:[~2022-02-24 10:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 10:58 properly validate the nvme uniqueue identifiers are unique Christoph Hellwig
2022-02-24 10:58 ` [PATCH 1/3] nvme: cleanup __nvme_check_ids Christoph Hellwig
2022-02-24 13:31   ` Kanchan Joshi
2022-02-24 15:29   ` Keith Busch
2022-02-24 10:58 ` Christoph Hellwig [this message]
2022-02-24 14:12   ` [PATCH 2/3] nvme: fix the IDs equality check Kanchan Joshi
2022-02-24 10:58 ` [PATCH 3/3] nvme: check that EUI/GUID/UUID are globally unique Christoph Hellwig
2022-02-24 15:43   ` Keith Busch
2022-02-24 16:51     ` Christoph Hellwig
2022-02-24 17:12       ` 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=20220224105852.862715-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