All of lore.kernel.org
 help / color / mirror / Atom feed
* [QEMU PATCH v2] x86: Set maximum APIC ID to KVM prior to vCPU creation
@ 2022-05-23  9:12 Zeng Guang
  0 siblings, 0 replies; only message in thread
From: Zeng Guang @ 2022-05-23  9:12 UTC (permalink / raw)
  To: Paolo Bonzini, Sean Christopherson, Michael S . Tsirkin,
	Marcel Apfelbaum, Richard Henderson, Eduardo Habkost
  Cc: qemu-devel, kvm, Gao Chao, Zeng Guang

Specify maximum possible APIC ID assigned for current VM session to KVM
prior to the creation of vCPUs. By this setting, KVM can set up VM-scoped
data structure indexed by the APIC ID, e.g. Posted-Interrupt Descriptor
table to support Intel IPI virtualization, with the most optimal memory
footprint.

It can be achieved by calling KVM_ENABLE_CAP for KVM_CAP_MAX_VCPU_ID
capability once KVM has already enabled it. Ignoring the return error
if KVM doesn't support this capability yet.

Signed-off-by: Zeng Guang <guang.zeng@intel.com>
---
 hw/i386/x86.c              | 5 +++++
 target/i386/kvm/kvm.c      | 5 +++++
 target/i386/kvm/kvm_i386.h | 1 +
 3 files changed, 11 insertions(+)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 4cf107baea..a6ab406f85 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -123,6 +123,11 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
      */
     x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms,
                                                       ms->smp.max_cpus - 1) + 1;
+
+    if (kvm_enabled()) {
+        kvm_set_max_apic_id(x86ms->apic_id_limit);
+    }
+
     possible_cpus = mc->possible_cpu_arch_ids(ms);
     for (i = 0; i < ms->smp.cpus; i++) {
         x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal);
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 9cf8e03669..cb2fe39365 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -5251,3 +5251,8 @@ void kvm_request_xsave_components(X86CPU *cpu, uint64_t mask)
         mask &= ~BIT_ULL(bit);
     }
 }
+
+void kvm_set_max_apic_id(uint32_t max_apic_id)
+{
+    kvm_vm_enable_cap(kvm_state, KVM_CAP_MAX_VCPU_ID, 0, max_apic_id);
+}
diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h
index 4124912c20..c133b32a58 100644
--- a/target/i386/kvm/kvm_i386.h
+++ b/target/i386/kvm/kvm_i386.h
@@ -54,4 +54,5 @@ uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address);
 bool kvm_enable_sgx_provisioning(KVMState *s);
 void kvm_request_xsave_components(X86CPU *cpu, uint64_t mask);
 
+void kvm_set_max_apic_id(uint32_t max_apic_id);
 #endif
-- 
2.27.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-23  9:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23  9:12 [QEMU PATCH v2] x86: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.