All of lore.kernel.org
 help / color / mirror / Atom feed
* [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory
@ 2021-11-04 11:56 Li RongQing
  2021-11-04 11:56 ` [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set Li RongQing
  2021-11-18 14:35 ` 答复: [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory Li,Rongqing
  0 siblings, 2 replies; 5+ messages in thread
From: Li RongQing @ 2021-11-04 11:56 UTC (permalink / raw)
  To: kvm, pbonzini, seanjc, vkuznets, lirongqing, stable

If guest gives MSR_KVM_PV_EOI_EN a wrong value, this printk() will
be trigged, and kernel log is spammed with the useless message

Fixes: 0d88800d5472 ("kvm: x86: ioapic and apic debug macros cleanup")
Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Cc: stable@kernel.org
---
 arch/x86/kvm/lapic.c |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index d6ac32f..752c48e 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -676,31 +676,25 @@ static inline bool pv_eoi_enabled(struct kvm_vcpu *vcpu)
 static bool pv_eoi_get_pending(struct kvm_vcpu *vcpu)
 {
 	u8 val;
-	if (pv_eoi_get_user(vcpu, &val) < 0) {
-		printk(KERN_WARNING "Can't read EOI MSR value: 0x%llx\n",
-			   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
+	if (pv_eoi_get_user(vcpu, &val) < 0)
 		return false;
-	}
+
 	return val & KVM_PV_EOI_ENABLED;
 }
 
 static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)
 {
-	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_ENABLED) < 0) {
-		printk(KERN_WARNING "Can't set EOI MSR value: 0x%llx\n",
-			   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
+	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_ENABLED) < 0)
 		return;
-	}
+
 	__set_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
 }
 
 static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
 {
-	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0) {
-		printk(KERN_WARNING "Can't clear EOI MSR value: 0x%llx\n",
-			   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
+	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0)
 		return;
-	}
+
 	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
 }
 
-- 
1.7.1


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

* [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set
  2021-11-04 11:56 [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory Li RongQing
@ 2021-11-04 11:56 ` Li RongQing
  2021-11-19 16:19   ` Vitaly Kuznetsov
  2021-11-18 14:35 ` 答复: [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory Li,Rongqing
  1 sibling, 1 reply; 5+ messages in thread
From: Li RongQing @ 2021-11-04 11:56 UTC (permalink / raw)
  To: kvm, pbonzini, seanjc, vkuznets, lirongqing, stable

merge pv_eoi_get_pending and pv_eoi_clr_pending into a single
function pv_eoi_test_and_clear_pending, which returns and clear
the value of the pending bit.

and clear pv eoi pending bit only when it is set, to avoid calling
pv_eoi_put_user(), this can speed about 300 nsec on AMD EPYC most
of the time

Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
diff v2: merge as pv_eoi_test_and_clear_pending
diff v3: remove printk in a new patch
diff v4: fix comments place
 arch/x86/kvm/lapic.c |   40 +++++++++++++++++++---------------------
 1 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 752c48e..b1de23e 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -673,15 +673,6 @@ static inline bool pv_eoi_enabled(struct kvm_vcpu *vcpu)
 	return vcpu->arch.pv_eoi.msr_val & KVM_MSR_ENABLED;
 }
 
-static bool pv_eoi_get_pending(struct kvm_vcpu *vcpu)
-{
-	u8 val;
-	if (pv_eoi_get_user(vcpu, &val) < 0)
-		return false;
-
-	return val & KVM_PV_EOI_ENABLED;
-}
-
 static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)
 {
 	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_ENABLED) < 0)
@@ -690,12 +681,26 @@ static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)
 	__set_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
 }
 
-static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
+static bool pv_eoi_test_and_clr_pending(struct kvm_vcpu *vcpu)
 {
-	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0)
-		return;
+	u8 val;
+
+	if (pv_eoi_get_user(vcpu, &val) < 0)
+		return false;
+
+	val &= KVM_PV_EOI_ENABLED;
+
+	if (val && pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0)
+		return false;
 
+	/*
+	 * Clear pending bit in any case: it will be set again on vmentry.
+	 * While this might not be ideal from performance point of view,
+	 * this makes sure pv eoi is only enabled when we know it's safe.
+	 */
 	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
+
+	return val;
 }
 
 static int apic_has_interrupt_for_ppr(struct kvm_lapic *apic, u32 ppr)
@@ -2671,7 +2676,6 @@ void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
 static void apic_sync_pv_eoi_from_guest(struct kvm_vcpu *vcpu,
 					struct kvm_lapic *apic)
 {
-	bool pending;
 	int vector;
 	/*
 	 * PV EOI state is derived from KVM_APIC_PV_EOI_PENDING in host
@@ -2685,14 +2689,8 @@ static void apic_sync_pv_eoi_from_guest(struct kvm_vcpu *vcpu,
 	 * 	-> host enabled PV EOI, guest executed EOI.
 	 */
 	BUG_ON(!pv_eoi_enabled(vcpu));
-	pending = pv_eoi_get_pending(vcpu);
-	/*
-	 * Clear pending bit in any case: it will be set again on vmentry.
-	 * While this might not be ideal from performance point of view,
-	 * this makes sure pv eoi is only enabled when we know it's safe.
-	 */
-	pv_eoi_clr_pending(vcpu);
-	if (pending)
+
+	if (pv_eoi_test_and_clr_pending(vcpu))
 		return;
 	vector = apic_set_eoi(apic);
 	trace_kvm_pv_eoi(apic, vector);
-- 
1.7.1


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

* 答复: [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory
  2021-11-04 11:56 [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory Li RongQing
  2021-11-04 11:56 ` [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set Li RongQing
@ 2021-11-18 14:35 ` Li,Rongqing
  1 sibling, 0 replies; 5+ messages in thread
From: Li,Rongqing @ 2021-11-18 14:35 UTC (permalink / raw)
  To: kvm, pbonzini, seanjc, vkuznets, stable

Ping

Thanks

-Li

> -----邮件原件-----
> 发件人: Li,Rongqing <lirongqing@baidu.com>
> 发送时间: 2021年11月4日 19:56
> 收件人: kvm@vger.kernel.org; pbonzini@redhat.com; seanjc@google.com;
> vkuznets@redhat.com; Li,Rongqing <lirongqing@baidu.com>;
> stable@kernel.org
> 主题: [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi
> memory
> 
> If guest gives MSR_KVM_PV_EOI_EN a wrong value, this printk() will be trigged,
> and kernel log is spammed with the useless message
> 
> Fixes: 0d88800d5472 ("kvm: x86: ioapic and apic debug macros cleanup")
> Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> Cc: stable@kernel.org
> ---
>  arch/x86/kvm/lapic.c |   18 ++++++------------
>  1 files changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index d6ac32f..752c48e
> 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -676,31 +676,25 @@ static inline bool pv_eoi_enabled(struct kvm_vcpu
> *vcpu)  static bool pv_eoi_get_pending(struct kvm_vcpu *vcpu)  {
>  	u8 val;
> -	if (pv_eoi_get_user(vcpu, &val) < 0) {
> -		printk(KERN_WARNING "Can't read EOI MSR value: 0x%llx\n",
> -			   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
> +	if (pv_eoi_get_user(vcpu, &val) < 0)
>  		return false;
> -	}
> +
>  	return val & KVM_PV_EOI_ENABLED;
>  }
> 
>  static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)  {
> -	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_ENABLED) < 0) {
> -		printk(KERN_WARNING "Can't set EOI MSR value: 0x%llx\n",
> -			   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
> +	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_ENABLED) < 0)
>  		return;
> -	}
> +
>  	__set_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);  }
> 
>  static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)  {
> -	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0) {
> -		printk(KERN_WARNING "Can't clear EOI MSR value: 0x%llx\n",
> -			   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
> +	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0)
>  		return;
> -	}
> +
>  	__clear_bit(KVM_APIC_PV_EOI_PENDING,
> &vcpu->arch.apic_attention);  }
> 
> --
> 1.7.1


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

* Re: [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set
  2021-11-04 11:56 ` [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set Li RongQing
@ 2021-11-19 16:19   ` Vitaly Kuznetsov
  2021-11-26 16:54     ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-19 16:19 UTC (permalink / raw)
  To: Li RongQing, kvm; +Cc: pbonzini, seanjc, lirongqing, stable

Li RongQing <lirongqing@baidu.com> writes:

> merge pv_eoi_get_pending and pv_eoi_clr_pending into a single
> function pv_eoi_test_and_clear_pending, which returns and clear
> the value of the pending bit.
>
> and clear pv eoi pending bit only when it is set, to avoid calling
> pv_eoi_put_user(), this can speed about 300 nsec on AMD EPYC most
> of the time
>
> Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> diff v2: merge as pv_eoi_test_and_clear_pending
> diff v3: remove printk in a new patch
> diff v4: fix comments place
>  arch/x86/kvm/lapic.c |   40 +++++++++++++++++++---------------------
>  1 files changed, 19 insertions(+), 21 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 752c48e..b1de23e 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -673,15 +673,6 @@ static inline bool pv_eoi_enabled(struct kvm_vcpu *vcpu)
>  	return vcpu->arch.pv_eoi.msr_val & KVM_MSR_ENABLED;
>  }
>  
> -static bool pv_eoi_get_pending(struct kvm_vcpu *vcpu)
> -{
> -	u8 val;
> -	if (pv_eoi_get_user(vcpu, &val) < 0)
> -		return false;
> -
> -	return val & KVM_PV_EOI_ENABLED;
> -}
> -
>  static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)
>  {
>  	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_ENABLED) < 0)
> @@ -690,12 +681,26 @@ static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)
>  	__set_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
>  }
>  
> -static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
> +static bool pv_eoi_test_and_clr_pending(struct kvm_vcpu *vcpu)
>  {
> -	if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0)
> -		return;
> +	u8 val;
> +
> +	if (pv_eoi_get_user(vcpu, &val) < 0)
> +		return false;
> +
> +	val &= KVM_PV_EOI_ENABLED;
> +
> +	if (val && pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0)
> +		return false;
>  
> +	/*
> +	 * Clear pending bit in any case: it will be set again on vmentry.
> +	 * While this might not be ideal from performance point of view,
> +	 * this makes sure pv eoi is only enabled when we know it's safe.
> +	 */
>  	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
> +
> +	return val;
>  }
>  
>  static int apic_has_interrupt_for_ppr(struct kvm_lapic *apic, u32 ppr)
> @@ -2671,7 +2676,6 @@ void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
>  static void apic_sync_pv_eoi_from_guest(struct kvm_vcpu *vcpu,
>  					struct kvm_lapic *apic)
>  {
> -	bool pending;
>  	int vector;
>  	/*
>  	 * PV EOI state is derived from KVM_APIC_PV_EOI_PENDING in host
> @@ -2685,14 +2689,8 @@ static void apic_sync_pv_eoi_from_guest(struct kvm_vcpu *vcpu,
>  	 * 	-> host enabled PV EOI, guest executed EOI.
>  	 */
>  	BUG_ON(!pv_eoi_enabled(vcpu));
> -	pending = pv_eoi_get_pending(vcpu);
> -	/*
> -	 * Clear pending bit in any case: it will be set again on vmentry.
> -	 * While this might not be ideal from performance point of view,
> -	 * this makes sure pv eoi is only enabled when we know it's safe.
> -	 */
> -	pv_eoi_clr_pending(vcpu);
> -	if (pending)
> +
> +	if (pv_eoi_test_and_clr_pending(vcpu))
>  		return;
>  	vector = apic_set_eoi(apic);
>  	trace_kvm_pv_eoi(apic, vector);

I see my R-b tag is missign, so

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

-- 
Vitaly


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

* Re: [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set
  2021-11-19 16:19   ` Vitaly Kuznetsov
@ 2021-11-26 16:54     ` Paolo Bonzini
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2021-11-26 16:54 UTC (permalink / raw)
  To: Vitaly Kuznetsov, Li RongQing, kvm; +Cc: seanjc, stable

On 11/19/21 17:19, Vitaly Kuznetsov wrote:
> Reviewed-by: Vitaly Kuznetsov<vkuznets@redhat.com>

Queued, thanks.

Paolo


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

end of thread, other threads:[~2021-11-26 16:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 11:56 [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory Li RongQing
2021-11-04 11:56 ` [v4][PATCH 2/2] KVM: Clear pv eoi pending bit only when it is set Li RongQing
2021-11-19 16:19   ` Vitaly Kuznetsov
2021-11-26 16:54     ` Paolo Bonzini
2021-11-18 14:35 ` 答复: [v4][PATCH 1/2] KVM: x86: don't print when fail to read/write pv eoi memory Li,Rongqing

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.