Andrew Melnychenko
2022-Feb-22 12:00 UTC
[PATCH v4 3/4] drivers/net/virtio_net: Added RSS hash report.
Added features for RSS hash report. If hash is provided - it sets to skb. Added checks if rss and/or hash are enabled together. Signed-off-by: Andrew Melnychenko <andrew at daynix.com> --- drivers/net/virtio_net.c | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index b5f2bb426a7b..8b317b3ef5aa 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -227,6 +227,7 @@ struct virtnet_info { /* Host supports rss and/or hash report */ bool has_rss; + bool has_rss_hash_report; u8 rss_key_size; u16 rss_indir_table_size; u32 rss_hash_types_supported; @@ -1148,6 +1149,35 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, return NULL; } +static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, + struct sk_buff *skb) +{ + enum pkt_hash_types rss_hash_type; + + if (!hdr_hash || !skb) + return; + + switch (hdr_hash->hash_report) { + case VIRTIO_NET_HASH_REPORT_TCPv4: + case VIRTIO_NET_HASH_REPORT_UDPv4: + case VIRTIO_NET_HASH_REPORT_TCPv6: + case VIRTIO_NET_HASH_REPORT_UDPv6: + case VIRTIO_NET_HASH_REPORT_TCPv6_EX: + case VIRTIO_NET_HASH_REPORT_UDPv6_EX: + rss_hash_type = PKT_HASH_TYPE_L4; + break; + case VIRTIO_NET_HASH_REPORT_IPv4: + case VIRTIO_NET_HASH_REPORT_IPv6: + case VIRTIO_NET_HASH_REPORT_IPv6_EX: + rss_hash_type = PKT_HASH_TYPE_L3; + break; + case VIRTIO_NET_HASH_REPORT_NONE: + default: + rss_hash_type = PKT_HASH_TYPE_NONE; + } + skb_set_hash(skb, hdr_hash->hash_value, rss_hash_type); +} + static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, void *buf, unsigned int len, void **ctx, unsigned int *xdp_xmit, @@ -1182,6 +1212,8 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, return; hdr = skb_vnet_hdr(skb); + if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report) + virtio_skb_set_hash((const struct virtio_net_hdr_v1_hash *)hdr, skb); if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) skb->ip_summed = CHECKSUM_UNNECESSARY; @@ -2232,7 +2264,8 @@ static bool virtnet_commit_rss_command(struct virtnet_info *vi) sg_set_buf(&sgs[3], vi->ctrl->rss.key, sg_buf_size); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, - VIRTIO_NET_CTRL_MQ_RSS_CONFIG, sgs)) { + vi->has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG + : VIRTIO_NET_CTRL_MQ_HASH_CONFIG, sgs)) { dev_warn(&dev->dev, "VIRTIONET issue with committing RSS sgs\n"); return false; } @@ -3231,6 +3264,8 @@ static bool virtnet_validate_features(struct virtio_device *vdev) VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR, "VIRTIO_NET_F_CTRL_VQ") || VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_RSS, + "VIRTIO_NET_F_CTRL_VQ") || + VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_HASH_REPORT, "VIRTIO_NET_F_CTRL_VQ"))) { return false; } @@ -3366,8 +3401,13 @@ static int virtnet_probe(struct virtio_device *vdev) if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) vi->mergeable_rx_bufs = true; - if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { + if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) + vi->has_rss_hash_report = true; + + if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) vi->has_rss = true; + + if (vi->has_rss || vi->has_rss_hash_report) { vi->rss_indir_table_size virtio_cread16(vdev, offsetof(struct virtio_net_config, rss_max_indirection_table_length)); @@ -3383,8 +3423,11 @@ static int virtnet_probe(struct virtio_device *vdev) dev->hw_features |= NETIF_F_RXHASH; } - if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF) || - virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) + + if (vi->has_rss_hash_report) + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); + else if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF) || + virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) vi->hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); else vi->hdr_len = sizeof(struct virtio_net_hdr); @@ -3451,7 +3494,7 @@ static int virtnet_probe(struct virtio_device *vdev) } } - if (vi->has_rss) + if (vi->has_rss || vi->has_rss_hash_report) virtnet_init_default_rss(vi); err = register_netdev(dev); @@ -3586,7 +3629,7 @@ static struct virtio_device_id id_table[] = { VIRTIO_NET_F_CTRL_MAC_ADDR, \ VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ - VIRTIO_NET_F_RSS + VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT static unsigned int features[] = { VIRTNET_FEATURES, -- 2.34.1
kernel test robot
2022-Feb-22 19:15 UTC
[PATCH v4 3/4] drivers/net/virtio_net: Added RSS hash report.
Hi Andrew, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on mst-vhost/linux-next] [also build test WARNING on net/master horms-ipvs/master net-next/master linus/master v5.17-rc5 next-20220217] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Andrew-Melnychenko/RSS-support-for-VirtioNet/20220222-200334 base: https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next config: i386-randconfig-s002-20220221 (https://download.01.org/0day-ci/archive/20220223/202202230342.HPYe6dHA-lkp at intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.4-dirty # https://github.com/0day-ci/linux/commit/4fda71c17afd24d8afb675baa0bb14dbbc6cd23c git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Andrew-Melnychenko/RSS-support-for-VirtioNet/20220222-200334 git checkout 4fda71c17afd24d8afb675baa0bb14dbbc6cd23c # save the config file to linux build tree mkdir build_dir make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp at intel.com> sparse warnings: (new ones prefixed by >>) drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer>> drivers/net/virtio_net.c:1178:35: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int [usertype] hash @@ got restricted __le32 const [usertype] hash_value @@drivers/net/virtio_net.c:1178:35: sparse: expected unsigned int [usertype] hash drivers/net/virtio_net.c:1178:35: sparse: got restricted __le32 const [usertype] hash_value vim +1178 drivers/net/virtio_net.c 1151 1152 static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, 1153 struct sk_buff *skb) 1154 { 1155 enum pkt_hash_types rss_hash_type; 1156 1157 if (!hdr_hash || !skb) 1158 return; 1159 1160 switch (hdr_hash->hash_report) { 1161 case VIRTIO_NET_HASH_REPORT_TCPv4: 1162 case VIRTIO_NET_HASH_REPORT_UDPv4: 1163 case VIRTIO_NET_HASH_REPORT_TCPv6: 1164 case VIRTIO_NET_HASH_REPORT_UDPv6: 1165 case VIRTIO_NET_HASH_REPORT_TCPv6_EX: 1166 case VIRTIO_NET_HASH_REPORT_UDPv6_EX: 1167 rss_hash_type = PKT_HASH_TYPE_L4; 1168 break; 1169 case VIRTIO_NET_HASH_REPORT_IPv4: 1170 case VIRTIO_NET_HASH_REPORT_IPv6: 1171 case VIRTIO_NET_HASH_REPORT_IPv6_EX: 1172 rss_hash_type = PKT_HASH_TYPE_L3; 1173 break; 1174 case VIRTIO_NET_HASH_REPORT_NONE: 1175 default: 1176 rss_hash_type = PKT_HASH_TYPE_NONE; 1177 }> 1178 skb_set_hash(skb, hdr_hash->hash_value, rss_hash_type);1179 } 1180 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org
Michael S. Tsirkin
2022-Mar-04 08:08 UTC
[PATCH v4 3/4] drivers/net/virtio_net: Added RSS hash report.
On Wed, Feb 23, 2022 at 03:15:28AM +0800, kernel test robot wrote:> Hi Andrew, > > Thank you for the patch! Perhaps something to improve: > > [auto build test WARNING on mst-vhost/linux-next] > [also build test WARNING on net/master horms-ipvs/master net-next/master linus/master v5.17-rc5 next-20220217] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch]Andrew, do you plan to fix this?> url: https://github.com/0day-ci/linux/commits/Andrew-Melnychenko/RSS-support-for-VirtioNet/20220222-200334 > base: https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next > config: i386-randconfig-s002-20220221 (https://download.01.org/0day-ci/archive/20220223/202202230342.HPYe6dHA-lkp at intel.com/config) > compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 > reproduce: > # apt-get install sparse > # sparse version: v0.6.4-dirty > # https://github.com/0day-ci/linux/commit/4fda71c17afd24d8afb675baa0bb14dbbc6cd23c > git remote add linux-review https://github.com/0day-ci/linux > git fetch --no-tags linux-review Andrew-Melnychenko/RSS-support-for-VirtioNet/20220222-200334 > git checkout 4fda71c17afd24d8afb675baa0bb14dbbc6cd23c > # save the config file to linux build tree > mkdir build_dir > make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot <lkp at intel.com> > > > sparse warnings: (new ones prefixed by >>) > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > drivers/net/virtio_net.c:1160:25: sparse: sparse: restricted __le16 degrades to integer > >> drivers/net/virtio_net.c:1178:35: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int [usertype] hash @@ got restricted __le32 const [usertype] hash_value @@ > drivers/net/virtio_net.c:1178:35: sparse: expected unsigned int [usertype] hash > drivers/net/virtio_net.c:1178:35: sparse: got restricted __le32 const [usertype] hash_value > > vim +1178 drivers/net/virtio_net.c > > 1151 > 1152 static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > 1153 struct sk_buff *skb) > 1154 { > 1155 enum pkt_hash_types rss_hash_type; > 1156 > 1157 if (!hdr_hash || !skb) > 1158 return; > 1159 > 1160 switch (hdr_hash->hash_report) { > 1161 case VIRTIO_NET_HASH_REPORT_TCPv4: > 1162 case VIRTIO_NET_HASH_REPORT_UDPv4: > 1163 case VIRTIO_NET_HASH_REPORT_TCPv6: > 1164 case VIRTIO_NET_HASH_REPORT_UDPv6: > 1165 case VIRTIO_NET_HASH_REPORT_TCPv6_EX: > 1166 case VIRTIO_NET_HASH_REPORT_UDPv6_EX: > 1167 rss_hash_type = PKT_HASH_TYPE_L4; > 1168 break; > 1169 case VIRTIO_NET_HASH_REPORT_IPv4: > 1170 case VIRTIO_NET_HASH_REPORT_IPv6: > 1171 case VIRTIO_NET_HASH_REPORT_IPv6_EX: > 1172 rss_hash_type = PKT_HASH_TYPE_L3; > 1173 break; > 1174 case VIRTIO_NET_HASH_REPORT_NONE: > 1175 default: > 1176 rss_hash_type = PKT_HASH_TYPE_NONE; > 1177 } > > 1178 skb_set_hash(skb, hdr_hash->hash_value, rss_hash_type); > 1179 } > 1180 > > --- > 0-DAY CI Kernel Test Service, Intel Corporation > https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org