Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp790322imm; Mon, 21 May 2018 14:30:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZojBXy0KswNoqiUYRPDZ0J57t18zMp59trvdSODVPV+0r/+r+7HnB06RZPi3q39NtIZO9sU X-Received: by 2002:a17:902:bcc4:: with SMTP id o4-v6mr13873052pls.308.1526938244274; Mon, 21 May 2018 14:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526938244; cv=none; d=google.com; s=arc-20160816; b=aKH2nFze85g1SGR1SezP8EZhzuXBfyqe3rBeB+zqJ4xKNQf8ahqU7IzIrku3xWQIWo RLAdocOnV0zfZKXQ+vxsN352Qx9rZv+i4SNgGB2OGGyIjVVSs5MCQO9bJICSV9AGETIM O4JFSLifXzcVsMNR2UfPr6HO5aKBXsZOkAcG3HqtZz7Y4L0n/6JyQNqQ/6S95kUWD9KT Amfva3J4n8VaQnBTeT1yB90ohhOcw3idVkm8+z3kx5Oocah+QZJQA7IlSO1uqMqEe0DK PCX0m0Sj73l/tgvnLlTYfoxZqNZOwjIxxxdMhTGRdYzZxYn5K1dGubeI7+yrV6aXMMNQ BZfg== 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:dkim-signature :arc-authentication-results; bh=nTLTXQZ9e4UgZysgaPzDwDpWTpsd3P9WJMVnUbjBEQ8=; b=n6LZE4jAmZw/MzmfIsVjdw8OJ0u2s+HFeYDu570BCqWjaOuh5wmo3uCdBDp7rSpgvK H3LqrNyGpAA36KwaAUvgz8Wt/HKN+UwoLEK+zhyDClnYXtGe4YsmVI+LA7ElxiRF8QeC Gz0a3LjWyL/24gODO2PSDRDUt33ygDT326kzH2RIuzBzUypovlIkYYTZNRKOfdiEF/Ce HAjD9snIhpZX7o70L15IhlCQTovc+CuOBYb/Ex9nihGRQOQAkhnAD94R0dS52aYEOmBW rXCpZzgXd66SSk0rvAKRmdITXr4lCD0M+5yYfFohjSSwsOxwvovKU2WDSvHN0LQUP/zX J2Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SEhobMx8; 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 w23-v6si14845911plq.214.2018.05.21.14.30.29; Mon, 21 May 2018 14:30:44 -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; dkim=pass header.i=@kernel.org header.s=default header.b=SEhobMx8; 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 S1751450AbeEUVaQ (ORCPT + 99 others); Mon, 21 May 2018 17:30:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:41628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932634AbeEUV0s (ORCPT ); Mon, 21 May 2018 17:26:48 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9031B20853; Mon, 21 May 2018 21:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526938008; bh=u1Eci+df1lka+zFB3Q+yLMIEQwM2moUB4h96AJYA8PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SEhobMx8DUgD8qPc1v6p49tGuvNt4xhZd18W2aw1LOy8xU2EdazoeFu384xsPXbRp O/58IrSc88nIpGxuYbMTdMD6NgwH8E4tpP5WvSQcGhEcxkMieI19QD3sMGHAELhL5X qlBPtuT3pfEN1/ojv1e7ggPVTASBQ2FE1P75ZPI0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner Subject: [PATCH 4.16 107/110] x86/speculation, KVM: Implement support for VIRT_SPEC_CTRL/LS_CFG Date: Mon, 21 May 2018 23:12:44 +0200 Message-Id: <20180521210515.018994479@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@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.16-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: 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 @@ -162,6 +162,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);