All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation
@ 2020-08-19  8:55 Wanpeng Li
  2020-08-19  8:55 ` [PATCH 2/2] KVM: VMX: Don't freeze guest when event delivery causes an APIC-access exit Wanpeng Li
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Wanpeng Li @ 2020-08-19  8:55 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

There is missing apic map recalculation after updating DFR, if it is 
INIT RESET, in x2apic mode, local apic is software enabled before. 
This patch fix it by introducing the function kvm_apic_set_dfr() to 
be called in INIT RESET handling path.

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/lapic.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 5ccbee7..248095a 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -310,6 +310,12 @@ static inline void kvm_apic_set_ldr(struct kvm_lapic *apic, u32 id)
 	atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
 }
 
+static inline void kvm_apic_set_dfr(struct kvm_lapic *apic, u32 val)
+{
+	kvm_lapic_set_reg(apic, APIC_DFR, val);
+	atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
+}
+
 static inline u32 kvm_apic_calc_x2apic_ldr(u32 id)
 {
 	return ((id >> 4) << 16) | (1 << (id & 0xf));
@@ -1984,10 +1990,9 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 		break;
 
 	case APIC_DFR:
-		if (!apic_x2apic_mode(apic)) {
-			kvm_lapic_set_reg(apic, APIC_DFR, val | 0x0FFFFFFF);
-			atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
-		} else
+		if (!apic_x2apic_mode(apic))
+			kvm_apic_set_dfr(apic, val | 0x0FFFFFFF);
+		else
 			ret = 1;
 		break;
 
@@ -2303,7 +2308,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
 			     SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT));
 	apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0));
 
-	kvm_lapic_set_reg(apic, APIC_DFR, 0xffffffffU);
+	kvm_apic_set_dfr(apic, 0xffffffffU);
 	apic_set_spiv(apic, 0xff);
 	kvm_lapic_set_reg(apic, APIC_TASKPRI, 0);
 	if (!apic_x2apic_mode(apic))
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] KVM: VMX: Don't freeze guest when event delivery causes an APIC-access exit
  2020-08-19  8:55 [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
@ 2020-08-19  8:55 ` Wanpeng Li
  2020-08-24  1:25 ` [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
  2020-09-09  8:41 ` Wanpeng Li
  2 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2020-08-19  8:55 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

According to SDM 27.2.4, Event delivery causes an APIC-access VM exit.
Don't report internal error and freeze guest when event delivery causes
an APIC-access exit, it is handleable and the event will be re-injected
during the next vmentry.

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/vmx/vmx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 46ba2e0..80ba8d4 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6054,6 +6054,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
 			(exit_reason != EXIT_REASON_EXCEPTION_NMI &&
 			exit_reason != EXIT_REASON_EPT_VIOLATION &&
 			exit_reason != EXIT_REASON_PML_FULL &&
+			exit_reason != EXIT_REASON_APIC_ACCESS &&
 			exit_reason != EXIT_REASON_TASK_SWITCH)) {
 		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
 		vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation
  2020-08-19  8:55 [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
  2020-08-19  8:55 ` [PATCH 2/2] KVM: VMX: Don't freeze guest when event delivery causes an APIC-access exit Wanpeng Li
@ 2020-08-24  1:25 ` Wanpeng Li
  2020-09-09  8:41 ` Wanpeng Li
  2 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2020-08-24  1:25 UTC (permalink / raw)
  To: LKML, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

ping, :)
On Wed, 19 Aug 2020 at 16:55, Wanpeng Li <kernellwp@gmail.com> wrote:
>
> From: Wanpeng Li <wanpengli@tencent.com>
>
> There is missing apic map recalculation after updating DFR, if it is
> INIT RESET, in x2apic mode, local apic is software enabled before.
> This patch fix it by introducing the function kvm_apic_set_dfr() to
> be called in INIT RESET handling path.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
>  arch/x86/kvm/lapic.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 5ccbee7..248095a 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -310,6 +310,12 @@ static inline void kvm_apic_set_ldr(struct kvm_lapic *apic, u32 id)
>         atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
>  }
>
> +static inline void kvm_apic_set_dfr(struct kvm_lapic *apic, u32 val)
> +{
> +       kvm_lapic_set_reg(apic, APIC_DFR, val);
> +       atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
> +}
> +
>  static inline u32 kvm_apic_calc_x2apic_ldr(u32 id)
>  {
>         return ((id >> 4) << 16) | (1 << (id & 0xf));
> @@ -1984,10 +1990,9 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
>                 break;
>
>         case APIC_DFR:
> -               if (!apic_x2apic_mode(apic)) {
> -                       kvm_lapic_set_reg(apic, APIC_DFR, val | 0x0FFFFFFF);
> -                       atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
> -               } else
> +               if (!apic_x2apic_mode(apic))
> +                       kvm_apic_set_dfr(apic, val | 0x0FFFFFFF);
> +               else
>                         ret = 1;
>                 break;
>
> @@ -2303,7 +2308,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
>                              SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT));
>         apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0));
>
> -       kvm_lapic_set_reg(apic, APIC_DFR, 0xffffffffU);
> +       kvm_apic_set_dfr(apic, 0xffffffffU);
>         apic_set_spiv(apic, 0xff);
>         kvm_lapic_set_reg(apic, APIC_TASKPRI, 0);
>         if (!apic_x2apic_mode(apic))
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation
  2020-08-19  8:55 [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
  2020-08-19  8:55 ` [PATCH 2/2] KVM: VMX: Don't freeze guest when event delivery causes an APIC-access exit Wanpeng Li
  2020-08-24  1:25 ` [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
@ 2020-09-09  8:41 ` Wanpeng Li
  2020-09-12  6:21   ` Paolo Bonzini
  2 siblings, 1 reply; 5+ messages in thread
From: Wanpeng Li @ 2020-09-09  8:41 UTC (permalink / raw)
  To: LKML, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

Any Reviewed-by for these two patches? :)
On Wed, 19 Aug 2020 at 16:55, Wanpeng Li <kernellwp@gmail.com> wrote:
>
> From: Wanpeng Li <wanpengli@tencent.com>
>
> There is missing apic map recalculation after updating DFR, if it is
> INIT RESET, in x2apic mode, local apic is software enabled before.
> This patch fix it by introducing the function kvm_apic_set_dfr() to
> be called in INIT RESET handling path.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
>  arch/x86/kvm/lapic.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 5ccbee7..248095a 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -310,6 +310,12 @@ static inline void kvm_apic_set_ldr(struct kvm_lapic *apic, u32 id)
>         atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
>  }
>
> +static inline void kvm_apic_set_dfr(struct kvm_lapic *apic, u32 val)
> +{
> +       kvm_lapic_set_reg(apic, APIC_DFR, val);
> +       atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
> +}
> +
>  static inline u32 kvm_apic_calc_x2apic_ldr(u32 id)
>  {
>         return ((id >> 4) << 16) | (1 << (id & 0xf));
> @@ -1984,10 +1990,9 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
>                 break;
>
>         case APIC_DFR:
> -               if (!apic_x2apic_mode(apic)) {
> -                       kvm_lapic_set_reg(apic, APIC_DFR, val | 0x0FFFFFFF);
> -                       atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
> -               } else
> +               if (!apic_x2apic_mode(apic))
> +                       kvm_apic_set_dfr(apic, val | 0x0FFFFFFF);
> +               else
>                         ret = 1;
>                 break;
>
> @@ -2303,7 +2308,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
>                              SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT));
>         apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0));
>
> -       kvm_lapic_set_reg(apic, APIC_DFR, 0xffffffffU);
> +       kvm_apic_set_dfr(apic, 0xffffffffU);
>         apic_set_spiv(apic, 0xff);
>         kvm_lapic_set_reg(apic, APIC_TASKPRI, 0);
>         if (!apic_x2apic_mode(apic))
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation
  2020-09-09  8:41 ` Wanpeng Li
@ 2020-09-12  6:21   ` Paolo Bonzini
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-09-12  6:21 UTC (permalink / raw)
  To: Wanpeng Li, LKML, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 09/09/20 10:41, Wanpeng Li wrote:
> Any Reviewed-by for these two patches? :)
> On Wed, 19 Aug 2020 at 16:55, Wanpeng Li <kernellwp@gmail.com> wrote:
>>
>> From: Wanpeng Li <wanpengli@tencent.com>
>>
>> There is missing apic map recalculation after updating DFR, if it is
>> INIT RESET, in x2apic mode, local apic is software enabled before.
>> This patch fix it by introducing the function kvm_apic_set_dfr() to
>> be called in INIT RESET handling path.
>>
>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
>> ---
>>  arch/x86/kvm/lapic.c | 15 ++++++++++-----
>>  1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
>> index 5ccbee7..248095a 100644
>> --- a/arch/x86/kvm/lapic.c
>> +++ b/arch/x86/kvm/lapic.c
>> @@ -310,6 +310,12 @@ static inline void kvm_apic_set_ldr(struct kvm_lapic *apic, u32 id)
>>         atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
>>  }
>>
>> +static inline void kvm_apic_set_dfr(struct kvm_lapic *apic, u32 val)
>> +{
>> +       kvm_lapic_set_reg(apic, APIC_DFR, val);
>> +       atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
>> +}
>> +
>>  static inline u32 kvm_apic_calc_x2apic_ldr(u32 id)
>>  {
>>         return ((id >> 4) << 16) | (1 << (id & 0xf));
>> @@ -1984,10 +1990,9 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
>>                 break;
>>
>>         case APIC_DFR:
>> -               if (!apic_x2apic_mode(apic)) {
>> -                       kvm_lapic_set_reg(apic, APIC_DFR, val | 0x0FFFFFFF);
>> -                       atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
>> -               } else
>> +               if (!apic_x2apic_mode(apic))
>> +                       kvm_apic_set_dfr(apic, val | 0x0FFFFFFF);
>> +               else
>>                         ret = 1;
>>                 break;
>>
>> @@ -2303,7 +2308,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
>>                              SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT));
>>         apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0));
>>
>> -       kvm_lapic_set_reg(apic, APIC_DFR, 0xffffffffU);
>> +       kvm_apic_set_dfr(apic, 0xffffffffU);
>>         apic_set_spiv(apic, 0xff);
>>         kvm_lapic_set_reg(apic, APIC_TASKPRI, 0);
>>         if (!apic_x2apic_mode(apic))
>> --
>> 2.7.4
>>
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-12  6:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19  8:55 [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
2020-08-19  8:55 ` [PATCH 2/2] KVM: VMX: Don't freeze guest when event delivery causes an APIC-access exit Wanpeng Li
2020-08-24  1:25 ` [PATCH 1/2] KVM: LAPIC: Fix updating DFR missing apic map recalculation Wanpeng Li
2020-09-09  8:41 ` Wanpeng Li
2020-09-12  6:21   ` Paolo Bonzini

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.