qtest: virtio: zeroed last VRingDesc after allocate
PATCH 1/1 qtest: virtio: zeroed last VRingDesc after allocate
As qvring_indirect_desc_setup() wouldn't initialize last VRingDesc, so it's filled with dirty data, this might cause virtio backend broken.
For example, the last bit of this VRingDesc's flags might be 1, so virtqueue_read_next_desc() would report "Desc next is ***".
This patch zeored the last VRingDesc in qvring_indirect_desc_setup().
--- tests/libqos/virtio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tests/libqos/virtio.c +8 -0
@@ -171,12 +171,20 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,for (i =0 ; i < elem -1 ; ++i) {/* indirect->desc[i].addr */ writeq (indirect->desc + (16 * i),0 ); +/* indirect->desc[i].len */ +writeq (indirect->desc + (16 * i) +8 ,0 );/* indirect->desc[i].flags */ writew (indirect->desc + (16 * i) +12 ,VRING_DESC_F_NEXT );/* indirect->desc[i].next */ writew (indirect->desc + (16 * i) +14 , i +1 ); } +/* zeroed last element */ +writeq (indirect->desc + (16 * i),0 );/* addr */ +writeq (indirect->desc + (16 * i) +8 ,0 );/*len*/ +writew (indirect->desc + (16 * i) +12 ,0 );/*flags*/ +writew (indirect->desc + (16 * i) +14 ,0 );/*next*/ +return indirect; }
Signature · 1 line
1.8.3.1
Quoted 18 lines · Longpeng(Mike)
As
qvring_indirect_desc_setup()wouldn't initialize last VRingDesc, so it's filled with dirty data, this might cause virtio backend broken.For example, the last bit of this VRingDesc's flags might be 1, so
virtqueue_read_next_desc()would report "Desc next is ***".This patch zeored the last VRingDesc in
qvring_indirect_desc_setup().Signed-off-by Longpeng(Mike) <[email protected]>--- tests/libqos/virtio.c | 8 ++++++++ 1 file changed, 8 insertions(+)tests/libqos/virtio.c +0
-0
tests/libqos/virtio.c QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, · line 175
Quoted 5 lines
tests/libqos/virtio.c +2
-0@@ -171,12 +171,20 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,for (i =0 ; i < elem -1 ; ++i) {/* indirect->desc[i].addr */ writeq (indirect->desc + (16 * i),0 ); +/* indirect->desc[i].len */ +writeq (indirect->desc + (16 * i) +8 ,0 );
The len field is 32 bits long. Please use writel().
tests/libqos/virtio.c QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, · line 184
Quoted 9 lines
tests/libqos/virtio.c +3
-0/* indirect->desc[i].flags */ writew (indirect->desc + (16 * i) +12 ,VRING_DESC_F_NEXT );/* indirect->desc[i].next */ writew (indirect->desc + (16 * i) +14 , i +1 ); } +/* zeroed last element */ +writeq (indirect->desc + (16 * i),0 );/* addr */ +writeq (indirect->desc + (16 * i) +8 ,0 );/*len*/
Same here.
Hi Stefan,
Quoted 1 line · Stefan Hajnoczi
On Sat, Jan 14, 2017 at 05:59:36PM +0800, Longpeng(Mike) wrote:
......
Quoted 19 lines
tests/libqos/virtio.c QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, · line 175
Quoted 10 lines
tests/libqos/virtio.c +2
-0@@ -171,12 +171,20 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,for (i =0 ; i < elem -1 ; ++i) {/* indirect->desc[i].addr */ writeq (indirect->desc + (16 * i),0 ); +/* indirect->desc[i].len */ +writeq (indirect->desc + (16 * i) +8 ,0 );The len field is 32 bits long. Please use
writel().Quoted 6 lines
tests/libqos/virtio.c +0
-0/* indirect->desc[i].flags */ writew (indirect->desc + (16 * i) +12 ,VRING_DESC_F_NEXT );/* indirect->desc[i].next */ writew (indirect->desc + (16 * i) +14 , i +1 ); }
Quoted 5 lines
tests/libqos/virtio.c QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, · line 184
Quoted 3 lines
tests/libqos/virtio.c +3
-0+/* zeroed last element */ +writeq (indirect->desc + (16 * i),0 );/* addr */ +writeq (indirect->desc + (16 * i) +8 ,0 );/*len*/ Same here.
OK. I will fix it in V2.
Signature · 2 lines
Regards, Longpeng(Mike)