]>
Commit | Line | Data |
---|---|---|
e6dde9d2 GKH |
1 | From 07464e88365e9236febaca9ed1a2e2006d8bc952 Mon Sep 17 00:00:00 2001 |
2 | From: Oliver O'Halloran <oohall@gmail.com> | |
3 | Date: Wed, 6 Feb 2019 13:04:53 +1100 | |
4 | Subject: libnvdimm: Fix altmap reservation size calculation | |
5 | ||
6 | From: Oliver O'Halloran <oohall@gmail.com> | |
7 | ||
8 | commit 07464e88365e9236febaca9ed1a2e2006d8bc952 upstream. | |
9 | ||
10 | Libnvdimm reserves the first 8K of pfn and devicedax namespaces to | |
11 | store a superblock describing the namespace. This 8K reservation | |
12 | is contained within the altmap area which the kernel uses for the | |
13 | vmemmap backing for the pages within the namespace. The altmap | |
14 | allows for some pages at the start of the altmap area to be reserved | |
15 | and that mechanism is used to protect the superblock from being | |
16 | re-used as vmemmap backing. | |
17 | ||
18 | The number of PFNs to reserve is calculated using: | |
19 | ||
20 | PHYS_PFN(SZ_8K) | |
21 | ||
22 | Which is implemented as: | |
23 | ||
24 | #define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT)) | |
25 | ||
26 | So on systems where PAGE_SIZE is greater than 8K the reservation | |
27 | size is truncated to zero and the superblock area is re-used as | |
28 | vmemmap backing. As a result all the namespace information stored | |
29 | in the superblock (i.e. if it's a PFN or DAX namespace) is lost | |
30 | and the namespace needs to be re-created to get access to the | |
31 | contents. | |
32 | ||
33 | This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure | |
34 | that at least one page is reserved. On systems with a 4K pages size this | |
35 | patch should have no effect. | |
36 | ||
37 | Cc: stable@vger.kernel.org | |
38 | Cc: Dan Williams <dan.j.williams@intel.com> | |
39 | Fixes: ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core") | |
40 | Signed-off-by: Oliver O'Halloran <oohall@gmail.com> | |
41 | Reviewed-by: Vishal Verma <vishal.l.verma@intel.com> | |
42 | Signed-off-by: Dan Williams <dan.j.williams@intel.com> | |
43 | Signed-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 | @@ -593,7 +593,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); |