Skip to content

Commit 26f8c38

Browse files
aeglgregkh
authored andcommitted
x86/mm, mm/hwpoison: Don't unconditionally unmap kernel 1:1 pages
commit fd0e786 upstream. In the following commit: ce0fa3e ("x86/mm, mm/hwpoison: Clear PRESENT bit for kernel 1:1 mappings of poison pages") ... we added code to memory_failure() to unmap the page from the kernel 1:1 virtual address space to avoid speculative access to the page logging additional errors. But memory_failure() may not always succeed in taking the page offline, especially if the page belongs to the kernel. This can happen if there are too many corrected errors on a page and either mcelog(8) or drivers/ras/cec.c asks to take a page offline. Since we remove the 1:1 mapping early in memory_failure(), we can end up with the page unmapped, but still in use. On the next access the kernel crashes :-( There are also various debug paths that call memory_failure() to simulate occurrence of an error. Since there is no actual error in memory, we don't need to map out the page for those cases. Revert most of the previous attempt and keep the solution local to arch/x86/kernel/cpu/mcheck/mce.c. Unmap the page only when: 1) there is a real error 2) memory_failure() succeeds. All of this only applies to 64-bit systems. 32-bit kernel doesn't map all of memory into kernel space. It isn't worth adding the code to unmap the piece that is mapped because nobody would run a 32-bit kernel on a machine that has recoverable machine checks. Signed-off-by: Tony Luck <tony.luck@intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@suse.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave <dave.hansen@intel.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Robert (Persistent Memory) <elliott@hpe.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-mm@kvack.org Cc: stable@vger.kernel.org #v4.14 Fixes: ce0fa3e ("x86/mm, mm/hwpoison: Clear PRESENT bit for kernel 1:1 mappings of poison pages") Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e4ea7c1 commit 26f8c38

5 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎arch/x86/include/asm/page_64.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ static inline void clear_page(void *page)
5252

5353
void copy_page(void *to, void *from);
5454

55-
#ifdef CONFIG_X86_MCE
56-
#define arch_unmap_kpfn arch_unmap_kpfn
57-
#endif
58-
5955
#endif /* !__ASSEMBLY__ */
6056

6157
#ifdef CONFIG_X86_VSYSCALL_EMULATION

‎arch/x86/kernel/cpu/mcheck/mce-internal.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,19 @@ static inline void mce_unregister_injector_chain(struct notifier_block *nb) { }
115115

116116
extern struct mca_config mca_cfg;
117117

118+
#ifndef CONFIG_X86_64
119+
/*
120+
* On 32-bit systems it would be difficult to safely unmap a poison page
121+
* from the kernel 1:1 map because there are no non-canonical addresses that
122+
* we can use to refer to the address without risking a speculative access.
123+
* However, this isn't much of an issue because:
124+
* 1) Few unmappable pages are in the 1:1 map. Most are in HIGHMEM which
125+
* are only mapped into the kernel as needed
126+
* 2) Few people would run a 32-bit kernel on a machine that supports
127+
* recoverable errors because they have too much memory to boot 32-bit.
128+
*/
129+
static inline void mce_unmap_kpfn(unsigned long pfn) {}
130+
#define mce_unmap_kpfn mce_unmap_kpfn
131+
#endif
132+
118133
#endif /* __X86_MCE_INTERNAL_H__ */

‎arch/x86/kernel/cpu/mcheck/mce.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ static struct irq_work mce_irq_work;
106106

107107
static void (*quirk_no_way_out)(int bank, struct mce *m, struct pt_regs *regs);
108108

109+
#ifndef mce_unmap_kpfn
110+
static void mce_unmap_kpfn(unsigned long pfn);
111+
#endif
112+
109113
/*
110114
* CPU/chipset specific EDAC code can register a notifier call here to print
111115
* MCE errors in a human-readable form.
@@ -582,7 +586,8 @@ static int srao_decode_notifier(struct notifier_block *nb, unsigned long val,
582586

583587
if (mce_usable_address(mce) && (mce->severity == MCE_AO_SEVERITY)) {
584588
pfn = mce->addr >> PAGE_SHIFT;
585-
memory_failure(pfn, MCE_VECTOR, 0);
589+
if (memory_failure(pfn, MCE_VECTOR, 0))
590+
mce_unmap_kpfn(pfn);
586591
}
587592

588593
return NOTIFY_OK;
@@ -1049,12 +1054,13 @@ static int do_memory_failure(struct mce *m)
10491054
ret = memory_failure(m->addr >> PAGE_SHIFT, MCE_VECTOR, flags);
10501055
if (ret)
10511056
pr_err("Memory error not recovered");
1057+
else
1058+
mce_unmap_kpfn(m->addr >> PAGE_SHIFT);
10521059
return ret;
10531060
}
10541061

1055-
#if defined(arch_unmap_kpfn) && defined(CONFIG_MEMORY_FAILURE)
1056-
1057-
void arch_unmap_kpfn(unsigned long pfn)
1062+
#ifndef mce_unmap_kpfn
1063+
static void mce_unmap_kpfn(unsigned long pfn)
10581064
{
10591065
unsigned long decoy_addr;
10601066

@@ -1065,7 +1071,7 @@ void arch_unmap_kpfn(unsigned long pfn)
10651071
* We would like to just call:
10661072
* set_memory_np((unsigned long)pfn_to_kaddr(pfn), 1);
10671073
* but doing that would radically increase the odds of a
1068-
* speculative access to the posion page because we'd have
1074+
* speculative access to the poison page because we'd have
10691075
* the virtual address of the kernel 1:1 mapping sitting
10701076
* around in registers.
10711077
* Instead we get tricky. We create a non-canonical address
@@ -1090,7 +1096,6 @@ void arch_unmap_kpfn(unsigned long pfn)
10901096

10911097
if (set_memory_np(decoy_addr, 1))
10921098
pr_warn("Could not invalidate pfn=0x%lx from 1:1 map\n", pfn);
1093-
10941099
}
10951100
#endif
10961101

‎include/linux/mm_inline.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,4 @@ static __always_inline enum lru_list page_lru(struct page *page)
127127

128128
#define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
129129

130-
#ifdef arch_unmap_kpfn
131-
extern void arch_unmap_kpfn(unsigned long pfn);
132-
#else
133-
static __always_inline void arch_unmap_kpfn(unsigned long pfn) { }
134-
#endif
135-
136130
#endif

‎mm/memory-failure.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,6 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11461146
return 0;
11471147
}
11481148

1149-
arch_unmap_kpfn(pfn);
1150-
11511149
orig_head = hpage = compound_head(p);
11521150
num_poisoned_pages_inc();
11531151

0 commit comments

Comments
 (0)