[PATCH] KVM: dirty ring: Add memory barrier when marking pfn collected

Peter Xu posted 1 patch 1 year, 6 months ago
Failed in applying to current master (apply log)
accel/kvm/kvm-all.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] KVM: dirty ring: Add memory barrier when marking pfn collected
Posted by Peter Xu 1 year, 6 months ago
Following commit 4802bf910eee9, add the other missing barrier when marking
the PFN as collected.  This will also be required just like 4802bf910eee9
on weak ordering architectures like aarch64.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Gavin Shan <gshan@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 accel/kvm/kvm-all.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 136c8eaed3..60a044048e 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -728,7 +728,11 @@ static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
 
 static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
 {
-    gfn->flags = KVM_DIRTY_GFN_F_RESET;
+    /*
+     * Write the flags after reading the entry.  Should pair with another
+     * smp_load_acquire() in KVM when reset dirty rings.
+     */
+    qatomic_store_release(&gfn->flags, KVM_DIRTY_GFN_F_RESET);
 }
 
 /*
-- 
2.32.0
Re: [PATCH] KVM: dirty ring: Add memory barrier when marking pfn collected
Posted by Peter Xu 1 year, 5 months ago
Ping?
Re: [PATCH] KVM: dirty ring: Add memory barrier when marking pfn collected
Posted by Gavin Shan 1 year, 6 months ago
On 9/23/22 7:35 AM, Peter Xu wrote:
> Following commit 4802bf910eee9, add the other missing barrier when marking
> the PFN as collected.  This will also be required just like 4802bf910eee9
> on weak ordering architectures like aarch64.
> 
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Gavin Shan <gshan@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   accel/kvm/kvm-all.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 

Reviewed-by: Gavin Shan <gshan@redhat.com>

> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 136c8eaed3..60a044048e 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -728,7 +728,11 @@ static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
>   
>   static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
>   {
> -    gfn->flags = KVM_DIRTY_GFN_F_RESET;
> +    /*
> +     * Write the flags after reading the entry.  Should pair with another
> +     * smp_load_acquire() in KVM when reset dirty rings.
> +     */
> +    qatomic_store_release(&gfn->flags, KVM_DIRTY_GFN_F_RESET);
>   }
>   
>   /*
>
Re: [PATCH] KVM: dirty ring: Add memory barrier when marking pfn collected
Posted by Philippe Mathieu-Daudé via 1 year, 6 months ago
On 22/9/22 23:35, Peter Xu wrote:
> Following commit 4802bf910eee9, add the other missing barrier when marking
> the PFN as collected.  This will also be required just like 4802bf910eee9
> on weak ordering architectures like aarch64.
> 
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Gavin Shan <gshan@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   accel/kvm/kvm-all.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 136c8eaed3..60a044048e 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -728,7 +728,11 @@ static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
>   
>   static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
>   {
> -    gfn->flags = KVM_DIRTY_GFN_F_RESET;
> +    /*
> +     * Write the flags after reading the entry.  Should pair with another
> +     * smp_load_acquire() in KVM when reset dirty rings.
> +     */
> +    qatomic_store_release(&gfn->flags, KVM_DIRTY_GFN_F_RESET);
>   }
>   
>   /*

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>