Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4803246ooa; Tue, 14 Aug 2018 10:45:59 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzm58Myip2CqrYAaM5rd4O4yEt7R5zUoImXTZXqqqQuA9QUmga+ON1R5gNgsQ3xJJDT1RX9 X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr21892239pgq.21.1534268759320; Tue, 14 Aug 2018 10:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268759; cv=none; d=google.com; s=arc-20160816; b=bqofiV+3BDhBeuRo+ho9cbWIFRBIHiMfhTIzwryiqp5aUL8IroSuiSBW4F9rznxEgg DE6VovyDpEzWlCAgSKHAx8NncbH9GMOcIk0ykrlj46+Yrr9Ew0vokDvhlknVg+T5FPAT XTMb1H5aVMJ/DuDiq/G1ErpxustCuQFzELncU2HlvAOpSRPEHrkZUYJRW2E0k8nWQqC5 vIu4jSu1fvAeub/ZRnY+vNNTvb75ICfNEzF0vcSw8wOxnDJBZVYV8kQzg4ilAbYh0KpD ln6BnhHE0slBN2SuMWb7h320p3IlMx58XG4dUYSkgcDTCuk45JloqNzKnIZvnQwq3duR b2JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4ZORqq4Y59TbMmk7bufeC2cQ8bx54jjuo1i7et6Gr/E=; b=EzAOc9tu913DRHNsdELjDVAvFKPJMNfvPhvl6iBPiVA59tD32xLVnxxUR4JEjZLrLD VDY77oVP9LwBMjxRVrbYYatrA7J7li/x34V7STE5bIsLgbA0MRTHmGkBGVaoYoJVpGgZ 6lX1oiPED36t8zXzVvlJ7jV+bATV6aF9d1aBNZHp2VD9f0i6cWWFB1LuBq7uW7pqfeL3 waCxfVVlBhYHZ5UG0xCstRqX7JGvRC2t4P0OMR/BH/RjPzoGm+TBu09F7jxzr3fDIyaD 8gnSieyF51jRGj1Y8ZK1AOLaHpEwFAjkXkbcA6V7Hd9gEC1jZZTA1aAE8BGSIawkoqgr zERA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si21963214pgh.627.2018.08.14.10.45.44; Tue, 14 Aug 2018 10:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390826AbeHNUdB (ORCPT + 99 others); Tue, 14 Aug 2018 16:33:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60102 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390355AbeHNUdA (ORCPT ); Tue, 14 Aug 2018 16:33:00 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D3B3D40B; Tue, 14 Aug 2018 17:44:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Bonzini , Konrad Rzeszutek Wilk , Thomas Gleixner , David Woodhouse Subject: [PATCH 4.9 060/107] x86/KVM/VMX: Add L1D MSR based flush Date: Tue, 14 Aug 2018 19:17:23 +0200 Message-Id: <20180814171524.695913954@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171520.883143803@linuxfoundation.org> References: <20180814171520.883143803@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini commit 3fa045be4c720146b18a19cea7a767dc6ad5df94 upstream 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." Use it instead of the loop based L1 flush algorithm. A copy of this document is available at https://bugzilla.kernel.org/show_bug.cgi?id=199511 [ tglx: Avoid allocating pages when the MSR is available ] Signed-off-by: Paolo Bonzini Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Thomas Gleixner Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/msr-index.h | 6 ++++++ arch/x86/kvm/vmx.c | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -69,6 +69,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 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -8553,6 +8553,11 @@ static void __maybe_unused vmx_l1d_flush { int size = PAGE_SIZE << L1D_CACHE_ORDER; + if (static_cpu_has(X86_FEATURE_FLUSH_L1D)) { + wrmsrl(MSR_IA32_FLUSH_CMD, L1D_FLUSH); + return; + } + asm volatile( /* First ensure the pages are in the TLB */ "xorl %%eax, %%eax\n" @@ -11601,11 +11606,13 @@ static int __init vmx_setup_l1d_flush(vo !boot_cpu_has_bug(X86_BUG_L1TF)) return 0; - page = alloc_pages(GFP_KERNEL, L1D_CACHE_ORDER); - if (!page) - return -ENOMEM; + if (!boot_cpu_has(X86_FEATURE_FLUSH_L1D)) { + page = alloc_pages(GFP_KERNEL, L1D_CACHE_ORDER); + if (!page) + return -ENOMEM; + vmx_l1d_flush_pages = page_address(page); + } - vmx_l1d_flush_pages = page_address(page); static_branch_enable(&vmx_l1d_should_flush); return 0; }