From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zeng Guang <guang.zeng@intel.com>, Peter Xu <peterx@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Subject: [PULL 3/5] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
Date: Wed, 2 Nov 2022 12:41:23 +0100 [thread overview]
Message-ID: <20221102114125.58902-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com>
From: Zeng Guang <guang.zeng@intel.com>
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
pointer 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 enabled it. Ignoring the return error if KVM
doesn't support this capability yet.
Signed-off-by: Zeng Guang <guang.zeng@intel.com>
Acked-by: Peter Xu <peterx@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20220825025246.26618-1-guang.zeng@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/i386/x86.c | 4 ++++
target/i386/kvm/kvm-stub.c | 5 +++++
target/i386/kvm/kvm.c | 5 +++++
target/i386/kvm/kvm_i386.h | 2 ++
4 files changed, 16 insertions(+)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index bd50a064a36d..78cc131926c8 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -140,6 +140,10 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
exit(EXIT_FAILURE);
}
+ 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-stub.c b/target/i386/kvm/kvm-stub.c
index f6e7e4466e1a..e052f1c7b0ef 100644
--- a/target/i386/kvm/kvm-stub.c
+++ b/target/i386/kvm/kvm-stub.c
@@ -44,3 +44,8 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp)
{
abort();
}
+
+void kvm_set_max_apic_id(uint32_t max_apic_id)
+{
+ return;
+}
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 4df04280890a..a21320937943 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -5723,3 +5723,8 @@ void kvm_arch_accel_class_init(ObjectClass *oc)
"Clock cycles without an event window "
"after which a notification VM exit occurs");
}
+
+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 b7c38ba2c462..6a5c24e3dc40 100644
--- a/target/i386/kvm/kvm_i386.h
+++ b/target/i386/kvm/kvm_i386.h
@@ -66,4 +66,6 @@ typedef struct kvm_msr_handlers {
bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr,
QEMUWRMSRHandler *wrmsr);
+void kvm_set_max_apic_id(uint32_t max_apic_id);
+
#endif
--
2.38.1
next prev parent reply other threads:[~2022-11-02 11:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-02 11:41 [PULL 0/5] Misc patches for QEMU 7.2 soft freeze Paolo Bonzini
2022-11-02 11:41 ` [PULL 1/5] target/i386: Fix calculation of LOCK NEG eflags Paolo Bonzini
2022-11-02 11:41 ` [PULL 2/5] os-posix: asynchronous teardown for shutdown on Linux Paolo Bonzini
2022-11-02 11:41 ` Paolo Bonzini [this message]
2022-11-02 11:41 ` [PULL 4/5] util/log: Close per-thread log file on thread termination Paolo Bonzini
2022-11-02 11:41 ` [PULL 5/5] target/i386: Fix test for paging enabled Paolo Bonzini
2022-11-02 12:13 ` [PULL 0/5] Misc patches for QEMU 7.2 soft freeze Bin Meng
2022-11-02 13:04 ` Paolo Bonzini
2022-11-03 21:27 ` Stefan Hajnoczi
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=20221102114125.58902-4-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=guang.zeng@intel.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 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.