x86/speculation/l1tf: fix overflow on l1tf_pfn_limit() on 32bit
Subsystems (3)
PATCH 1/1 x86/speculation/l1tf: fix overflow on 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.
--- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/processor.h +2 -2
@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op;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 );
arch/x86/mm/init.c +2 -2
@@ -923,7 +923,7 @@ unsigned long max_swapfile_size(void)if (boot_cpu_has_bug (X86_BUG_L1TF )) {/* 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 * which makes the usable limit higher.
@@ -931,7 +931,7 @@ unsigned long max_swapfile_size(void)#if CONFIG_PGTABLE_LEVELS >2 l1tf_limit <<=PAGE_SHIFT -SWP_OFFSET_FIRST_BIT ;#endif - pages = min_t(unsigned long, l1tf_limit, pages); + pages = min_t(unsigned long long, l1tf_limit, pages); }return pages; }
Signature · 1 line
2.18.0
Quoted 9 lines · Vlastimil Babka
On 32bit PAE kernels on 64bit hardware with enough physical bits,
l1tf_pfn_limit()will overflow unsigned long. This in turn affectsmax_swapfile_size()and can lead to swapon returning-EINVAL. This has been observed in a 32bit guest with 42 bits physical address size, wheremax_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
Quoted 8 lines
Fix this by using unsigned long long instead.
Reported-by Dominique Leuenberger <[email protected]>Reported-by Adrian Schroeter <[email protected]>Fixes 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")Fixes 377eeaa8e11f ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2")Signed-off-by Vlastimil Babka <[email protected]>
Looks good to me. I would probably use phys_addr_t which would be more descriptive but this is just minor thing.
Quoted 45 lines
--- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)arch/x86/include/asm/processor.h +2
-2@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op;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 );arch/x86/mm/init.c +2
-2@@ -923,7 +923,7 @@ unsigned long max_swapfile_size(void)if (boot_cpu_has_bug (X86_BUG_L1TF )) {/* 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 * which makes the usable limit higher. @@ -931,7 +931,7 @@ unsigned long max_swapfile_size(void)#if CONFIG_PGTABLE_LEVELS >2 l1tf_limit <<=PAGE_SHIFT -SWP_OFFSET_FIRST_BIT ;#endif - pages = min_t(unsigned long, l1tf_limit, pages); + pages = min_t(unsigned long long, l1tf_limit, pages); }return pages; }Signature · 1 line
2.18.0
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 19 lines · Michal Hocko
Quoted 9 lines · Vlastimil Babka
On 32bit PAE kernels on 64bit hardware with enough physical bits,
l1tf_pfn_limit()will overflow unsigned long. This in turn affectsmax_swapfile_size()and can lead to swapon returning-EINVAL. This has been observed in a 32bit guest with 42 bits physical address size, wheremax_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 2047996kQuoted 8 lines
Fix this by using unsigned long long instead.
Reported-by Dominique Leuenberger <[email protected]>Reported-by Adrian Schroeter <[email protected]>Fixes 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")Fixes 377eeaa8e11f ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2")Signed-off-by Vlastimil Babka <[email protected]>
Quoted 2 lines
Looks good to me. I would probably use
phys_addr_twhich would be more descriptive but this is just minor thing.
Hmm phys_addr_t is still 32bit on !PAE so there the overflow could still happen. I guess max_swapfile_size() should skip the whole L1TF part for !PAE since there is no pte inverting done anyway.
Also the value is "number of pages" which is not the same as "physical address" so the phys_addr_t could be misleading anyway?
Quoted 1 line
Acked-by Michal Hocko <[email protected]>
Thanks!
Quoted 10 lines · Vlastimil Babka
On 32bit PAE kernels on 64bit hardware with enough physical bits,
l1tf_pfn_limit()will overflow unsigned long. This in turn affectsmax_swapfile_size()and can lead to swapon returning-EINVAL. This has been observed in a 32bit guest with 42 bits physical address size, wheremax_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 2047996kFix this by using unsigned long long instead.
Looks good.
BTW our much worse problems right now are crash reports on several stable kernels, especially with large pages
I'll dig into this more today, but if you have any hints from testing/fixing your own backports please share them.
-Andi
Quoted 10 lines · Andi Kleen
Quoted 9 lines · Vlastimil Babka
On 32bit PAE kernels on 64bit hardware with enough physical bits,
l1tf_pfn_limit()will overflow unsigned long. This in turn affectsmax_swapfile_size()and can lead to swapon returning-EINVAL. This has been observed in a 32bit guest with 42 bits physical address size, wheremax_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
Quoted 8 lines
Quoted 1 line
Fix this by using unsigned long long instead.
Looks good.
Acked-by Andi Kleen <[email protected]>BTW our much worse problems right now are crash reports on several stable kernels, especially with large pages
Do you have any reference?
Quoted 2 lines
I'll dig into this more today, but if you have any hints from testing/fixing your own backports please share them.
Well, we have seen some issues on pre 3.12 kernels due to misbackporting prot_none mitigations. PMD format is different in pre 4.4 kernels. Maybe this is a similar issue.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 20 lines · Vlastimil Babka
Quoted 19 lines · Michal Hocko
Quoted 17 lines · Vlastimil Babka
On 32bit PAE kernels on 64bit hardware with enough physical bits,
l1tf_pfn_limit()will overflow unsigned long. This in turn affectsmax_swapfile_size()and can lead to swapon returning-EINVAL. This has been observed in a 32bit guest with 42 bits physical address size, wheremax_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 2047996kFix this by using unsigned long long instead.
Reported-by Dominique Leuenberger <[email protected]>Reported-by Adrian Schroeter <[email protected]>Fixes 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")Fixes 377eeaa8e11f ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2")Signed-off-by Vlastimil Babka <[email protected]>
Quoted 6 lines
Quoted 2 lines
Looks good to me. I would probably use
phys_addr_twhich would be more descriptive but this is just minor thing.Hmm
phys_addr_tis still 32bit on !PAE so there the overflow could still happen. I guessmax_swapfile_size()should skip the whole L1TF part for !PAE since there is no pte inverting done anyway.
Yeah, I misremembered that we are already doing that.
Quoted 2 lines
Also the value is "number of pages" which is not the same as "physical address" so the
phys_addr_tcould be misleading anyway?
right
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 4 lines
Quoted 2 lines
BTW our much worse problems right now are crash reports on several stable kernels, especially with large pages
Do you have any reference?
https://lkml.org/lkml/2018/8/17/546
https://bugzilla.redhat.com/show_bug.cgi?id=1618792 (this is 4.17, not 4.18)
(might be different problems. I wasn't able to reproduce the 4.17 one so far)
-Andi
tip-bot for Vlastimil Babka
merge bot[tip:x86/urgent] x86/speculation/l1tf: Fix overflow in l1tf_pfn_limit() on 32bit
In reply to Vlastimil Babkax86/speculation/l1tf: Fix overflow in l1tf_pfn_limit() on 32bit
Commit-ID: 9df9516940a61d29aedf4d91b483ca6597e7d480 Gitweb: https://git.kernel.org/tip/9df9516940a61d29aedf4d91b483ca6597e7d480 Author: Vlastimil Babka <[email protected]> AuthorDate: Mon, 20 Aug 2018 11:58:35 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Mon, 20 Aug 2018 18:04:42 +0200
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.
--- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/processor.h +2 -2
@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op;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 );
arch/x86/mm/init.c +2 -2
@@ -923,7 +923,7 @@ unsigned long max_swapfile_size(void)if (boot_cpu_has_bug (X86_BUG_L1TF )) {/* 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 * which makes the usable limit higher.
@@ -931,7 +931,7 @@ unsigned long max_swapfile_size(void)#if CONFIG_PGTABLE_LEVELS >2 l1tf_limit <<=PAGE_SHIFT -SWP_OFFSET_FIRST_BIT ;#endif - pages = min_t(unsigned long, l1tf_limit, pages); + pages = min_t(unsigned long long, l1tf_limit, pages); }return pages; }