From: Vlastimil Babka Date: Thu, 21 Jun 2018 10:36:29 +0000 (+0200) Subject: x86/speculation/l1tf: Extend 64bit swap file size limit X-Git-Tag: v4.1.12-124.31.3~649 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b0f572f32ff27a5868c4a67ff7127eca86c9d9b4;p=users%2Fjedix%2Flinux-maple.git x86/speculation/l1tf: Extend 64bit swap file size limit The previous patch has limited swap file size so that large offsets cannot clear bits above MAX_PA/2 in the pte and interfere with L1TF mitigation. It assumed that offsets are encoded starting with bit 12, same as pfn. But on x86_64, offsets are encoded starting with bit 9. Thus the limit can be raised by 3 bits. That means 16TB with 42bit MAX_PA and 256TB with 46bit MAX_PA. Fixes: 377eeaa8e11f ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2") Signed-off-by: Vlastimil Babka Signed-off-by: Thomas Gleixner Orabug: 28220674 CVE: CVE-2018-3620 (cherry picked from commit 1a7ed1ba4bba6c075d5ad61bb75e3fbc870840d6) Signed-off-by: Mihai Carabas Reviewed-by: Darren Kenny Reviewed-by: Boris Ostrovsky --- diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 9880dc4d7dfd..4dc599f536cf 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -777,7 +777,15 @@ 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 */ - pages = min_t(unsigned long, l1tf_pfn_limit() + 1, pages); + unsigned 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. + */ +#ifdef CONFIG_X86_64 + l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT; +#endif + pages = min_t(unsigned long, l1tf_limit, pages); } return pages; }