qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: dirty ring: add missing memory barrier
@ 2022-08-26 11:00 Paolo Bonzini
  2022-08-26 15:59 ` Philippe Mathieu-Daudé via
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2022-08-26 11:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Gavin Shan

The KVM_DIRTY_GFN_F_DIRTY flag ensures that the entry is valid.  If
the read of the fields are not ordered after the read of the flag,
QEMU might see stale values.

Cc: Peter Xu <peterx@redhat.com>
Cc: Gavin Shan <gshan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 accel/kvm/kvm-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 8d81ab74de..f49643cd24 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -719,7 +719,7 @@ static void kvm_dirty_ring_mark_page(KVMState *s, uint32_t as_id,
 
 static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
 {
-    return gfn->flags == KVM_DIRTY_GFN_F_DIRTY;
+    return qatomic_load_acquire(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);
 }
 
 static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
-- 
2.37.1



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

* Re: [PATCH] KVM: dirty ring: add missing memory barrier
  2022-08-26 11:00 [PATCH] KVM: dirty ring: add missing memory barrier Paolo Bonzini
@ 2022-08-26 15:59 ` Philippe Mathieu-Daudé via
  2022-08-26 20:12   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-08-26 15:59 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel@nongnu.org Developers, Peter Xu, Gavin Shan

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

Hi Paolo,

On Fri, Aug 26, 2022 at 1:17 PM Paolo Bonzini <pbonzini@redhat.com> wrote:

> The KVM_DIRTY_GFN_F_DIRTY flag ensures that the entry is valid.  If
> the read of the fields are not ordered after the read of the flag,
> QEMU might see stale values.
>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Gavin Shan <gshan@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  accel/kvm/kvm-all.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 8d81ab74de..f49643cd24 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -719,7 +719,7 @@ static void kvm_dirty_ring_mark_page(KVMState *s,
> uint32_t as_id,
>
>  static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
>  {
> -    return gfn->flags == KVM_DIRTY_GFN_F_DIRTY;
> +    return qatomic_load_acquire(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);
>

Is this patch based on another which changes the qatomic_load_acquire()
prototype?


>  }
>
>  static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
> --
> 2.37.1
>
>
>

[-- Attachment #2: Type: text/html, Size: 1845 bytes --]

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

* Re: [PATCH] KVM: dirty ring: add missing memory barrier
  2022-08-26 15:59 ` Philippe Mathieu-Daudé via
@ 2022-08-26 20:12   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-08-26 20:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel@nongnu.org Developers, Peter Xu, Gavin Shan

[-- Attachment #1: Type: text/plain, Size: 1305 bytes --]

Yikes no, the patch is obviously bogus.

Paolo

Il ven 26 ago 2022, 17:59 Philippe Mathieu-Daudé <f4bug@amsat.org> ha
scritto:

> Hi Paolo,
>
> On Fri, Aug 26, 2022 at 1:17 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>> The KVM_DIRTY_GFN_F_DIRTY flag ensures that the entry is valid.  If
>> the read of the fields are not ordered after the read of the flag,
>> QEMU might see stale values.
>>
>> Cc: Peter Xu <peterx@redhat.com>
>> Cc: Gavin Shan <gshan@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  accel/kvm/kvm-all.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>> index 8d81ab74de..f49643cd24 100644
>> --- a/accel/kvm/kvm-all.c
>> +++ b/accel/kvm/kvm-all.c
>> @@ -719,7 +719,7 @@ static void kvm_dirty_ring_mark_page(KVMState *s,
>> uint32_t as_id,
>>
>>  static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
>>  {
>> -    return gfn->flags == KVM_DIRTY_GFN_F_DIRTY;
>> +    return qatomic_load_acquire(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);
>>
>
> Is this patch based on another which changes the qatomic_load_acquire()
> prototype?
>
>
>>  }
>>
>>  static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
>> --
>> 2.37.1
>>
>>
>>

[-- Attachment #2: Type: text/html, Size: 2361 bytes --]

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

end of thread, other threads:[~2022-08-26 20:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-26 11:00 [PATCH] KVM: dirty ring: add missing memory barrier Paolo Bonzini
2022-08-26 15:59 ` Philippe Mathieu-Daudé via
2022-08-26 20:12   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).