Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753339AbeAKCrK (ORCPT + 1 other); Wed, 10 Jan 2018 21:47:10 -0500 Received: from mga03.intel.com ([134.134.136.65]:13925 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752917AbeAKCrJ (ORCPT ); Wed, 10 Jan 2018 21:47:09 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,343,1511856000"; d="scan'208";a="20025088" Subject: Re: [PATCH 3/7] kvm: vmx: pass MSR_IA32_SPEC_CTRL and MSR_IA32_PRED_CMD down to the guest To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: jmattson@google.com, aliguori@amazon.com, thomas.lendacky@amd.com, dwmw@amazon.co.uk, bp@alien8.de, ashok.raj@intel.com References: <1515434925-10250-1-git-send-email-pbonzini@redhat.com> <1515434925-10250-4-git-send-email-pbonzini@redhat.com> From: Tim Chen Message-ID: <32efe0b2-d041-a70d-0e5a-8523553f068b@linux.intel.com> Date: Wed, 10 Jan 2018 18:47:06 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <1515434925-10250-4-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 01/08/2018 10:08 AM, Paolo Bonzini wrote: > @@ -9597,6 +9620,9 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > > pt_guest_enter(vmx); > > + if (have_spec_ctrl && vmx->spec_ctrl != 0) > + wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); > + Say host uses IBRS (have_spec_ctrl==1), and have IBRS set to 1. And say guest's vmx->spec_ctrl is 0 and not using IBRS. We will be leaving IBRS msr as 1 and won't be switching it to 0 before entering guest. Guest will be running with incorrect IBRS value. Seems like the correct logic is if (host_supports_ibrs) /* switch IBRS if host and guest ibrs differs */ if ((host_uses_ibrs && vmx->spec_ctrl == 0) || /* host IBRS 1, guest IBRS 0 */ (!host_uses_ibrs && vmx->spec_ctrl == 1)) /* host IBRS 0, guest IBRS 1 */ wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); } Your have_spec_ctrl logic specifies that IBRS is available. But that doesn't necessarily mean that we will use IBRS in host. Tim