Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5764270imm; Mon, 23 Jul 2018 05:48:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfBx+IZKC+vLdGetqdYLRe6oJFSpW+V3yorELa42UNmWbyT0F9Es228EPFB8us32N4afkcV X-Received: by 2002:a17:902:561:: with SMTP id 88-v6mr12722919plf.320.1532350086949; Mon, 23 Jul 2018 05:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350086; cv=none; d=google.com; s=arc-20160816; b=lQYjxhBICTYdL3uLQihc9ywZgdSf7SW8cBexCNc9RCNAiswYf8KvrHduYpAY7nUxCD xw4C78YmF6T6hubtwna8yh6ov6yWVmYqBQX5NoJSG7EfZvf/plnNge1DmLI97tMF9E6f S+LECp0PzltxmmdQq14CeOccQwO420wQayEC8Evcfqh9FCfuVJMQKgHh3q5DoU+3kTvu 5zm06KAjfqroHi5QO42brj4PpAayBhgGBF5HCHi1z48UzM4fipiUsl1yA74TVDyviHBQ 02jIDR1ouNu80+/Pz+RlaBg4ifGXXPakfbLeXFn3TLlVa1pl0uFKi4kZMNV1A4ePACzh cehg== 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=iNmuTGBzvf0SGjaZa3KZ+sEs+t8j/EKn8L/We8szGiQ=; b=RRdsDd8EeHgfKRp1cokNVuom8sEV4+gNCnEPi4tam3reHYCq6mb3OXYlppoVU/OaeQ eG5HMUQGSmaDJfG02O436C0ZA3ZFEFlYXuEJFzVbaHJo17+9AwwtQ9IkjcvhrlAO5eWu 8IRY+GvyFFRvDRab6dj0LQteC8XaH2i6ob8iS+JH7nYQgBQqV1K6cQWsfMDB5kLOPVNU 9PmuJG6tonH//HMkqSgVBEouNSPXpDz1BqUhdkhHMO3EXnFi/JLEBht/5/6Ij8guLlfz 9uJiTKDHnPW6rv9kzBlbI3N5pbKitXLHo47CdeTHw4f9jjXkxxE753L/sd7qjczN1Xaa 4dLw== 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 bc12-v6si7894534plb.373.2018.07.23.05.47.52; Mon, 23 Jul 2018 05:48:06 -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 S2389685AbeGWNsI (ORCPT + 99 others); Mon, 23 Jul 2018 09:48:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51470 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388725AbeGWNsH (ORCPT ); Mon, 23 Jul 2018 09:48:07 -0400 Received: from localhost (LFbn-1-12238-233.w90-92.abo.wanadoo.fr [90.92.53.233]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 71CEFCA8; Mon, 23 Jul 2018 12:46:58 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , David Woodhouse , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 096/107] x86/speculation, KVM: Implement support for VIRT_SPEC_CTRL/LS_CFG Date: Mon, 23 Jul 2018 14:42:30 +0200 Message-Id: <20180723122418.320458689@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723122413.003644357@linuxfoundation.org> References: <20180723122413.003644357@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit 47c61b3955cf712cadfc25635bf9bc174af030ea upstream Add the necessary logic for supporting the emulated VIRT_SPEC_CTRL MSR to x86_virt_spec_ctrl(). If either X86_FEATURE_LS_CFG_SSBD or X86_FEATURE_VIRT_SPEC_CTRL is set then use the new guest_virt_spec_ctrl argument to check whether the state must be modified on the host. The update reuses speculative_store_bypass_update() so the ZEN-specific sibling coordination can be reused. Signed-off-by: Thomas Gleixner Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/spec-ctrl.h | 6 ++++++ arch/x86/kernel/cpu/bugs.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) --- a/arch/x86/include/asm/spec-ctrl.h +++ b/arch/x86/include/asm/spec-ctrl.h @@ -53,6 +53,12 @@ static inline u64 ssbd_tif_to_spec_ctrl( return (tifn & _TIF_SSBD) >> (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT); } +static inline unsigned long ssbd_spec_ctrl_to_tif(u64 spec_ctrl) +{ + BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT); + return (spec_ctrl & SPEC_CTRL_SSBD) << (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT); +} + static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn) { return (tifn & _TIF_SSBD) ? x86_amd_ls_cfg_ssbd_mask : 0ULL; --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -160,6 +160,36 @@ x86_virt_spec_ctrl(u64 guest_spec_ctrl, wrmsrl(MSR_IA32_SPEC_CTRL, msrval); } } + + /* + * If SSBD is not handled in MSR_SPEC_CTRL on AMD, update + * MSR_AMD64_L2_CFG or MSR_VIRT_SPEC_CTRL if supported. + */ + if (!static_cpu_has(X86_FEATURE_LS_CFG_SSBD) && + !static_cpu_has(X86_FEATURE_VIRT_SSBD)) + return; + + /* + * If the host has SSBD mitigation enabled, force it in the host's + * virtual MSR value. If its not permanently enabled, evaluate + * current's TIF_SSBD thread flag. + */ + if (static_cpu_has(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE)) + hostval = SPEC_CTRL_SSBD; + else + hostval = ssbd_tif_to_spec_ctrl(ti->flags); + + /* Sanitize the guest value */ + guestval = guest_virt_spec_ctrl & SPEC_CTRL_SSBD; + + if (hostval != guestval) { + unsigned long tif; + + tif = setguest ? ssbd_spec_ctrl_to_tif(guestval) : + ssbd_spec_ctrl_to_tif(hostval); + + speculative_store_bypass_update(tif); + } } EXPORT_SYMBOL_GPL(x86_virt_spec_ctrl);