Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 23 Jun 2018 13:59:13 -0000 Received: from userp2120.oracle.com ([156.151.31.85]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fWj4I-00066m-Nk for speck@linutronix.de; Sat, 23 Jun 2018 15:59:11 +0200 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5NDsF8E178575 for ; Sat, 23 Jun 2018 13:59:04 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2jsfg0rh7c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 23 Jun 2018 13:59:04 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w5NDx3cX012139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 23 Jun 2018 13:59:03 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5NDx3ZH021176 for ; Sat, 23 Jun 2018 13:59:03 GMT Message-Id: <20180623135445.641656585@localhost.localdomain> Date: Sat, 23 Jun 2018 09:54:17 -0400 From: konrad.wilk@oracle.com Subject: [MODERATED] [PATCH v4 3/8] [PATCH v4 3/8] Linux Patch #3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: 336996-Speculative-Execution-Side-Channel-Mitigations.pdf defines a new MSR (IA32_FLUSH_CMD aka 0x10B) which has similar write-only semantics to other MSRs defined in the document. The semantics of this MSR is to allow "finer granularity invalidation of caching structures than existing mechanisms like WBINVD. It will writeback and invalidate the L1 data cache, including all cachelines brought in by preceding instructions, without invalidating all caches (eg. L2 or LLC). Some processors may also invalidate the first level level instruction cache on a L1D_FLUSH command. The L1 data and instruction caches may be shared across the logical processors of a core." Hence right before we do an VMENTER we need to flush the L1 data cache to thwart against untrusted guests reading the host memory that is cached in L1 data cache. A copy of this document is available at https://bugzilla.kernel.org/show_bug.cgi?id=199511 Signed-off-by: Paolo Bonzini Signed-off-by: Konrad Rzeszutek Wilk --- v3: Redo the commit --- arch/x86/include/asm/msr-index.h | 6 ++++++ arch/x86/kvm/x86.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 68b2c3150de1..0e7517089b80 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -76,6 +76,12 @@ * control required. */ +#define MSR_IA32_FLUSH_CMD 0x0000010b +#define L1D_FLUSH (1 << 0) /* + * Writeback and invalidate the + * L1 data cache. + */ + #define MSR_IA32_BBL_CR_CTL 0x00000119 #define MSR_IA32_BBL_CR_CTL3 0x0000011e diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4d2e4975f91d..f0f25d31e5e2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6551,11 +6551,17 @@ static void *__read_mostly empty_zero_pages; void kvm_l1d_flush(void) { - /* FIXME: could this be boot_cpu_data.x86_cache_size * 2? */ - int size = PAGE_SIZE << L1D_CACHE_ORDER; + int size; ASSERT(boot_cpu_has(X86_BUG_L1TF)); + if (static_cpu_has(X86_FEATURE_FLUSH_L1D)) { + wrmsrl(MSR_IA32_FLUSH_CMD, L1D_FLUSH); + return; + } + + /* FIXME: could this be boot_cpu_data.x86_cache_size * 2? */ + size = PAGE_SIZE << L1D_CACHE_ORDER; asm volatile( /* First ensure the pages are in the TLB */ "xorl %%eax, %%eax\n\t" -- 2.14.3