qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zeng Guang <guang.zeng@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Eduardo Habkost <eduardo@habkost.net>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org,
	Gao Chao <chao.gao@intel.com>, Zeng Guang <guang.zeng@intel.com>
Subject: [QEMU PATCH] x86: Set maximum APIC ID to KVM prior to vCPU creation
Date: Fri, 20 May 2022 14:39:28 +0800	[thread overview]
Message-ID: <20220520063928.23645-1-guang.zeng@intel.com> (raw)

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



             reply	other threads:[~2022-05-20  7:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20  6:39 Zeng Guang [this message]
2022-05-20  7:56 ` [QEMU PATCH] x86: Set maximum APIC ID to KVM prior to vCPU creation Chao Gao

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=20220520063928.23645-1-guang.zeng@intel.com \
    --to=guang.zeng@intel.com \
    --cc=chao.gao@intel.com \
    --cc=eduardo@habkost.net \
    --cc=kvm@vger.kernel.org \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=seanjc@google.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;
as well as URLs for NNTP newsgroup(s).