2022-10-01 01:17:34

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH v4 18/32] KVM: x86: Explicitly skip optimized logical map setup if vCPU's LDR==0

Explicitly skip the optimized map setup if the vCPU's LDR is '0', i.e. if
the vCPU will never respond to logical mode interrupts. KVM already
skips setup in this case, but relies on kvm_apic_map_get_logical_dest()
to generate mask==0. KVM still needs the mask=0 check as a non-zero LDR
can yield mask==0 depending on the mode, but explicitly handling the LDR
will make it simpler to clean up the logical mode tracking in the future.

No functional change intended.

Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/lapic.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 42b61469674d..cef8b202490b 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -286,10 +286,12 @@ void kvm_recalculate_apic_map(struct kvm *kvm)
continue;

ldr = kvm_lapic_get_reg(apic, APIC_LDR);
+ if (!ldr)
+ continue;

if (apic_x2apic_mode(apic)) {
new->mode |= KVM_APIC_MODE_X2APIC;
- } else if (ldr) {
+ } else {
ldr = GET_APIC_LOGICAL_ID(ldr);
if (kvm_lapic_get_reg(apic, APIC_DFR) == APIC_DFR_FLAT)
new->mode |= KVM_APIC_MODE_XAPIC_FLAT;
--
2.38.0.rc1.362.ged0d419d3c-goog


2022-12-08 22:38:19

by Maxim Levitsky

[permalink] [raw]
Subject: Re: [PATCH v4 18/32] KVM: x86: Explicitly skip optimized logical map setup if vCPU's LDR==0

On Sat, 2022-10-01 at 00:59 +0000, Sean Christopherson wrote:
> Explicitly skip the optimized map setup if the vCPU's LDR is '0', i.e. if
> the vCPU will never respond to logical mode interrupts. KVM already
> skips setup in this case, but relies on kvm_apic_map_get_logical_dest()
> to generate mask==0. KVM still needs the mask=0 check as a non-zero LDR
> can yield mask==0 depending on the mode, but explicitly handling the LDR
> will make it simpler to clean up the logical mode tracking in the future.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <[email protected]>
> ---
> arch/x86/kvm/lapic.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 42b61469674d..cef8b202490b 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -286,10 +286,12 @@ void kvm_recalculate_apic_map(struct kvm *kvm)
> continue;
>
> ldr = kvm_lapic_get_reg(apic, APIC_LDR);
> + if (!ldr)
> + continue;
>
> if (apic_x2apic_mode(apic)) {
> new->mode |= KVM_APIC_MODE_X2APIC;
> - } else if (ldr) {
> + } else {
> ldr = GET_APIC_LOGICAL_ID(ldr);
> if (kvm_lapic_get_reg(apic, APIC_DFR) == APIC_DFR_FLAT)
> new->mode |= KVM_APIC_MODE_XAPIC_FLAT;

Reviewed-by: Maxim Levitsky <[email protected]>

Best regards,
Maxim Levitsky