Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp414406pxk; Fri, 11 Sep 2020 10:13:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiVTNy3WCSGAKoQa8lZFYWLLdpO0rcm8ReSiIRTW0OnpU04Uw5pmu2aOVD6H19ky2/Imbj X-Received: by 2002:a05:6402:114d:: with SMTP id g13mr3146508edw.157.1599844411582; Fri, 11 Sep 2020 10:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599844411; cv=none; d=google.com; s=arc-20160816; b=OQqhqcS3RQhSFaVpO964TkLLeCrEPY2m+MiwFUaP9lNk4jHdNNCXZaQ+I6aZQNHDyC AKAw0fIF6Y1WeUK9o82X1uLubnxdEcpPF2eI6AkOnG/DimqmfCqiLbewzWQSWdxwm9dK Fs5L7+WkG+BUay/C1mcaBxVWHajVI71pF3NJFiJZh9CB6EqUNiiAwR/V4AbtCMvskzUH qUmOebgfvs7fjSBWvO2qQctUnRA8FUBYHyS1uta5T8ly2uvUc2+kLsSekVFF19MBiN74 +AeJhIkUrSCeI9tOaYiieZw5WxjMVyNGWSgXaDQOHIN5eUGW7LcaH9mUZBIG8g5k9Kiq 2NlQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=T4JkIThZtF0RdLNQoUDiKXmb6/K82XCLQ+U784yJ8XQ=; b=bSsiShasEuNkpo6NN/qO2UWxAV4QRSi8GESsIaTrTv+FbehAHMM4hd0PeVmUYaSSrJ v1wODYWQlk83QvBFsjeqYIM07NVrh6dZ2KiWX5KmRonl5vz9xYdBOp/1gI2LBPJCHp0f 2VA+35b6qlqOZk6ppch4Hccd1ZBpCYoaPl37UhqpxVwxyPOrQq0Lmz/zak4zPeVwLcQi jaz3+slOAjDH4u98Krmp2CWZEvl3p+eNFeiH48QCUHexVC63YbCf33CHylYZJCn68EXX r3Dtv0tOebNL1+9CyyAGXDRqCpMSIlsSKE2467uS+kAdJBkbvSPPYK/El2mzkiqYjwyU yXWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F9ZUZWFU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si1733275edy.412.2020.09.11.10.13.09; Fri, 11 Sep 2020 10:13:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F9ZUZWFU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726336AbgIKRKE (ORCPT + 99 others); Fri, 11 Sep 2020 13:10:04 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24516 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726324AbgIKRJe (ORCPT ); Fri, 11 Sep 2020 13:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599844172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T4JkIThZtF0RdLNQoUDiKXmb6/K82XCLQ+U784yJ8XQ=; b=F9ZUZWFUZjo8kEwRxJ8VV35BtpY/mTbRr+mJyFFRjhCrhPYVpkT1pZs+6PFZdlXv4+x3nf 3O0vOT2SJgKVmHU0D6IDrNaSG1osUsTpN2VJOqg1QiVJ2C26N92tlnaQhLUGzztkeExV77 5bKZ/755wOAw3nqRXdWBpBVXyHw5VHU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-461-bm0KYASQN1C1CBxdHoOQCA-1; Fri, 11 Sep 2020 13:09:31 -0400 X-MC-Unique: bm0KYASQN1C1CBxdHoOQCA-1 Received: by mail-wm1-f72.google.com with SMTP id m20so847860wmg.6 for ; Fri, 11 Sep 2020 10:09:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=T4JkIThZtF0RdLNQoUDiKXmb6/K82XCLQ+U784yJ8XQ=; b=Ehky9iFnCUUsi4beTLVKrrCiVeh70OFnveMhFhP1fUOqLORCW01JKdK0dWB1GblTjV t0UqdpxZ3Oo9Mr1qFPVElwdkWN7i2famKd/zBF8s+Hqj3j4q903oNx6qKL6oflOt0nrI EW0XA6UIv2IsPrigXQFt/uYUhEd668SZwWitbHBG3BKVxVjSuj1pHeWxljquAB+oRGlk rNWkTnSlwkU/PBShSWFmCHWOOFRMswE2cuSxo+CEU7820CsClF0QPOy6rlXPnn5JD2um VcguSogkMDcezkgDfkQVPbJGfA+ZHQoT/epp/NWjZ+RwJkeBGbifnCimmNB0pLNeTJTy 5HQw== X-Gm-Message-State: AOAM5311Ofg3VP1B4l/WAA4IIoD/JpDPPZjSOXV9M+oC/ZRCXPLxyyer /88NYO08ucTgm6lpGpxuvHfHy/C+Rvjvq2i40HXbvZQ0qbnkfhSLy3T7w8YQg19R4tJNkVLKc/E VR4F3ApeR5KnqlFfSofJm5SfW X-Received: by 2002:adf:dc47:: with SMTP id m7mr3015664wrj.100.1599844169917; Fri, 11 Sep 2020 10:09:29 -0700 (PDT) X-Received: by 2002:adf:dc47:: with SMTP id m7mr3015629wrj.100.1599844169608; Fri, 11 Sep 2020 10:09:29 -0700 (PDT) Received: from [192.168.10.150] ([93.56.170.5]) by smtp.gmail.com with ESMTPSA id g12sm5838009wro.89.2020.09.11.10.09.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Sep 2020 10:09:29 -0700 (PDT) Subject: Re: [PATCH 3/5] KVM: nVMX: Update VMX controls MSR according to guest CPUID after setting VMX MSRs To: Jim Mattson , Sean Christopherson Cc: Chenyi Qiang , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , Xiaoyao Li , kvm list , LKML References: <20200828085622.8365-1-chenyi.qiang@intel.com> <20200828085622.8365-4-chenyi.qiang@intel.com> <20200902181654.GH11695@sjchrist-ice> From: Paolo Bonzini Message-ID: <48fd0fd9-97b4-471e-d8e8-628f51dcdeff@redhat.com> Date: Fri, 11 Sep 2020 19:09:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/09/20 20:32, Jim Mattson wrote: > > /* If not VM_EXIT_CLEAR_BNDCFGS, the L2 value propagates to L1. */ > if (vmcs12->vm_exit_controls & VM_EXIT_CLEAR_BNDCFGS) > vmcs_write64(GUEST_BNDCFGS, 0); > > BTW, where does the L2 value propagate to L1 if not VM_EXIT_CLEAR_BNDCFGS? Hmm, nowhere. :/ Probably something like this (not really thought through): diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1e903d51912b..aba76aa99465 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3317,7 +3317,8 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL); if (kvm_mpx_supported() && - !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS)) + (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS) || + !(vmcs12->vm_exit_controls & VM_EXIT_CLEAR_BNDCFGS))) vmx->nested.vmcs01_guest_bndcfgs = vmcs_read64(GUEST_BNDCFGS); /* @@ -4186,9 +4187,12 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu, vmcs_write32(GUEST_IDTR_LIMIT, 0xFFFF); vmcs_write32(GUEST_GDTR_LIMIT, 0xFFFF); - /* If not VM_EXIT_CLEAR_BNDCFGS, the L2 value propagates to L1. */ - if (vmcs12->vm_exit_controls & VM_EXIT_CLEAR_BNDCFGS) - vmcs_write64(GUEST_BNDCFGS, 0); + if (kvm_mpx_supported()) { + if (vmcs12->vm_exit_controls & VM_EXIT_CLEAR_BNDCFGS) + vmcs_write64(GUEST_BNDCFGS, 0); + else + vmcs_write64(GUEST_BNDCFGS, vmx->nested.vmcs01_guest_bndcfgs); + } if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) { vmcs_write64(GUEST_IA32_PAT, vmcs12->host_ia32_pat); @@ -4466,6 +4470,10 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason, vmx_set_virtual_apic_mode(vcpu); } + /* If not VM_EXIT_CLEAR_BNDCFGS, the L2 value propagates to L1. */ + if (!(vmcs12->vm_exit_controls & VM_EXIT_CLEAR_BNDCFGS)) + vmx->nested.vmcs01_guest_bndcfgs = vmcs12->guest_bndcfgs; + /* Unpin physical memory we referred to in vmcs02 */ if (vmx->nested.apic_access_page) { kvm_release_page_clean(vmx->nested.apic_access_page); which will also work in the failed vmentry case. Paolo