mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	<linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>
Cc: <seanjc@google.com>, Yan Zhao <yan.y.zhao@intel.com>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>
Subject: Re: [PATCH 25/33] KVM: x86: expose cpuid_entry2_find for TDX
Date: Thu, 27 Feb 2025 11:03:12 +1300	[thread overview]
Message-ID: <9079202f-2b0d-4bcf-8f61-36c7234245d1@intel.com> (raw)
In-Reply-To: <20250226181453.2311849-26-pbonzini@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1601 bytes --]



On 27/02/2025 7:14 am, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Kai Huang <kai.huang@intel.com>

... assuming there will be a changelog, e.g., perhaps something like below:

TDX will need to search a CPUID leaf from a list of per-TD scope CPUID 
entries w/o any vCPU context.  Abstract the code which does CPUID entry 
search from a given list of CPUID entries as kvm_find_cpuid_entry2() and 
Export it for TDX to use.

And one nit below ...

> @@ -141,23 +141,26 @@ static struct kvm_cpuid_entry2 *cpuid_entry2_find(struct kvm_vcpu *vcpu,
>   
>   	return NULL;
>   }
> +EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry2);
>   
>   struct kvm_cpuid_entry2 *kvm_find_cpuid_entry_index(struct kvm_vcpu *vcpu,
>   						    u32 function, u32 index)
>   {
> -	return cpuid_entry2_find(vcpu, function, index);
> +	return kvm_find_cpuid_entry2(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
> +				     function, index);
>   }
>   EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry_index);
>   
>   struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
>   					      u32 function)
>   {
> -	return cpuid_entry2_find(vcpu, function, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
> +	return kvm_find_cpuid_entry2(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
> +				     function, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
>   }
>   EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);

... I think we can change both kvm_find_cpuid_entry_index() and 
kvm_find_cpuid_entry() to 'static inline' and place them in the 
kvm/cpuid.h to avoid exporting them.

See attached diff.  Build test only.

[-- Attachment #2: tdx_cpuid.diff --]
[-- Type: text/plain, Size: 2682 bytes --]

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 7ff84079c1f4..ecf2750693d4 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -143,22 +143,6 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry2(
 }
 EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry2);
 
-struct kvm_cpuid_entry2 *kvm_find_cpuid_entry_index(struct kvm_vcpu *vcpu,
-						    u32 function, u32 index)
-{
-	return kvm_find_cpuid_entry2(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
-				     function, index);
-}
-EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry_index);
-
-struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
-					      u32 function)
-{
-	return kvm_find_cpuid_entry2(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
-				     function, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
-}
-EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
-
 /*
  * kvm_find_cpuid_entry2() and KVM_CPUID_INDEX_NOT_SIGNIFICANT should never be used
  * directly outside of kvm_find_cpuid_entry() and kvm_find_cpuid_entry_index().
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index 46e059b47825..738b396416cd 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -14,10 +14,29 @@ void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu);
 void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu);
 struct kvm_cpuid_entry2 *kvm_find_cpuid_entry2(struct kvm_cpuid_entry2 *entries,
 					       int nent, u32 function, u64 index);
-struct kvm_cpuid_entry2 *kvm_find_cpuid_entry_index(struct kvm_vcpu *vcpu,
-						    u32 function, u32 index);
-struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
-					      u32 function);
+/*
+ * Magic value used by KVM when querying userspace-provided CPUID entries and
+ * doesn't care about the CPIUD index because the index of the function in
+ * question is not significant.  Note, this magic value must have at least one
+ * bit set in bits[63:32] and must be consumed as a u64 by kvm_find_cpuid_entry2()
+ * to avoid false positives when processing guest CPUID input.
+ */
+#define KVM_CPUID_INDEX_NOT_SIGNIFICANT -1ull
+
+static inline struct kvm_cpuid_entry2 *kvm_find_cpuid_entry_index(struct kvm_vcpu *vcpu,
+								  u32 function, u32 index)
+{
+	return kvm_find_cpuid_entry2(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
+				     function, index);
+}
+
+static inline struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
+							    u32 function)
+{
+	return kvm_find_cpuid_entry2(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
+				     function, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
+}
+
 int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
 			    struct kvm_cpuid_entry2 __user *entries,
 			    unsigned int type);

  reply	other threads:[~2025-02-26 22:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 18:14 [PATCH v4 00/33] TDX initialization + vCPU/VM creation Paolo Bonzini
2025-02-26 18:14 ` [PATCH 01/33] KVM: x86: Free vCPUs before freeing VM state Paolo Bonzini
2025-02-26 18:14 ` [PATCH 02/33] KVM: x86: move vm_destroy callback at end of kvm_arch_destroy_vm Paolo Bonzini
2025-02-26 18:14 ` [PATCH 03/33] KVM: x86: Don't load/put vCPU when unloading its MMU during teardown Paolo Bonzini
2025-02-26 18:14 ` [PATCH 04/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX KeyID management Paolo Bonzini
2025-02-26 18:14 ` [PATCH 05/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX TD creation Paolo Bonzini
2025-02-26 18:14 ` [PATCH 06/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX vCPU creation Paolo Bonzini
2025-02-26 18:14 ` [PATCH 07/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX page cache management Paolo Bonzini
2025-03-03  0:22   ` Chenyi Qiang
2025-02-26 18:14 ` [PATCH 08/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX VM/vCPU field access Paolo Bonzini
2025-02-26 18:14 ` [PATCH 09/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX flush operations Paolo Bonzini
2025-02-26 18:14 ` [PATCH 10/33] x86/virt/tdx: allocate tdx_sys_info in static memory Paolo Bonzini
2025-02-26 18:14 ` [PATCH 11/33] x86/virt/tdx: Read essential global metadata for KVM Paolo Bonzini
2025-02-26 18:14 ` [PATCH 12/33] x86/virt/tdx: Add tdx_guest_keyid_alloc/free() to alloc and free TDX guest KeyID Paolo Bonzini
2025-02-26 18:14 ` [PATCH 13/33] KVM: Export hardware virtualization enabling/disabling functions Paolo Bonzini
2025-02-26 18:14 ` [PATCH 14/33] KVM: VMX: Refactor VMX module init/exit functions Paolo Bonzini
2025-02-26 18:14 ` [PATCH 15/33] KVM: VMX: Initialize TDX during KVM module load Paolo Bonzini
2025-02-26 18:14 ` [PATCH 16/33] KVM: TDX: Get TDX global information Paolo Bonzini
2025-02-26 18:14 ` [PATCH 17/33] KVM: TDX: Add placeholders for TDX VM/vCPU structures Paolo Bonzini
2025-02-26 18:14 ` [PATCH 18/33] KVM: TDX: Define TDX architectural definitions Paolo Bonzini
2025-02-26 18:14 ` [PATCH 19/33] KVM: TDX: Add TDX "architectural" error codes Paolo Bonzini
2025-02-26 18:14 ` [PATCH 20/33] KVM: TDX: Add helper functions to print TDX SEAMCALL error Paolo Bonzini
2025-02-26 18:14 ` [PATCH 21/33] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Paolo Bonzini
2025-02-26 18:14 ` [PATCH 22/33] KVM: TDX: Get system-wide info about TDX module on initialization Paolo Bonzini
2025-02-26 18:14 ` [PATCH 23/33] KVM: TDX: create/destroy VM structure Paolo Bonzini
2025-06-25 15:46   ` Dave Hansen
2025-06-25 16:12     ` Sean Christopherson
2025-02-26 18:14 ` [PATCH 24/33] KVM: TDX: Support per-VM KVM_CAP_MAX_VCPUS extension check Paolo Bonzini
2025-02-26 18:14 ` [PATCH 25/33] KVM: x86: expose cpuid_entry2_find for TDX Paolo Bonzini
2025-02-26 22:03   ` Huang, Kai [this message]
2025-02-26 18:14 ` [PATCH 26/33] KVM: TDX: add ioctl to initialize VM with TDX specific parameters Paolo Bonzini
2025-02-26 18:14 ` [PATCH 27/33] KVM: TDX: Make pmu_intel.c ignore guest TD case Paolo Bonzini
2025-02-26 18:14 ` [PATCH 28/33] KVM: TDX: Don't offline the last cpu of one package when there's TDX guest Paolo Bonzini
2025-02-26 18:14 ` [PATCH 29/33] KVM: TDX: create/free TDX vcpu structure Paolo Bonzini
2025-02-26 18:14 ` [PATCH 30/33] KVM: TDX: Do TDX specific vcpu initialization Paolo Bonzini
2025-02-26 18:14 ` [PATCH 31/33] KVM: x86: Introduce KVM_TDX_GET_CPUID Paolo Bonzini
2025-02-26 18:14 ` [PATCH 32/33] KVM: x86/mmu: Taking guest pa into consideration when calculate tdp level Paolo Bonzini
2025-02-26 18:14 ` [PATCH 33/33] KVM: TDX: Register TDX host key IDs to cgroup misc controller Paolo Bonzini
2025-02-28  1:56   ` Chenyi Qiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9079202f-2b0d-4bcf-8f61-36c7234245d1@intel.com \
    --to=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=yan.y.zhao@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®