Commit 9df95169 authored by Vlastimil Babka's avatar Vlastimil Babka Committed by Thomas Gleixner

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: 17dbca11 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")
Fixes: 377eeaa8 ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2")
Reported-by: default avatarDominique Leuenberger <dimstar@suse.de>
Reported-by: default avatarAdrian Schroeter <adrian@suse.de>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarMichal 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
parent dc76803e
...@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op; ...@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op;
extern void cpu_detect(struct cpuinfo_x86 *c); extern void cpu_detect(struct cpuinfo_x86 *c);
static inline unsigned long l1tf_pfn_limit(void) static inline unsigned long long l1tf_pfn_limit(void)
{ {
return BIT(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1; return BIT_ULL(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1;
} }
extern void early_cpu_init(void); extern void early_cpu_init(void);
......
...@@ -923,7 +923,7 @@ unsigned long max_swapfile_size(void) ...@@ -923,7 +923,7 @@ unsigned long max_swapfile_size(void)
if (boot_cpu_has_bug(X86_BUG_L1TF)) { if (boot_cpu_has_bug(X86_BUG_L1TF)) {
/* Limit the swap file size to MAX_PA/2 for L1TF workaround */ /* Limit the swap file size to MAX_PA/2 for L1TF workaround */
unsigned long l1tf_limit = l1tf_pfn_limit() + 1; unsigned long long l1tf_limit = l1tf_pfn_limit() + 1;
/* /*
* We encode swap offsets also with 3 bits below those for pfn * We encode swap offsets also with 3 bits below those for pfn
* which makes the usable limit higher. * which makes the usable limit higher.
...@@ -931,7 +931,7 @@ unsigned long max_swapfile_size(void) ...@@ -931,7 +931,7 @@ unsigned long max_swapfile_size(void)
#if CONFIG_PGTABLE_LEVELS > 2 #if CONFIG_PGTABLE_LEVELS > 2
l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT; l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT;
#endif #endif
pages = min_t(unsigned long, l1tf_limit, pages); pages = min_t(unsigned long long, l1tf_limit, pages);
} }
return pages; return pages;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment