Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3602081ybv; Tue, 25 Feb 2020 04:10:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxeJOr9yrS5l+qOChlSIVfe+/OwszBqzR6DWM6v+IR62IX1663gE1ogkSiADLQaPMWNnEd3 X-Received: by 2002:a54:4091:: with SMTP id i17mr3343701oii.99.1582632657594; Tue, 25 Feb 2020 04:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582632657; cv=none; d=google.com; s=arc-20160816; b=pvEAgMmEW+VCUuZhlqewGUyUupQVYbL0KQmis8fTndqUPmQxys/x+Y1o7APc0X+sbG DlnxCKaVdtwheK7qFXcf5tB3dX4NUVZ5Zz9g4FWmYCMaWfTApKwLi4vTHlkBea4MbuBJ YPsqGvQus5WszXeoWd9SAxrSJzMoc7gmCG0EpinY/Le0KA4BZKKlAY2acNO8lhVEP88e qWSedrKNpG4js5khMPV8nAvBR40t2/2nw9r5Rd8sKfUa1jqsViu7Y80CZDyg0UZOmH/+ m3HnU5OoZHgv4Bx2XT7xjKlm4v/As2vuDMbqiqqaT8GcvN0k5EQa6rIYCn5r0W5XUTKj gkBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=U3hPikohRml3lL8Jogc7iVoQHY1Ph6Jcqk0meeV3PT4=; b=Dwovv8uRiFl/YTvYA1YKWVpFZTrOrkE4zWHowVa6TwVlREC8/d/Wh+5hj8u8Ia6Cou 5iRb52mF8cbPNLWYmqxgwXSkqD2lck9Bxj5ux+PDAw+M2O2CQajWyts1C2WFWcUD28Ud Gg3gxzByOB/gp+mC1GKToGZuZ/2H1q8+7ZbPaf0aV7W8IHDd5aaU0k+CR+bW8rfhQm5/ aD3i+cSPCVoKUN0wRHjk+q4uT1ql76m652T8nL/w5a3V6LFnyL7aPQ/yEXyLjZQd786I spdx27PT3TP9FgI86VuQuM8lz6tOsSNkf/Stbvopnd/cbwX5SefDclIKy2/Gl7UJuLMW OpzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LtFNel6g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13si7725710otq.201.2020.02.25.04.10.45; Tue, 25 Feb 2020 04:10:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LtFNel6g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730453AbgBYLTp (ORCPT + 99 others); Tue, 25 Feb 2020 06:19:45 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:42747 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729708AbgBYLTp (ORCPT ); Tue, 25 Feb 2020 06:19:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582629582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=U3hPikohRml3lL8Jogc7iVoQHY1Ph6Jcqk0meeV3PT4=; b=LtFNel6glRAsmWsWPrgUNsD4m5ETvQJYK7a13H5RzEACZIkNfo63C2klMEKPbZY4wGAn/h PLVTmShrDsy+K78owDlDXqXe7i6TCxCiW2ONDv4Sia45mPGloFfaEy3ZSo1uPNdE130DM7 ZPzay6qb1pacKzJyHiNseZO6FNg5odI= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-wmU98-eQMBOt_ndOGwwkRQ-1; Tue, 25 Feb 2020 06:19:37 -0500 X-MC-Unique: wmU98-eQMBOt_ndOGwwkRQ-1 Received: by mail-qt1-f197.google.com with SMTP id e37so14472297qtk.7 for ; Tue, 25 Feb 2020 03:19:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=U3hPikohRml3lL8Jogc7iVoQHY1Ph6Jcqk0meeV3PT4=; b=kkcP5Ql6mbSB2IrEETEhtmQV/4mIjF6xswaNDJm1YOyjTLeNjgc3ZIm2fqilmu4reS upLkVdslO4ymJ3X7fc7k+trEoHGJLg0WRUHwzYAMAHWc4Ineu0sOjfkMWF3nUeSZ2hS4 tHP3Sixgz+Dk35ZoKL9KSIsNuXjvXFMQag3EmKRUtOAbt9jeWJIchKq3cki56lyXXMLb LPsOnukybLngf3RVUZ32vveVDWSpDAIzhIg3Nw9lN44Vnai6wXoNWoIbs92rWZOFhVV/ 26nmn06HKbiQ/VFkMQuxJ9rILpMBayJSt/2oftiJ4lxpc54r3PehqXhqhMFmQmgy90SA 779g== X-Gm-Message-State: APjAAAUIGuiZxhwm31u76ZkQUiKu62gn01aC9xxMsR0gA46nlO6BameN bkMmaAUGyC/7aaYce2jSRl9Z6Ui/BA75/KQE/1LpjI7YGBWMGcnnb7TawJ6XAYbNL5+NG+EZSIn GGEMnZk3ZEjESfIXO78Jkdgmi X-Received: by 2002:a0c:cc89:: with SMTP id f9mr33125103qvl.17.1582629577152; Tue, 25 Feb 2020 03:19:37 -0800 (PST) X-Received: by 2002:a0c:cc89:: with SMTP id f9mr33125064qvl.17.1582629576871; Tue, 25 Feb 2020 03:19:36 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id t6sm3732951qke.57.2020.02.25.03.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 03:19:36 -0800 (PST) Date: Tue, 25 Feb 2020 06:19:30 -0500 From: "Michael S. Tsirkin" To: Yuya Kusakabe Cc: jasowang@redhat.com, andriin@fb.com, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, davem@davemloft.net, hawk@kernel.org, john.fastabend@gmail.com, kafai@fb.com, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, songliubraving@fb.com, yhs@fb.com Subject: Re: [PATCH bpf-next v6 2/2] virtio_net: add XDP meta data support Message-ID: <20200225061923-mutt-send-email-mst@kernel.org> References: <20200225033103.437305-1-yuya.kusakabe@gmail.com> <20200225033212.437563-1-yuya.kusakabe@gmail.com> <20200225033212.437563-2-yuya.kusakabe@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200225033212.437563-2-yuya.kusakabe@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 25, 2020 at 12:32:12PM +0900, Yuya Kusakabe wrote: > Implement support for transferring XDP meta data into skb for > virtio_net driver; before calling into the program, xdp.data_meta points > to xdp.data, where on program return with pass verdict, we call > into skb_metadata_set(). > > Tested with the script at > https://github.com/higebu/virtio_net-xdp-metadata-test. > > Signed-off-by: Yuya Kusakabe > --- Acked-by: Michael S. Tsirkin > drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++---------------- > 1 file changed, 32 insertions(+), 20 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index f39d0218bdaa..12d115ef5e74 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -371,7 +371,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, > struct receive_queue *rq, > struct page *page, unsigned int offset, > unsigned int len, unsigned int truesize, > - bool hdr_valid) > + bool hdr_valid, unsigned int metasize) > { > struct sk_buff *skb; > struct virtio_net_hdr_mrg_rxbuf *hdr; > @@ -393,6 +393,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, > else > hdr_padded_len = sizeof(struct padded_vnet_hdr); > > + /* hdr_valid means no XDP, so we can copy the vnet header */ > if (hdr_valid) > memcpy(hdr, p, hdr_len); > > @@ -405,6 +406,11 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, > copy = skb_tailroom(skb); > skb_put_data(skb, p, copy); > > + if (metasize) { > + __skb_pull(skb, metasize); > + skb_metadata_set(skb, metasize); > + } > + > len -= copy; > offset += copy; > > @@ -450,10 +456,6 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi, > struct virtio_net_hdr_mrg_rxbuf *hdr; > int err; > > - /* virtqueue want to use data area in-front of packet */ > - if (unlikely(xdpf->metasize > 0)) > - return -EOPNOTSUPP; > - > if (unlikely(xdpf->headroom < vi->hdr_len)) > return -EOVERFLOW; > > @@ -644,6 +646,7 @@ static struct sk_buff *receive_small(struct net_device *dev, > unsigned int delta = 0; > struct page *xdp_page; > int err; > + unsigned int metasize = 0; > > len -= vi->hdr_len; > stats->bytes += len; > @@ -683,8 +686,8 @@ static struct sk_buff *receive_small(struct net_device *dev, > > xdp.data_hard_start = buf + VIRTNET_RX_PAD + vi->hdr_len; > xdp.data = xdp.data_hard_start + xdp_headroom; > - xdp_set_data_meta_invalid(&xdp); > xdp.data_end = xdp.data + len; > + xdp.data_meta = xdp.data; > xdp.rxq = &rq->xdp_rxq; > orig_data = xdp.data; > act = bpf_prog_run_xdp(xdp_prog, &xdp); > @@ -695,6 +698,7 @@ static struct sk_buff *receive_small(struct net_device *dev, > /* Recalculate length in case bpf program changed it */ > delta = orig_data - xdp.data; > len = xdp.data_end - xdp.data; > + metasize = xdp.data - xdp.data_meta; > break; > case XDP_TX: > stats->xdp_tx++; > @@ -740,6 +744,9 @@ static struct sk_buff *receive_small(struct net_device *dev, > memcpy(skb_vnet_hdr(skb), buf, vi->hdr_len); > } /* keep zeroed vnet hdr since XDP is loaded */ > > + if (metasize) > + skb_metadata_set(skb, metasize); > + > err: > return skb; > > @@ -760,8 +767,8 @@ static struct sk_buff *receive_big(struct net_device *dev, > struct virtnet_rq_stats *stats) > { > struct page *page = buf; > - struct sk_buff *skb = page_to_skb(vi, rq, page, 0, len, > - PAGE_SIZE, true); > + struct sk_buff *skb = > + page_to_skb(vi, rq, page, 0, len, PAGE_SIZE, true, 0); > > stats->bytes += len - vi->hdr_len; > if (unlikely(!skb)) > @@ -793,6 +800,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, > unsigned int truesize; > unsigned int headroom = mergeable_ctx_to_headroom(ctx); > int err; > + unsigned int metasize = 0; > > head_skb = NULL; > stats->bytes += len - vi->hdr_len; > @@ -839,8 +847,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, > data = page_address(xdp_page) + offset; > xdp.data_hard_start = data - VIRTIO_XDP_HEADROOM + vi->hdr_len; > xdp.data = data + vi->hdr_len; > - xdp_set_data_meta_invalid(&xdp); > xdp.data_end = xdp.data + (len - vi->hdr_len); > + xdp.data_meta = xdp.data; > xdp.rxq = &rq->xdp_rxq; > > act = bpf_prog_run_xdp(xdp_prog, &xdp); > @@ -848,24 +856,27 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, > > switch (act) { > case XDP_PASS: > + metasize = xdp.data - xdp.data_meta; > + > /* recalculate offset to account for any header > - * adjustments. Note other cases do not build an > - * skb and avoid using offset > + * adjustments and minus the metasize to copy the > + * metadata in page_to_skb(). Note other cases do not > + * build an skb and avoid using offset > */ > - offset = xdp.data - > - page_address(xdp_page) - vi->hdr_len; > + offset = xdp.data - page_address(xdp_page) - > + vi->hdr_len - metasize; > > - /* recalculate len if xdp.data or xdp.data_end were > - * adjusted > + /* recalculate len if xdp.data, xdp.data_end or > + * xdp.data_meta were adjusted > */ > - len = xdp.data_end - xdp.data + vi->hdr_len; > + len = xdp.data_end - xdp.data + vi->hdr_len + metasize; > /* We can only create skb based on xdp_page. */ > if (unlikely(xdp_page != page)) { > rcu_read_unlock(); > put_page(page); > - head_skb = page_to_skb(vi, rq, xdp_page, > - offset, len, > - PAGE_SIZE, false); > + head_skb = page_to_skb(vi, rq, xdp_page, offset, > + len, PAGE_SIZE, false, > + metasize); > return head_skb; > } > break; > @@ -921,7 +932,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, > goto err_skb; > } > > - head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog); > + head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog, > + metasize); > curr_skb = head_skb; > > if (unlikely(!curr_skb)) > -- > 2.24.1