提交 3afc9621 编写于 作者: J Jason Wang 提交者: Michael S. Tsirkin

macvtap: zerocopy: fix offset calculation when building skb

This patch fixes the offset calculation when building skb:

- offset1 were used as skb data offset not vector offset
- reset offset to zero only when we advance to next vector
Signed-off-by: NJason Wang <jasowang@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 64d09888
...@@ -505,10 +505,11 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from, ...@@ -505,10 +505,11 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
if (copy > size) { if (copy > size) {
++from; ++from;
--count; --count;
} offset = 0;
} else
offset += size;
copy -= size; copy -= size;
offset1 += size; offset1 += size;
offset = 0;
} }
if (len == offset1) if (len == offset1)
...@@ -519,13 +520,13 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from, ...@@ -519,13 +520,13 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
int num_pages; int num_pages;
unsigned long base; unsigned long base;
len = from->iov_len - offset1; len = from->iov_len - offset;
if (!len) { if (!len) {
offset1 = 0; offset = 0;
++from; ++from;
continue; continue;
} }
base = (unsigned long)from->iov_base + offset1; base = (unsigned long)from->iov_base + offset;
size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT; size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
num_pages = get_user_pages_fast(base, size, 0, &page[i]); num_pages = get_user_pages_fast(base, size, 0, &page[i]);
if ((num_pages != size) || if ((num_pages != size) ||
...@@ -546,7 +547,7 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from, ...@@ -546,7 +547,7 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
len -= size; len -= size;
i++; i++;
} }
offset1 = 0; offset = 0;
++from; ++from;
} }
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册