* [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running
@ 2017-01-05 3:11 John Fastabend
2017-01-05 3:11 ` [net PATCH 2/2] virtio_net: use dev_kfree_skb for small buffer XDP receive John Fastabend
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: John Fastabend @ 2017-01-05 3:11 UTC (permalink / raw)
To: jasowang, mst; +Cc: john.r.fastabend, netdev, john.fastabend
XDP programs can not consume multiple pages so we cap the MTU to
avoid this case. Virtio-net however only checks the MTU at XDP
program load and does not block MTU changes after the program
has loaded.
This patch sets/clears the max_mtu value at XDP load/unload time.
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
---
drivers/net/virtio_net.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4a10500..261103d9 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1699,11 +1699,28 @@ static void virtnet_init_settings(struct net_device *dev)
.set_settings = virtnet_set_settings,
};
+#define MIN_MTU ETH_MIN_MTU
+#define MAX_MTU ETH_MAX_MTU
+
+static unsigned long int virtnet_xdp_mtu(struct bpf_prog *prog,
+ struct virtnet_info *vi)
+{
+ if (!prog && virtio_has_feature(vi->vdev, VIRTIO_NET_F_MTU))
+ return virtio_cread16(vi->vdev,
+ offsetof(struct virtio_net_config, mtu));
+ else if (!prog)
+ return ETH_MAX_MTU;
+ else if (vi->mergeable_rx_bufs)
+ return PAGE_SIZE - sizeof(struct padded_vnet_hdr);
+ else
+ return GOOD_PACKET_LEN;
+}
+
static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
{
- unsigned long int max_sz = PAGE_SIZE - sizeof(struct padded_vnet_hdr);
struct virtnet_info *vi = netdev_priv(dev);
struct bpf_prog *old_prog;
+ unsigned long int max_sz;
u16 xdp_qp = 0, curr_qp;
int i, err;
@@ -1720,6 +1737,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
return -EINVAL;
}
+ max_sz = virtnet_xdp_mtu(prog, vi);
if (dev->mtu > max_sz) {
netdev_warn(dev, "XDP requires MTU less than %lu\n", max_sz);
return -EINVAL;
@@ -1748,6 +1766,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
virtnet_set_queues(vi, curr_qp);
return PTR_ERR(prog);
}
+ dev->max_mtu = max_sz;
+ } else {
+ dev->max_mtu = ETH_MAX_MTU;
}
vi->xdp_queue_pairs = xdp_qp;
@@ -2133,9 +2154,6 @@ static bool virtnet_validate_features(struct virtio_device *vdev)
return true;
}
-#define MIN_MTU ETH_MIN_MTU
-#define MAX_MTU ETH_MAX_MTU
-
static int virtnet_probe(struct virtio_device *vdev)
{
int i, err;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [net PATCH 2/2] virtio_net: use dev_kfree_skb for small buffer XDP receive
2017-01-05 3:11 [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
@ 2017-01-05 3:11 ` John Fastabend
2017-01-05 3:14 ` [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
2017-01-05 3:18 ` Michael S. Tsirkin
2 siblings, 0 replies; 5+ messages in thread
From: John Fastabend @ 2017-01-05 3:11 UTC (permalink / raw)
To: jasowang, mst; +Cc: john.r.fastabend, netdev, john.fastabend
In the small buffer case during driver unload we currently use
put_page instead of dev_kfree_skb. Resolve this by adding a check
for virtnet mode when checking XDP queue type. Also name the
function so that the code reads correctly to match the additional
check.
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
---
drivers/net/virtio_net.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 261103d9..a224d3e 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1911,8 +1911,12 @@ static void free_receive_page_frags(struct virtnet_info *vi)
put_page(vi->rq[i].alloc_frag.page);
}
-static bool is_xdp_queue(struct virtnet_info *vi, int q)
+static bool is_xdp_raw_buffer_queue(struct virtnet_info *vi, int q)
{
+ /* For small receive mode always use kfree_skb variants */
+ if (!vi->mergeable_rx_bufs)
+ return false;
+
if (q < (vi->curr_queue_pairs - vi->xdp_queue_pairs))
return false;
else if (q < vi->curr_queue_pairs)
@@ -1929,7 +1933,7 @@ static void free_unused_bufs(struct virtnet_info *vi)
for (i = 0; i < vi->max_queue_pairs; i++) {
struct virtqueue *vq = vi->sq[i].vq;
while ((buf = virtqueue_detach_unused_buf(vq)) != NULL) {
- if (!is_xdp_queue(vi, i))
+ if (!is_xdp_raw_buffer_queue(vi, i))
dev_kfree_skb(buf);
else
put_page(virt_to_head_page(buf));
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running
2017-01-05 3:11 [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
2017-01-05 3:11 ` [net PATCH 2/2] virtio_net: use dev_kfree_skb for small buffer XDP receive John Fastabend
@ 2017-01-05 3:14 ` John Fastabend
2017-01-05 3:18 ` Michael S. Tsirkin
2 siblings, 0 replies; 5+ messages in thread
From: John Fastabend @ 2017-01-05 3:14 UTC (permalink / raw)
To: jasowang, mst; +Cc: john.r.fastabend, netdev
On 17-01-04 07:11 PM, John Fastabend wrote:
> XDP programs can not consume multiple pages so we cap the MTU to
> avoid this case. Virtio-net however only checks the MTU at XDP
> program load and does not block MTU changes after the program
> has loaded.
>
> This patch sets/clears the max_mtu value at XDP load/unload time.
>
> Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
> ---
> drivers/net/virtio_net.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
[...]
> static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
> {
> - unsigned long int max_sz = PAGE_SIZE - sizeof(struct padded_vnet_hdr);
> struct virtnet_info *vi = netdev_priv(dev);
> struct bpf_prog *old_prog;
> + unsigned long int max_sz;
> u16 xdp_qp = 0, curr_qp;
> int i, err;
>
> @@ -1720,6 +1737,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
> return -EINVAL;
> }
>
> + max_sz = virtnet_xdp_mtu(prog, vi);
> if (dev->mtu > max_sz) {
> netdev_warn(dev, "XDP requires MTU less than %lu\n", max_sz);
> return -EINVAL;
> @@ -1748,6 +1766,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
> virtnet_set_queues(vi, curr_qp);
> return PTR_ERR(prog);
> }
> + dev->max_mtu = max_sz;
> + } else {
> + dev->max_mtu = ETH_MAX_MTU;
> }
oops v2 needed. The else branch is not required anymore. :/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running
2017-01-05 3:11 [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
2017-01-05 3:11 ` [net PATCH 2/2] virtio_net: use dev_kfree_skb for small buffer XDP receive John Fastabend
2017-01-05 3:14 ` [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
@ 2017-01-05 3:18 ` Michael S. Tsirkin
2017-01-05 9:34 ` Jason Wang
2 siblings, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2017-01-05 3:18 UTC (permalink / raw)
To: John Fastabend; +Cc: jasowang, john.r.fastabend, netdev
On Wed, Jan 04, 2017 at 07:11:18PM -0800, John Fastabend wrote:
> XDP programs can not consume multiple pages so we cap the MTU to
> avoid this case. Virtio-net however only checks the MTU at XDP
> program load and does not block MTU changes after the program
> has loaded.
Do drivers really have to tweak max mtu all the time?
Seems strange, I would say drivers just report device caps
and net core enforces rules.
Can't net core do these checks?
>
> This patch sets/clears the max_mtu value at XDP load/unload time.
>
> Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
> ---
> drivers/net/virtio_net.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 4a10500..261103d9 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1699,11 +1699,28 @@ static void virtnet_init_settings(struct net_device *dev)
> .set_settings = virtnet_set_settings,
> };
>
> +#define MIN_MTU ETH_MIN_MTU
> +#define MAX_MTU ETH_MAX_MTU
> +
> +static unsigned long int virtnet_xdp_mtu(struct bpf_prog *prog,
> + struct virtnet_info *vi)
> +{
> + if (!prog && virtio_has_feature(vi->vdev, VIRTIO_NET_F_MTU))
> + return virtio_cread16(vi->vdev,
> + offsetof(struct virtio_net_config, mtu));
> + else if (!prog)
> + return ETH_MAX_MTU;
> + else if (vi->mergeable_rx_bufs)
> + return PAGE_SIZE - sizeof(struct padded_vnet_hdr);
> + else
> + return GOOD_PACKET_LEN;
> +}
> +
> static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
> {
> - unsigned long int max_sz = PAGE_SIZE - sizeof(struct padded_vnet_hdr);
> struct virtnet_info *vi = netdev_priv(dev);
> struct bpf_prog *old_prog;
> + unsigned long int max_sz;
> u16 xdp_qp = 0, curr_qp;
> int i, err;
>
> @@ -1720,6 +1737,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
> return -EINVAL;
> }
>
> + max_sz = virtnet_xdp_mtu(prog, vi);
> if (dev->mtu > max_sz) {
> netdev_warn(dev, "XDP requires MTU less than %lu\n", max_sz);
> return -EINVAL;
> @@ -1748,6 +1766,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
> virtnet_set_queues(vi, curr_qp);
> return PTR_ERR(prog);
> }
> + dev->max_mtu = max_sz;
> + } else {
> + dev->max_mtu = ETH_MAX_MTU;
> }
>
> vi->xdp_queue_pairs = xdp_qp;
> @@ -2133,9 +2154,6 @@ static bool virtnet_validate_features(struct virtio_device *vdev)
> return true;
> }
>
> -#define MIN_MTU ETH_MIN_MTU
> -#define MAX_MTU ETH_MAX_MTU
> -
> static int virtnet_probe(struct virtio_device *vdev)
> {
> int i, err;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running
2017-01-05 3:18 ` Michael S. Tsirkin
@ 2017-01-05 9:34 ` Jason Wang
0 siblings, 0 replies; 5+ messages in thread
From: Jason Wang @ 2017-01-05 9:34 UTC (permalink / raw)
To: Michael S. Tsirkin, John Fastabend; +Cc: john.r.fastabend, netdev
On 2017年01月05日 11:18, Michael S. Tsirkin wrote:
> On Wed, Jan 04, 2017 at 07:11:18PM -0800, John Fastabend wrote:
>> XDP programs can not consume multiple pages so we cap the MTU to
>> avoid this case. Virtio-net however only checks the MTU at XDP
>> program load and does not block MTU changes after the program
>> has loaded.
> Do drivers really have to tweak max mtu all the time?
> Seems strange, I would say drivers just report device caps
> and net core enforces rules.
> Can't net core do these checks?
I think this needs host co-operation, at least this patch prevents user
from misconfiguring mtu in guest.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-05 9:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-05 3:11 [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
2017-01-05 3:11 ` [net PATCH 2/2] virtio_net: use dev_kfree_skb for small buffer XDP receive John Fastabend
2017-01-05 3:14 ` [net PATCH 1/2] virtio_net: cap mtu when XDP programs are running John Fastabend
2017-01-05 3:18 ` Michael S. Tsirkin
2017-01-05 9:34 ` Jason Wang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.