Skip to content

Commit 192f68c

Browse files
jasowangdavem330
authored andcommitted
virtio-net: switch to use new ctx API for small buffer
Use ctx API to store headroom for small buffers. Following patches will retrieve this info and use it for XDP. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 28b39bc commit 192f68c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/net/virtio_net.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ static unsigned int virtnet_get_headroom(struct virtnet_info *vi)
410410
static struct sk_buff *receive_small(struct net_device *dev,
411411
struct virtnet_info *vi,
412412
struct receive_queue *rq,
413-
void *buf, unsigned int len)
413+
void *buf, void *ctx,
414+
unsigned int len)
414415
{
415416
struct sk_buff *skb;
416417
struct bpf_prog *xdp_prog;
@@ -773,7 +774,7 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
773774
else if (vi->big_packets)
774775
skb = receive_big(dev, vi, rq, buf, len);
775776
else
776-
skb = receive_small(dev, vi, rq, buf, len);
777+
skb = receive_small(dev, vi, rq, buf, ctx, len);
777778

778779
if (unlikely(!skb))
779780
return 0;
@@ -806,12 +807,18 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
806807
return 0;
807808
}
808809

810+
/* Unlike mergeable buffers, all buffers are allocated to the
811+
* same size, except for the headroom. For this reason we do
812+
* not need to use mergeable_len_to_ctx here - it is enough
813+
* to store the headroom as the context ignoring the truesize.
814+
*/
809815
static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
810816
gfp_t gfp)
811817
{
812818
struct page_frag *alloc_frag = &rq->alloc_frag;
813819
char *buf;
814820
unsigned int xdp_headroom = virtnet_get_headroom(vi);
821+
void *ctx = (void *)(unsigned long)xdp_headroom;
815822
int len = vi->hdr_len + VIRTNET_RX_PAD + GOOD_PACKET_LEN + xdp_headroom;
816823
int err;
817824

@@ -825,7 +832,7 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
825832
alloc_frag->offset += len;
826833
sg_init_one(rq->sg, buf + VIRTNET_RX_PAD + xdp_headroom,
827834
vi->hdr_len + GOOD_PACKET_LEN);
828-
err = virtqueue_add_inbuf(rq->vq, rq->sg, 1, buf, gfp);
835+
err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
829836
if (err < 0)
830837
put_page(virt_to_head_page(buf));
831838

@@ -1034,7 +1041,7 @@ static int virtnet_receive(struct receive_queue *rq, int budget)
10341041
void *buf;
10351042
struct virtnet_stats *stats = this_cpu_ptr(vi->stats);
10361043

1037-
if (vi->mergeable_rx_bufs) {
1044+
if (!vi->big_packets || vi->mergeable_rx_bufs) {
10381045
void *ctx;
10391046

10401047
while (received < budget &&
@@ -2202,7 +2209,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
22022209
names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
22032210
if (!names)
22042211
goto err_names;
2205-
if (vi->mergeable_rx_bufs) {
2212+
if (!vi->big_packets || vi->mergeable_rx_bufs) {
22062213
ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
22072214
if (!ctx)
22082215
goto err_ctx;

0 commit comments

Comments
 (0)