Skip to content

Commit 50bfcae

Browse files
LPhghPaolo Abeni
authored andcommitted
virtio_net: Update rss when set queue
RSS configuration should be updated with queue number. In particular, it should be updated when (1) rss enabled and (2) default rss configuration is used without user modification. During rss command processing, device updates queue_pairs using rss.max_tx_vq. That is, the device updates queue_pairs together with rss, so we can skip the sperate queue_pairs update (VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET below) and return directly. Also remove the `vi->has_rss ?` check when setting vi->rss.max_tx_vq, because this is not used in the other hash_report case. Fixes: c7114b1 ("drivers/net/virtio_net: Added basic RSS support.") Signed-off-by: Philo Lu <[email protected]> Signed-off-by: Xuan Zhuo <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent dc749b7 commit 50bfcae

File tree

1 file changed

+51
-14
lines changed

1 file changed

+51
-14
lines changed

drivers/net/virtio_net.c

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,15 +3394,59 @@ static void virtnet_ack_link_announce(struct virtnet_info *vi)
33943394
dev_warn(&vi->dev->dev, "Failed to ack link announce.\n");
33953395
}
33963396

3397+
static bool virtnet_commit_rss_command(struct virtnet_info *vi);
3398+
3399+
static void virtnet_rss_update_by_qpairs(struct virtnet_info *vi, u16 queue_pairs)
3400+
{
3401+
u32 indir_val = 0;
3402+
int i = 0;
3403+
3404+
for (; i < vi->rss_indir_table_size; ++i) {
3405+
indir_val = ethtool_rxfh_indir_default(i, queue_pairs);
3406+
vi->rss.indirection_table[i] = indir_val;
3407+
}
3408+
vi->rss.max_tx_vq = queue_pairs;
3409+
}
3410+
33973411
static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
33983412
{
33993413
struct virtio_net_ctrl_mq *mq __free(kfree) = NULL;
3400-
struct scatterlist sg;
3414+
struct virtio_net_ctrl_rss old_rss;
34013415
struct net_device *dev = vi->dev;
3416+
struct scatterlist sg;
34023417

34033418
if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ))
34043419
return 0;
34053420

3421+
/* Firstly check if we need update rss. Do updating if both (1) rss enabled and
3422+
* (2) no user configuration.
3423+
*
3424+
* During rss command processing, device updates queue_pairs using rss.max_tx_vq. That is,
3425+
* the device updates queue_pairs together with rss, so we can skip the sperate queue_pairs
3426+
* update (VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET below) and return directly.
3427+
*/
3428+
if (vi->has_rss && !netif_is_rxfh_configured(dev)) {
3429+
memcpy(&old_rss, &vi->rss, sizeof(old_rss));
3430+
if (rss_indirection_table_alloc(&vi->rss, vi->rss_indir_table_size)) {
3431+
vi->rss.indirection_table = old_rss.indirection_table;
3432+
return -ENOMEM;
3433+
}
3434+
3435+
virtnet_rss_update_by_qpairs(vi, queue_pairs);
3436+
3437+
if (!virtnet_commit_rss_command(vi)) {
3438+
/* restore ctrl_rss if commit_rss_command failed */
3439+
rss_indirection_table_free(&vi->rss);
3440+
memcpy(&vi->rss, &old_rss, sizeof(old_rss));
3441+
3442+
dev_warn(&dev->dev, "Fail to set num of queue pairs to %d, because committing RSS failed\n",
3443+
queue_pairs);
3444+
return -EINVAL;
3445+
}
3446+
rss_indirection_table_free(&old_rss);
3447+
goto succ;
3448+
}
3449+
34063450
mq = kzalloc(sizeof(*mq), GFP_KERNEL);
34073451
if (!mq)
34083452
return -ENOMEM;
@@ -3415,12 +3459,12 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
34153459
dev_warn(&dev->dev, "Fail to set num of queue pairs to %d\n",
34163460
queue_pairs);
34173461
return -EINVAL;
3418-
} else {
3419-
vi->curr_queue_pairs = queue_pairs;
3420-
/* virtnet_open() will refill when device is going to up. */
3421-
if (dev->flags & IFF_UP)
3422-
schedule_delayed_work(&vi->refill, 0);
34233462
}
3463+
succ:
3464+
vi->curr_queue_pairs = queue_pairs;
3465+
/* virtnet_open() will refill when device is going to up. */
3466+
if (dev->flags & IFF_UP)
3467+
schedule_delayed_work(&vi->refill, 0);
34243468

34253469
return 0;
34263470
}
@@ -3880,21 +3924,14 @@ static bool virtnet_commit_rss_command(struct virtnet_info *vi)
38803924

38813925
static void virtnet_init_default_rss(struct virtnet_info *vi)
38823926
{
3883-
u32 indir_val = 0;
3884-
int i = 0;
3885-
38863927
vi->rss.hash_types = vi->rss_hash_types_supported;
38873928
vi->rss_hash_types_saved = vi->rss_hash_types_supported;
38883929
vi->rss.indirection_table_mask = vi->rss_indir_table_size
38893930
? vi->rss_indir_table_size - 1 : 0;
38903931
vi->rss.unclassified_queue = 0;
38913932

3892-
for (; i < vi->rss_indir_table_size; ++i) {
3893-
indir_val = ethtool_rxfh_indir_default(i, vi->curr_queue_pairs);
3894-
vi->rss.indirection_table[i] = indir_val;
3895-
}
3933+
virtnet_rss_update_by_qpairs(vi, vi->curr_queue_pairs);
38963934

3897-
vi->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0;
38983935
vi->rss.hash_key_length = vi->rss_key_size;
38993936

39003937
netdev_rss_key_fill(vi->rss.key, vi->rss_key_size);

0 commit comments

Comments
 (0)