Skip to contentSkip to conversation

NetKVM: fix for indirectc mode when vring is full

PATCH In review Ting Wang 2 participants 3 messages Dec 10, 2014 – Dec 15, 2014

lore
Share & tools
lore

Ting Wang

author
#0 lore raw

PATCH 1/1 NetKVM: fix for indirectc mode when vring is full

In function vring_add_indirect, there is no limiti about free entry in vring. If vring is full, vq->num_free will be less than zero, and the address of vq->vring.desc becomes illegal.

---
 NetKVM/NDIS5/VirtIO/VirtIORing.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
NetKVM/NDIS5/VirtIO/VirtIORing.c +1 -1
index 90ace4c..0f3783c 100644
@@ -150,7 +150,7 @@ static int vring_add_buf(struct virtqueue *_vq,
         return -1;
     }
 
-    if (va_indirect)
+    if (va_indirect && (out + in) > 1 && vq->num_free)
     {
         int ret = vring_add_indirect(_vq, sg, out, in, va_indirect, phys_indirect);
         if (ret >= 0)
Signature · 1 line
1.8.5
#1 lore raw

Thanks!

The fix is correct, but I am not sure this patch is needed.
This is a frozen part of the code with XP and Windows 2003 support for NetKVM only.

The library that is used for newer OSes and other drivers has this fix: https://github.com/YanVugenfirer/kvm-guest-drivers-windows/commit/264f1b6c86f5eeca5e2c9fbd24e3de8dbd0bee1d

In the NetKVM driver code itself we are testing for those conditions before calling to add_buf (check ParaNdis_DoSubmitPacket function in https://github.com/YanVugenfirer/kvm-guest-drivers-windows/blob/stable/NetKVM/NDIS5/Common/ParaNdis-Common.c#L1528).

Best regads,
Yan.

Quoted 29 lines · Ting Wang

In function vring_add_indirect, there is no limiti about free entry in vring. If vring is full, vq->num_free will be less than zero, and the address of vq->vring.desc becomes illegal.

---
NetKVM/NDIS5/VirtIO/VirtIORing.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
NetKVM/NDIS5/VirtIO/VirtIORing.c +1 -1
index 90ace4c..0f3783c 100644
@@ -150,7 +150,7 @@ static int vring_add_buf(struct virtqueue *_vq,
        return -1;
    }
 
-    if (va_indirect)
+    if (va_indirect && (out + in) > 1 && vq->num_free)
    {
        int ret = vring_add_indirect(_vq, sg, out, in, va_indirect, phys_indirect);
        if (ret >= 0)
Signature · 1 line
1.8.5
#2 lore raw

okay, thank you, I think it is better for net and other feature with one virtio code set like linux.

Quoted 45 lines · Yan Vugenfirer

Thanks!

The fix is correct, but I am not sure this patch is needed.
This is a frozen part of the code with XP and Windows 2003 support for NetKVM only.

The library that is used for newer OSes and other drivers has this fix: https://github.com/YanVugenfirer/kvm-guest-drivers-windows/commit/264f1b6c86f5eeca5e2c9fbd24e3de8dbd0bee1d

In the NetKVM driver code itself we are testing for those conditions before calling to add_buf (check ParaNdis_DoSubmitPacket function in https://github.com/YanVugenfirer/kvm-guest-drivers-windows/blob/stable/NetKVM/NDIS5/Common/ParaNdis-Common.c#L1528).

Best regads,
Yan.

Quoted 29 lines · Ting Wang

In function vring_add_indirect, there is no limiti about free entry in vring. If vring is full, vq->num_free will be less than zero, and the address of vq->vring.desc becomes illegal.

---
NetKVM/NDIS5/VirtIO/VirtIORing.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
NetKVM/NDIS5/VirtIO/VirtIORing.c +1 -1
index 90ace4c..0f3783c 100644
@@ -150,7 +150,7 @@ static int vring_add_buf(struct virtqueue *_vq,
        return -1;
    }
 
-    if (va_indirect)
+    if (va_indirect && (out + in) > 1 && vq->num_free)
    {
        int ret = vring_add_indirect(_vq, sg, out, in, va_indirect, phys_indirect);
        if (ret >= 0)
Signature · 1 line
1.8.5

.