]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.31/libnvdimm-fix-altmap-reservation-size-calculation.patch
Linux 4.19.31
[thirdparty/kernel/stable-queue.git] / releases / 4.19.31 / libnvdimm-fix-altmap-reservation-size-calculation.patch
CommitLineData
489cd451
GKH
1From 07464e88365e9236febaca9ed1a2e2006d8bc952 Mon Sep 17 00:00:00 2001
2From: Oliver O'Halloran <oohall@gmail.com>
3Date: Wed, 6 Feb 2019 13:04:53 +1100
4Subject: libnvdimm: Fix altmap reservation size calculation
5
6From: Oliver O'Halloran <oohall@gmail.com>
7
8commit 07464e88365e9236febaca9ed1a2e2006d8bc952 upstream.
9
10Libnvdimm reserves the first 8K of pfn and devicedax namespaces to
11store a superblock describing the namespace. This 8K reservation
12is contained within the altmap area which the kernel uses for the
13vmemmap backing for the pages within the namespace. The altmap
14allows for some pages at the start of the altmap area to be reserved
15and that mechanism is used to protect the superblock from being
16re-used as vmemmap backing.
17
18The number of PFNs to reserve is calculated using:
19
20 PHYS_PFN(SZ_8K)
21
22Which is implemented as:
23
24 #define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))
25
26So on systems where PAGE_SIZE is greater than 8K the reservation
27size is truncated to zero and the superblock area is re-used as
28vmemmap backing. As a result all the namespace information stored
29in the superblock (i.e. if it's a PFN or DAX namespace) is lost
30and the namespace needs to be re-created to get access to the
31contents.
32
33This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure
34that at least one page is reserved. On systems with a 4K pages size this
35patch should have no effect.
36
37Cc: stable@vger.kernel.org
38Cc: Dan Williams <dan.j.williams@intel.com>
39Fixes: ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core")
40Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
41Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
42Signed-off-by: Dan Williams <dan.j.williams@intel.com>
43Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
44
45---
46 drivers/nvdimm/pfn_devs.c | 2 +-
47 1 file changed, 1 insertion(+), 1 deletion(-)
48
49--- a/drivers/nvdimm/pfn_devs.c
50+++ b/drivers/nvdimm/pfn_devs.c
51@@ -534,7 +534,7 @@ static unsigned long init_altmap_base(re
52
53 static unsigned long init_altmap_reserve(resource_size_t base)
54 {
55- unsigned long reserve = PHYS_PFN(SZ_8K);
56+ unsigned long reserve = PFN_UP(SZ_8K);
57 unsigned long base_pfn = PHYS_PFN(base);
58
59 reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn);