2019-11-30 18:31:24 +00:00
|
|
|
From 688769df7c2365ae836eb755ccf5b196b45cbd56 Mon Sep 17 00:00:00 2001
|
2015-12-17 08:24:01 +00:00
|
|
|
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
|
|
|
|
<marmarek@invisiblethingslab.com>
|
|
|
|
Date: Wed, 16 Dec 2015 05:09:55 +0100
|
2018-08-15 12:57:19 +00:00
|
|
|
Subject: [PATCH] xen-netfront: copy response out of shared buffer before
|
2015-12-17 08:24:01 +00:00
|
|
|
accessing it
|
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
Make local copy of the response, otherwise backend might modify it while
|
|
|
|
frontend is already processing it - leading to time of check / time of
|
|
|
|
use issue.
|
|
|
|
|
|
|
|
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
|
|
|
|
---
|
2018-08-15 12:57:19 +00:00
|
|
|
drivers/net/xen-netfront.c | 51 +++++++++++++++++++-------------------
|
2015-12-17 08:24:01 +00:00
|
|
|
1 file changed, 25 insertions(+), 26 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
|
2019-11-30 18:31:24 +00:00
|
|
|
index 8f0a790ec5e7..abb9b3cd87b8 100644
|
2015-12-17 08:24:01 +00:00
|
|
|
--- a/drivers/net/xen-netfront.c
|
|
|
|
+++ b/drivers/net/xen-netfront.c
|
2019-03-15 21:28:57 +00:00
|
|
|
@@ -385,13 +385,13 @@ static void xennet_tx_buf_gc(struct netfront_queue *queue)
|
2015-12-17 08:24:01 +00:00
|
|
|
rmb(); /* Ensure we see responses up to 'rp'. */
|
|
|
|
|
|
|
|
for (cons = queue->tx.rsp_cons; cons != prod; cons++) {
|
|
|
|
- struct xen_netif_tx_response *txrsp;
|
|
|
|
+ struct xen_netif_tx_response txrsp;
|
|
|
|
|
|
|
|
- txrsp = RING_GET_RESPONSE(&queue->tx, cons);
|
|
|
|
- if (txrsp->status == XEN_NETIF_RSP_NULL)
|
|
|
|
+ RING_COPY_RESPONSE(&queue->tx, cons, &txrsp);
|
|
|
|
+ if (txrsp.status == XEN_NETIF_RSP_NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
- id = txrsp->id;
|
|
|
|
+ id = txrsp.id;
|
|
|
|
skb = queue->tx_skbs[id].skb;
|
|
|
|
if (unlikely(gnttab_query_foreign_access(
|
|
|
|
queue->grant_tx_ref[id]) != 0)) {
|
2019-07-27 21:01:02 +00:00
|
|
|
@@ -739,7 +739,7 @@ static int xennet_get_extras(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
RING_IDX rp)
|
|
|
|
|
|
|
|
{
|
|
|
|
- struct xen_netif_extra_info *extra;
|
|
|
|
+ struct xen_netif_extra_info extra;
|
|
|
|
struct device *dev = &queue->info->netdev->dev;
|
|
|
|
RING_IDX cons = queue->rx.rsp_cons;
|
|
|
|
int err = 0;
|
2019-07-27 21:01:02 +00:00
|
|
|
@@ -755,24 +755,23 @@ static int xennet_get_extras(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
- extra = (struct xen_netif_extra_info *)
|
|
|
|
- RING_GET_RESPONSE(&queue->rx, ++cons);
|
|
|
|
+ RING_COPY_RESPONSE(&queue->rx, ++cons, &extra);
|
|
|
|
|
|
|
|
- if (unlikely(!extra->type ||
|
|
|
|
- extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
|
|
|
|
+ if (unlikely(!extra.type ||
|
|
|
|
+ extra.type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
|
|
|
|
if (net_ratelimit())
|
|
|
|
dev_warn(dev, "Invalid extra type: %d\n",
|
|
|
|
- extra->type);
|
|
|
|
+ extra.type);
|
|
|
|
err = -EINVAL;
|
|
|
|
} else {
|
|
|
|
- memcpy(&extras[extra->type - 1], extra,
|
|
|
|
- sizeof(*extra));
|
|
|
|
+ memcpy(&extras[extra.type - 1], &extra,
|
|
|
|
+ sizeof(extra));
|
|
|
|
}
|
|
|
|
|
|
|
|
skb = xennet_get_rx_skb(queue, cons);
|
|
|
|
ref = xennet_get_rx_ref(queue, cons);
|
|
|
|
xennet_move_rx_slot(queue, skb, ref);
|
|
|
|
- } while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
|
|
|
|
+ } while (extra.flags & XEN_NETIF_EXTRA_FLAG_MORE);
|
|
|
|
|
|
|
|
queue->rx.rsp_cons = cons;
|
|
|
|
return err;
|
2019-07-27 21:01:02 +00:00
|
|
|
@@ -782,28 +781,28 @@ static int xennet_get_responses(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
struct netfront_rx_info *rinfo, RING_IDX rp,
|
|
|
|
struct sk_buff_head *list)
|
|
|
|
{
|
|
|
|
- struct xen_netif_rx_response *rx = &rinfo->rx;
|
|
|
|
+ struct xen_netif_rx_response rx = rinfo->rx;
|
|
|
|
struct xen_netif_extra_info *extras = rinfo->extras;
|
|
|
|
struct device *dev = &queue->info->netdev->dev;
|
|
|
|
RING_IDX cons = queue->rx.rsp_cons;
|
|
|
|
struct sk_buff *skb = xennet_get_rx_skb(queue, cons);
|
|
|
|
grant_ref_t ref = xennet_get_rx_ref(queue, cons);
|
2018-08-15 12:57:19 +00:00
|
|
|
- int max = XEN_NETIF_NR_SLOTS_MIN + (rx->status <= RX_COPY_THRESHOLD);
|
|
|
|
+ int max = XEN_NETIF_NR_SLOTS_MIN + (rx.status <= RX_COPY_THRESHOLD);
|
2015-12-17 08:24:01 +00:00
|
|
|
int slots = 1;
|
|
|
|
int err = 0;
|
|
|
|
unsigned long ret;
|
|
|
|
|
|
|
|
- if (rx->flags & XEN_NETRXF_extra_info) {
|
|
|
|
+ if (rx.flags & XEN_NETRXF_extra_info) {
|
|
|
|
err = xennet_get_extras(queue, extras, rp);
|
|
|
|
cons = queue->rx.rsp_cons;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
- if (unlikely(rx->status < 0 ||
|
2016-05-08 18:45:02 +00:00
|
|
|
- rx->offset + rx->status > XEN_PAGE_SIZE)) {
|
2015-12-17 08:24:01 +00:00
|
|
|
+ if (unlikely(rx.status < 0 ||
|
2016-05-08 18:45:02 +00:00
|
|
|
+ rx.offset + rx.status > XEN_PAGE_SIZE)) {
|
2015-12-17 08:24:01 +00:00
|
|
|
if (net_ratelimit())
|
2016-01-04 11:54:07 +00:00
|
|
|
dev_warn(dev, "rx->offset: %u, size: %d\n",
|
2015-12-17 08:24:01 +00:00
|
|
|
- rx->offset, rx->status);
|
|
|
|
+ rx.offset, rx.status);
|
|
|
|
xennet_move_rx_slot(queue, skb, ref);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto next;
|
2019-07-27 21:01:02 +00:00
|
|
|
@@ -817,7 +816,7 @@ static int xennet_get_responses(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
if (ref == GRANT_INVALID_REF) {
|
|
|
|
if (net_ratelimit())
|
|
|
|
dev_warn(dev, "Bad rx response id %d.\n",
|
|
|
|
- rx->id);
|
|
|
|
+ rx.id);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto next;
|
|
|
|
}
|
2019-07-27 21:01:02 +00:00
|
|
|
@@ -830,7 +829,7 @@ static int xennet_get_responses(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
__skb_queue_tail(list, skb);
|
|
|
|
|
|
|
|
next:
|
|
|
|
- if (!(rx->flags & XEN_NETRXF_more_data))
|
|
|
|
+ if (!(rx.flags & XEN_NETRXF_more_data))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (cons + slots == rp) {
|
2019-07-27 21:01:02 +00:00
|
|
|
@@ -840,7 +839,7 @@ static int xennet_get_responses(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
- rx = RING_GET_RESPONSE(&queue->rx, cons + slots);
|
|
|
|
+ RING_COPY_RESPONSE(&queue->rx, cons + slots, &rx);
|
|
|
|
skb = xennet_get_rx_skb(queue, cons + slots);
|
|
|
|
ref = xennet_get_rx_ref(queue, cons + slots);
|
|
|
|
slots++;
|
2019-11-30 18:31:24 +00:00
|
|
|
@@ -895,9 +894,9 @@ static int xennet_fill_frags(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
struct sk_buff *nskb;
|
|
|
|
|
|
|
|
while ((nskb = __skb_dequeue(list))) {
|
|
|
|
- struct xen_netif_rx_response *rx =
|
|
|
|
- RING_GET_RESPONSE(&queue->rx, ++cons);
|
|
|
|
+ struct xen_netif_rx_response rx;
|
|
|
|
skb_frag_t *nfrag = &skb_shinfo(nskb)->frags[0];
|
|
|
|
+ RING_COPY_RESPONSE(&queue->rx, ++cons, &rx);
|
|
|
|
|
2018-08-15 12:57:19 +00:00
|
|
|
if (skb_shinfo(skb)->nr_frags == MAX_SKB_FRAGS) {
|
2015-12-17 08:24:01 +00:00
|
|
|
unsigned int pull_to = NETFRONT_SKB_CB(skb)->pull_to;
|
2019-11-30 18:31:24 +00:00
|
|
|
@@ -913,7 +912,7 @@ static int xennet_fill_frags(struct netfront_queue *queue,
|
2015-12-17 08:24:01 +00:00
|
|
|
|
2018-08-15 12:57:19 +00:00
|
|
|
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
|
|
|
|
skb_frag_page(nfrag),
|
2015-12-17 08:24:01 +00:00
|
|
|
- rx->offset, rx->status, PAGE_SIZE);
|
|
|
|
+ rx.offset, rx.status, PAGE_SIZE);
|
|
|
|
|
|
|
|
skb_shinfo(nskb)->nr_frags = 0;
|
|
|
|
kfree_skb(nskb);
|
2019-11-30 18:31:24 +00:00
|
|
|
@@ -1011,7 +1010,7 @@ static int xennet_poll(struct napi_struct *napi, int budget)
|
2015-12-17 08:24:01 +00:00
|
|
|
i = queue->rx.rsp_cons;
|
|
|
|
work_done = 0;
|
|
|
|
while ((i != rp) && (work_done < budget)) {
|
|
|
|
- memcpy(rx, RING_GET_RESPONSE(&queue->rx, i), sizeof(*rx));
|
|
|
|
+ RING_COPY_RESPONSE(&queue->rx, i, rx);
|
|
|
|
memset(extras, 0, sizeof(rinfo.extras));
|
|
|
|
|
|
|
|
err = xennet_get_responses(queue, &rinfo, rp, &tmpq);
|
|
|
|
--
|
2019-11-30 18:31:24 +00:00
|
|
|
2.21.0
|
2015-12-17 08:24:01 +00:00
|
|
|
|