Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2801775ybf; Mon, 2 Mar 2020 16:04:43 -0800 (PST) X-Google-Smtp-Source: ADFU+vtb9gYblaGdFxrJZq8a4vZLYNObCYGJQSaKrYTwHWyeZ32Z3IJpqktJN9LpE6DN3Epgo808 X-Received: by 2002:a05:6830:2009:: with SMTP id e9mr1411734otp.296.1583193883802; Mon, 02 Mar 2020 16:04:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583193883; cv=none; d=google.com; s=arc-20160816; b=fciihPwX7gSNOanpPPRH+COtVH5CVIlSTvm+7xgb0XJHLOTdzESZR8DhLPNrrmPMuS 69hbHyCWZDjBWHfHOK16bL3vT1aQ4a/Xy22p0Q1W+c4PSc+v7EnArR2U/Qt41xPbQMWe E5Gd9nWFYhmpubksGH34qXSjm3keNQIkdEuXGZ+dTltUUqRQ+LLJcKq9Kdn+V7iIrc1Z QGrEZ4uoHnn63dHlxHuLjEwe+kpPQV/z20vAEC8/tcgdLHBsSQD++Zubb3K0fuYh88vz SchY2u+OsGJrNxvtUpS9ArC7u9HhftYZwlDlY6JRu5f7jCW3nkD/zU1lCalktKOeSmO9 9ziQ== 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=ZQDjEVo5SfgPWRqDr3eQy7l9h44BgoqZxx9ICcq1bUk=; b=q1uQbBfQlFPo7qJoHf9G3NFkjAO+3irXFeuXCoJw3T70zw2p8Atc0LY/gghb7A6pN/ PDlTAyp0omfuXaO/ZxAy1mAlPychS4Mi94tQtb0w6U94F5Kj7q0CB4GAyV9AGzxpHV5Z frrj5MkPr+nEWatGxmE5b6pXE+8hEAC09qt9olwHkp26UTRX4xRBiETYPrnFh13nzZN+ 9AEJLpBX5UZf7OjxgG7CMTDz0ac41274HIe9hRMQTKn8GuEBFMIM4obW8FP4+Lvgf4mX WDv23DhUUNHH/RhDoDFyoKpf3Ut1lZYLtbEvi92qgpd0t1wP5A8UiwrtceFtvlAOW3cZ BKGA== 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 w202si637295oia.157.2020.03.02.16.04.31; Mon, 02 Mar 2020 16:04:43 -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 S1727536AbgCCACr (ORCPT + 99 others); Mon, 2 Mar 2020 19:02:47 -0500 Received: from mga17.intel.com ([192.55.52.151]:37738 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbgCBX5X (ORCPT ); Mon, 2 Mar 2020 18:57:23 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2020 15:57:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,509,1574150400"; d="scan'208";a="243384631" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by orsmga006.jf.intel.com with ESMTP; 02 Mar 2020 15:57:21 -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, Xiaoyao Li Subject: [PATCH v2 03/66] KVM: x86: Simplify handling of Centaur CPUID leafs Date: Mon, 2 Mar 2020 15:56:06 -0800 Message-Id: <20200302235709.27467-4-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200302235709.27467-1-sean.j.christopherson@intel.com> References: <20200302235709.27467-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 Refactor the handling of the Centaur-only CPUID leaf to detect the leaf via a runtime query instead of adding a one-off callback in the static array. When the callback was introduced, there were additional fields in the array's structs, and more importantly, retpoline wasn't a thing. No functional change intended. Reviewed-by: Vitaly Kuznetsov Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index f49fdd06f511..de52cbb46171 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -829,15 +829,7 @@ static int do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 func, return __do_cpuid_func(entry, func, nent, maxnent); } -struct kvm_cpuid_param { - u32 func; - bool (*qualifier)(const struct kvm_cpuid_param *param); -}; - -static bool is_centaur_cpu(const struct kvm_cpuid_param *param) -{ - return boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR; -} +#define CENTAUR_CPUID_SIGNATURE 0xC0000000 static int get_cpuid_func(struct kvm_cpuid_entry2 *entries, u32 func, int *nent, int maxnent, unsigned int type) @@ -845,6 +837,10 @@ static int get_cpuid_func(struct kvm_cpuid_entry2 *entries, u32 func, u32 limit; int r; + if (func == CENTAUR_CPUID_SIGNATURE && + boot_cpu_data.x86_vendor != X86_VENDOR_CENTAUR) + return 0; + r = do_cpuid_func(&entries[*nent], func, nent, maxnent, type); if (r) return r; @@ -896,11 +892,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 *cpuid_entries; int nent = 0, r = -E2BIG, i; - static const struct kvm_cpuid_param param[] = { - { .func = 0 }, - { .func = 0x80000000 }, - { .func = 0xC0000000, .qualifier = is_centaur_cpu }, - { .func = KVM_CPUID_SIGNATURE }, + static const u32 funcs[] = { + 0, 0x80000000, CENTAUR_CPUID_SIGNATURE, KVM_CPUID_SIGNATURE, }; if (cpuid->nent < 1) @@ -918,14 +911,9 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, goto out; r = 0; - for (i = 0; i < ARRAY_SIZE(param); i++) { - const struct kvm_cpuid_param *ent = ¶m[i]; - - if (ent->qualifier && !ent->qualifier(ent)) - continue; - - r = get_cpuid_func(cpuid_entries, ent->func, &nent, - cpuid->nent, type); + for (i = 0; i < ARRAY_SIZE(funcs); i++) { + r = get_cpuid_func(cpuid_entries, funcs[i], &nent, cpuid->nent, + type); if (r) goto out_free; } -- 2.24.1