2024-04-29 16:21:07

by Alejandro Jimenez

[permalink] [raw]
Subject: [PATCH 0/4] Export APICv-related state via binary stats interface

After discussion in the RFC thread[0], the following items were identified as
desirable to expose via the stats interface:

- APICv status: (apicv_enabled, boolean, per-vCPU)

- Guest using SynIC's AutoEOI: (synic_auto_eoi_used, boolean, per-VM)

- KVM PIT in reinject mode inhibits AVIC: (pit_reinject_mode, boolean, per-VM)

- APICv unaccelerated injections causing a vmexit (i.e. AVIC_INCOMPLETE_IPI,
AVIC_UNACCELERATED_ACCESS, APIC_WRITE): (apicv_unaccelerated_inj, counter,
per-vCPU)

Example retrieving the newly introduced stats for guest running on AMD Genoa
host, with AVIC enabled:

(QEMU) query-stats target=vcpu vcpus=['/machine/unattached/device[0]'] providers=[{'provider':'kvm','names':['apicv_unaccelerated_inj','apicv_active']}]
{
"return": [
{
"provider": "kvm",
"qom-path": "/machine/unattached/device[0]",
"stats": [
{
"name": "apicv_unaccelerated_inj",
"value": 2561
},
{
"name": "apicv_active",
"value": true
}
]
}
]
}
(QEMU) query-stats target=vm providers=[{'provider':'kvm','names':['pit_reinject_mode','synic_auto_eoi_used']}]
{
"return": [
{
"provider": "kvm",
"stats": [
{
"name": "pit_reinject_mode",
"value": false
},
{
"name": "synic_auto_eoi_used",
"value": false
}
]
}
]
}

Changes were also sanity tested on Intel Sapphire Rapids platform, with/without
IPI virtualization.

Regards,
Alejandro

[0] https://lore.kernel.org/all/[email protected]/

Alejandro Jimenez (4):
KVM: x86: Expose per-vCPU APICv status
KVM: x86: Add a VM stat exposing when SynIC AutoEOI is in use
KVM: x86: Add a VM stat exposing when KVM PIT is set to reinject mode
KVM: x86: Add vCPU stat for APICv interrupt injections causing #VMEXIT

arch/x86/include/asm/kvm_host.h | 4 ++++
arch/x86/kvm/hyperv.c | 2 ++
arch/x86/kvm/i8254.c | 2 ++
arch/x86/kvm/lapic.c | 1 +
arch/x86/kvm/svm/avic.c | 7 +++++++
arch/x86/kvm/vmx/vmx.c | 2 ++
arch/x86/kvm/x86.c | 7 ++++++-
7 files changed, 24 insertions(+), 1 deletion(-)


base-commit: 7b076c6a308ec5bce9fc96e2935443ed228b9148
--
2.39.3



2024-04-29 16:21:36

by Alejandro Jimenez

[permalink] [raw]
Subject: [PATCH 2/4] KVM: x86: Add a VM stat exposing when SynIC AutoEOI is in use

APICv/AVIC is inhibited for guests using Hyper-V's synthetic interrupt
controller (SynIC) enlightenment, and specifically SynIC's AutoEOI feature.
It is recommended that guests do not enable AutoEOI (see flag
HV_DEPRECATING_AEOI_RECOMMENDED and commit 0f250a646382 ("KVM: x86:
hyper-v: Deactivate APICv only when AutoEOI feature is in use")), but it
can still be used in legacy configurations.

Suggested-by: Paolo Bonzini <[email protected]>
Signed-off-by: Alejandro Jimenez <[email protected]>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/hyperv.c | 2 ++
arch/x86/kvm/x86.c | 3 ++-
3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 12f30cb5c842..f3b40cfebec4 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1534,6 +1534,7 @@ struct kvm_vm_stat {
u64 nx_lpage_splits;
u64 max_mmu_page_hash_collisions;
u64 max_mmu_rmap_size;
+ u64 synic_auto_eoi_used;
};

struct kvm_vcpu_stat {
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 8a47f8541eab..4263b4ad71c5 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -149,6 +149,8 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic,
APICV_INHIBIT_REASON_HYPERV,
!!hv->synic_auto_eoi_used);

+ vcpu->kvm->stat.synic_auto_eoi_used = !!hv->synic_auto_eoi_used;
+
up_write(&vcpu->kvm->arch.apicv_update_lock);
}

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0451c4c8d731..27e339133068 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -256,7 +256,8 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
STATS_DESC_ICOUNTER(VM, pages_1g),
STATS_DESC_ICOUNTER(VM, nx_lpage_splits),
STATS_DESC_PCOUNTER(VM, max_mmu_rmap_size),
- STATS_DESC_PCOUNTER(VM, max_mmu_page_hash_collisions)
+ STATS_DESC_PCOUNTER(VM, max_mmu_page_hash_collisions),
+ STATS_DESC_IBOOLEAN(VM, synic_auto_eoi_used)
};

const struct kvm_stats_header kvm_vm_stats_header = {
--
2.39.3


2024-05-23 18:49:37

by Alejandro Jimenez

[permalink] [raw]
Subject: Re: [PATCH 0/4] Export APICv-related state via binary stats interface



On 4/29/24 11:57, Alejandro Jimenez wrote:
> After discussion in the RFC thread[0], the following items were identified as
> desirable to expose via the stats interface:
>
> - APICv status: (apicv_enabled, boolean, per-vCPU)
>
> - Guest using SynIC's AutoEOI: (synic_auto_eoi_used, boolean, per-VM)
>
> - KVM PIT in reinject mode inhibits AVIC: (pit_reinject_mode, boolean, per-VM)
>
> - APICv unaccelerated injections causing a vmexit (i.e. AVIC_INCOMPLETE_IPI,
> AVIC_UNACCELERATED_ACCESS, APIC_WRITE): (apicv_unaccelerated_inj, counter,
> per-vCPU)
>
> Example retrieving the newly introduced stats for guest running on AMD Genoa
> host, with AVIC enabled:
>
> (QEMU) query-stats target=vcpu vcpus=['/machine/unattached/device[0]'] providers=[{'provider':'kvm','names':['apicv_unaccelerated_inj','apicv_active']}]
> {
> "return": [
> {
> "provider": "kvm",
> "qom-path": "/machine/unattached/device[0]",
> "stats": [
> {
> "name": "apicv_unaccelerated_inj",
> "value": 2561
> },
> {
> "name": "apicv_active",
> "value": true
> }
> ]
> }
> ]
> }
> (QEMU) query-stats target=vm providers=[{'provider':'kvm','names':['pit_reinject_mode','synic_auto_eoi_used']}]
> {
> "return": [
> {
> "provider": "kvm",
> "stats": [
> {
> "name": "pit_reinject_mode",
> "value": false
> },
> {
> "name": "synic_auto_eoi_used",
> "value": false
> }
> ]
> }
> ]
> }
>
> Changes were also sanity tested on Intel Sapphire Rapids platform, with/without
> IPI virtualization.

ping...

This series implements the suggestions from earlier RFC discussion [0]. Additional comments/reviews are appreciated.

Thank you,
Alejandro

>
> [0] https://lore.kernel.org/all/[email protected]/
>
> Alejandro Jimenez (4):
> KVM: x86: Expose per-vCPU APICv status
> KVM: x86: Add a VM stat exposing when SynIC AutoEOI is in use
> KVM: x86: Add a VM stat exposing when KVM PIT is set to reinject mode
> KVM: x86: Add vCPU stat for APICv interrupt injections causing #VMEXIT
>
> arch/x86/include/asm/kvm_host.h | 4 ++++
> arch/x86/kvm/hyperv.c | 2 ++
> arch/x86/kvm/i8254.c | 2 ++
> arch/x86/kvm/lapic.c | 1 +
> arch/x86/kvm/svm/avic.c | 7 +++++++
> arch/x86/kvm/vmx/vmx.c | 2 ++
> arch/x86/kvm/x86.c | 7 ++++++-
> 7 files changed, 24 insertions(+), 1 deletion(-)
>
>
> base-commit: 7b076c6a308ec5bce9fc96e2935443ed228b9148

2024-05-31 09:20:21

by Vasant Hegde

[permalink] [raw]
Subject: Re: [PATCH 0/4] Export APICv-related state via binary stats interface

Hi,



On 4/29/2024 9:27 PM, Alejandro Jimenez wrote:
> After discussion in the RFC thread[0], the following items were identified as
> desirable to expose via the stats interface:
>
> - APICv status: (apicv_enabled, boolean, per-vCPU)
>
> - Guest using SynIC's AutoEOI: (synic_auto_eoi_used, boolean, per-VM)
>
> - KVM PIT in reinject mode inhibits AVIC: (pit_reinject_mode, boolean, per-VM)
>
> - APICv unaccelerated injections causing a vmexit (i.e. AVIC_INCOMPLETE_IPI,
> AVIC_UNACCELERATED_ACCESS, APIC_WRITE): (apicv_unaccelerated_inj, counter,
> per-vCPU)
>
> Example retrieving the newly introduced stats for guest running on AMD Genoa
> host, with AVIC enabled:


I have reviewed generic and AMD driver related code. Also tested this series on
AMD systems and its working fine.

Tested-by: Vasant Hegde <[email protected]>

-Vasant


>
> (QEMU) query-stats target=vcpu vcpus=['/machine/unattached/device[0]'] providers=[{'provider':'kvm','names':['apicv_unaccelerated_inj','apicv_active']}]
> {
> "return": [
> {
> "provider": "kvm",
> "qom-path": "/machine/unattached/device[0]",
> "stats": [
> {
> "name": "apicv_unaccelerated_inj",
> "value": 2561
> },
> {
> "name": "apicv_active",
> "value": true
> }
> ]
> }
> ]
> }
> (QEMU) query-stats target=vm providers=[{'provider':'kvm','names':['pit_reinject_mode','synic_auto_eoi_used']}]
> {
> "return": [
> {
> "provider": "kvm",
> "stats": [
> {
> "name": "pit_reinject_mode",
> "value": false
> },
> {
> "name": "synic_auto_eoi_used",
> "value": false
> }
> ]
> }
> ]
> }
>
> Changes were also sanity tested on Intel Sapphire Rapids platform, with/without
> IPI virtualization.
>
> Regards,
> Alejandro
>
> [0] https://lore.kernel.org/all/[email protected]/
>
> Alejandro Jimenez (4):
> KVM: x86: Expose per-vCPU APICv status
> KVM: x86: Add a VM stat exposing when SynIC AutoEOI is in use
> KVM: x86: Add a VM stat exposing when KVM PIT is set to reinject mode
> KVM: x86: Add vCPU stat for APICv interrupt injections causing #VMEXIT
>
> arch/x86/include/asm/kvm_host.h | 4 ++++
> arch/x86/kvm/hyperv.c | 2 ++
> arch/x86/kvm/i8254.c | 2 ++
> arch/x86/kvm/lapic.c | 1 +
> arch/x86/kvm/svm/avic.c | 7 +++++++
> arch/x86/kvm/vmx/vmx.c | 2 ++
> arch/x86/kvm/x86.c | 7 ++++++-
> 7 files changed, 24 insertions(+), 1 deletion(-)
>
>
> base-commit: 7b076c6a308ec5bce9fc96e2935443ed228b9148