Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5771144imm; Mon, 23 Jul 2018 05:55:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcK/VWirtBDCCV0pV843p9vhQ6firy/lnHKXN2MSI51m0kzD2nT/I5ZXkQT1HQKnkoOjiYQ X-Received: by 2002:a65:5545:: with SMTP id t5-v6mr12145227pgr.157.1532350533129; Mon, 23 Jul 2018 05:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350533; cv=none; d=google.com; s=arc-20160816; b=DFr7vLLvklkcsGvldZGtmk1TFoKEM54EwBc1Z1ySDlTVww6jYyu76nLWhUK3DdLyK4 c/x3V/KLOb+U/2Z+QbylKBKrYgThr6ylWQDl7yEzgSbEF6INjgn8wurvkyQygpm3KFpH +0EONYLffzogyyr06rqLZK2Vm2XUjSojXnGMYpVl5Uo/QJQ7v+OaIbjpw+GILXtyrZ4V 3i9Ox4uQKSN92GNKAgQ/lDn1FCUg6TnIfYgAeAffjygQMf4Wqe/JhzhHZlLeip1mg7YX 0LGu8ME9uvM0SI3CDEjYYDpBLSs3OZPKdAA56p5JJoJB4xzQcGH/4i8rRDZolW/Zz0vk ZBEg== 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=jGWr9bDuKc8bI56lZGZmTF0TuNhyl8isbjg/2scP1Ss=; b=Q1PSELYEQ910qM6XDOZIBBLQQ/PBeB4v3L0HZk6jHyrGwkH1f1RCtgLoM7VdPVgrdQ 1o4f2RG36sllDnyDC82WoZcwZb8m0iY2vB0DmVaBY7nkRLFKWyTkQyneyuU++IW9uQ7I hyyp5clsOVkaQyKzjM5eneQii/CAFIg8hL6WWIR59WTl0UEHE0va/t4oMaVb9ua8mygz vyPKlczBckoST0YHY6fEEUwPGhzXCrK8nLFoy9Nx2Z5ajoxdggFW5EY8fH30wafN8s0c Wpp9IotPDx1c2PTricD7aaqcw+MQdDLOjr9Y77UGKufOhVE8yJKeyIrTSyBj4OJLg9a7 egzw== 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 o8-v6si8697301pgo.175.2018.07.23.05.55.18; Mon, 23 Jul 2018 05:55:33 -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 S2389127AbeGWNre (ORCPT + 99 others); Mon, 23 Jul 2018 09:47:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50966 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388621AbeGWNrd (ORCPT ); Mon, 23 Jul 2018 09:47:33 -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 59E72CA6; Mon, 23 Jul 2018 12:44:53 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konrad Rzeszutek Wilk , Thomas Gleixner , Borislav Petkov , Ingo Molnar , David Woodhouse , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 052/107] x86/bugs, KVM: Support the combination of guest and host IBRS Date: Mon, 23 Jul 2018 14:41:46 +0200 Message-Id: <20180723122415.577475807@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: Konrad Rzeszutek Wilk commit 5cf687548705412da47c9cec342fd952d71ed3d5 upstream A guest may modify the SPEC_CTRL MSR from the value used by the kernel. Since the kernel doesn't use IBRS, this means a value of zero is what is needed in the host. But the 336996-Speculative-Execution-Side-Channel-Mitigations.pdf refers to the other bits as reserved so the kernel should respect the boot time SPEC_CTRL value and use that. This allows to deal with future extensions to the SPEC_CTRL interface if any at all. Note: This uses wrmsrl() instead of native_wrmsl(). I does not make any difference as paravirt will over-write the callq *0xfff.. with the wrmsrl assembler code. Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Thomas Gleixner Reviewed-by: Borislav Petkov Reviewed-by: Ingo Molnar Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman [ Srivatsa: Backported to 4.4.y, skipping the KVM changes in this patch. ] 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/nospec-branch.h | 10 ++++++++++ arch/x86/kernel/cpu/bugs.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -183,6 +183,16 @@ enum spectre_v2_mitigation { extern void x86_spec_ctrl_set(u64); extern u64 x86_spec_ctrl_get_default(void); +/* + * On VMENTER we must preserve whatever view of the SPEC_CTRL MSR + * the guest has, while on VMEXIT we restore the host view. This + * would be easier if SPEC_CTRL were architecturally maskable or + * shadowable for guests but this is not (currently) the case. + * Takes the guest view of SPEC_CTRL MSR as a parameter. + */ +extern void x86_spec_ctrl_set_guest(u64); +extern void x86_spec_ctrl_restore_host(u64); + extern char __indirect_thunk_start[]; extern char __indirect_thunk_end[]; --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -122,6 +122,24 @@ u64 x86_spec_ctrl_get_default(void) } EXPORT_SYMBOL_GPL(x86_spec_ctrl_get_default); +void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl) +{ + if (!boot_cpu_has(X86_FEATURE_IBRS)) + return; + if (x86_spec_ctrl_base != guest_spec_ctrl) + wrmsrl(MSR_IA32_SPEC_CTRL, guest_spec_ctrl); +} +EXPORT_SYMBOL_GPL(x86_spec_ctrl_set_guest); + +void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl) +{ + if (!boot_cpu_has(X86_FEATURE_IBRS)) + return; + if (x86_spec_ctrl_base != guest_spec_ctrl) + wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); +} +EXPORT_SYMBOL_GPL(x86_spec_ctrl_restore_host); + #ifdef RETPOLINE static bool spectre_v2_bad_module;