From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 641933E7BBC for ; Mon, 1 Jun 2026 17:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780336491; cv=none; b=bMdsi54aJRJAV+sPX1NX8meO7Yjrp2MfbgYF5PYMTmdk42M17dEzxAtU41VT8Ct8C9TlU6FoWgvwQJJnZ9CSEsMV71NNkpPTI8n2pfRQJRdUcPTANZ5V9ljR+yTKu4q755zQxNk8KMlTznVpG+pgUVe++LCe41GBeCzXTHcGx4o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780336491; c=relaxed/simple; bh=iAUa34wr2sG4wWkLRYAz6J5talu+FiBo/4nXrRuuwn8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OxXHHaQGwXKZFsY2U0sAeIt27MSJ9eGnMHwTjp4nkKHm+Xb769Tbo8mkXYkA4SNlA1MQTrqez9ImbM4cJYMUOB4dwK3ip4H6B2CQ0OR8jfCHXVywDNb2TTqIIIurvJAYvQjRt21TvmrO5QiHQ6pka5CS6PEogHoI8DPgvnfFbo8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G0pIXXYG; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G0pIXXYG" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-84240b58211so1270055b3a.1 for ; Mon, 01 Jun 2026 10:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780336489; x=1780941289; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0ywzuwl+0ezSOXY+MtyKwZEpX1/Y/0FxoeN6/NGkMFU=; b=G0pIXXYGh9NRR6EzHqXildvC/cI5mWDvsyO0AUCCt627aswXJjcX820KDTR5wpZ4iA vhHxQ+EI7i8TSi2NxtG8HLN/S159U1NtDnoyzdYfSwHrZbDYMUXeBFk4MwQMELTW8dca Yl8oW8s9pGzfss+z56mX0h2624NH5NfvedJ1qIU4pvTcEIhyutLIk2UgDPdXXUfXun5+ /rcA8aHZW96rNGmT2W1VMtjuRvJ6ALFTJNIKdLabblw1XoSffQi4Zp0SKCvfd46rTvgo JMW46xHQvXW5OSUFg2u5L43eMgIQ6pd5kzbzXWnWpDAW8Ld0/BfGtRfdrSv3TenVIkBL V+BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780336489; x=1780941289; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0ywzuwl+0ezSOXY+MtyKwZEpX1/Y/0FxoeN6/NGkMFU=; b=SivgYXd/hsyoB8TsPzlfW83gplutc9rGwhCWu5/LIuJkBCngAjACPfHK4lw48uBcLm 7fv+O5C7yjIw/1uZGKhWUiM0Uc80uZUinqqOVUI3f8mZdP4aCEwJbP4OofoGiqmnjHWa uV24AL8wf3nYmexx4yVxMNxQiA+NttcWWEH4WN3kaaUeHHmtr7DoTQaLDBwSuJkE4xAt 1rNq05RcO9a9LMURH8U8BSZsxAOnurCWIKWex0N0pTBvdDn84vZw4TrYaHYP1D6/utXJ 34oYbbtqmaAjuQccv3RchdGsW0PXGKos9zp5nmoiEIG4SuITvlXUZLklVwZ/qVBHAdz7 fKlQ== X-Gm-Message-State: AOJu0YzBOLRDspLjB86dDUkKi1u4lFjcdru4E5WnmQH0BbkJbmTU3X80 nuarP7vIwRpPrPWljNMYONMLSYjRgo1c7+eq9xLB9LAvHvzhoASfB3EqawV5TRhGE0AG+1IesdO uLV4u5fU32Hh1qUDGi9wvSe7gXjna8+IBvvIbIoFjBc8zMbnsZPsoAsuZqtuRd5XXzHd9YxGUe9 MqmK2zUSlcIQQGHDp/kZcxpdwBTVWqyqCBUJJUiFayjXztiF6g2GrtFU17huF7rd8= X-Received: from pfbbr13.prod.google.com ([2002:a05:6a00:440d:b0:842:4a9c:2fd3]) (user=hramamurthy job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a223:b0:842:5931:7b8c with SMTP id d2e1a72fcca58-8425931803amr4122620b3a.1.1780336488382; Mon, 01 Jun 2026 10:54:48 -0700 (PDT) Date: Mon, 1 Jun 2026 17:54:33 +0000 In-Reply-To: <20260601175437.3767283-1-hramamurthy@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260601175437.3767283-1-hramamurthy@google.com> X-Mailer: git-send-email 2.54.0.1013.g208068f2d8-goog Message-ID: <20260601175437.3767283-12-hramamurthy@google.com> Subject: [PATCH net-next 11/15] gve: split up notify block allocation and setup paths From: Harshitha Ramamurthy To: netdev@vger.kernel.org Cc: joshwash@google.com, hramamurthy@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, willemb@google.com, jordanrhee@google.com, jfraker@google.com, nktgrg@google.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" From: Joshua Washington Before this patch, notify block allocation and setup occurred in the same method. This all occurred before gve_adminq_configure_device_resources, which populates the irq_db_indicies array, a DMA region with BAR offsets for MSI-X vectors. The coming mailbox mode will require notify blocks to be set up only after receiving the IRQ doorbell offsets, as the request does not work with a supplied DMA buffer in the way that admin queue mode does. The intended flow in that case would be: 1) allocate notify blocks 2) request doorbell information 3) set up MSI-X vectors based on doorbell info This ordering also works for admin queue mode, so it will be updated to match. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy --- drivers/net/ethernet/google/gve/gve.h | 2 + drivers/net/ethernet/google/gve/gve_main.c | 158 ++++++++++++--------- 2 files changed, 89 insertions(+), 71 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index f8976017ca60..12591a1fd746 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_tx_ring *tx; /* tx rings on this block */ struct gve_rx_ring *rx; /* rx rings on this block */ u32 irq; + bool irq_requested; }; /* Tracks allowed and current rx queue settings */ @@ -964,6 +965,7 @@ struct gve_priv { u64 link_speed; bool up_before_suspend; /* True if dev was up before suspend */ + bool mgmt_irq_requested; struct gve_ptype_lut *ptype_lut_dqo; /* Must be a power of two. */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 06df6d8ad429..98970508ae54 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -425,6 +425,24 @@ int gve_napi_poll_dqo(struct napi_struct *napi, int budget) return work_done; } +static void gve_free_notify_blocks(struct gve_priv *priv) +{ + pci_disable_msix(priv->pdev); + if (priv->irq_db_indices) { + dma_free_coherent(&priv->pdev->dev, + priv->num_ntfy_blks * + sizeof(*priv->irq_db_indices), + priv->irq_db_indices, + priv->irq_db_indices_bus); + priv->irq_db_indices = NULL; + } + + kvfree(priv->ntfy_blocks); + priv->ntfy_blocks = NULL; + kvfree(priv->msix_vectors); + priv->msix_vectors = NULL; +} + static const struct cpumask *gve_get_node_mask(struct gve_priv *priv) { if (priv->numa_node == NUMA_NO_NODE) @@ -436,11 +454,9 @@ static const struct cpumask *gve_get_node_mask(struct gve_priv *priv) static int gve_alloc_notify_blocks(struct gve_priv *priv) { int num_vecs_requested = priv->num_ntfy_blks + 1; - const struct cpumask *node_mask; - unsigned int cur_cpu; int vecs_enabled; - int i, j; int err; + int i; priv->msix_vectors = kvzalloc_objs(*priv->msix_vectors, num_vecs_requested); @@ -454,7 +470,7 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) dev_err(&priv->pdev->dev, "Could not enable min msix %d/%d\n", GVE_MIN_MSIX, vecs_enabled); err = vecs_enabled; - goto abort_with_msix_vectors; + goto abort; } if (vecs_enabled != num_vecs_requested) { int new_num_ntfy_blks = (vecs_enabled - 1) & ~0x1; @@ -477,15 +493,6 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) priv->rx_cfg.num_queues = priv->rx_cfg.max_queues; } - /* Setup Management Vector - the last vector */ - snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), "gve-mgmnt@pci:%s", - pci_name(priv->pdev)); - err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, - gve_mgmnt_intr, 0, priv->mgmt_msix_name, priv); - if (err) { - dev_err(&priv->pdev->dev, "Did not receive management vector.\n"); - goto abort_with_msix_enabled; - } priv->irq_db_indices = dma_alloc_coherent(&priv->pdev->dev, priv->num_ntfy_blks * @@ -493,15 +500,65 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) &priv->irq_db_indices_bus, GFP_KERNEL); if (!priv->irq_db_indices) { err = -ENOMEM; - goto abort_with_mgmt_vector; + goto abort; } priv->ntfy_blocks = kvzalloc(priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks), GFP_KERNEL); if (!priv->ntfy_blocks) { err = -ENOMEM; - goto abort_with_irq_db_indices; + goto abort; + } + return 0; + +abort: + gve_free_notify_blocks(priv); + return err; +} + +static void gve_teardown_notify_blocks(struct gve_priv *priv) +{ + int i; + + if (!priv->ntfy_blocks) + return; + + for (i = 0; i < priv->num_ntfy_blks; i++) { + struct gve_notify_block *block = &priv->ntfy_blocks[i]; + + if (!block->irq_requested) + continue; + + irq_set_affinity_hint(priv->msix_vectors[i].vector, + NULL); + free_irq(priv->msix_vectors[i].vector, block); + block->irq = 0; + block->irq_requested = false; + } + + if (priv->mgmt_irq_requested) { + free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); + priv->mgmt_irq_requested = false; + } +} + +static int gve_setup_notify_blocks(struct gve_priv *priv) +{ + const struct cpumask *node_mask; + unsigned int cur_cpu; + int i; + int err; + + /* Setup Management Vector - the last vector */ + snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), + "gve-mgmnt@pci:%s", pci_name(priv->pdev)); + err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, + gve_mgmnt_intr, 0, priv->mgmt_msix_name, priv); + if (err) { + dev_err(&priv->pdev->dev, "Did not receive management vector.\n"); + return err; } + priv->mgmt_irq_requested = true; /* Setup the other blocks - the first n-1 vectors */ node_mask = gve_get_node_mask(priv); @@ -519,9 +576,10 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) if (err) { dev_err(&priv->pdev->dev, "Failed to receive msix vector %d\n", i); - goto abort_with_some_ntfy_blocks; + goto abort; } block->irq = priv->msix_vectors[msix_idx].vector; + block->irq_requested = true; irq_set_affinity_and_hint(block->irq, cpumask_of(cur_cpu)); block->irq_db_index = &priv->irq_db_indices[i].index; @@ -535,61 +593,12 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) cur_cpu = cpumask_first(node_mask); } return 0; -abort_with_some_ntfy_blocks: - for (j = 0; j < i; j++) { - struct gve_notify_block *block = &priv->ntfy_blocks[j]; - int msix_idx = j; - irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, - NULL); - free_irq(priv->msix_vectors[msix_idx].vector, block); - block->irq = 0; - } - kvfree(priv->ntfy_blocks); - priv->ntfy_blocks = NULL; -abort_with_irq_db_indices: - dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * - sizeof(*priv->irq_db_indices), - priv->irq_db_indices, priv->irq_db_indices_bus); - priv->irq_db_indices = NULL; -abort_with_mgmt_vector: - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); -abort_with_msix_enabled: - pci_disable_msix(priv->pdev); -abort_with_msix_vectors: - kvfree(priv->msix_vectors); - priv->msix_vectors = NULL; +abort: + gve_teardown_notify_blocks(priv); return err; } -static void gve_free_notify_blocks(struct gve_priv *priv) -{ - int i; - - if (!priv->msix_vectors) - return; - - /* Free the irqs */ - for (i = 0; i < priv->num_ntfy_blks; i++) { - struct gve_notify_block *block = &priv->ntfy_blocks[i]; - int msix_idx = i; - - irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, - NULL); - free_irq(priv->msix_vectors[msix_idx].vector, block); - block->irq = 0; - } - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); - kvfree(priv->ntfy_blocks); - priv->ntfy_blocks = NULL; - dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * - sizeof(*priv->irq_db_indices), - priv->irq_db_indices, priv->irq_db_indices_bus); - priv->irq_db_indices = NULL; - pci_disable_msix(priv->pdev); - kvfree(priv->msix_vectors); - priv->msix_vectors = NULL; -} static void gve_free_control_plane_resources(struct gve_priv *priv) { @@ -743,6 +752,7 @@ static void gve_teardown_control_plane_resources(struct gve_priv *priv) static void gve_teardown_device(struct gve_priv *priv) { + gve_teardown_notify_blocks(priv); gve_teardown_control_plane_resources(priv); gve_adminq_free(priv); /* @@ -2463,13 +2473,16 @@ static int gve_setup_device(struct gve_priv *priv) err = gve_alloc_control_plane_resources(priv); if (err) - goto err; + return err; + err = gve_setup_control_plane_resources(priv); if (err) - goto err; + return err; + + err = gve_setup_notify_blocks(priv); + if (err) + return err; return 0; -err: - return err; } static const struct gve_ctrl_ops gve_adminq_ops = { @@ -2591,6 +2604,9 @@ int gve_reset(struct gve_priv *priv, bool skip_queue_setup) gve_unregister_qpls(priv); } + gve_teardown_notify_blocks(priv); + gve_teardown_control_plane_resources(priv); + /* Reset the device by releasing the AQ. Rings and other resources * within the NIC are implicitly destroyed if commands fail. */ -- 2.54.0.669.g59709faab0-goog