Skip to contentSkip to conversation

vhost-net: fix reversed logic in mask notifiers

PATCH Applied Michael S. Tsirkin 5 participants 9 messages May 25, 2010 – May 27, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost-net: fix reversed logic in mask notifiers

When guest notifier is assigned, we set mask notifier, which will assign kvm irqfd.
When guest notifier is unassigned, mask notifier is unset, which should unassign kvm irqfd.

The way to do this is to call mask notifier telling it to mask the vector. This, unless vector is already masked which unassigns irqfd already.

The logic in unassign was reversed, which left kvm irqfd assigned.

This patch is qemu-kvm only as irqfd is not upstream.

---
 hw/msix.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/msix.c +3 -1
index 8f9a621..1398680 100644
@@ -617,6 +617,7 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque)
     assert(opaque);
     assert(!dev->msix_mask_notifier_opaque[vector]);
 
+    /* Unmask the new notifier unless vector is masked. */
     if (msix_is_masked(dev, vector)) {
         return 0;
     }
@@ -638,12 +639,13 @@ int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector)
     assert(dev->msix_mask_notifier);
     assert(dev->msix_mask_notifier_opaque[vector]);
 
+    /* Mask the old notifier unless it is already masked. */
     if (msix_is_masked(dev, vector)) {
         return 0;
     }
     r = dev->msix_mask_notifier(dev, vector,
                                 dev->msix_mask_notifier_opaque[vector],
-                                msix_is_masked(dev, vector));
+                                !msix_is_masked(dev, vector));
     if (r < 0) {
         return r;
     }
Signature · 1 line
1.7.1.12.g42b7f
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Michael S. Tsirkin

When guest notifier is assigned, we set mask notifier, which will assign kvm irqfd.
When guest notifier is unassigned, mask notifier is unset, which should unassign kvm irqfd.

The way to do this is to call mask notifier telling it to mask the vector. This, unless vector is already masked which unassigns irqfd already.

Quoted 6 lines

The logic in unassign was reversed, which left kvm irqfd assigned.

This patch is qemu-kvm only as irqfd is not upstream.

Amit

#2 lore raw
In reply to Michael S. Tsirkin
Quoted 32 lines · Michael S. Tsirkin

When guest notifier is assigned, we set mask notifier, which will assign kvm irqfd.
When guest notifier is unassigned, mask notifier is unset, which should unassign kvm irqfd.

The way to do this is to call mask notifier telling it to mask the vector. This, unless vector is already masked which unassigns irqfd already.

The logic in unassign was reversed, which left kvm irqfd assigned.

This patch is qemu-kvm only as irqfd is not upstream.

---
 hw/msix.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/msix.c +1 -0
index 8f9a621..1398680 100644
@@ -617,6 +617,7 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque)
     assert(opaque);
     assert(!dev->msix_mask_notifier_opaque[vector]);
 
+    /* Unmask the new notifier unless vector is masked. */
     if (msix_is_masked(dev, vector)) {
         return 0;
     }
@@ -638,12 +639,13 @@ int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector)
     assert(dev->msix_mask_notifier);

hw/msix.c int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector) · line 648

Quoted 10 lines
hw/msix.c +2 -1
     assert(dev->msix_mask_notifier_opaque[vector]);
 
+    /* Mask the old notifier unless it is already masked. */
     if (msix_is_masked(dev, vector)) {
         return 0;
     }
     r = dev->msix_mask_notifier(dev, vector,
                                 dev->msix_mask_notifier_opaque[vector],
-                                msix_is_masked(dev, vector));
+                                !msix_is_masked(dev, vector));

Why don't put just a 1 here?

we have:

if (msix_is_masked())
return 0
r = msix_mask_notifier(....., !msix_is_masked());

i.e. at that point msix_is_masked() is false, or we really, really needs locking.

Puttting a !foo, when we know that it needs to be an 1 looks strange.

Later, Juan.

PD. Yes, I already asked in a previous version to just have two methods, mask/unmask. we now at call time which one we need.

#3 lore raw
Quoted 55 lines · Juan Quintela
Quoted 32 lines · Michael S. Tsirkin

When guest notifier is assigned, we set mask notifier, which will assign kvm irqfd.
When guest notifier is unassigned, mask notifier is unset, which should unassign kvm irqfd.

The way to do this is to call mask notifier telling it to mask the vector. This, unless vector is already masked which unassigns irqfd already.

The logic in unassign was reversed, which left kvm irqfd assigned.

This patch is qemu-kvm only as irqfd is not upstream.

---
 hw/msix.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/msix.c +1 -0
index 8f9a621..1398680 100644
@@ -617,6 +617,7 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque)
     assert(opaque);
     assert(!dev->msix_mask_notifier_opaque[vector]);
 
+    /* Unmask the new notifier unless vector is masked. */
     if (msix_is_masked(dev, vector)) {
         return 0;
     }
@@ -638,12 +639,13 @@ int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector)
     assert(dev->msix_mask_notifier);

hw/msix.c int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector) · line 648

Quoted 10 lines
hw/msix.c +2 -1
     assert(dev->msix_mask_notifier_opaque[vector]);
 
+    /* Mask the old notifier unless it is already masked. */
     if (msix_is_masked(dev, vector)) {
         return 0;
     }
     r = dev->msix_mask_notifier(dev, vector,
                                 dev->msix_mask_notifier_opaque[vector],
-                                msix_is_masked(dev, vector));
+                                !msix_is_masked(dev, vector));

Why don't put just a 1 here?

we have:

if (msix_is_masked())
return 0
r = msix_mask_notifier(....., !msix_is_masked());

i.e. at that point msix_is_masked() is false, or we really, really needs locking.

Quoted 6 lines

Puttting a !foo, when we know that it needs to be an 1 looks strange.

Later, Juan.

PD. Yes, I already asked in a previous version to just have two methods, mask/unmask. we now at call time which one we need.

I find msix_is_masked clearer here than true since you don't need to look up definition to understand what this 'true' stands for. The value is clear from code above. What do you think?

Signature · 1 line
MST
#4 lore raw
Quoted 15 lines · Michael S. Tsirkin
Quoted 13 lines · Juan Quintela

we have:

if (msix_is_masked())
return 0
r = msix_mask_notifier(....., !msix_is_masked());

i.e. at that point msix_is_masked() is false, or we really, really needs locking.

Puttting a !foo, when we know that it needs to be an 1 looks strange.

Later, Juan.

Quoted 7 lines
Quoted 2 lines

PD. Yes, I already asked in a previous version to just have two methods, mask/unmask. we now at call time which one we need.

I find msix_is_masked clearer here than true since you don't need to look up definition to understand what this 'true' stands for. The value is clear from code above. What do you think?

I preffer the change, but it is up to you.

at that point, we are using !msix_masked() to mean "true"

i.e. we know that msix_masked() is false. What you want to do is "mask".

Later, Juan.

#5 lore raw
Quoted 24 lines · Juan Quintela
Quoted 15 lines · Michael S. Tsirkin
Quoted 13 lines · Juan Quintela

we have:

if (msix_is_masked())
return 0
r = msix_mask_notifier(....., !msix_is_masked());

i.e. at that point msix_is_masked() is false, or we really, really needs locking.

Puttting a !foo, when we know that it needs to be an 1 looks strange.

Later, Juan.

Quoted 7 lines
Quoted 2 lines

PD. Yes, I already asked in a previous version to just have two methods, mask/unmask. we now at call time which one we need.

I find msix_is_masked clearer here than true since you don't need to look up definition to understand what this 'true' stands for. The value is clear from code above. What do you think?

Quoted 7 lines

I preffer the change, but it is up to you.

at that point, we are using !msix_masked() to mean "true"

i.e. we know that msix_masked() is false. What you want to do is "mask".

Later, Juan.

Right. I guess I'll keep it as is, when I look at it with a fresh mind next time, I'll clean it all up.

Signature · 1 line
MST
#6 lore raw
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Juan Quintela
Quoted 15 lines · Michael S. Tsirkin
Quoted 13 lines · Juan Quintela

we have:

if (msix_is_masked())
return 0
r = msix_mask_notifier(....., !msix_is_masked());

i.e. at that point msix_is_masked() is false, or we really, really needs locking.

Puttting a !foo, when we know that it needs to be an 1 looks strange.

Later, Juan.

Quoted 7 lines
Quoted 2 lines

PD. Yes, I already asked in a previous version to just have two methods, mask/unmask. we now at call time which one we need.

I find msix_is_masked clearer here than true since you don't need to look up definition to understand what this 'true' stands for. The value is clear from code above. What do you think?

I preffer the change, but it is up to you.

Quoted 8 lines
Quoted 5 lines

at that point, we are using !msix_masked() to mean "true"

i.e. we know that msix_masked() is false. What you want to do is "mask".

Later, Juan.

Right. I guess I'll keep it as is, when I look at it with a fresh mind next time, I'll clean it all up.

ok with me.

Acked-by on v1 1/1
#7 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

When guest notifier is assigned, we set mask notifier, which will assign kvm irqfd.
When guest notifier is unassigned, mask notifier is unset, which should unassign kvm irqfd.

The way to do this is to call mask notifier telling it to mask the vector. This, unless vector is already masked which unassigns irqfd already.

Quoted 6 lines

The logic in unassign was reversed, which left kvm irqfd assigned.

This patch is qemu-kvm only as irqfd is not upstream.

cheers,
Gerd

Applied
#8 lore raw
In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin

When guest notifier is assigned, we set mask notifier, which will assign kvm irqfd.
When guest notifier is unassigned, mask notifier is unset, which should unassign kvm irqfd.

Quoted 7 lines

The way to do this is to call mask notifier telling it to mask the vector. This, unless vector is already masked which unassigns irqfd already.

The logic in unassign was reversed, which left kvm irqfd assigned.

This patch is qemu-kvm only as irqfd is not upstream.

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function