All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: X86: Sanity check on gfn before removal
@ 2020-04-16 15:59 Peter Xu
  2020-05-04 16:59 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Xu @ 2020-04-16 15:59 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, peterx

The index returned by kvm_async_pf_gfn_slot() will be removed when an
async pf gfn is going to be removed.  However kvm_async_pf_gfn_slot()
is not reliable in that it can return the last key it loops over even
if the gfn is not found in the async gfn array.  It should never
happen, but it's still better to sanity check against that to make
sure no unexpected gfn will be removed.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fc74dafa72ff..f1c6e604dd12 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10308,6 +10308,10 @@ static void kvm_del_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
 	u32 i, j, k;
 
 	i = j = kvm_async_pf_gfn_slot(vcpu, gfn);
+
+	if (WARN_ON_ONCE(vcpu->arch.apf.gfns[i] != gfn))
+		return;
+
 	while (true) {
 		vcpu->arch.apf.gfns[i] = ~0;
 		do {
-- 
2.24.1


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

* Re: [PATCH] KVM: X86: Sanity check on gfn before removal
  2020-04-16 15:59 [PATCH] KVM: X86: Sanity check on gfn before removal Peter Xu
@ 2020-05-04 16:59 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-05-04 16:59 UTC (permalink / raw)
  To: Peter Xu, kvm; +Cc: Sean Christopherson, Vitaly Kuznetsov

On 16/04/20 17:59, Peter Xu wrote:
> The index returned by kvm_async_pf_gfn_slot() will be removed when an
> async pf gfn is going to be removed.  However kvm_async_pf_gfn_slot()
> is not reliable in that it can return the last key it loops over even
> if the gfn is not found in the async gfn array.  It should never
> happen, but it's still better to sanity check against that to make
> sure no unexpected gfn will be removed.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fc74dafa72ff..f1c6e604dd12 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -10308,6 +10308,10 @@ static void kvm_del_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
>  	u32 i, j, k;
>  
>  	i = j = kvm_async_pf_gfn_slot(vcpu, gfn);
> +
> +	if (WARN_ON_ONCE(vcpu->arch.apf.gfns[i] != gfn))
> +		return;
> +
>  	while (true) {
>  		vcpu->arch.apf.gfns[i] = ~0;
>  		do {
> 

Queued, thanks.

Paolo


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

end of thread, other threads:[~2020-05-04 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16 15:59 [PATCH] KVM: X86: Sanity check on gfn before removal Peter Xu
2020-05-04 16:59 ` 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.