Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4536425yba; Tue, 9 Apr 2019 22:45:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRZZ1LmWlMMgoFUdtjxXo/rVZ2TyFe8TNA/sXGzCRT9Q6CKnZ5uLK3ws97if+7eYmXU54s X-Received: by 2002:a63:e048:: with SMTP id n8mr23578035pgj.41.1554875136267; Tue, 09 Apr 2019 22:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554875136; cv=none; d=google.com; s=arc-20160816; b=U/gVwsyHf3YtoZUUv5vhha/5DrsW00WgWWiq9TIqICrK/IrnPTXKfY7pggasS11yb1 YZICPhVTbBsqWtN+sCuY8soBBwMlniu2se/9S1PzJfQIA83D4dMCR/Mljr6GBD8tESDL Bfi2nsiA+8y2G2jFLtZ71EQ0QZkncJENnL41Jdp2Y7TZpORG6G6Gh3qgK+Bv71O4SXqC XA8VkaZEws4XBmRKItHCQLMVTyic3hplOre6Mw22GRqaVX3xGxgs/jK6yEGs2kY+I/BR bqxp3y4U9KtpwqSe+WW1oNkqDDvrgj66TktckbZbRWwhkZHOsoY2WJ/5Iqr7w4PvggEr WOxQ== 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 :references:in-reply-to:date:cc:to:from:subject:message-id; bh=YscLQFNYDzbHut6jlHIF1RN4bnrOeMzMJhmzv9TyIEg=; b=RvBsK1LdS53h+Sw0+xB9pLI7egyKansz9dzkS6Jb/ylJzeuRDImnivZzIFXfbYMFGW vF4ZddBF3hQcWNK/zfBxdVm57IifOFm1DF0c5Z0+pSoTjt3HPy1I9A8oxB74DDzpOpoi 7vkBnjsxeGh+0fy2smXN6LqNx/2Zxscewwfedoiri7RW5clRuABmFh5zwFzXTF0dJu9h SqEGasN7N+CfaOK4IYLjFN/KUyzl1T4ZSFtsmgT5eeuew2UULMEjp9/0LNYt8d8Z8ykI 8YNs6ruWBvX+XeRxE+HyH+huM9SzInkRif/o93OmQZdrUNsTpPFI4PbavuT/hf9MkupY CoUw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si32430380plb.276.2019.04.09.22.45.17; Tue, 09 Apr 2019 22:45:36 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727335AbfDJFHY (ORCPT + 99 others); Wed, 10 Apr 2019 01:07:24 -0400 Received: from mga05.intel.com ([192.55.52.43]:19538 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726826AbfDJFHY (ORCPT ); Wed, 10 Apr 2019 01:07:24 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Apr 2019 22:07:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,332,1549958400"; d="scan'208";a="222112098" Received: from lxy-dell.sh.intel.com ([10.239.159.145]) by orsmga001.jf.intel.com with ESMTP; 09 Apr 2019 22:07:19 -0700 Message-ID: <9b16b5c5379eb6b5352de26e56b8064a6b6f1aa7.camel@linux.intel.com> Subject: Re: [PATCH v6 12/20] kvm/vmx: Emulate MSR TEST_CTL From: Xiaoyao Li To: Sean Christopherson Cc: Thomas Gleixner , Fenghua Yu , Ingo Molnar , Borislav Petkov , H Peter Anvin , Dave Hansen , Paolo Bonzini , Ashok Raj , Peter Zijlstra , Kalle Valo , Michael Chan , Ravi V Shankar , linux-kernel , x86 , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org Date: Wed, 10 Apr 2019 13:03:59 +0800 In-Reply-To: <20190408174805.GJ25880@linux.intel.com> References: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> <1554326526-172295-13-git-send-email-fenghua.yu@intel.com> <423f329a8e194d799c6c41470266a04a9f90bc84.camel@linux.intel.com> <20190408174805.GJ25880@linux.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-2.el7) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-04-08 at 10:48 -0700, Sean Christopherson wrote: > On Mon, Apr 08, 2019 at 05:54:25PM +0800, Xiaoyao Li wrote: > > On Fri, 2019-04-05 at 14:30 +0200, Thomas Gleixner wrote: > > > On Wed, 3 Apr 2019, Fenghua Yu wrote: > > > > @@ -1663,6 +1663,12 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, > > > > struct > > > > msr_data *msr_info) > > > > u32 index; > > > > > > > > switch (msr_info->index) { > > > > + case MSR_TEST_CTL: > > > > + if (!msr_info->host_initiated && > > > > + !(vcpu->arch.core_capability & > > > > CORE_CAP_SPLIT_LOCK_DETECT)) > > > > > > Errm? If the MSR_TEST_CTL is exposed to the guest via CPUID then the > > > rdmsr() in the guest is not supposed to fail just because > > > CORE_CAP_SPLIT_LOCK_DETECT is not set. > > > > you're right. > > > > > vmx->msr_test_ctl holds the proper value, which is either 0 or > > > CORE_CAP_SPLIT_LOCK_DETECT until more bits are supported. > > > > > > So the chek needs to be guest_cpuid_has(X86_FEATURE_CORE_CAPABILITY). > > > > I don't think so. There is no dependecy between > > guest_cpuid_has(X86_FEATURE_CORE_CAPABILITY) and MSR_TEST_CTL. > > guest_cpuid_has(X86_FEATURE_CORE_CAPABILITY) only indicates that guest has > > MSR > > CORE_CAPABILITY. > > > > Due to the fact that MSR_TEST_CTL is emulated with vmx->msr_test_ctl. I > > think it > > 's ok to always let userspace or guest to read MSR_TEST_CTL, it just returns > > the > > emulated value. Like you said, " vmx->msr_test_ctl holds the proper value, > > which > > is either 0 or CORE_CAP_SPLIT_LOCK_DETECT until more bits are supported." > > Assuming the next version implements "vmx->msr_test_ctl_mask", KVM should > inject #GP if the guest attempts RDMSR(MSR_TEST_CTL) and the mask is zero. > It stands to reason that a kernel can only reasonably assume the MSR exists > if the (virtual) CPU supports at least one feature enabled via MSR_TEST_CTL. It makes sense to me. Thanks for your reminder. Will apply it in next version.