From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 21 Jun 2018 13:20:17 -0000 Received: from mx2.suse.de ([195.135.220.15]) by Galois.linutronix.de with esmtps (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1fVzVW-0007iq-Gl for speck@linutronix.de; Thu, 21 Jun 2018 15:20:16 +0200 Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 51CFDAEB2 for ; Thu, 21 Jun 2018 13:20:08 +0000 (UTC) Subject: [MODERATED] Re: [PATCH 8/8] L1TFv8 6 References: <20180614150632.E064C61183@crypto-ml.lab.linutronix.de> <4ad5c4d2-7721-729e-3af6-6c8ed84dda9f@suse.cz> <260fce1e-c5fe-cace-56a8-a83c2a41f115@suse.cz> From: Vlastimil Babka Message-ID: <5524ddaf-13c3-0026-0f33-057d8625e9e0@suse.cz> Date: Thu, 21 Jun 2018 15:17:56 +0200 MIME-Version: 1.0 In-Reply-To: <260fce1e-c5fe-cace-56a8-a83c2a41f115@suse.cz> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On 06/21/2018 01:43 PM, speck for Vlastimil Babka wrote: > On 06/21/2018 11:02 AM, speck for Vlastimil Babka wrote: >> On 06/14/2018 12:48 AM, speck for Andi Kleen wrote: >>> +unsigned long max_swapfile_size(void) >>> +{ >>> + unsigned long pages; >>> + >>> + pages = generic_max_swapfile_size(); >>> + >>> + 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); >> >> Is this actually correct? IIUC l1tf_pfn_limit() is in page granularity, >> which are encoded in bits 12 to $LIMIT., but we have swap offsets in >> bits 9 to $LIMIT (after patch 2/8), i.e. 3 bits more? Same for the >> limits described in the changelog? > > Yeah, I was able to verify this with some printk's, constructing a pte > with max allowed offset and printing it. In VM with 42bit limits, the > pte is 7ffffc000000000, so the unusable bits start with 38, not 41. Here's a patch for the 64bit case. The testing pte is then 7fffe0000000000, so all bits up to bit 40 are used. Not sure what to do with the 32bit case, we'll probably have to start using both words of the pte to avoid tiny offsets? ----8<---- >From ca293624a2cc776d9d87edc9497dd406dbe460c0 Mon Sep 17 00:00:00 2001 From: Vlastimil Babka Date: Thu, 21 Jun 2018 12:36:29 +0200 Subject: [PATCH] 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, we encode offsets starting with bit 9. We can thus raise the limit by 3 bits. That means 16TB with 42bit MAX_PA and 256TB with 46bit MAX_PA. Signed-off-by: Vlastimil Babka --- arch/x86/mm/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 0cd3a534b7eb..f1e03047de90 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -889,7 +889,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; } -- 2.17.1