All of lore.kernel.org
 help / color / mirror / Atom feed
* [QEMU PATCH] x86: Set maximum APIC ID to KVM prior to vCPU creation
@ 2022-05-20  6:39 Zeng Guang
  2022-05-20  7:56 ` Chao Gao
  0 siblings, 1 reply; 2+ messages in thread
From: Zeng Guang @ 2022-05-20  6:39 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 prior to
the creation of vCPUs. KVM need set up VM-scoped data structure indexed by
the APIC ID, e.g. Posted-Interrupt Descriptor table to support Intel IPI
virtualization.

It can be achieved by calling KVM_ENABLE_CAP for KVM_CAP_MAX_VCPU_ID
capability once KVM has already enabled it. Otherwise, simply prompts
that KVM doesn't support this capability yet.

Signed-off-by: Zeng Guang <guang.zeng@intel.com>
---
 hw/i386/x86.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 4cf107baea..ff74492325 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -106,7 +106,7 @@ out:
 
 void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
 {
-    int i;
+    int i, ret;
     const CPUArchIdList *possible_cpus;
     MachineState *ms = MACHINE(x86ms);
     MachineClass *mc = MACHINE_GET_CLASS(x86ms);
@@ -123,6 +123,13 @@ 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;
+
+    ret = kvm_vm_enable_cap(kvm_state, KVM_CAP_MAX_VCPU_ID,
+                            0, x86ms->apic_id_limit);
+    if (ret < 0) {
+        error_report("kvm: Set max vcpu id not supported: %s", strerror(-ret));
+    }
+
     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);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [QEMU PATCH] x86: Set maximum APIC ID to KVM prior to vCPU creation
  2022-05-20  6:39 [QEMU PATCH] x86: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang
@ 2022-05-20  7:56 ` Chao Gao
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Gao @ 2022-05-20  7:56 UTC (permalink / raw)
  To: Zeng Guang
  Cc: Paolo Bonzini, Sean Christopherson, Michael S . Tsirkin,
	Marcel Apfelbaum, Richard Henderson, Eduardo Habkost, qemu-devel,
	kvm

On Fri, May 20, 2022 at 02:39:28PM +0800, Zeng Guang wrote:
>Specify maximum possible APIC ID assigned for current VM session prior to
>the creation of vCPUs. KVM need set up VM-scoped data structure indexed by
>the APIC ID, e.g. Posted-Interrupt Descriptor table to support Intel IPI
>virtualization.
>
>It can be achieved by calling KVM_ENABLE_CAP for KVM_CAP_MAX_VCPU_ID
>capability once KVM has already enabled it. Otherwise, simply prompts
>that KVM doesn't support this capability yet.
>
>Signed-off-by: Zeng Guang <guang.zeng@intel.com>
>---
> hw/i386/x86.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
>diff --git a/hw/i386/x86.c b/hw/i386/x86.c
>index 4cf107baea..ff74492325 100644
>--- a/hw/i386/x86.c
>+++ b/hw/i386/x86.c
>@@ -106,7 +106,7 @@ out:
> 
> void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
> {
>-    int i;
>+    int i, ret;
>     const CPUArchIdList *possible_cpus;
>     MachineState *ms = MACHINE(x86ms);
>     MachineClass *mc = MACHINE_GET_CLASS(x86ms);
>@@ -123,6 +123,13 @@ 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;
>+
>+    ret = kvm_vm_enable_cap(kvm_state, KVM_CAP_MAX_VCPU_ID,
>+                            0, x86ms->apic_id_limit);
>+    if (ret < 0) {
>+        error_report("kvm: Set max vcpu id not supported: %s", strerror(-ret));
>+    }

This piece of code is specific to KVM. Please move it to kvm-all.c and
invoke a wrapper function here. As kvm accelerator isn't necessarily
enabled, the function call should be guarded by kvm_enabled().

And I think the error message can be omitted because the failure doesn't
impact functionality; just a few more pages will be allocated by KVM.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-20  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20  6:39 [QEMU PATCH] x86: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang
2022-05-20  7:56 ` Chao Gao

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.