Return-Path: Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1fNkVl-0000Xb-9t for speck@linutronix.de; Tue, 29 May 2018 21:42:25 +0200 Received: by mail-wr0-x22c.google.com with SMTP id i14-v6so27191348wre.2 for ; Tue, 29 May 2018 12:42:25 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-189-60.clienti.tiscali.it. [78.12.189.60]) by smtp.gmail.com with ESMTPSA id f10-v6sm13298551wmc.0.2018.05.29.12.42.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 12:42:18 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Subject: [MODERATED] [PATCH 2/2] L1TF KVM 2 Date: Tue, 29 May 2018 21:42:14 +0200 Message-Id: <20180529194214.2600-3-pbonzini@redhat.com> In-Reply-To: <20180529194214.2600-1-pbonzini@redhat.com> References: <20180529194214.2600-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 | 4 ++++ 3 files changed, 8 insertions(+) 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 ada9e55fc871..43738283aa2a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6518,6 +6518,10 @@ static int pvclock_gtod_notify(struct notifier_block *nb, unsigned long unused, void kvm_l1d_flush(void) { + if (static_cpu_has(X86_FEATURE_FLUSH_L1D)) { + wrmsrl(MSR_IA32_FLUSH_L1D, MSR_IA32_FLUSH_L1D_VALUE); + return; + } asm volatile( "movq %0, %%rax\n\t" "leaq 65536(%0), %%rdx\n\t" -- 1.8.3.1