nvdimm/pmem: propagate personality discovery errors
Subsystems (3)
PATCH v2 1/1 nvdimm/pmem: propagate personality discovery errors
nd_pmem_probe() ignores errors from BTT discovery and only propagates -EOPNOTSUPP from PFN and DAX discovery. Allocation failures can therefore be mistaken for an absent personality, allowing a namespace to fall back to raw PMEM.
Report -ENOMEM when allocating the BTT, PFN, or DAX info-block buffer fails, retaining the existing device cleanup paths. Propagate discovery errors other than -ENODEV and -ENXIO, and keep raw-PMEM fallback for those two error codes.
---
v2:
- return -ENOMEM for BTT, PFN, and DAX superblock buffer allocation failures, retaining the existing cleanup paths
- correct/clarify the comment describing raw-PMEM fallback and namespace-seed advancement
- rebase to v7.4-rc1
drivers/nvdimm/btt_devs.c | 4 +++- drivers/nvdimm/dax_devs.c | 4 +++- drivers/nvdimm/pfn_devs.c | 4 +++- drivers/nvdimm/pmem.c | 19 ++++++++----------- 4 files changed, 17 insertions(+), 14 deletions(-)
drivers/nvdimm/btt_devs.c +3 -1
@@ -349,7 +349,9 @@ int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns)if (!btt_dev)return -ENOMEM ; btt_sb =devm_kzalloc (dev,sizeof (*btt_sb),GFP_KERNEL ); - rc =__nd_btt_probe (to_nd_btt (btt_dev), ndns, btt_sb); + rc = -ENOMEM ; +if (btt_sb) + rc =__nd_btt_probe (to_nd_btt (btt_dev), ndns, btt_sb);dev_dbg (dev,"btt: %s\n" , rc ==0 ?dev_name (btt_dev) :"<none>" );if (rc <0 ) {struct nd_btt *nd_btt =to_nd_btt (btt_dev);
drivers/nvdimm/dax_devs.c +3 -1
@@ -113,7 +113,9 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) pfn_sb =devm_kmalloc (dev,sizeof (*pfn_sb),GFP_KERNEL ); nd_pfn = &nd_dax->nd_pfn; nd_pfn->pfn_sb = pfn_sb; - rc =nd_pfn_validate (nd_pfn,DAX_SIG ); + rc = -ENOMEM ; +if (pfn_sb) + rc =nd_pfn_validate (nd_pfn,DAX_SIG );dev_dbg (dev,"dax: %s\n" , rc ==0 ?dev_name (dax_dev) :"<none>" );if (rc <0 ) {nd_detach_ndns (dax_dev, &nd_pfn->ndns);
drivers/nvdimm/pfn_devs.c +3 -1
@@ -637,7 +637,9 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns) pfn_sb =devm_kmalloc (dev,sizeof (*pfn_sb),GFP_KERNEL ); nd_pfn =to_nd_pfn (pfn_dev); nd_pfn->pfn_sb = pfn_sb; - rc =nd_pfn_validate (nd_pfn,PFN_SIG ); + rc = -ENOMEM ; +if (pfn_sb) + rc =nd_pfn_validate (nd_pfn,PFN_SIG );dev_dbg (dev,"pfn: %s\n" , rc ==0 ?dev_name (pfn_dev) :"<none>" );if (rc <0 ) {nd_detach_ndns (pfn_dev, &nd_pfn->ndns);
drivers/nvdimm/pmem.c +8 -11
@@ -632,28 +632,25 @@ static int nd_pmem_probe(struct device *dev) ret =nd_btt_probe (dev, ndns);if (ret ==0 )return -ENXIO ; +else if (ret != -ENODEV && ret != -ENXIO ) +return ret;/* -* We have two failure conditions here, there is no -* info reserver block or we found a valid info reserve block -* but failed to initialize the pfn superblock. -* -* For the first case consider namespace as a raw pmem namespace -* and attach a disk. -* -* For the latter, consider this a success and advance the namespace -* seed. +* An absent or unreadable PFN/DAX info block allows probing the +* next personality or falling back to raw PMEM. Other errors +* are propagated, including -EOPNOTSUPP, which causes +* nvdimm_bus_probe() to advance the namespace seed. */ ret =nd_pfn_probe (dev, ndns);if (ret ==0 )return -ENXIO ; -else if (ret == -EOPNOTSUPP ) +else if (ret != -ENODEV && ret != -ENXIO )return ret; ret =nd_dax_probe (dev, ndns);if (ret ==0 )return -ENXIO ; -else if (ret == -EOPNOTSUPP ) +else if (ret != -ENODEV && ret != -ENXIO )return ret;/* probe complete, attach handles namespace enabling */
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.43.0
Alison Schofield
maintainerQuoted 9 lines · Avi Weiss
nd_pmem_probe()ignores errors from BTT discovery and only propagates-EOPNOTSUPPfrom PFN and DAX discovery. Allocation failures can therefore be mistaken for an absent personality, allowing a namespace to fall back to raw PMEM.Report
-ENOMEMwhen allocating the BTT, PFN, or DAX info-block buffer fails, retaining the existing device cleanup paths. Propagate discovery errors other than-ENODEVand-ENXIO, and keep raw-PMEM fallback for those two error codes.
Hi Avi,
Thanks for the updates from v1.
This has checkpatch errors, trailing whitespace, and renders some code dead, so it'll need another rev. Please go ahead and rebase on 7.4-rc5. I had a conflict applying your rc1 based version because there were tree-wide changes to the devm_kalloc helpers in rc2.
FYI - 4dd10fbbeb9c treewide: Convert devm_kmalloc() family to the devm_kmalloc_obj() family
Quoted 23 lines
Fixes 8c2f7e8658df ("libnvdimm: infrastructure for btt devices")Signed-off-by Avi Weiss <[email protected]>---
v2:
- return-ENOMEMfor BTT, PFN, and DAX superblock buffer allocation failures, retaining the existing cleanup paths
- correct/clarify the comment describing raw-PMEM fallback and namespace-seed advancement
- rebase to v7.4-rc1drivers/nvdimm/btt_devs.c | 4 +++- drivers/nvdimm/dax_devs.c | 4 +++- drivers/nvdimm/pfn_devs.c | 4 +++- drivers/nvdimm/pmem.c | 19 ++++++++----------- 4 files changed, 17 insertions(+), 14 deletions(-)drivers/nvdimm/btt_devs.c +0
-0
drivers/nvdimm/btt_devs.c int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns) · line 354
Quoted 7 lines
drivers/nvdimm/btt_devs.c +3
-1@@ -349,7 +349,9 @@ int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns)if (!btt_dev)return -ENOMEM ; btt_sb =devm_kzalloc (dev,sizeof (*btt_sb),GFP_KERNEL ); - rc =__nd_btt_probe (to_nd_btt (btt_dev), ndns, btt_sb); + rc = -ENOMEM ; +if (btt_sb) + rc =__nd_btt_probe (to_nd_btt (btt_dev), ndns, btt_sb);
This check makes the btt_sb test in __nd_btt_probe() dead code.
The pfn_sb test in nd_pfn_validate() is dead now too.
-- Alison
Quoted 79 lines
drivers/nvdimm/btt_devs.c +0
-0dev_dbg (dev,"btt: %s\n" , rc ==0 ?dev_name (btt_dev) :"<none>" );if (rc <0 ) {struct nd_btt *nd_btt =to_nd_btt (btt_dev);drivers/nvdimm/dax_devs.c +3
-1@@ -113,7 +113,9 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) pfn_sb =devm_kmalloc (dev,sizeof (*pfn_sb),GFP_KERNEL ); nd_pfn = &nd_dax->nd_pfn; nd_pfn->pfn_sb = pfn_sb; - rc =nd_pfn_validate (nd_pfn,DAX_SIG ); + rc = -ENOMEM ; +if (pfn_sb) + rc =nd_pfn_validate (nd_pfn,DAX_SIG );dev_dbg (dev,"dax: %s\n" , rc ==0 ?dev_name (dax_dev) :"<none>" );if (rc <0 ) {nd_detach_ndns (dax_dev, &nd_pfn->ndns);drivers/nvdimm/pfn_devs.c +3
-1@@ -637,7 +637,9 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns) pfn_sb =devm_kmalloc (dev,sizeof (*pfn_sb),GFP_KERNEL ); nd_pfn =to_nd_pfn (pfn_dev); nd_pfn->pfn_sb = pfn_sb; - rc =nd_pfn_validate (nd_pfn,PFN_SIG ); + rc = -ENOMEM ; +if (pfn_sb) + rc =nd_pfn_validate (nd_pfn,PFN_SIG );dev_dbg (dev,"pfn: %s\n" , rc ==0 ?dev_name (pfn_dev) :"<none>" );if (rc <0 ) {nd_detach_ndns (pfn_dev, &nd_pfn->ndns);drivers/nvdimm/pmem.c +8
-11@@ -632,28 +632,25 @@ static int nd_pmem_probe(struct device *dev) ret =nd_btt_probe (dev, ndns);if (ret ==0 )return -ENXIO ; +else if (ret != -ENODEV && ret != -ENXIO ) +return ret;/* -* We have two failure conditions here, there is no -* info reserver block or we found a valid info reserve block -* but failed to initialize the pfn superblock. -* -* For the first case consider namespace as a raw pmem namespace -* and attach a disk. -* -* For the latter, consider this a success and advance the namespace -* seed. +* An absent or unreadable PFN/DAX info block allows probing the +* next personality or falling back to raw PMEM. Other errors +* are propagated, including -EOPNOTSUPP, which causes +* nvdimm_bus_probe() to advance the namespace seed. */ ret =nd_pfn_probe (dev, ndns);if (ret ==0 )return -ENXIO ; -else if (ret == -EOPNOTSUPP ) +else if (ret != -ENODEV && ret != -ENXIO )return ret; ret =nd_dax_probe (dev, ndns);if (ret ==0 )return -ENXIO ; -else if (ret == -EOPNOTSUPP ) +else if (ret != -ENODEV && ret != -ENXIO )return ret;/* probe complete, attach handles namespace enabling */ base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4Signature · 1 line
2.43.0