|
51 | 51 | #include <asm/mce.h> |
52 | 52 | #include <asm/msr.h> |
53 | 53 | #include <asm/reboot.h> |
| 54 | +#include <asm/set_memory.h> |
54 | 55 |
|
55 | 56 | #include "mce-internal.h" |
56 | 57 |
|
@@ -1051,6 +1052,48 @@ static int do_memory_failure(struct mce *m) |
1051 | 1052 | return ret; |
1052 | 1053 | } |
1053 | 1054 |
|
| 1055 | +#if defined(arch_unmap_kpfn) && defined(CONFIG_MEMORY_FAILURE) |
| 1056 | + |
| 1057 | +void arch_unmap_kpfn(unsigned long pfn) |
| 1058 | +{ |
| 1059 | + unsigned long decoy_addr; |
| 1060 | + |
| 1061 | + /* |
| 1062 | + * Unmap this page from the kernel 1:1 mappings to make sure |
| 1063 | + * we don't log more errors because of speculative access to |
| 1064 | + * the page. |
| 1065 | + * We would like to just call: |
| 1066 | + * set_memory_np((unsigned long)pfn_to_kaddr(pfn), 1); |
| 1067 | + * but doing that would radically increase the odds of a |
| 1068 | + * speculative access to the posion page because we'd have |
| 1069 | + * the virtual address of the kernel 1:1 mapping sitting |
| 1070 | + * around in registers. |
| 1071 | + * Instead we get tricky. We create a non-canonical address |
| 1072 | + * that looks just like the one we want, but has bit 63 flipped. |
| 1073 | + * This relies on set_memory_np() not checking whether we passed |
| 1074 | + * a legal address. |
| 1075 | + */ |
| 1076 | + |
| 1077 | +/* |
| 1078 | + * Build time check to see if we have a spare virtual bit. Don't want |
| 1079 | + * to leave this until run time because most developers don't have a |
| 1080 | + * system that can exercise this code path. This will only become a |
| 1081 | + * problem if/when we move beyond 5-level page tables. |
| 1082 | + * |
| 1083 | + * Hard code "9" here because cpp doesn't grok ilog2(PTRS_PER_PGD) |
| 1084 | + */ |
| 1085 | +#if PGDIR_SHIFT + 9 < 63 |
| 1086 | + decoy_addr = (pfn << PAGE_SHIFT) + (PAGE_OFFSET ^ BIT(63)); |
| 1087 | +#else |
| 1088 | +#error "no unused virtual bit available" |
| 1089 | +#endif |
| 1090 | + |
| 1091 | + if (set_memory_np(decoy_addr, 1)) |
| 1092 | + pr_warn("Could not invalidate pfn=0x%lx from 1:1 map\n", pfn); |
| 1093 | + |
| 1094 | +} |
| 1095 | +#endif |
| 1096 | + |
1054 | 1097 | /* |
1055 | 1098 | * The actual machine check handler. This only handles real |
1056 | 1099 | * exceptions when something got corrupted coming in through int 18. |
|
0 commit comments