From: Eugene Lee User XPS settings are lost when the GVE driver performs a soft reset because the driver overrides the user XPS settings with the default mappings. Remove default XPS configuration when the driver performs a soft reset and configure default XPS mappings only during driver initialization and when the TX queue count is adjusted. Store the CPU affinity mask assigned to each notify block in gve_setup_notify_blocks() and reuse it when configuring XPS rather than duplicating the CPU affinity calculation logic. This issue was hit on GCE VMs when modifying queue counts or ring parameters with custom XPS mappings, and the fix was tested on GCE gVNIC VMs using both GQI and DQO queue formats. Fixes: 4edf8249bcd1 ("gve: Add netif_set_xps_queue call") Cc: stable@vger.kernel.org Reviewed-by: Jordan Rhee Signed-off-by: Eugene Lee Signed-off-by: Joshua Washington --- drivers/net/ethernet/google/gve/gve.h | 1 + drivers/net/ethernet/google/gve/gve_main.c | 42 +++++++++++++++++++-- drivers/net/ethernet/google/gve/gve_utils.c | 4 -- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 143d8cd595aa..6180434d5776 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -673,6 +673,7 @@ struct gve_notify_block { struct gve_priv *priv; struct gve_tx_ring *tx; /* tx rings on this block */ struct gve_rx_ring *rx; /* rx rings on this block */ + const struct cpumask *affinity_mask; u32 irq; bool irq_requested; }; diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 35cf0f06a0f2..074ccbbf449c 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -624,8 +624,8 @@ static int gve_setup_notify_blocks(struct gve_priv *priv) } block->irq = priv->msix_vectors[msix_idx].vector; block->irq_requested = true; - irq_set_affinity_and_hint(block->irq, - cpumask_of(cur_cpu)); + block->affinity_mask = cpumask_of(cur_cpu); + irq_set_affinity_and_hint(block->irq, block->affinity_mask); cur_cpu = cpumask_next(cur_cpu, node_mask); /* Wrap once CPUs in the node have been exhausted, or when @@ -1935,6 +1935,27 @@ int gve_adjust_config(struct gve_priv *priv, return 0; } +static void gve_set_xps_mapping(struct gve_priv *priv, int old_num_tx, + int new_num_tx) +{ + struct gve_notify_block *block; + int ntfy_idx; + int i; + + /* Clear XPS mappings for removed queues in case the queue count was + * reduced while the interface is down. + */ + for (i = new_num_tx; i < old_num_tx; i++) + netif_set_xps_queue(priv->dev, cpu_none_mask, i); + + for (i = old_num_tx; i < new_num_tx; i++) { + ntfy_idx = gve_tx_idx_to_ntfy(priv, i); + block = &priv->ntfy_blocks[ntfy_idx]; + + netif_set_xps_queue(priv->dev, block->affinity_mask, i); + } +} + int gve_adjust_queues(struct gve_priv *priv, struct gve_rx_queue_config new_rx_config, struct gve_tx_queue_config new_tx_config, @@ -1942,6 +1963,7 @@ int gve_adjust_queues(struct gve_priv *priv, { struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0}; struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0}; + u16 old_num_tx = priv->tx_cfg.num_queues; int err; gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg); @@ -1954,7 +1976,10 @@ int gve_adjust_queues(struct gve_priv *priv, if (netif_running(priv->dev)) { err = gve_adjust_config(priv, &tx_alloc_cfg, &rx_alloc_cfg); - return err; + if (err) + return err; + + goto config_xps; } /* Set the config for the next up. */ if (reset_rss) { @@ -1965,6 +1990,11 @@ int gve_adjust_queues(struct gve_priv *priv, priv->tx_cfg = new_tx_config; priv->rx_cfg = new_rx_config; +config_xps: + /* Update default XPS mappings for added or removed TX queues + * while preserving custom XPS mappings of existing TX queues. + */ + gve_set_xps_mapping(priv, old_num_tx, priv->tx_cfg.num_queues); return 0; } @@ -3085,9 +3115,10 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (!gve_is_gqi(priv) && !gve_is_qpl(priv)) dev->netmem_tx = NETMEM_TX_DMA; + gve_set_xps_mapping(priv, 0, priv->tx_cfg.num_queues); err = register_netdev(dev); if (err) - goto abort_teardown_device; + goto abort_clear_xps; dev_info(&pdev->dev, "GVE version %s\n", gve_version_str); dev_info(&pdev->dev, "GVE queue format %d\n", (int)priv->queue_format); @@ -3095,6 +3126,9 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) queue_work(priv->gve_wq, &priv->service_task); return 0; +abort_clear_xps: + gve_set_xps_mapping(priv, priv->tx_cfg.num_queues, 0); + abort_teardown_device: disable_work_sync(&priv->service_task); gve_teardown_device(priv); diff --git a/drivers/net/ethernet/google/gve/gve_utils.c b/drivers/net/ethernet/google/gve/gve_utils.c index 930555ac8fe9..2750c8c18fbe 100644 --- a/drivers/net/ethernet/google/gve/gve_utils.c +++ b/drivers/net/ethernet/google/gve/gve_utils.c @@ -26,16 +26,12 @@ void gve_tx_remove_from_block(struct gve_priv *priv, int queue_idx) void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx) { - unsigned int active_cpus = min_t(int, priv->num_ntfy_blks / 2, - num_online_cpus()); int ntfy_idx = gve_tx_idx_to_ntfy(priv, queue_idx); struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx]; struct gve_tx_ring *tx = &priv->tx[queue_idx]; block->tx = tx; tx->ntfy_id = ntfy_idx; - netif_set_xps_queue(priv->dev, get_cpu_mask(ntfy_idx % active_cpus), - queue_idx); } bool gve_rx_was_added_to_block(struct gve_priv *priv, int queue_idx) base-commit: c1c39137dcc3134010566ff29a81c93124efa539 -- 2.56.1.915.g69d5ec7298-goog