From nobody Mon Feb 9 03:46:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCD60EB64DD for ; Tue, 25 Jul 2023 22:26:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233148AbjGYW0W (ORCPT ); Tue, 25 Jul 2023 18:26:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233380AbjGYWXw (ORCPT ); Tue, 25 Jul 2023 18:23:52 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35F1C26B6; Tue, 25 Jul 2023 15:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323569; x=1721859569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oacKdQeMh8QuirRSr8ipRHm85rmLeDu5QPcTK7AXcqY=; b=PqQffRyldbnRumqqjYLFc4M1uBnuIfa5rDEBDQN2uQO06gmo0CMTFlqY B0V0ULRV3IjsxZ8OWtpbb3rr0m7T9Qf9bJzS3avWM6mfaaGB/9gpZ64nZ aFjUMp31P+7qHg1XPQ+TovhvERSxKcVpGN6WekmFFZsDxBlIHr38h+xXj BXGRsxbRmbag6l3AcnFdj2a6EGEejXZO0dIK601po+mgxoLQWn5SansEf YZk8nHFe2jUFcXaYYZNCw8szkHUwAr3gutMrDwQ4POu8KmroCH1Zvb9dq KwwnBfy70bA7emS69CARyekmn5s+lMB0z+qHyOedv+F+od4vHJ5YTKbFv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882800" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882800" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001978" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001978" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:12 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 113/115] RFC: KVM: x86: Add x86 callback to check cpuid Date: Tue, 25 Jul 2023 15:15:04 -0700 Message-Id: <8787693c245ceeeada515fcca5ef78da3a1a7343.1690322424.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata The x86 backend should check the consistency of KVM_SET_CPUID2 because it has its constraint. Add a callback for it. The backend code will come as another patch. Suggested-by: Sean Christopherson Link: https://lore.kernel.org/lkml/ZDiGpCkXOcCm074O@google.com/ Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm-x86-ops.h | 2 ++ arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-= x86-ops.h index ba9cc4ac9093..aaa7db45d809 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -20,6 +20,8 @@ KVM_X86_OP(hardware_disable) KVM_X86_OP(hardware_unsetup) KVM_X86_OP_OPTIONAL_RET0(offline_cpu) KVM_X86_OP(has_emulated_msr) +/* TODO: Once all backend implemented this op, remove _OPTIONAL_RET0. */ +KVM_X86_OP_OPTIONAL_RET0(vcpu_check_cpuid) KVM_X86_OP(vcpu_after_set_cpuid) KVM_X86_OP(is_vm_type_supported) KVM_X86_OP_OPTIONAL(max_vcpus); diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 291d36a668e5..304c01945115 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1590,6 +1590,7 @@ struct kvm_x86_ops { void (*hardware_unsetup)(void); int (*offline_cpu)(void); bool (*has_emulated_msr)(struct kvm *kvm, u32 index); + int (*vcpu_check_cpuid)(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e= 2, int nent); void (*vcpu_after_set_cpuid)(struct kvm_vcpu *vcpu); =20 bool (*is_vm_type_supported)(unsigned long vm_type); diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 09b83f7c228d..de10a2de1dd5 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -123,6 +123,7 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, { struct kvm_cpuid_entry2 *best; u64 xfeatures; + int r; =20 /* * The existing code assumes virtual address is 48-bit or 57-bit in the @@ -150,7 +151,10 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, if (!xfeatures) return 0; =20 - return fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); + r =3D fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); + if (r) + return r; + return static_call(kvm_x86_vcpu_check_cpuid)(vcpu, entries, nent); } =20 /* Check whether the supplied CPUID data is equal to what is already set f= or the vCPU. */ --=20 2.25.1