From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, HK_RANDOM_FROM,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CD97C433DF for ; Wed, 24 Jun 2020 00:40:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C1EE20874 for ; Wed, 24 Jun 2020 00:40:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388084AbgFXAkR (ORCPT ); Tue, 23 Jun 2020 20:40:17 -0400 Received: from mga05.intel.com ([192.55.52.43]:5063 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387586AbgFXAkR (ORCPT ); Tue, 23 Jun 2020 20:40:17 -0400 IronPort-SDR: qTpRyEPjTfSu2eBUZYRGqgxCVIIFpMVDv12Wxua2ksdPaWEFQtZ10ESRWEL25e+tDTPh7A9wj0 XHBMmwQDHOWQ== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="228964118" X-IronPort-AV: E=Sophos;i="5.75,273,1589266800"; d="scan'208";a="228964118" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 17:40:16 -0700 IronPort-SDR: 4rbmInvG3yqk+WGpQtfSk6qnzq3kaKehHPA+gtmKCH/MeZoC06bDIFTP15RgNt94gjrQ2xLe45 gvXEiYEPfrSw== X-IronPort-AV: E=Sophos;i="5.75,273,1589266800"; d="scan'208";a="452446201" Received: from cli46-mobl2.ccr.corp.intel.com (HELO [10.255.29.15]) ([10.255.29.15]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 17:40:13 -0700 Subject: Re: [PATCH v2 1/7] KVM: X86: Reset vcpu->arch.cpuid_nent to 0 if SET_CPUID fails To: Jim Mattson Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML References: <20200623115816.24132-1-xiaoyao.li@intel.com> <20200623115816.24132-2-xiaoyao.li@intel.com> From: Xiaoyao Li Message-ID: <59535ddb-373a-952f-f049-91d8f142c6a9@intel.com> Date: Wed, 24 Jun 2020 08:40:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed 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 6/24/2020 2:20 AM, Jim Mattson wrote: > On Tue, Jun 23, 2020 at 4:58 AM Xiaoyao Li wrote: >> >> It needs to invalidate CPUID configruations if usersapce provides > > Nits: configurations, userspace oh, I'll fix it. >> illegal input. >> >> Signed-off-by: Xiaoyao Li >> --- >> arch/x86/kvm/cpuid.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >> index 8a294f9747aa..1d13bad42bf9 100644 >> --- a/arch/x86/kvm/cpuid.c >> +++ b/arch/x86/kvm/cpuid.c >> @@ -207,6 +207,8 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, >> kvm_apic_set_version(vcpu); >> kvm_x86_ops.cpuid_update(vcpu); >> r = kvm_update_cpuid(vcpu); >> + if (r) >> + vcpu->arch.cpuid_nent = 0; >> >> kvfree(cpuid_entries); >> out: >> @@ -230,6 +232,8 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, >> kvm_apic_set_version(vcpu); >> kvm_x86_ops.cpuid_update(vcpu); >> r = kvm_update_cpuid(vcpu); >> + if (r) >> + vcpu->arch.cpuid_nent = 0; >> out: >> return r; >> } >> -- >> 2.18.2 > > What if vcpu->arch.cpuid_nent was greater than 0 before the ioctl in question? > Nice catch! If considering it, then we have to restore the old CPUID configuration. So how about making it simpler to just add one line of comment in API doc: If KVM_SET_CPUID{2} fails, the old valid configuration is cleared as a side effect.