Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3052664ybi; Tue, 2 Jul 2019 01:11:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS5mA6DvkF1fQlsPurxKJwAiF12V53ry54d7RAz5uqaYJwd39fnSl/rudCe/RgT8mtfzBV X-Received: by 2002:a17:90a:26e4:: with SMTP id m91mr4128850pje.93.1562055115396; Tue, 02 Jul 2019 01:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055115; cv=none; d=google.com; s=arc-20160816; b=iUEcGGYj3h3l7voeLkINzME4ocHGbtTykWh9wKCvNDfNKDtkqr8iL20pzLkh/WZs/B AeMimCdVABDUGuJH0z5kRUHncwp6F/LqhGULrTG8D+Rfi0Uuuf4lNDEsGWrvKsEGgSm8 2Yf84rZEXZGb3ssNgltr2393MRhwiz304Me97lF/cyGLMgq/dWyFdGCIJITfCyQf5bjC j/PDHBMlpkhZi4yWnrtFiruE4NmxPy2d4KbsVCuzbPg3OPy1Ucbuc3Hft03KVnPAnogH qHEmb2D0QOy1wrlQZzcnkONBB1QB6LV2qv3IfVpk/GRcZT9xxo3YJIde3PuHm1R/m7VY Ji4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kGxoeUPzTrTvnAB3aCUnuBjsk/xETb7D+OlGcLEsAmM=; b=Vcigz0SLT3tmxXdYmMBLLmzTMehY+pO6jjw6OZmJp9D0aXpfSnUjlpRIlLOObteqp/ IE2+J0QDzjFdCXkMDYUHbBT6F9MlpoBk/cU3RKSanc4WgKs+iE1dv3hxfHVKqfZYriry 29VYun5KPJqQJ0k/Li6k3qt5RnVEZFfFuLNEZBfZnHWcJN9albtqsgeiOJ6MxfiOVxhR UIqSsIaBCUBEp0vAGQ4QOkgxxMZZvmwD2XadKWMXlsVYtfaNDquvFlA9emieqfOIfhDq jajqtGugUeo81OXk4XP6du3tZb8h3Z1gc/X10f+Y5NBVkJPYLC/UB0twtPMKq1lKsh71 qmkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UYaL0caH; 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 cx20si1659249pjb.97.2019.07.02.01.11.40; Tue, 02 Jul 2019 01:11:55 -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=UYaL0caH; 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 S1728866AbfGBIKl (ORCPT + 99 others); Tue, 2 Jul 2019 04:10:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:59050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbfGBIKe (ORCPT ); Tue, 2 Jul 2019 04:10:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C7E1021852; Tue, 2 Jul 2019 08:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562055033; bh=JzhaEiPOMzUPEDdCttlNaZQHACR4FpyS+c4Ey6GXKhw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UYaL0caHGGZOPL/IAH/RHafBj3bu7CKbFJz+CnsML+dIdn4TPTBlUU5kxaH6WEuPP NP1JzQO7D2CTnZiLWDZtHfinsDReQthsk/KSURifvcOquAbxwEog2YYB8xo4HrSVk0 xrkldG0C7WslH/7awFqRIxDOgU740ayAI3WUwWjQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alejandro Jimenez , Thomas Gleixner , Liam Merwick , Mark Kanda , Paolo Bonzini , bp@alien8.de, rkrcmar@redhat.com, kvm@vger.kernel.org Subject: [PATCH 4.14 22/43] x86/speculation: Allow guests to use SSBD even if host does not Date: Tue, 2 Jul 2019 10:02:02 +0200 Message-Id: <20190702080124.964149146@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080123.904399496@linuxfoundation.org> References: <20190702080123.904399496@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alejandro Jimenez commit c1f7fec1eb6a2c86d01bc22afce772c743451d88 upstream. The bits set in x86_spec_ctrl_mask are used to calculate the guest's value of SPEC_CTRL that is written to the MSR before VMENTRY, and control which mitigations the guest can enable. In the case of SSBD, unless the host has enabled SSBD always on mode (by passing "spec_store_bypass_disable=on" in the kernel parameters), the SSBD bit is not set in the mask and the guest can not properly enable the SSBD always on mitigation mode. This has been confirmed by running the SSBD PoC on a guest using the SSBD always on mitigation mode (booted with kernel parameter "spec_store_bypass_disable=on"), and verifying that the guest is vulnerable unless the host is also using SSBD always on mode. In addition, the guest OS incorrectly reports the SSB vulnerability as mitigated. Always set the SSBD bit in x86_spec_ctrl_mask when the host CPU supports it, allowing the guest to use SSBD whether or not the host has chosen to enable the mitigation in any of its modes. Fixes: be6fcb5478e9 ("x86/bugs: Rework spec_ctrl base and mask logic") Signed-off-by: Alejandro Jimenez Signed-off-by: Thomas Gleixner Reviewed-by: Liam Merwick Reviewed-by: Mark Kanda Reviewed-by: Paolo Bonzini Cc: bp@alien8.de Cc: rkrcmar@redhat.com Cc: kvm@vger.kernel.org Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1560187210-11054-1-git-send-email-alejandro.j.jimenez@oracle.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -821,6 +821,16 @@ static enum ssb_mitigation __init __ssb_ } /* + * If SSBD is controlled by the SPEC_CTRL MSR, then set the proper + * bit in the mask to allow guests to use the mitigation even in the + * case where the host does not enable it. + */ + if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) || + static_cpu_has(X86_FEATURE_AMD_SSBD)) { + x86_spec_ctrl_mask |= SPEC_CTRL_SSBD; + } + + /* * We have three CPU feature flags that are in play here: * - X86_BUG_SPEC_STORE_BYPASS - CPU is susceptible. * - X86_FEATURE_SSBD - CPU is able to turn off speculative store bypass @@ -837,7 +847,6 @@ static enum ssb_mitigation __init __ssb_ x86_amd_ssb_disable(); } else { x86_spec_ctrl_base |= SPEC_CTRL_SSBD; - x86_spec_ctrl_mask |= SPEC_CTRL_SSBD; wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); } }