Skip to contentSkip to conversation

libnvdimm: Fix altmap reservation size calculation

PATCH In review Oliver O'Halloran 3 participants 4 messages Feb 6, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnvdimm: Fix altmap reservation size calculation

Libnvdimm reserves the first 8K of pfn and devicedax namespaces to store a superblock describing the namespace. This 8K reservation is contained within the altmap area which the kernel uses for the vmemmap backing for the pages within the namespace. The altmap allows for some pages at the start of the altmap area to be reserved and that mechanism is used to protect the superblock from being re-used as vmemmap backing.

The number of PFNs to reserve is calculated using:

	PHYS_PFN(SZ_8K)

Which is implemented as:

#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))

So on systems where PAGE_SIZE is greater than 8K the reservation size is truncated to zero and the superblock area is re-used as vmemmap backing. As a result all the namespace information stored in the superblock (i.e. if it's a PFN or DAX namespace) is lost and the namespace needs to be re-created to get access to the contents.

This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure that at least one page is reserved. On systems with a 4K pages size this patch should have no effect.

Cc Dan Williams <[email protected]>
Fixes ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core")

---

---
 drivers/nvdimm/pfn_devs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/pfn_devs.c +1 -1
index 6f22272e8d80..9b9be83da0e7 100644
@@ -593,7 +593,7 @@ static unsigned long init_altmap_base(resource_size_t base)
 
 static unsigned long init_altmap_reserve(resource_size_t base)
 {
-	unsigned long reserve = PHYS_PFN(SZ_8K);
+	unsigned long reserve = PFN_UP(SZ_8K);
 	unsigned long base_pfn = PHYS_PFN(base);
 
 	reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn);
Signature · 6 lines
2.20.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Oliver O'Halloran

Libnvdimm reserves the first 8K of pfn and devicedax namespaces to store a superblock describing the namespace. This 8K reservation is contained within the altmap area which the kernel uses for the vmemmap backing for the pages within the namespace. The altmap allows for some pages at the start of the altmap area to be reserved and that mechanism is used to protect the superblock from being re-used as vmemmap backing.

The number of PFNs to reserve is calculated using:

	PHYS_PFN(SZ_8K)

Which is implemented as:

#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))

So on systems where PAGE_SIZE is greater than 8K the reservation size is truncated to zero and the superblock area is re-used as vmemmap backing. As a result all the namespace information stored in the superblock (i.e. if it's a PFN or DAX namespace) is lost and the namespace needs to be re-created to get access to the contents.

This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure that at least one page is reserved. On systems with a 4K pages size this patch should have no effect.

Quoted 8 lines
Cc Dan Williams <[email protected]>
Fixes ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core")

---

---
 drivers/nvdimm/pfn_devs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Looks good to me,

Quoted 6 lines
drivers/nvdimm/pfn_devs.c +0 -0
index 6f22272e8d80..9b9be83da0e7 100644

drivers/nvdimm/pfn_devs.c static unsigned long init_altmap_base(resource_size_t base) · line 599

Quoted 8 lines
drivers/nvdimm/pfn_devs.c +1 -1
@@ -593,7 +593,7 @@ static unsigned long init_altmap_base(resource_size_t base)
 
 static unsigned long init_altmap_reserve(resource_size_t base)
 {
-	unsigned long reserve = PHYS_PFN(SZ_8K);
+	unsigned long reserve = PFN_UP(SZ_8K);
 	unsigned long base_pfn = PHYS_PFN(base);
 
 	reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn);

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
In reply to Oliver O'Halloran
Quoted 42 lines · Oliver O'Halloran

Libnvdimm reserves the first 8K of pfn and devicedax namespaces to store a superblock describing the namespace. This 8K reservation is contained within the altmap area which the kernel uses for the vmemmap backing for the pages within the namespace. The altmap allows for some pages at the start of the altmap area to be reserved and that mechanism is used to protect the superblock from being re-used as vmemmap backing.

The number of PFNs to reserve is calculated using:

        PHYS_PFN(SZ_8K)

Which is implemented as:

#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))

So on systems where PAGE_SIZE is greater than 8K the reservation size is truncated to zero and the superblock area is re-used as vmemmap backing. As a result all the namespace information stored in the superblock (i.e. if it's a PFN or DAX namespace) is lost and the namespace needs to be re-created to get access to the contents.

This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure that at least one page is reserved. On systems with a 4K pages size this patch should have no effect.

Cc Dan Williams <[email protected]>
Fixes ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core")

---

---
 drivers/nvdimm/pfn_devs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/pfn_devs.c +0 -0
index 6f22272e8d80..9b9be83da0e7 100644

drivers/nvdimm/pfn_devs.c static unsigned long init_altmap_base(resource_size_t base) · line 597

Quoted 6 lines
drivers/nvdimm/pfn_devs.c +1 -1
@@ -593,7 +593,7 @@ static unsigned long init_altmap_base(resource_size_t base)
 
 static unsigned long init_altmap_reserve(resource_size_t base)
 {
-       unsigned long reserve = PHYS_PFN(SZ_8K);
+       unsigned long reserve = PFN_UP(SZ_8K);
        unsigned long base_pfn = PHYS_PFN(base);

Good find. I know how annoying it is to debug altmap issues.

I'll get this queued up.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw
Quoted 53 lines · Dan Williams
Quoted 42 lines · Oliver O'Halloran

Libnvdimm reserves the first 8K of pfn and devicedax namespaces to store a superblock describing the namespace. This 8K reservation is contained within the altmap area which the kernel uses for the vmemmap backing for the pages within the namespace. The altmap allows for some pages at the start of the altmap area to be reserved and that mechanism is used to protect the superblock from being re-used as vmemmap backing.

The number of PFNs to reserve is calculated using:

        PHYS_PFN(SZ_8K)

Which is implemented as:

#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))

So on systems where PAGE_SIZE is greater than 8K the reservation size is truncated to zero and the superblock area is re-used as vmemmap backing. As a result all the namespace information stored in the superblock (i.e. if it's a PFN or DAX namespace) is lost and the namespace needs to be re-created to get access to the contents.

This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure that at least one page is reserved. On systems with a 4K pages size this patch should have no effect.

Cc Dan Williams <[email protected]>
Fixes ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core")

---

---
 drivers/nvdimm/pfn_devs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/pfn_devs.c +0 -0
index 6f22272e8d80..9b9be83da0e7 100644

drivers/nvdimm/pfn_devs.c static unsigned long init_altmap_base(resource_size_t base) · line 597

Quoted 6 lines
drivers/nvdimm/pfn_devs.c +1 -1
@@ -593,7 +593,7 @@ static unsigned long init_altmap_base(resource_size_t base)
 
 static unsigned long init_altmap_reserve(resource_size_t base)
 {
-       unsigned long reserve = PHYS_PFN(SZ_8K);
+       unsigned long reserve = PFN_UP(SZ_8K);
        unsigned long base_pfn = PHYS_PFN(base);

Good find. I know how annoying it is to debug altmap issues.

Quoted 1 line

I'll get this queued up.

Hmm, this consideration should also be included in the data_offset calculation. I'll take a look.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm