diff options
author | Vlastimil Babka <vbabka@suse.cz> | 2018-08-20 05:58:35 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2018-08-20 12:04:42 -0400 |
commit | 9df9516940a61d29aedf4d91b483ca6597e7d480 (patch) | |
tree | 446dddbc72dc1059d59be9c4e49f1d6745db1537 | |
parent | dc76803e57cc86589c4efcb5362918f9b0c0436f (diff) |
x86/speculation/l1tf: Fix overflow in l1tf_pfn_limit() on 32bit
On 32bit PAE kernels on 64bit hardware with enough physical bits,
l1tf_pfn_limit() will overflow unsigned long. This in turn affects
max_swapfile_size() and can lead to swapon returning -EINVAL. This has been
observed in a 32bit guest with 42 bits physical address size, where
max_swapfile_size() overflows exactly to 1 << 32, thus zero, and produces
the following warning to dmesg:
[ 6.396845] Truncating oversized swap area, only using 0k out of 2047996k
Fix this by using unsigned long long instead.
Fixes: 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")
Fixes: 377eeaa8e11f ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2")
Reported-by: Dominique Leuenberger <dimstar@suse.de>
Reported-by: Adrian Schroeter <adrian@suse.de>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20180820095835.5298-1-vbabka@suse.cz
-rw-r--r-- | arch/x86/include/asm/processor.h | 4 | ||||
-rw-r--r-- | arch/x86/mm/init.c | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 682286aca881..a0a52274cb4a 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h | |||
@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op; | |||
181 | 181 | ||
182 | extern void cpu_detect(struct cpuinfo_x86 *c); | 182 | extern void cpu_detect(struct cpuinfo_x86 *c); |
183 | 183 | ||
184 | static inline unsigned long l1tf_pfn_limit(void) | 184 | static inline unsigned long long l1tf_pfn_limit(void) |
185 | { | 185 | { |
186 | return BIT(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1; | 186 | return BIT_ULL(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1; |
187 | } | 187 | } |
188 | 188 | ||
189 | extern void early_cpu_init(void); | 189 | extern void early_cpu_init(void); |
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index acfab322fbe0..02de3d6065c4 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c | |||
@@ -923,7 +923,7 @@ unsigned long max_swapfile_size(void) | |||
923 | 923 | ||
924 | if (boot_cpu_has_bug(X86_BUG_L1TF)) { | 924 | if (boot_cpu_has_bug(X86_BUG_L1TF)) { |
925 | /* Limit the swap file size to MAX_PA/2 for L1TF workaround */ | 925 | /* Limit the swap file size to MAX_PA/2 for L1TF workaround */ |
926 | unsigned long l1tf_limit = l1tf_pfn_limit() + 1; | 926 | unsigned long long l1tf_limit = l1tf_pfn_limit() + 1; |
927 | /* | 927 | /* |
928 | * We encode swap offsets also with 3 bits below those for pfn | 928 | * We encode swap offsets also with 3 bits below those for pfn |
929 | * which makes the usable limit higher. | 929 | * which makes the usable limit higher. |
@@ -931,7 +931,7 @@ unsigned long max_swapfile_size(void) | |||
931 | #if CONFIG_PGTABLE_LEVELS > 2 | 931 | #if CONFIG_PGTABLE_LEVELS > 2 |
932 | l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT; | 932 | l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT; |
933 | #endif | 933 | #endif |
934 | pages = min_t(unsigned long, l1tf_limit, pages); | 934 | pages = min_t(unsigned long long, l1tf_limit, pages); |
935 | } | 935 | } |
936 | return pages; | 936 | return pages; |
937 | } | 937 | } |