U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ana Bobillo <anabobillo3@gmail.com>
To: Tom Rini <trini@konsulko.com>
Cc: u-boot@lists.u-boot-project.org, Simon Glass <sjg@chromium.org>,
	Marek Vasut <marek.vasut+usb@mailbox.org>,
	Bin Meng <bmeng.cn@gmail.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Alexey Charkov <alchark@flipper.net>,
	Javier Martinez Canillas <javierm@redhat.com>
Subject: [PATCH v2 07/12] nvme: Skip a namespace with an unsupported LBA data size
Date: Wed, 28 Oct 2026 05:51:37 +0000	[thread overview]
Message-ID: <5bdc9bbe-e232-49c1-a1cb-d79d952ad6c8@gmail.com> (raw)
In-Reply-To: <01ba3f81-06b7-428b-9224-bd887c35e1c3@gmail.com>

From: Ana Bobillo <anabobillo3@gmail.com>

nvme_blk_probe() takes the LBA data size (log2 of the block size) of the
namespace's current LBA format as the device reports it, and shifts by
it: 1 << ns->lba_shift is undefined for a value of 31 or more, and
nvme_blk_rw() sizes each transfer with
1 << (dev->max_transfer_shift - ns->lba_shift), a negative shift for a
block larger than the maximum transfer size of the controller.

Check it, through a new nvme_lba_shift(), against the block sizes
blk_valid_blksz() accepts and the maximum transfer size. nvme_init()
skips a namespace with an unsupported LBA data size, as it skips an
inactive one, rather than create a block device for it that then fails
to probe, failing nvme_init() and leaving the namespaces it has already
probed on a controller that failed to probe. nvme_blk_probe() checks the
value it uses again.

Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
(no changes since v1)

 drivers/nvme/nvme.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index c815a967137..3df9b531bfd 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -15,6 +15,7 @@
 #include <time.h>
 #include <dm/device-internal.h>
 #include <linux/compat.h>
+#include <linux/log2.h>
 #include "nvme.h"
 
 #define NVME_Q_DEPTH		2
@@ -701,6 +702,26 @@ int nvme_scan_namespace(void)
 	return 0;
 }
 
+/**
+ * nvme_lba_shift() - Get the LBA data size of a namespace
+ *
+ * @dev: NVMe controller
+ * @id: Identify Namespace data of the namespace
+ * Return: log2 of its block size, or -EINVAL if that size is not supported
+ */
+static int nvme_lba_shift(struct nvme_dev *dev, struct nvme_id_ns *id)
+{
+	u8 ds = id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ds;
+
+	if (ds < ilog2(DEFAULT_BLKSZ) || ds > ilog2(BLK_MAX_BLKSZ) ||
+	    ds > dev->max_transfer_shift) {
+		log_err("Unsupported LBA data size 2^%d\n", ds);
+		return -EINVAL;
+	}
+
+	return ds;
+}
+
 static int nvme_blk_probe(struct udevice *udev)
 {
 	struct nvme_dev *ndev = dev_get_priv(udev->parent);
@@ -708,6 +729,7 @@ static int nvme_blk_probe(struct udevice *udev)
 	struct nvme_ns *ns = dev_get_priv(udev);
 	u8 flbas;
 	struct nvme_id_ns *id;
+	int ret;
 
 	id = memalign(ndev->page_size, sizeof(struct nvme_id_ns));
 	if (!id)
@@ -724,7 +746,12 @@ static int nvme_blk_probe(struct udevice *udev)
 	memcpy(&ns->eui64, &id->eui64, sizeof(id->eui64));
 	flbas = id->flbas & NVME_NS_FLBAS_LBA_MASK;
 	ns->flbas = flbas;
-	ns->lba_shift = id->lbaf[flbas].ds;
+	ret = nvme_lba_shift(ndev, id);
+	if (ret < 0) {
+		free(id);
+		return ret;
+	}
+	ns->lba_shift = ret;
 	list_add(&ns->list, &ndev->namespaces);
 
 	desc->lba = le64_to_cpu(id->nsze);
@@ -899,6 +926,10 @@ int nvme_init(struct udevice *udev)
 		if (!id->nsze)
 			continue;
 
+		/* skip a namespace whose block size is not supported */
+		if (nvme_lba_shift(ndev, id) < 0)
+			continue;
+
 		/*
 		 * Encode the namespace id to the device name so that
 		 * we can extract it when doing the probe.

  parent reply	other threads:[~2026-10-28  5:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  5:50 [PATCH v2 00/12] block, disk: Check block sizes and partition tables of devices Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 01/12] treewide: Use is_power_of_2() from linux/log2.h Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` [PATCH v2 02/12] block: Add blk_valid_blksz() to check a block size Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` [PATCH v2 03/12] usb: storage: Fix the capacity faked when READ CAPACITY fails Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` [PATCH v2 04/12] usb: storage: Refuse a block size the block layer cannot use Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` [PATCH v2 05/12] scsi: " Ana Bobillo
2026-10-28  5:51 ` [PATCH v2 06/12] ide: Refuse an ATAPI block size atapi_read() cannot read Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` Ana Bobillo [this message]
2026-10-28  5:51 ` [PATCH v2 08/12] block: Refuse a device with an unsupported block size Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` [PATCH v2 09/12] disk: part_efi: Check the header and entry sizes of a GPT Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:51 ` [PATCH v2 10/12] disk: part_dos: Walk the extended partition tables in a bounded loop Ana Bobillo
2026-10-28  8:56   ` Simon Glass
2026-10-28  5:52 ` [PATCH v2 11/12] disk: part_dos: Make room for a three-digit partition number in the UUID Ana Bobillo
2026-10-28  5:52 ` [PATCH v2 12/12] efi_loader: Measure the GPT the partition driver uses Ana Bobillo
2026-10-28  8:57   ` Simon Glass
2026-10-28  9:32     ` Ana Bobillo

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=5bdc9bbe-e232-49c1-a1cb-d79d952ad6c8@gmail.com \
    --to=anabobillo3@gmail.com \
    --cc=alchark@flipper.net \
    --cc=bmeng.cn@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=javierm@redhat.com \
    --cc=marek.vasut+usb@mailbox.org \
    --cc=neil.armstrong@linaro.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=xypron.glpk@gmx.de \
    /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