* [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
@ 2022-08-25 2:52 Zeng Guang
2022-09-05 1:27 ` Zeng Guang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Zeng Guang @ 2022-08-25 2:52 UTC (permalink / raw)
To: Paolo Bonzini, Sean Christopherson, Michael S . Tsirkin,
Marcel Apfelbaum, Richard Henderson, Eduardo Habkost,
Marcelo Tosatti
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
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>
---
hw/i386/x86.c | 4 ++++
target/i386/kvm/kvm-stub.c | 5 +++++
target/i386/kvm/kvm.c | 5 +++++
target/i386/kvm/kvm_i386.h | 1 +
4 files changed, 15 insertions(+)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 050eedc0c8..4831193c86 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -139,6 +139,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 f6e7e4466e..e052f1c7b0 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 f148a6d52f..af4ef1e8f0 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -5428,3 +5428,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] 6+ messages in thread
* Re: [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
2022-08-25 2:52 [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang
@ 2022-09-05 1:27 ` Zeng Guang
2022-10-14 1:01 ` Zeng Guang
2022-09-09 16:11 ` Peter Xu
2022-10-26 16:30 ` Paolo Bonzini
2 siblings, 1 reply; 6+ messages in thread
From: Zeng Guang @ 2022-09-05 1:27 UTC (permalink / raw)
To: Paolo Bonzini, Christopherson,,
Sean, Michael S . Tsirkin, Marcel Apfelbaum, Richard Henderson,
Eduardo Habkost, Marcelo Tosatti
Cc: qemu-devel, kvm, Gao, Chao
Kindly PING!
On 8/25/2022 10:52 AM, Zeng Guang wrote:
> 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>
> ---
> hw/i386/x86.c | 4 ++++
> target/i386/kvm/kvm-stub.c | 5 +++++
> target/i386/kvm/kvm.c | 5 +++++
> target/i386/kvm/kvm_i386.h | 1 +
> 4 files changed, 15 insertions(+)
>
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index 050eedc0c8..4831193c86 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -139,6 +139,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 f6e7e4466e..e052f1c7b0 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 f148a6d52f..af4ef1e8f0 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -5428,3 +5428,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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
2022-08-25 2:52 [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang
2022-09-05 1:27 ` Zeng Guang
@ 2022-09-09 16:11 ` Peter Xu
2022-10-26 16:30 ` Paolo Bonzini
2 siblings, 0 replies; 6+ messages in thread
From: Peter Xu @ 2022-09-09 16:11 UTC (permalink / raw)
To: Zeng Guang
Cc: Paolo Bonzini, Sean Christopherson, Michael S . Tsirkin,
Marcel Apfelbaum, Richard Henderson, Eduardo Habkost,
Marcelo Tosatti, qemu-devel, kvm, Gao Chao
On Thu, Aug 25, 2022 at 10:52:46AM +0800, Zeng Guang wrote:
> 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>
--
Peter Xu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
2022-09-05 1:27 ` Zeng Guang
@ 2022-10-14 1:01 ` Zeng Guang
2022-10-14 5:34 ` Michael S. Tsirkin
0 siblings, 1 reply; 6+ messages in thread
From: Zeng Guang @ 2022-10-14 1:01 UTC (permalink / raw)
To: Paolo Bonzini, Christopherson,,
Sean, Michael S . Tsirkin, Marcel Apfelbaum, Richard Henderson,
Eduardo Habkost, Marcelo Tosatti
Cc: qemu-devel, kvm, Gao, Chao
PING again !
This QEMU patch is to optimize max APIC ID set for current VM session
introduced since linux v6.0. It's also compatible with previous linux
version.
Thanks.
On 9/5/2022 9:27 AM, Zeng Guang wrote:
> Kindly PING!
>
> On 8/25/2022 10:52 AM, Zeng Guang wrote:
>> 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>
>> ---
>> hw/i386/x86.c | 4 ++++
>> target/i386/kvm/kvm-stub.c | 5 +++++
>> target/i386/kvm/kvm.c | 5 +++++
>> target/i386/kvm/kvm_i386.h | 1 +
>> 4 files changed, 15 insertions(+)
>>
>> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
>> index 050eedc0c8..4831193c86 100644
>> --- a/hw/i386/x86.c
>> +++ b/hw/i386/x86.c
>> @@ -139,6 +139,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 f6e7e4466e..e052f1c7b0 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 f148a6d52f..af4ef1e8f0 100644
>> --- a/target/i386/kvm/kvm.c
>> +++ b/target/i386/kvm/kvm.c
>> @@ -5428,3 +5428,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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
2022-10-14 1:01 ` Zeng Guang
@ 2022-10-14 5:34 ` Michael S. Tsirkin
0 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2022-10-14 5:34 UTC (permalink / raw)
To: Zeng Guang
Cc: Paolo Bonzini, Christopherson,,
Sean, Marcel Apfelbaum, Richard Henderson, Eduardo Habkost,
Marcelo Tosatti, qemu-devel, kvm, Gao, Chao
On Fri, Oct 14, 2022 at 09:01:02AM +0800, Zeng Guang wrote:
> PING again !
> This QEMU patch is to optimize max APIC ID set for current VM session
> introduced since linux v6.0. It's also compatible with previous linux
> version.
>
> Thanks.
>
> On 9/5/2022 9:27 AM, Zeng Guang wrote:
> > Kindly PING!
> >
> > On 8/25/2022 10:52 AM, Zeng Guang wrote:
> > > 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>
> > > ---
> > > hw/i386/x86.c | 4 ++++
> > > target/i386/kvm/kvm-stub.c | 5 +++++
> > > target/i386/kvm/kvm.c | 5 +++++
> > > target/i386/kvm/kvm_i386.h | 1 +
> > > 4 files changed, 15 insertions(+)
> > >
> > > diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> > > index 050eedc0c8..4831193c86 100644
> > > --- a/hw/i386/x86.c
> > > +++ b/hw/i386/x86.c
> > > @@ -139,6 +139,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 f6e7e4466e..e052f1c7b0 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 f148a6d52f..af4ef1e8f0 100644
> > > --- a/target/i386/kvm/kvm.c
> > > +++ b/target/i386/kvm/kvm.c
> > > @@ -5428,3 +5428,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
Looks ok on the surface, but this is Paolo's area.
Acked-by: Michael S. Tsirkin <mst@redhat.com>
--
MST
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation
2022-08-25 2:52 [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang
2022-09-05 1:27 ` Zeng Guang
2022-09-09 16:11 ` Peter Xu
@ 2022-10-26 16:30 ` Paolo Bonzini
2 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-10-26 16:30 UTC (permalink / raw)
To: Zeng Guang
Cc: Sean Christopherson, Michael S . Tsirkin, Marcel Apfelbaum,
Richard Henderson, Eduardo Habkost, Marcelo Tosatti, qemu-devel,
kvm, Gao Chao
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-10-26 16:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-25 2:52 [PATCH v3] target/i386: Set maximum APIC ID to KVM prior to vCPU creation Zeng Guang
2022-09-05 1:27 ` Zeng Guang
2022-10-14 1:01 ` Zeng Guang
2022-10-14 5:34 ` Michael S. Tsirkin
2022-09-09 16:11 ` Peter Xu
2022-10-26 16:30 ` Paolo Bonzini
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).