Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 20 Jun 2018 16:47:26 -0000 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1fVgBU-0000N8-OM for speck@linutronix.de; Wed, 20 Jun 2018 18:42:16 +0200 Received: by mail-wr0-x22e.google.com with SMTP id o12-v6so174772wrm.12 for ; Wed, 20 Jun 2018 09:42:16 -0700 (PDT) Received: from donizetti.redhat.com (dynamic-adsl-78-12-154-24.clienti.tiscali.it. [78.12.154.24]) by smtp.gmail.com with ESMTPSA id b190-v6sm4892446wma.24.2018.06.20.09.42.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 09:42:10 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Subject: [MODERATED] [PATCH 2/2] L1TF KVM v2 2 Date: Wed, 20 Jun 2018 18:42:07 +0200 Message-Id: <20180620164207.31771-3-pbonzini@redhat.com> In-Reply-To: <20180620164207.31771-1-pbonzini@redhat.com> References: <20180620164207.31771-1-pbonzini@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 To: speck@linutronix.de List-ID: Intel's new microcode adds a new feature bit in CPUID[7,0].EDX[28]. If it is active, the displacement flush is unnecessary. Tested on a Coffee Lake machine. Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 3 +++ arch/x86/kvm/x86.c | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 578793e97431..aebf89c4175d 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -333,6 +333,7 @@ #define X86_FEATURE_PCONFIG (18*32+18) /* Intel PCONFIG */ #define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */ #define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */ +#define X86_FEATURE_FLUSH_L1D (18*32+28) /* IA32_FLUSH_L1D MSR */ #define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */ /* diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 53d5b1b9255e..f43bd9f23053 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -65,6 +65,9 @@ #define MSR_MTRRcap 0x000000fe +#define MSR_IA32_FLUSH_L1D 0x10b +#define MSR_IA32_FLUSH_L1D_VALUE 0x00000001 + #define MSR_IA32_ARCH_CAPABILITIES 0x0000010a #define ARCH_CAP_RDCL_NO (1 << 0) /* Not susceptible to Meltdown */ #define ARCH_CAP_IBRS_ALL (1 << 1) /* Enhanced IBRS support */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8bf8f672cece..c88ed554bb66 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6551,8 +6551,15 @@ static int pvclock_gtod_notify(struct notifier_block *nb, unsigned long unused, void kvm_l1d_flush(void) { + int size; + + if (static_cpu_has(X86_FEATURE_FLUSH_L1D)) { + wrmsrl(MSR_IA32_FLUSH_L1D, MSR_IA32_FLUSH_L1D_VALUE); + return; + } + /* FIXME: could this be boot_cpu_data.x86_cache_size * 2? */ - int size = PAGE_SIZE << L1D_CACHE_ORDER; + size = PAGE_SIZE << L1D_CACHE_ORDER; asm volatile( /* First ensure the pages are in the TLB */ "xorl %%eax, %%eax\n\t" -- 1.8.3.1