From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Wanlong Gao <gaowanlong@cn.fujitsu.com>,
asias@redhat.com, Rusty Russell <rusty@rustcorp.com.au>,
mst@redhat.com, kvm@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: [RFC PATCH 6/8] virtio-net: unmark scatterlist ending after virtqueue_add_buf
Date: Thu, 7 Feb 2013 13:22:30 +0100 [thread overview]
Message-ID: <1360239752-2470-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1360239752-2470-1-git-send-email-pbonzini@redhat.com>
Prepare for when virtqueue_add_buf will use sg_next instead of
ignoring ending markers.
Note that for_each_sg (and thus virtqueue_add_buf) allows you
to pass a "truncated" scatterlist that does not have a marker
on the last item. We rely on this in add_recvbuf_mergeable.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
This is the only part that survived of Rusty's ideas. :)
drivers/net/virtio_net.c | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 35c00c5..ce08b54 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -440,13 +440,17 @@ static int add_recvbuf_small(struct receive_queue *rq, gfp_t gfp)
hdr = skb_vnet_hdr(skb);
sg_set_buf(rq->sg, &hdr->hdr, sizeof hdr->hdr);
-
skb_to_sgvec(skb, rq->sg + 1, 0, skb->len);
err = virtqueue_add_buf(rq->vq, rq->sg, 0, 2, skb, gfp);
if (err < 0)
dev_kfree_skb(skb);
+ /*
+ * An optimization: clear the end bit set by skb_to_sgvec, so
+ * we can simply re-use rq->sg[] next time.
+ */
+ sg_unmark_end(rq->sg + 1);
return err;
}
@@ -505,8 +509,7 @@ static int add_recvbuf_mergeable(struct receive_queue *rq, gfp_t gfp)
if (!page)
return -ENOMEM;
- sg_init_one(rq->sg, page_address(page), PAGE_SIZE);
-
+ sg_set_page(rq->sg, page, PAGE_SIZE, 0);
err = virtqueue_add_buf(rq->vq, rq->sg, 0, 1, page, gfp);
if (err < 0)
give_pages(rq, page);
@@ -671,6 +674,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
struct virtnet_info *vi = sq->vq->vdev->priv;
unsigned num_sg;
+ int ret;
pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest);
@@ -710,8 +714,15 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
sg_set_buf(sq->sg, &hdr->hdr, sizeof hdr->hdr);
num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len) + 1;
- return virtqueue_add_buf(sq->vq, sq->sg, num_sg,
- 0, skb, GFP_ATOMIC);
+ ret = virtqueue_add_buf(sq->vq, sq->sg, num_sg,
+ 0, skb, GFP_ATOMIC);
+
+ /*
+ * An optimization: clear the end bit set by skb_to_sgvec, so
+ * we can simply re-use sq->sg[] next time.
+ */
+ sg_unmark_end(&sq->sg[num_sg-1]);
+ return ret;
}
static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
--
1.7.1
next prev parent reply other threads:[~2013-02-07 12:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-07 12:22 [RFC PATCH 0/8] virtio: new API for addition of buffers, scatterlist changes Paolo Bonzini
2013-02-07 12:22 ` [RFC PATCH 1/8] virtio: add functions for piecewise addition of buffers Paolo Bonzini
2013-02-07 12:22 ` [RFC PATCH 2/8] virtio-blk: reorganize virtblk_add_req Paolo Bonzini
2013-02-07 12:22 ` [RFC PATCH 3/8] virtio-blk: use virtqueue_start_buf on bio path Paolo Bonzini
2013-02-07 12:22 ` [RFC PATCH 4/8] virtio-blk: use virtqueue_start_buf on req path Paolo Bonzini
2013-02-07 12:22 ` [RFC PATCH 5/8] scatterlist: introduce sg_unmark_end Paolo Bonzini
2013-02-07 12:35 ` Jens Axboe
2013-02-07 12:22 ` Paolo Bonzini [this message]
2013-02-07 12:22 ` [RFC PATCH 7/8] virtio-scsi: use virtqueue_start_buf Paolo Bonzini
2013-02-07 12:22 ` [RFC PATCH 8/8] virtio: reimplement virtqueue_add_buf using new functions Paolo Bonzini
2013-02-07 13:09 ` [RFC PATCH 0/8] virtio: new API for addition of buffers, scatterlist changes Michael S. Tsirkin
2013-02-07 13:14 ` Paolo Bonzini
2013-02-07 13:23 ` Michael S. Tsirkin
2013-02-07 13:20 ` Paolo Bonzini
2013-02-07 13:31 ` Michael S. Tsirkin
2013-02-07 13:30 ` Paolo Bonzini
2013-02-08 4:05 ` Rusty Russell
2013-02-08 6:35 ` Paolo Bonzini
2013-02-08 11:52 ` Jens Axboe
2013-02-13 9:46 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360239752-2470-7-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=asias@redhat.com \
--cc=gaowanlong@cn.fujitsu.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).