cdd9f568ebe521af3cd0e17ed5ea0f94fcd70351
[openwrt/staging/pepe2k.git] /
1 From ec72823546e39cd486360f44db16cf47f7e8f59e Mon Sep 17 00:00:00 2001
2 From: Henning Schild <henning.schild@siemens.com>
3 Date: Mon, 18 Sep 2017 18:02:08 +0200
4 Subject: [PATCH] ivshmem-net: fill in and check used descriptor chain len
5
6 We are using chains of len==1 make that explicit and expect that from
7 the remote.
8
9 Signed-off-by: Henning Schild <henning.schild@siemens.com>
10 Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
11 (cherry picked from commit f958c360044184f58605815d428b83fe4329cafd)
12 ---
13 drivers/net/ivshmem-net.c | 14 ++++++++------
14 1 file changed, 8 insertions(+), 6 deletions(-)
15
16 --- a/drivers/net/ivshmem-net.c
17 +++ b/drivers/net/ivshmem-net.c
18 @@ -335,10 +335,10 @@ static void ivshm_net_tx_clean(struct ne
19 {
20 struct ivshm_net *in = netdev_priv(ndev);
21 struct ivshm_net_queue *tx = &in->tx;
22 + struct vring_used_elem *used;
23 struct vring *vr = &tx->vr;
24 struct vring_desc *desc;
25 struct vring_desc *fdesc;
26 - unsigned int used;
27 unsigned int num;
28 u16 used_idx;
29 u16 last;
30 @@ -358,13 +358,14 @@ static void ivshm_net_tx_clean(struct ne
31 u32 len;
32 u32 tail;
33
34 - used = vr->used->ring[last & (vr->num - 1)].id;
35 - if (used >= vr->num) {
36 - netdev_err(ndev, "invalid tx used %d\n", used);
37 + used = vr->used->ring + (last % vr->num);
38 + if (used->id >= vr->num || used->len != 1) {
39 + netdev_err(ndev, "invalid tx used->id %d ->len %d\n",
40 + used->id, used->len);
41 break;
42 }
43
44 - desc = &vr->desc[used];
45 + desc = &vr->desc[used->id];
46
47 data = ivshm_net_desc_data(in, &in->tx, desc, &len);
48 if (!data) {
49 @@ -383,7 +384,7 @@ static void ivshm_net_tx_clean(struct ne
50 else
51 desc->next = fhead;
52
53 - fhead = used;
54 + fhead = used->id;
55 last++;
56 num++;
57 }
58 @@ -433,6 +434,7 @@ static void ivshm_net_rx_finish(struct i
59
60 used = rx->last_used_idx++ & (vr->num - 1);
61 vr->used->ring[used].id = desc_id;
62 + vr->used->ring[used].len = 1;
63
64 virt_store_release(&vr->used->idx, rx->last_used_idx);
65 }