All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shyam Saini <shyamsaini@linux.microsoft.com>
To: nvdimm@lists.linux.dev
Cc: vishal.l.verma@intel.com, dave.jiang@intel.com,
	alison.schofield@intel.com, iweiny@kernel.org,
	tgopinath@linux.microsoft.com, bboscaccy@linux.microsoft.com,
	srivatsa@csail.mit.edu
Subject: [RFC PATCH] drivers: nvdimm: validate dataoffset
Date: Tue, 13 Oct 2026 19:04:30 -0700	[thread overview]
Message-ID: <20261014020430.295282-1-shyamsaini@linux.microsoft.com> (raw)

On some platforms cold reboot may not zero out DRAM and
as a consequence, the next kernel boot with a new pmem layout
change may end up using stale superblocks. This can cause
altmap to run out of memory and consequently the pmem drivers
may fail to probe.

    failed to free all reserved pages
   [trimmed]
    Call trace:
     memunmap_pages+0x2f8/0x358
     memremap_pages+0x590/0x728
     devm_memremap_pages+0x30/0x88
     pmem_attach_disk+0x178/0x488
     nd_pmem_probe+0x60/0xe0
     nvdimm_bus_probe+0xec/0x208
     really_probe+0xc0/0x2e8
     __driver_probe_device+0xc4/0x168
     driver_probe_device+0x48/0x218
     __device_attach_driver+0x130/0x160
     bus_for_each_drv+0x94/0xf0
     __device_attach+0xfc/0x1a0
     device_initial_probe+0x18/0x28
     bus_probe_device+0x40/0xa0
     device_add+0x270/0x498
     nd_async_device_register+0x20/0x70
     async_run_entry_fn+0x30/0x158
     process_scheduled_works+0x248/0x4b0
     worker_thread+0x284/0x3a0
     kthread+0xe0/0x180
     ret_from_fork+0x10/0x20
    ---[ end trace 0000000000000000 ]---
    nd_pmem: probe of pfnX.1 failed with error -12

Fix this by discarding superblock if there is a mismatch b/w
dataoffset value from the preserved superblock and the
dataoffset from the resource.

While this fix is not robust but it can be combined with userspace
namespace destruction and recreation to remove all the stale pmems
metadata and reconfigure the fresh data using ndctl

Signed-off-by: Shyam Saini <shyamsaini@linux.microsoft.com>
---
 drivers/nvdimm/pfn_devs.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
index 8fa9c16aba7ea..667115ce88e40 100644
--- a/drivers/nvdimm/pfn_devs.c
+++ b/drivers/nvdimm/pfn_devs.c
@@ -439,12 +439,12 @@ static bool nd_supported_alignment(unsigned long align)
  */
 int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 {
-	u64 checksum, offset;
+	u64 checksum, offset, offset_res;
 	struct resource *res;
 	enum nd_pfn_mode mode;
-	resource_size_t res_size;
+	resource_size_t res_start, res_size;
 	struct nd_namespace_io *nsio;
-	unsigned long align, start_pad, end_trunc;
+	unsigned long align, start_pad, end_trunc, npfns;
 	struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
 	struct nd_namespace_common *ndns = nd_pfn->ndns;
 	const uuid_t *parent_uuid = nd_dev_to_uuid(&ndns->dev);
@@ -577,6 +577,12 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
 	nsio = to_nd_namespace_io(&ndns->dev);
 	res = &nsio->res;
 	res_size = resource_size(res);
+	res_start = res->start;
+	npfns = PHYS_PFN(res_size - SZ_8K);
+	offset_res = ALIGN(res_start + SZ_8K + (MAX_STRUCT_PAGE_SIZE * npfns), align) - res_start;
+	if ((mode == PFN_MODE_PMEM) && offset_res != offset)
+		return -ENODEV;
+
 	if (offset >= res_size) {
 		dev_err(&nd_pfn->dev, "pfn array size exceeds capacity of %s\n",
 				dev_name(&ndns->dev));
-- 
2.43.0


             reply	other threads:[~2026-10-14  2:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  2:04 Shyam Saini [this message]
2026-10-14  2:21 ` [RFC PATCH] drivers: nvdimm: validate dataoffset sashiko-bot

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=20261014020430.295282-1-shyamsaini@linux.microsoft.com \
    --to=shyamsaini@linux.microsoft.com \
    --cc=alison.schofield@intel.com \
    --cc=bboscaccy@linux.microsoft.com \
    --cc=dave.jiang@intel.com \
    --cc=iweiny@kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=srivatsa@csail.mit.edu \
    --cc=tgopinath@linux.microsoft.com \
    --cc=vishal.l.verma@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.