@@ -410,7 +410,8 @@ static unsigned int virtnet_get_headroom(struct virtnet_info *vi)
410
410
static struct sk_buff * receive_small (struct net_device * dev ,
411
411
struct virtnet_info * vi ,
412
412
struct receive_queue * rq ,
413
- void * buf , unsigned int len )
413
+ void * buf , void * ctx ,
414
+ unsigned int len )
414
415
{
415
416
struct sk_buff * skb ;
416
417
struct bpf_prog * xdp_prog ;
@@ -773,7 +774,7 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
773
774
else if (vi -> big_packets )
774
775
skb = receive_big (dev , vi , rq , buf , len );
775
776
else
776
- skb = receive_small (dev , vi , rq , buf , len );
777
+ skb = receive_small (dev , vi , rq , buf , ctx , len );
777
778
778
779
if (unlikely (!skb ))
779
780
return 0 ;
@@ -806,12 +807,18 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
806
807
return 0 ;
807
808
}
808
809
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
+ */
809
815
static int add_recvbuf_small (struct virtnet_info * vi , struct receive_queue * rq ,
810
816
gfp_t gfp )
811
817
{
812
818
struct page_frag * alloc_frag = & rq -> alloc_frag ;
813
819
char * buf ;
814
820
unsigned int xdp_headroom = virtnet_get_headroom (vi );
821
+ void * ctx = (void * )(unsigned long )xdp_headroom ;
815
822
int len = vi -> hdr_len + VIRTNET_RX_PAD + GOOD_PACKET_LEN + xdp_headroom ;
816
823
int err ;
817
824
@@ -825,7 +832,7 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
825
832
alloc_frag -> offset += len ;
826
833
sg_init_one (rq -> sg , buf + VIRTNET_RX_PAD + xdp_headroom ,
827
834
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 );
829
836
if (err < 0 )
830
837
put_page (virt_to_head_page (buf ));
831
838
@@ -1034,7 +1041,7 @@ static int virtnet_receive(struct receive_queue *rq, int budget)
1034
1041
void * buf ;
1035
1042
struct virtnet_stats * stats = this_cpu_ptr (vi -> stats );
1036
1043
1037
- if (vi -> mergeable_rx_bufs ) {
1044
+ if (! vi -> big_packets || vi -> mergeable_rx_bufs ) {
1038
1045
void * ctx ;
1039
1046
1040
1047
while (received < budget &&
@@ -2202,7 +2209,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
2202
2209
names = kmalloc (total_vqs * sizeof (* names ), GFP_KERNEL );
2203
2210
if (!names )
2204
2211
goto err_names ;
2205
- if (vi -> mergeable_rx_bufs ) {
2212
+ if (! vi -> big_packets || vi -> mergeable_rx_bufs ) {
2206
2213
ctx = kzalloc (total_vqs * sizeof (* ctx ), GFP_KERNEL );
2207
2214
if (!ctx )
2208
2215
goto err_ctx ;
0 commit comments