linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] update label size handlings per UEFI 2.7
@ 2018-02-23 21:59 Toshi Kani
  2018-02-23 21:59 ` [PATCH 1/2] libnvdimm, label: change min label storage size " Toshi Kani
  2018-02-23 21:59 ` [PATCH 2/2] libnvdimm, label: change nvdimm_num_label_slots " Toshi Kani
  0 siblings, 2 replies; 3+ messages in thread
From: Toshi Kani @ 2018-02-23 21:59 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm, linux-kernel

This patchset updates label storage size check and index block size
calculation according to UEFI 2.7 spec.

---
Toshi Kani (2):
 1/2 libnvdimm, label: change min label storage size per UEFI 2.7
 2/2 libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7

---
 drivers/nvdimm/label.c | 34 ++++++++++++++++++++++++----------
 drivers/nvdimm/label.h |  2 +-
 2 files changed, 25 insertions(+), 11 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] libnvdimm, label: change min label storage size per UEFI 2.7
  2018-02-23 21:59 [PATCH 0/2] update label size handlings per UEFI 2.7 Toshi Kani
@ 2018-02-23 21:59 ` Toshi Kani
  2018-02-23 21:59 ` [PATCH 2/2] libnvdimm, label: change nvdimm_num_label_slots " Toshi Kani
  1 sibling, 0 replies; 3+ messages in thread
From: Toshi Kani @ 2018-02-23 21:59 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm, linux-kernel, Toshi Kani

UEFI 2.7 defines in page 758 that:

  Initial Label Storage Area Configuration
     :
  The minimum size of the Label Storage Area is large enough to
  hold 2 index blocks and 2 labels.

The mininum index block size is 256 bytes, and the minimum label size
is also 256 bytes.

Change ND_LABEL_MIN_SIZE to (256 * 4) so that NVDIMM devices with
the minimum label storage area do not fail with the size check in
nvdimm_init_config_data().

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Dan Williams <dan.j.williams@intel.com>
---
 drivers/nvdimm/label.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvdimm/label.h b/drivers/nvdimm/label.h
index 1ebf4d3d01ba..18bbe183b3a9 100644
--- a/drivers/nvdimm/label.h
+++ b/drivers/nvdimm/label.h
@@ -33,7 +33,7 @@ enum {
 	BTTINFO_UUID_LEN = 16,
 	BTTINFO_FLAG_ERROR = 0x1,    /* error state (read-only) */
 	BTTINFO_MAJOR_VERSION = 1,
-	ND_LABEL_MIN_SIZE = 512 * 129, /* see sizeof_namespace_index() */
+	ND_LABEL_MIN_SIZE = 256 * 4, /* see sizeof_namespace_index() */
 	ND_LABEL_ID_SIZE = 50,
 	ND_NSINDEX_INIT = 0x1,
 };

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7
  2018-02-23 21:59 [PATCH 0/2] update label size handlings per UEFI 2.7 Toshi Kani
  2018-02-23 21:59 ` [PATCH 1/2] libnvdimm, label: change min label storage size " Toshi Kani
@ 2018-02-23 21:59 ` Toshi Kani
  1 sibling, 0 replies; 3+ messages in thread
From: Toshi Kani @ 2018-02-23 21:59 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm, linux-kernel, Toshi Kani

sizeof_namespace_index() fails when NVDIMM devices have the minimum
1024 bytes label storage area.  nvdimm_num_label_slots() returns 3
slots while the area is only big enough for 2 slots.

Change nvdimm_num_label_slots() to calculate a number of label slots
according to UEFI 2.7 spec.

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Dan Williams <dan.j.williams@intel.com>
---
 drivers/nvdimm/label.c |   34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c
index de66c02f6140..be3ccf7c5413 100644
--- a/drivers/nvdimm/label.c
+++ b/drivers/nvdimm/label.c
@@ -45,9 +45,27 @@ unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd)
 	return ndd->nslabel_size;
 }
 
+static size_t __sizeof_namespace_index(u32 nslot)
+{
+	return ALIGN(sizeof(struct nd_namespace_index) + DIV_ROUND_UP(nslot, 8),
+			NSINDEX_ALIGN);
+}
+
+static int __nvdimm_num_label_slots(struct nvdimm_drvdata *ndd,
+		size_t index_size)
+{
+	return (ndd->nsarea.config_size - index_size * 2) /
+			sizeof_namespace_label(ndd);
+}
+
 int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd)
 {
-	return ndd->nsarea.config_size / (sizeof_namespace_label(ndd) + 1);
+	u32 tmp_nslot, n;
+
+	tmp_nslot = ndd->nsarea.config_size / sizeof_namespace_label(ndd);
+	n = __sizeof_namespace_index(tmp_nslot) / NSINDEX_ALIGN;
+
+	return __nvdimm_num_label_slots(ndd, NSINDEX_ALIGN * n);
 }
 
 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd)
@@ -55,18 +73,14 @@ size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd)
 	u32 nslot, space, size;
 
 	/*
-	 * The minimum index space is 512 bytes, with that amount of
-	 * index we can describe ~1400 labels which is less than a byte
-	 * of overhead per label.  Round up to a byte of overhead per
-	 * label and determine the size of the index region.  Yes, this
-	 * starts to waste space at larger config_sizes, but it's
-	 * unlikely we'll ever see anything but 128K.
+	 * Per UEFI 2.7, the minimum size of the Label Storage Area is large
+	 * enough to hold 2 index blocks and 2 labels.  The minimum index
+	 * block size is 256 bytes, and the minimum label size is 256 bytes.
 	 */
 	nslot = nvdimm_num_label_slots(ndd);
 	space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd);
-	size = ALIGN(sizeof(struct nd_namespace_index) + DIV_ROUND_UP(nslot, 8),
-			NSINDEX_ALIGN) * 2;
-	if (size <= space)
+	size = __sizeof_namespace_index(nslot) * 2;
+	if (size <= space && nslot >= 2)
 		return size / 2;
 
 	dev_err(ndd->dev, "label area (%d) too small to host (%d byte) labels\n",

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-23 21:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-23 21:59 [PATCH 0/2] update label size handlings per UEFI 2.7 Toshi Kani
2018-02-23 21:59 ` [PATCH 1/2] libnvdimm, label: change min label storage size " Toshi Kani
2018-02-23 21:59 ` [PATCH 2/2] libnvdimm, label: change nvdimm_num_label_slots " Toshi Kani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).