Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4785295ooa; Tue, 14 Aug 2018 10:30:53 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxqzJEfwXHl1gK/4PYeAWKzgzmNhjVPUpYhkmFSc9J+9bxftCq0B08IiJ4H6JTCzfS1b5p+ X-Received: by 2002:a62:c4c3:: with SMTP id h64-v6mr24175643pfk.39.1534267853105; Tue, 14 Aug 2018 10:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534267853; cv=none; d=google.com; s=arc-20160816; b=HX+quI1mmSNhZ7Na/uD+Jubp0wZHt8DjcKiSlfQSV7rqOQp5el8HJv3qQTXs0gLPKE /wBeoHE8tE5kYh+RnHmuicG8Zntl2FyQfYAzE9mQ+ZreSzPIQSg4CfZu3s8eT9QQnd/4 HnEVbXc4iZvSjxj13j58WKx9B/cLixE4Z+Skxh6cER6/AOc/8eAmloUktiRqlOPnRT1V XB+r538yA9qUcxMrwL5iJAfX7VgZuJHz8Ws823hSbuGzZ3CYNWWD9HcypG8kqlpEk9jN H4FEKoSJk0ow4yupelFaBq/j2SiuVvtJ03gKNMB1fzgcwAQoNfR+G7ynPfdPuzqE2Qcb 0zdw== 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=4Bvn87/0CdihCeqC6KSC5gx0PEuQoDBJhWedh+VdjHo=; b=nqeb6sIFAGHNPcDnbILVyHRpKeZJ9ZHHaI8Jra/epUEDrY9njJaM08/u49hncpkBHY TcEzKWjwNs3qJ8m273DjnRI+Rk7CiVVRyUfaZKeUYJ/ytlTbhwmx4iXTVpBTnVOq/pgG 5C5B0lbTdtyKJvNnvsSXxs3fpery0vBbisDtfVIk70hdBCBqRBdC2R/9z8UPwnglHzv5 EYKqa4GUei/HTqzhouuK6NN64t3gW2BSGGc+lZiBwOMZ0TXtb6aqiZQ1j23RjPScvX9Q 8X2Kg2edHSnbsqu8iD9svcKHUzrD3l17C0XkTA9uXDCRP6qu1r2Dva2HilyjmHCG0nbV Cc5A== 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 b35-v6si21038039pgl.562.2018.08.14.10.30.38; Tue, 14 Aug 2018 10:30:53 -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 S2388807AbeHNUPy (ORCPT + 99 others); Tue, 14 Aug 2018 16:15:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52524 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387825AbeHNUPy (ORCPT ); Tue, 14 Aug 2018 16:15:54 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D13B140B; Tue, 14 Aug 2018 17:27:46 +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 Subject: [PATCH 4.18 38/79] x86/KVM/VMX: Add L1D MSR based flush Date: Tue, 14 Aug 2018 19:16:57 +0200 Message-Id: <20180814171338.272528784@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171336.799314117@linuxfoundation.org> References: <20180814171336.799314117@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini 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: 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 @@ -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 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -9616,6 +9616,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" @@ -13246,11 +13251,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; }