Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Thumshirn <jthumshirn@suse.de>2018-10-31 10:48:30 +0100
committerJohannes Thumshirn <jthumshirn@suse.de>2018-10-31 10:48:39 +0100
commita32f30eeb4929e2a2833731104196f3b2dd20402 (patch)
tree318f7d97320765bf6189bd2c557097440e320ba3
parentff2e99796c256bccd6f0e0367227ca8f02932ba8 (diff)
libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7
(bsc#1111921, bsc#1113408, FATE#326765).
-rw-r--r--patches.fixes/libnvdimm-label-change-nvdimm_num_label_slots-per-uefi-2-7.patch79
-rw-r--r--series.conf1
2 files changed, 80 insertions, 0 deletions
diff --git a/patches.fixes/libnvdimm-label-change-nvdimm_num_label_slots-per-uefi-2-7.patch b/patches.fixes/libnvdimm-label-change-nvdimm_num_label_slots-per-uefi-2-7.patch
new file mode 100644
index 0000000000..af631470b8
--- /dev/null
+++ b/patches.fixes/libnvdimm-label-change-nvdimm_num_label_slots-per-uefi-2-7.patch
@@ -0,0 +1,79 @@
+From: Toshi Kani <toshi.kani@hpe.com>
+Date: Fri, 23 Feb 2018 14:59:22 -0700
+Subject: libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7
+Git-commit: 9e694d9c18dde0fa57ec067043b581bd57c9fb65
+Patch-mainline: v4.17-rc1
+References: bsc#1111921, bsc#1113408, FATE#326765
+
+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>
+Signed-off-by: Dan Williams <dan.j.williams@intel.com>
+Acked-by: Johannes Thumshirn <jthumshirn@suse.de>
+---
+ 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 c858cfadea40..1d28cd656536 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",
+
diff --git a/series.conf b/series.conf
index cae809f419..cb10fce04b 100644
--- a/series.conf
+++ b/series.conf
@@ -14980,6 +14980,7 @@
patches.drivers/rtc-hctosys-Ensure-system-time-doesn-t-overflow-time
patches.drivers/rtc-snvs-Fix-usage-of-snvs_rtc_enable
patches.drivers/libnvdimm-label-change-min-label-storage-size-per-uefi-2.7.patch
+ patches.fixes/libnvdimm-label-change-nvdimm_num_label_slots-per-uefi-2-7.patch
patches.drivers/nfit-skip-region-registration-for-incomplete-control-regions.patch
patches.fixes/0001-acpi-nfit-rework-NVDIMM-leaf-method-detection.patch
patches.drivers/nfit-fix-region-registration-vs-block-data-window-ra