Skip to content

Commit 6acd7d5

Browse files
committed
libnvdimm/namespace: Enforce memremap_compat_align()
The pmem driver on PowerPC crashes with the following signature when instantiating misaligned namespaces that map their capacity via memremap_pages(). BUG: Unable to handle kernel data access at 0xc001000406000000 Faulting instruction address: 0xc000000000090790 NIP [c000000000090790] arch_add_memory+0xc0/0x130 LR [c000000000090744] arch_add_memory+0x74/0x130 Call Trace: arch_add_memory+0x74/0x130 (unreliable) memremap_pages+0x74c/0xa30 devm_memremap_pages+0x3c/0xa0 pmem_attach_disk+0x188/0x770 nvdimm_bus_probe+0xd8/0x470 With the assumption that only memremap_pages() has alignment constraints, enforce memremap_compat_align() for pmem_should_map_pages(), nd_pfn, and nd_dax cases. This includes preventing the creation of namespaces where the base address is misaligned and cases there infoblock padding parameters are invalid. Reported-by: Aneesh Kumar K.V <[email protected]> Cc: Jeff Moyer <[email protected]> Fixes: a361919 ("libnvdimm/pfn: stop padding pmem namespaces to section alignment") Reviewed-by: Aneesh Kumar K.V <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent b2ba7e9 commit 6acd7d5

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

drivers/nvdimm/namespace_devs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/nd.h>
1111
#include "nd-core.h"
1212
#include "pmem.h"
13+
#include "pfn.h"
1314
#include "nd.h"
1415

1516
static void namespace_io_release(struct device *dev)
@@ -1739,6 +1740,22 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
17391740
return ERR_PTR(-ENODEV);
17401741
}
17411742

1743+
/*
1744+
* Note, alignment validation for fsdax and devdax mode
1745+
* namespaces happens in nd_pfn_validate() where infoblock
1746+
* padding parameters can be applied.
1747+
*/
1748+
if (pmem_should_map_pages(dev)) {
1749+
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
1750+
struct resource *res = &nsio->res;
1751+
1752+
if (!IS_ALIGNED(res->start | (res->end + 1),
1753+
memremap_compat_align())) {
1754+
dev_err(&ndns->dev, "%pr misaligned, unable to map\n", res);
1755+
return ERR_PTR(-EOPNOTSUPP);
1756+
}
1757+
}
1758+
17421759
if (is_namespace_pmem(&ndns->dev)) {
17431760
struct nd_namespace_pmem *nspm;
17441761

drivers/nvdimm/pfn.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ struct nd_pfn_sb {
2424
__le64 npfns;
2525
__le32 mode;
2626
/* minor-version-1 additions for section alignment */
27+
/**
28+
* @start_pad: Deprecated attribute to pad start-misaligned namespaces
29+
*
30+
* start_pad is deprecated because the original definition did
31+
* not comprehend that dataoff is relative to the base address
32+
* of the namespace not the start_pad adjusted base. The result
33+
* is that the dax path is broken, but the block-I/O path is
34+
* not. The kernel will no longer create namespaces using start
35+
* padding, but it still supports block-I/O for legacy
36+
* configurations mainly to allow a backup, reconfigure the
37+
* namespace, and restore flow to repair dax operation.
38+
*/
2739
__le32 start_pad;
2840
__le32 end_trunc;
2941
/* minor-version-2 record the base alignment of the mapping */

drivers/nvdimm/pfn_devs.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ static bool nd_supported_alignment(unsigned long align)
446446
int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
447447
{
448448
u64 checksum, offset;
449+
struct resource *res;
449450
enum nd_pfn_mode mode;
450451
struct nd_namespace_io *nsio;
451452
unsigned long align, start_pad;
@@ -578,20 +579,33 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
578579
* established.
579580
*/
580581
nsio = to_nd_namespace_io(&ndns->dev);
581-
if (offset >= resource_size(&nsio->res)) {
582+
res = &nsio->res;
583+
if (offset >= resource_size(res)) {
582584
dev_err(&nd_pfn->dev, "pfn array size exceeds capacity of %s\n",
583585
dev_name(&ndns->dev));
584586
return -EOPNOTSUPP;
585587
}
586588

587-
if ((align && !IS_ALIGNED(nsio->res.start + offset + start_pad, align))
589+
if ((align && !IS_ALIGNED(res->start + offset + start_pad, align))
588590
|| !IS_ALIGNED(offset, PAGE_SIZE)) {
589591
dev_err(&nd_pfn->dev,
590592
"bad offset: %#llx dax disabled align: %#lx\n",
591593
offset, align);
592594
return -EOPNOTSUPP;
593595
}
594596

597+
if (!IS_ALIGNED(res->start + le32_to_cpu(pfn_sb->start_pad),
598+
memremap_compat_align())) {
599+
dev_err(&nd_pfn->dev, "resource start misaligned\n");
600+
return -EOPNOTSUPP;
601+
}
602+
603+
if (!IS_ALIGNED(res->end + 1 - le32_to_cpu(pfn_sb->end_trunc),
604+
memremap_compat_align())) {
605+
dev_err(&nd_pfn->dev, "resource end misaligned\n");
606+
return -EOPNOTSUPP;
607+
}
608+
595609
return 0;
596610
}
597611
EXPORT_SYMBOL(nd_pfn_validate);
@@ -750,7 +764,19 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
750764
start = nsio->res.start;
751765
size = resource_size(&nsio->res);
752766
npfns = PHYS_PFN(size - SZ_8K);
753-
align = max(nd_pfn->align, SUBSECTION_SIZE);
767+
align = max(nd_pfn->align, memremap_compat_align());
768+
769+
/*
770+
* When @start is misaligned fail namespace creation. See
771+
* the 'struct nd_pfn_sb' commentary on why ->start_pad is not
772+
* an option.
773+
*/
774+
if (!IS_ALIGNED(start, memremap_compat_align())) {
775+
dev_err(&nd_pfn->dev, "%s: start %pa misaligned to %#lx\n",
776+
dev_name(&ndns->dev), &start,
777+
memremap_compat_align());
778+
return -EINVAL;
779+
}
754780
end_trunc = start + size - ALIGN_DOWN(start + size, align);
755781
if (nd_pfn->mode == PFN_MODE_PMEM) {
756782
/*

0 commit comments

Comments
 (0)