Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2602264ybf; Mon, 2 Mar 2020 11:59:26 -0800 (PST) X-Google-Smtp-Source: ADFU+vvQrzAPnf+NMrRbuOvMXCNA8mQ+S9BNTp2/V1nfNt0OjCycj9OQsuZJCRdoV+QmYkryvPpd X-Received: by 2002:a05:6830:1d5:: with SMTP id r21mr711297ota.54.1583179165914; Mon, 02 Mar 2020 11:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583179165; cv=none; d=google.com; s=arc-20160816; b=hxMtqpqMRlujajnbktI7ZjDWEV+doWTlJftf5pnaleVQnJdIL2JYcQa5HWPAXdHluT FDHgcs3yvDkYg8DRCQDcwsNcYXqhZmDLBzGy8NLZwC+/MHmOBapHnmihzkj0qzvEebJ0 7sCzKCyzcZAu09YV8GYZzCkmOfTCn2Bvveg9l5jAtJUoanmzpGRrYAbGpo/V+hJTbN3v zvnGnE+oqsBQ4tqIIPLUkyKG/uScrWA4XU/MoWoKnrX2Zp9VSJpqosLVeFdfUSCn88NB xnqxCIKKGX0YlJm5TU0G0IcD3RUkh+v7+l1oioxAOByWKFsgVi19AzwSnioAWhI3veqp WcFA== 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:message-id:date:subject:cc:to:from; bh=GBdk3aMvewTAgE0T3WIyFS848jgfIPcba+0ECTpGMmg=; b=Qsoc70YJ93KZq0faBy2LpbIbPs69kffV04fTiz+OdjbGIl5JGiJdi/R0LLz7jn7M1P TkowKmLozp6hKijREAlRdu0Ra5RihR6QHHZ0AyYhaUfc50p0n0mUKXA4U8WgxVHH0cNa cFu2U5PneqeRLvUWvKzDj/HsbMlHc6iYiwFfo5WqNmW4UrhAPp/81qCw4kH5nUahsJ+K UrBuTxZvLo5YeHkTRxuqpNjtcURPJel0rocWmSF9N/O2hlfICNX9rGFmn4/lIxm3gjRH Cr7hrxAA5GD5K8AmPDG0JpnrTXqfYEiPouJXjiR4RslavrKq+gHW+YBIEPK1wwbCAZHI zU4Q== 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 o2si7146377otj.312.2020.03.02.11.59.13; Mon, 02 Mar 2020 11:59:25 -0800 (PST) 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 S1726785AbgCBT5i (ORCPT + 99 others); Mon, 2 Mar 2020 14:57:38 -0500 Received: from mga05.intel.com ([192.55.52.43]:30422 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbgCBT5i (ORCPT ); Mon, 2 Mar 2020 14:57:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2020 11:57:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,508,1574150400"; d="scan'208";a="438404973" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by fmsmga005.fm.intel.com with ESMTP; 02 Mar 2020 11:57:37 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kiszka , Xiaoyao Li Subject: [PATCH 1/6] KVM: x86: Fix tracing of CPUID.function when function is out-of-range Date: Mon, 2 Mar 2020 11:57:31 -0800 Message-Id: <20200302195736.24777-2-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200302195736.24777-1-sean.j.christopherson@intel.com> References: <20200302195736.24777-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rework kvm_cpuid() to query entry->function when adjusting the output values so that the original function (in the aptly named "function") is preserved for tracing. This fixes a bug where trace_kvm_cpuid() will trace the max function for a range instead of the requested function if the requested function is out-of-range and an entry for the max function exists. Fixes: 43561123ab37 ("kvm: x86: Improve emulation of CPUID leaves 0BH and 1FH") Reported-by: Jan Kiszka Cc: Jim Mattson Cc: Xiaoyao Li Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index b1c469446b07..6be012937eba 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -997,12 +997,12 @@ static bool cpuid_function_in_range(struct kvm_vcpu *vcpu, u32 function) return max && function <= max->eax; } +/* Returns true if the requested leaf/function exists in guest CPUID. */ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx, bool check_limit) { - u32 function = *eax, index = *ecx; + const u32 function = *eax, index = *ecx; struct kvm_cpuid_entry2 *entry; - struct kvm_cpuid_entry2 *max; bool found; entry = kvm_find_cpuid_entry(vcpu, function, index); @@ -1015,18 +1015,17 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, */ if (!entry && check_limit && !guest_cpuid_is_amd(vcpu) && !cpuid_function_in_range(vcpu, function)) { - max = kvm_find_cpuid_entry(vcpu, 0, 0); - if (max) { - function = max->eax; - entry = kvm_find_cpuid_entry(vcpu, function, index); - } + entry = kvm_find_cpuid_entry(vcpu, 0, 0); + if (entry) + entry = kvm_find_cpuid_entry(vcpu, entry->eax, index); } if (entry) { *eax = entry->eax; *ebx = entry->ebx; *ecx = entry->ecx; *edx = entry->edx; - if (function == 7 && index == 0) { + + if (entry->function == 7 && index == 0) { u64 data; if (!__kvm_get_msr(vcpu, MSR_IA32_TSX_CTRL, &data, true) && (data & TSX_CTRL_CPUID_CLEAR)) -- 2.24.1