Message ID | 20230619105738.117733-3-hengqi@linux.alibaba.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | virtio-net: avoid XDP and _F_GUEST_CSUM | expand |
On Mon, Jun 19, 2023 at 06:57:36PM +0800, Heng Qi wrote: > Currently, the VIRTIO_NET_F_GUEST_CSUM (corresponds to NETIF_F_RXCSUM > for netdev) feature of the virtio-net driver conflicts with the loading > of XDP, which is caused by the problem described in [1][2], that is, > XDP may cause errors in partial csumed-related fields which can lead > to packet dropping. > > In addition, when communicating between vm and vm on the same host, the > receiving side vm will receive packets marked as > VIRTIO_NET_HDR_F_NEEDS_CSUM, but after these packets are processed by > XDP, the VIRTIO_NET_HDR_F_NEEDS_CSUM and skb CHECKSUM_PARTIAL flags will > be cleared, causing the packet dropping. > > This patch introduces a helper function, which will try to solve the > above problems in the subsequent patch. > > [1] commit 18ba58e1c234 ("virtio-net: fail XDP set if guest csum is negotiated") > [2] commit e59ff2c49ae1 ("virtio-net: disable guest csum during XDP set") > > Signed-off-by: Heng Qi <hengqi@linux.alibaba.com> > Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> squash this and patch 1 into where the helpers are used. in particular so we don't get warnings with bisect. > --- > drivers/net/virtio_net.c | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 36cae78f6311..07b4801d689c 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -1663,6 +1663,44 @@ static int virtnet_flow_dissect_udp_tcp(struct virtnet_info *vi, struct sk_buff > return 0; > } > > +static int virtnet_set_csum_after_xdp(struct virtnet_info *vi, > + struct sk_buff *skb, > + __u8 flags) > +{ > + int err; > + > + /* When XDP program is loaded, for example, the vm-vm scenario > + * on the same host, packets marked as VIRTIO_NET_HDR_F_NEEDS_CSUM > + * will travel. Although these packets are safe from the point of > + * view of the vm, to avoid modification by XDP and successful > + * forwarding in the upper layer, we re-probe the necessary checksum > + * related information: skb->csum_{start, offset}, pseudo-header csum. > + * > + * This benefits us: > + * 1. XDP can be loaded when there's _F_GUEST_CSUM. > + * 2. The device verifies the checksum of packets , especially > + * benefiting for large packets. > + * 3. In the same-host vm-vm scenario, packets marked as > + * VIRTIO_NET_HDR_F_NEEDS_CSUM are no longer dropped after being > + * processed by XDP. > + */ > + if (flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { > + err = virtnet_flow_dissect_udp_tcp(vi, skb); > + if (err < 0) > + return -EINVAL; > + > + skb->ip_summed = CHECKSUM_PARTIAL; > + } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { > + /* We want to benefit from this: XDP guarantees that packets marked > + * as VIRTIO_NET_HDR_F_DATA_VALID still have correct csum after they > + * are processed. > + */ > + skb->ip_summed = CHECKSUM_UNNECESSARY; > + } > + > + return 0; > +} > + > static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, > void *buf, unsigned int len, void **ctx, > unsigned int *xdp_xmit, > -- > 2.19.1.6.gb485710b
On Mon, Jun 19, 2023 at 07:27:26AM -0400, Michael S. Tsirkin wrote: > On Mon, Jun 19, 2023 at 06:57:36PM +0800, Heng Qi wrote: > > Currently, the VIRTIO_NET_F_GUEST_CSUM (corresponds to NETIF_F_RXCSUM > > for netdev) feature of the virtio-net driver conflicts with the loading > > of XDP, which is caused by the problem described in [1][2], that is, > > XDP may cause errors in partial csumed-related fields which can lead > > to packet dropping. > > > > In addition, when communicating between vm and vm on the same host, the > > receiving side vm will receive packets marked as > > VIRTIO_NET_HDR_F_NEEDS_CSUM, but after these packets are processed by > > XDP, the VIRTIO_NET_HDR_F_NEEDS_CSUM and skb CHECKSUM_PARTIAL flags will > > be cleared, causing the packet dropping. > > > > This patch introduces a helper function, which will try to solve the > > above problems in the subsequent patch. > > > > [1] commit 18ba58e1c234 ("virtio-net: fail XDP set if guest csum is negotiated") > > [2] commit e59ff2c49ae1 ("virtio-net: disable guest csum during XDP set") > > > > Signed-off-by: Heng Qi <hengqi@linux.alibaba.com> > > Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> > > > squash this and patch 1 into where the helpers are used. > > in particular so we don't get warnings with bisect. Ok. Will modify. Thanks. > > > --- > > drivers/net/virtio_net.c | 38 ++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 38 insertions(+) > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > index 36cae78f6311..07b4801d689c 100644 > > --- a/drivers/net/virtio_net.c > > +++ b/drivers/net/virtio_net.c > > @@ -1663,6 +1663,44 @@ static int virtnet_flow_dissect_udp_tcp(struct virtnet_info *vi, struct sk_buff > > return 0; > > } > > > > +static int virtnet_set_csum_after_xdp(struct virtnet_info *vi, > > + struct sk_buff *skb, > > + __u8 flags) > > +{ > > + int err; > > + > > + /* When XDP program is loaded, for example, the vm-vm scenario > > + * on the same host, packets marked as VIRTIO_NET_HDR_F_NEEDS_CSUM > > + * will travel. Although these packets are safe from the point of > > + * view of the vm, to avoid modification by XDP and successful > > + * forwarding in the upper layer, we re-probe the necessary checksum > > + * related information: skb->csum_{start, offset}, pseudo-header csum. > > + * > > + * This benefits us: > > + * 1. XDP can be loaded when there's _F_GUEST_CSUM. > > + * 2. The device verifies the checksum of packets , especially > > + * benefiting for large packets. > > + * 3. In the same-host vm-vm scenario, packets marked as > > + * VIRTIO_NET_HDR_F_NEEDS_CSUM are no longer dropped after being > > + * processed by XDP. > > + */ > > + if (flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { > > + err = virtnet_flow_dissect_udp_tcp(vi, skb); > > + if (err < 0) > > + return -EINVAL; > > + > > + skb->ip_summed = CHECKSUM_PARTIAL; > > + } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { > > + /* We want to benefit from this: XDP guarantees that packets marked > > + * as VIRTIO_NET_HDR_F_DATA_VALID still have correct csum after they > > + * are processed. > > + */ > > + skb->ip_summed = CHECKSUM_UNNECESSARY; > > + } > > + > > + return 0; > > +} > > + > > static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, > > void *buf, unsigned int len, void **ctx, > > unsigned int *xdp_xmit, > > -- > > 2.19.1.6.gb485710b
Hi Heng, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Heng-Qi/virtio-net-a-helper-for-probing-the-pseudo-header-checksum/20230619-190212 base: net-next/main patch link: https://lore.kernel.org/r/20230619105738.117733-3-hengqi%40linux.alibaba.com patch subject: [PATCH net-next 2/4] virtio-net: reprobe csum related fields for skb passed by XDP config: x86_64-randconfig-r014-20230619 (https://download.01.org/0day-ci/archive/20230619/202306192151.YMz3NiKw-lkp@intel.com/config) compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) reproduce: (https://download.01.org/0day-ci/archive/20230619/202306192151.YMz3NiKw-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306192151.YMz3NiKw-lkp@intel.com/ All warnings (new ones prefixed by >>): drivers/net/virtio_net.c:1648:17: error: call to undeclared function 'csum_ipv6_magic'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] uh->check = ~csum_ipv6_magic((const struct in6_addr *)&ip6h->saddr, ^ drivers/net/virtio_net.c:1648:17: note: did you mean 'csum_tcpudp_magic'? include/asm-generic/checksum.h:52:1: note: 'csum_tcpudp_magic' declared here csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len, ^ drivers/net/virtio_net.c:1657:17: error: call to undeclared function 'csum_ipv6_magic'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] th->check = ~csum_ipv6_magic((const struct in6_addr *)&ip6h->saddr, ^ >> drivers/net/virtio_net.c:1695:19: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/virtio_net.c:1695:19: note: use '&' for a bitwise operation } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { ^~ & drivers/net/virtio_net.c:1695:19: note: remove constant to silence this warning } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning and 2 errors generated. vim +1695 drivers/net/virtio_net.c 1667 1668 static int virtnet_set_csum_after_xdp(struct virtnet_info *vi, 1669 struct sk_buff *skb, 1670 __u8 flags) 1671 { 1672 int err; 1673 1674 /* When XDP program is loaded, for example, the vm-vm scenario 1675 * on the same host, packets marked as VIRTIO_NET_HDR_F_NEEDS_CSUM 1676 * will travel. Although these packets are safe from the point of 1677 * view of the vm, to avoid modification by XDP and successful 1678 * forwarding in the upper layer, we re-probe the necessary checksum 1679 * related information: skb->csum_{start, offset}, pseudo-header csum. 1680 * 1681 * This benefits us: 1682 * 1. XDP can be loaded when there's _F_GUEST_CSUM. 1683 * 2. The device verifies the checksum of packets , especially 1684 * benefiting for large packets. 1685 * 3. In the same-host vm-vm scenario, packets marked as 1686 * VIRTIO_NET_HDR_F_NEEDS_CSUM are no longer dropped after being 1687 * processed by XDP. 1688 */ 1689 if (flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { 1690 err = virtnet_flow_dissect_udp_tcp(vi, skb); 1691 if (err < 0) 1692 return -EINVAL; 1693 1694 skb->ip_summed = CHECKSUM_PARTIAL; > 1695 } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { 1696 /* We want to benefit from this: XDP guarantees that packets marked 1697 * as VIRTIO_NET_HDR_F_DATA_VALID still have correct csum after they 1698 * are processed. 1699 */ 1700 skb->ip_summed = CHECKSUM_UNNECESSARY; 1701 } 1702 1703 return 0; 1704 } 1705
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 36cae78f6311..07b4801d689c 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1663,6 +1663,44 @@ static int virtnet_flow_dissect_udp_tcp(struct virtnet_info *vi, struct sk_buff return 0; } +static int virtnet_set_csum_after_xdp(struct virtnet_info *vi, + struct sk_buff *skb, + __u8 flags) +{ + int err; + + /* When XDP program is loaded, for example, the vm-vm scenario + * on the same host, packets marked as VIRTIO_NET_HDR_F_NEEDS_CSUM + * will travel. Although these packets are safe from the point of + * view of the vm, to avoid modification by XDP and successful + * forwarding in the upper layer, we re-probe the necessary checksum + * related information: skb->csum_{start, offset}, pseudo-header csum. + * + * This benefits us: + * 1. XDP can be loaded when there's _F_GUEST_CSUM. + * 2. The device verifies the checksum of packets , especially + * benefiting for large packets. + * 3. In the same-host vm-vm scenario, packets marked as + * VIRTIO_NET_HDR_F_NEEDS_CSUM are no longer dropped after being + * processed by XDP. + */ + if (flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { + err = virtnet_flow_dissect_udp_tcp(vi, skb); + if (err < 0) + return -EINVAL; + + skb->ip_summed = CHECKSUM_PARTIAL; + } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) { + /* We want to benefit from this: XDP guarantees that packets marked + * as VIRTIO_NET_HDR_F_DATA_VALID still have correct csum after they + * are processed. + */ + skb->ip_summed = CHECKSUM_UNNECESSARY; + } + + return 0; +} + static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, void *buf, unsigned int len, void **ctx, unsigned int *xdp_xmit,