Message ID | 20220117080009.3055012-4-andrew@daynix.com (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | RSS support for VirtioNet. | expand |
在 2022/1/17 下午4:00, Andrew Melnychenko 写道: > 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@daynix.com> > --- > drivers/net/virtio_net.c | 58 ++++++++++++++++++++++++++++++++-------- > 1 file changed, 47 insertions(+), 11 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 9aae11cb568e..2c61f96ce3e6 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; > @@ -420,7 +421,9 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, > hdr_p = p; > > hdr_len = vi->hdr_len; > - if (vi->mergeable_rx_bufs) > + if (vi->has_rss_hash_report) > + hdr_padded_len = sizeof(struct virtio_net_hdr_v1_hash); This seems wrong, add_recvbuf_big() will always try to use sizeof(struct padded_vnet_hdr). This can be tested by disabling mrg_rxbuf. > + else if (vi->mergeable_rx_bufs) > hdr_padded_len = sizeof(*hdr); > else > hdr_padded_len = sizeof(struct padded_vnet_hdr); > @@ -1156,6 +1159,8 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, > struct net_device *dev = vi->dev; > struct sk_buff *skb; > struct virtio_net_hdr_mrg_rxbuf *hdr; > + struct virtio_net_hdr_v1_hash *hdr_hash; > + enum pkt_hash_types rss_hash_type; > > if (unlikely(len < vi->hdr_len + ETH_HLEN)) { > pr_debug("%s: short packet %i\n", dev->name, len); > @@ -1182,6 +1187,29 @@ 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) { > + hdr_hash = (struct virtio_net_hdr_v1_hash *)(hdr); > + > + 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); > + } > > if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) > skb->ip_summed = CHECKSUM_UNNECESSARY; > @@ -2232,7 +2260,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; > } > @@ -3230,6 +3259,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; > } > @@ -3365,16 +3396,18 @@ 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)); > + rss_max_indirection_table_length)); Unnecessary changes. > vi->rss_key_size = > virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size)); > - } > - > - if (vi->has_rss) { This can be squashed into previous patch. Thanks > vi->rss_hash_types_supported = > virtio_cread32(vdev, offsetof(struct virtio_net_config, supported_hash_types)); > vi->rss_hash_types_supported &= > @@ -3384,8 +3417,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); > @@ -3452,7 +3488,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); > @@ -3587,7 +3623,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,
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9aae11cb568e..2c61f96ce3e6 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; @@ -420,7 +421,9 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, hdr_p = p; hdr_len = vi->hdr_len; - if (vi->mergeable_rx_bufs) + if (vi->has_rss_hash_report) + hdr_padded_len = sizeof(struct virtio_net_hdr_v1_hash); + else if (vi->mergeable_rx_bufs) hdr_padded_len = sizeof(*hdr); else hdr_padded_len = sizeof(struct padded_vnet_hdr); @@ -1156,6 +1159,8 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, struct net_device *dev = vi->dev; struct sk_buff *skb; struct virtio_net_hdr_mrg_rxbuf *hdr; + struct virtio_net_hdr_v1_hash *hdr_hash; + enum pkt_hash_types rss_hash_type; if (unlikely(len < vi->hdr_len + ETH_HLEN)) { pr_debug("%s: short packet %i\n", dev->name, len); @@ -1182,6 +1187,29 @@ 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) { + hdr_hash = (struct virtio_net_hdr_v1_hash *)(hdr); + + 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); + } if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) skb->ip_summed = CHECKSUM_UNNECESSARY; @@ -2232,7 +2260,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; } @@ -3230,6 +3259,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; } @@ -3365,16 +3396,18 @@ 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)); + rss_max_indirection_table_length)); vi->rss_key_size = virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size)); - } - - if (vi->has_rss) { vi->rss_hash_types_supported = virtio_cread32(vdev, offsetof(struct virtio_net_config, supported_hash_types)); vi->rss_hash_types_supported &= @@ -3384,8 +3417,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); @@ -3452,7 +3488,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); @@ -3587,7 +3623,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,
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@daynix.com> --- drivers/net/virtio_net.c | 58 ++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 11 deletions(-)