* Re: [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected
2026-09-20 15:54 [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected Luka Absandze
@ 2026-09-20 16:00 ` sashiko-bot
2026-09-21 5:10 ` Sandipan Das
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-09-20 16:00 UTC (permalink / raw)
To: Luka Absandze; +Cc: kvm, linux-perf-users
> kvm_pmu_handle_event() re-arms the reprogram bit for every failed
> reprogram, on the assumption that the failure is transient and a later
> refresh will succeed. That is true for contention, e.g. the -EBUSY from
> x86_reserve_hardware(), but not for a configuration the host PMU driver
> rejects outright. A rejected config can never succeed on retry, so the
> counter is reprogrammed on every PMU refresh for as long as the guest
> leaves it enabled, and every attempt fails the same way.
>
> Re-arm only for the errnos that indicate a transient condition, i.e.
> -EBUSY and -ENOMEM.
>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Link: https://lore.kernel.org/all/20260916123315.89042-1-absandze@amazon.de/
> Signed-off-by: Luka Absandze <absandze@amazon.de>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260920155453.10836-1-absandze@amazon.de?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected
2026-09-20 15:54 [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected Luka Absandze
2026-09-20 16:00 ` sashiko-bot
@ 2026-09-21 5:10 ` Sandipan Das
2026-09-21 5:11 ` Sandipan Das
2026-10-02 21:06 ` Sean Christopherson
3 siblings, 0 replies; 5+ messages in thread
From: Sandipan Das @ 2026-09-21 5:10 UTC (permalink / raw)
To: Luka Absandze, seanjc, pbonzini
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, dwmw2, kvm,
linux-perf-users, linux-kernel
On 20-09-2026 21:24, Luka Absandze wrote:
> kvm_pmu_handle_event() re-arms the reprogram bit for every failed
> reprogram, on the assumption that the failure is transient and a later
> refresh will succeed. That is true for contention, e.g. the -EBUSY from
> x86_reserve_hardware(), but not for a configuration the host PMU driver
> rejects outright. A rejected config can never succeed on retry, so the
> counter is reprogrammed on every PMU refresh for as long as the guest
> leaves it enabled, and every attempt fails the same way.
>
> Re-arm only for the errnos that indicate a transient condition, i.e.
> -EBUSY and -ENOMEM.
>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Link: https://lore.kernel.org/all/20260916123315.89042-1-absandze@amazon.de/
> Signed-off-by: Luka Absandze <absandze@amazon.de>
> ---
> v2:
> - Use an allow-list of transient errnos (-EBUSY, -ENOMEM) rather than
> excluding -EINVAL, and hoist 'r' out of the loop. Diff taken from
> Sean's suggestion verbatim. [Sean]
> - Reword the comment to say "fails on a transient condition". [Sean]
> - v1: https://lore.kernel.org/all/20260918160006.61816-1-absandze@amazon.de/
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index a7d60c8785cd..03a470c49a74 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -662,7 +662,7 @@ void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
> DECLARE_BITMAP(bitmap, X86_PMC_IDX_MAX);
> struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
> struct kvm_pmc *pmc;
> - int bit;
> + int bit, r;
>
> bitmap_copy(bitmap, pmu->reprogram_pmi, X86_PMC_IDX_MAX);
>
> @@ -676,12 +676,14 @@ void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
>
> kvm_for_each_pmc(pmu, pmc, bit, bitmap) {
> /*
> - * If reprogramming fails, e.g. due to contention, re-set the
> - * reprogram bit, i.e. opportunistically try again on the next
> - * PMU refresh. Don't make a new request as doing so can stall
> - * the guest if reprogramming repeatedly fails.
> + * If reprogramming fails on a transient condition, e.g. due to
> + * contention, re-set the reprogram bit, i.e. opportunistically
> + * try again on the next PMU refresh. Don't make a new request
> + * as doing so can stall the guest if reprogramming repeatedly
> + * fails.
> */
> - if (reprogram_counter(pmc))
> + r = reprogram_counter(pmc);
> + if (r == -EBUSY || r == -ENOMEM)
> set_bit(pmc->idx, pmu->reprogram_pmi);
> }
>
Reviewed-by: Sandipan Das <sandipan.das@amd.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected
2026-09-20 15:54 [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected Luka Absandze
2026-09-20 16:00 ` sashiko-bot
2026-09-21 5:10 ` Sandipan Das
@ 2026-09-21 5:11 ` Sandipan Das
2026-10-02 21:06 ` Sean Christopherson
3 siblings, 0 replies; 5+ messages in thread
From: Sandipan Das @ 2026-09-21 5:11 UTC (permalink / raw)
To: Luka Absandze, seanjc, pbonzini
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, dwmw2, kvm,
linux-perf-users, linux-kernel
On 20-09-2026 21:24, Luka Absandze wrote:
> kvm_pmu_handle_event() re-arms the reprogram bit for every failed
> reprogram, on the assumption that the failure is transient and a later
> refresh will succeed. That is true for contention, e.g. the -EBUSY from
> x86_reserve_hardware(), but not for a configuration the host PMU driver
> rejects outright. A rejected config can never succeed on retry, so the
> counter is reprogrammed on every PMU refresh for as long as the guest
> leaves it enabled, and every attempt fails the same way.
>
> Re-arm only for the errnos that indicate a transient condition, i.e.
> -EBUSY and -ENOMEM.
>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Link: https://lore.kernel.org/all/20260916123315.89042-1-absandze@amazon.de/
> Signed-off-by: Luka Absandze <absandze@amazon.de>
> ---
> v2:
> - Use an allow-list of transient errnos (-EBUSY, -ENOMEM) rather than
> excluding -EINVAL, and hoist 'r' out of the loop. Diff taken from
> Sean's suggestion verbatim. [Sean]
> - Reword the comment to say "fails on a transient condition". [Sean]
> - v1: https://lore.kernel.org/all/20260918160006.61816-1-absandze@amazon.de/
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index a7d60c8785cd..03a470c49a74 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -662,7 +662,7 @@ void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
> DECLARE_BITMAP(bitmap, X86_PMC_IDX_MAX);
> struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
> struct kvm_pmc *pmc;
> - int bit;
> + int bit, r;
>
> bitmap_copy(bitmap, pmu->reprogram_pmi, X86_PMC_IDX_MAX);
>
> @@ -676,12 +676,14 @@ void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
>
> kvm_for_each_pmc(pmu, pmc, bit, bitmap) {
> /*
> - * If reprogramming fails, e.g. due to contention, re-set the
> - * reprogram bit, i.e. opportunistically try again on the next
> - * PMU refresh. Don't make a new request as doing so can stall
> - * the guest if reprogramming repeatedly fails.
> + * If reprogramming fails on a transient condition, e.g. due to
> + * contention, re-set the reprogram bit, i.e. opportunistically
> + * try again on the next PMU refresh. Don't make a new request
> + * as doing so can stall the guest if reprogramming repeatedly
> + * fails.
> */
> - if (reprogram_counter(pmc))
> + r = reprogram_counter(pmc);
> + if (r == -EBUSY || r == -ENOMEM)
> set_bit(pmc->idx, pmu->reprogram_pmi);
> }
>
Reviewed-by: Sandipan Das <sandipan.das@amd.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected
2026-09-20 15:54 [PATCH v2] KVM: x86/pmu: Don't retry a counter whose config was rejected Luka Absandze
` (2 preceding siblings ...)
2026-09-21 5:11 ` Sandipan Das
@ 2026-10-02 21:06 ` Sean Christopherson
3 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2026-10-02 21:06 UTC (permalink / raw)
To: Sean Christopherson, pbonzini, Luka Absandze
Cc: sandipan.das, tglx, mingo, bp, dave.hansen, x86, hpa, dwmw2, kvm,
linux-perf-users, linux-kernel
On Sun, 20 Sep 2026 15:54:53 +0000, Luka Absandze wrote:
> kvm_pmu_handle_event() re-arms the reprogram bit for every failed
> reprogram, on the assumption that the failure is transient and a later
> refresh will succeed. That is true for contention, e.g. the -EBUSY from
> x86_reserve_hardware(), but not for a configuration the host PMU driver
> rejects outright. A rejected config can never succeed on retry, so the
> counter is reprogrammed on every PMU refresh for as long as the guest
> leaves it enabled, and every attempt fails the same way.
>
> [...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86/pmu: Don't retry a counter whose config was rejected
https://github.com/kvm-x86/linux/commit/1c24893fdb4d
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 5+ messages in thread