From: Simon Horman <horms@kernel.org>
To: Shradha Gupta <shradhagupta@linux.microsoft.com>
Cc: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, "Nipun Gupta" <nipun.gupta@amd.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Jonathan Cameron" <Jonathan.Cameron@huwei.com>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Shivamurthy Shastri" <shivamurthy.shastri@linutronix.de>,
"Kevin Tian" <kevin.tian@intel.com>,
"Long Li" <longli@microsoft.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Rob Herring" <robh@kernel.org>,
"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Dexuan Cui" <decui@microsoft.com>,
"Wei Liu" <wei.liu@kernel.org>,
"Haiyang Zhang" <haiyangz@microsoft.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Konstantin Taranov" <kotaranov@microsoft.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Maxim Levitsky" <mlevitsk@redhat.com>,
"Erni Sri Satya Vennela" <ernis@linux.microsoft.com>,
"Peter Zijlstra" <peterz@infradead.org>,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
"Paul Rosswurm" <paulros@microsoft.com>,
"Shradha Gupta" <shradhagupta@microsoft.com>
Subject: Re: [PATCH 2/2] net: mana: Allow MANA driver to allocate PCI vector dynamically
Date: Thu, 24 Apr 2025 17:57:43 +0100 [thread overview]
Message-ID: <20250424165743.GJ3042781@horms.kernel.org> (raw)
In-Reply-To: <1744817781-3243-1-git-send-email-shradhagupta@linux.microsoft.com>
On Wed, Apr 16, 2025 at 08:36:21AM -0700, Shradha Gupta wrote:
> Currently, the MANA driver allocates pci vector statically based on
> MANA_MAX_NUM_QUEUES and num_online_cpus() values and in some cases ends
> up allocating more vectors than it needs.
> This is because, by this time we do not have a HW channel and do not know
> how many IRQs should be allocated.
> To avoid this, we allocate 1 IRQ vector during the creation of HWC and
> after getting the value supported by hardware, dynamically add the
> remaining vectors.
>
> Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
Hi Shradha,
Some minor nits from my side.
...
> diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
...
> @@ -465,9 +475,10 @@ static int mana_gd_register_irq(struct gdma_queue *queue,
> struct gdma_irq_context *gic;
> struct gdma_context *gc;
> unsigned int msi_index;
> - unsigned long flags;
> + struct list_head *pos;
> + unsigned long flags, flag_irq;
> struct device *dev;
> - int err = 0;
> + int err = 0, count;
As this is Networking code, please preserve the arrangement of local
variables in reverse xmas tree order - longest line to shortest.
Edward Cree's tool can be useful in this area:
https://github.com/ecree-solarflare/xmastree
>
> gc = gd->gdma_context;
> dev = gc->dev;
> @@ -482,7 +493,22 @@ static int mana_gd_register_irq(struct gdma_queue *queue,
> }
>
> queue->eq.msix_index = msi_index;
> - gic = &gc->irq_contexts[msi_index];
> +
> + /* get the msi_index value from the list*/
> + count = 0;
> + spin_lock_irqsave(&gc->irq_ctxs_lock, flag_irq);
> + list_for_each(pos, &gc->irq_contexts) {
> + if (count == msi_index) {
> + gic = list_entry(pos, struct gdma_irq_context, gic_list);
Please consider line wrapping to 80 columns or less, as is still preferred
in Networking code.
Likewise elsewhere in this patch.
checkpatch.pl --max-line-length=80
can be helpful here.
> + break;
> + }
> +
> + count++;
> + }
> + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flag_irq);
> +
> + if (!gic)
> + return -1;
>
> spin_lock_irqsave(&gic->lock, flags);
> list_add_rcu(&queue->entry, &gic->eq_list);
> @@ -497,8 +523,10 @@ static void mana_gd_deregiser_irq(struct gdma_queue *queue)
> struct gdma_irq_context *gic;
> struct gdma_context *gc;
> unsigned int msix_index;
> - unsigned long flags;
> + struct list_head *pos;
> + unsigned long flags, flag_irq;
> struct gdma_queue *eq;
> + int count;
Reverse xmas tree here too.
>
> gc = gd->gdma_context;
>
> @@ -507,7 +535,22 @@ static void mana_gd_deregiser_irq(struct gdma_queue *queue)
> if (WARN_ON(msix_index >= gc->num_msix_usable))
> return;
>
> - gic = &gc->irq_contexts[msix_index];
> + /* get the msi_index value from the list*/
> + count = 0;
> + spin_lock_irqsave(&gc->irq_ctxs_lock, flag_irq);
> + list_for_each(pos, &gc->irq_contexts) {
> + if (count == msix_index) {
> + gic = list_entry(pos, struct gdma_irq_context, gic_list);
> + break;
> + }
> +
> + count++;
> + }
> + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flag_irq);
> +
Does gic need to be initialised to NULL before the list_for_each loop
to ensure that it is always initialised here?
Flagged by Clang 20.1.2 KCFLAGS=-Wsometimes-uninitialized builds, and Smatch
> + if (!gic)
> + return;
> +
> spin_lock_irqsave(&gic->lock, flags);
> list_for_each_entry_rcu(eq, &gic->eq_list, entry) {
> if (queue == eq) {
...
> @@ -1317,29 +1372,92 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node)
> return 0;
> }
>
> -static int mana_gd_setup_irqs(struct pci_dev *pdev)
> +static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)
> {
> struct gdma_context *gc = pci_get_drvdata(pdev);
> - unsigned int max_queues_per_port;
> struct gdma_irq_context *gic;
> - unsigned int max_irqs, cpu;
> - int start_irq_index = 1;
> - int nvec, *irqs, irq;
> + int *irqs, irq, skip_first_cpu = 0;
> + unsigned long flags;
> int err, i = 0, j;
Reverse xmas tree here too.
>
> cpus_read_lock();
> - max_queues_per_port = num_online_cpus();
> - if (max_queues_per_port > MANA_MAX_NUM_QUEUES)
> - max_queues_per_port = MANA_MAX_NUM_QUEUES;
> + spin_lock_irqsave(&gc->irq_ctxs_lock, flags);
> + irqs = kmalloc_array(nvec, sizeof(int), GFP_KERNEL);
> + if (!irqs) {
> + err = -ENOMEM;
> + goto free_irq_vector;
> + }
...
next prev parent reply other threads:[~2025-04-24 16:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 15:35 [PATCH 0/2] Allow dyn pci vector allocation of MANA Shradha Gupta
2025-04-16 15:36 ` [PATCH 1/2] PCI: hv: enable pci_hyperv to allow dynamic vector allocation Shradha Gupta
2025-04-16 18:30 ` Bjorn Helgaas
2025-04-17 7:29 ` Shradha Gupta
2025-04-17 10:00 ` Thomas Gleixner
2025-04-21 6:33 ` Shradha Gupta
2025-04-16 15:36 ` [PATCH 2/2] net: mana: Allow MANA driver to allocate PCI vector dynamically Shradha Gupta
2025-04-16 17:22 ` Yury Norov
2025-04-17 7:32 ` Shradha Gupta
2025-04-22 12:09 ` Shradha Gupta
2025-04-16 18:32 ` Bjorn Helgaas
2025-04-17 7:33 ` Shradha Gupta
2025-04-24 16:57 ` Simon Horman [this message]
2025-04-25 7:29 ` Shradha Gupta
2025-05-07 16:28 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250424165743.GJ3042781@horms.kernel.org \
--to=horms@kernel.org \
--cc=Jonathan.Cameron@huwei.com \
--cc=andrew+netdev@lunn.ch \
--cc=anna-maria@linutronix.de \
--cc=bhelgaas@google.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=ernis@linux.microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kotaranov@microsoft.com \
--cc=kuba@kernel.org \
--cc=kw@linux.com \
--cc=kys@microsoft.com \
--cc=leon@kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mlevitsk@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=nipun.gupta@amd.com \
--cc=pabeni@redhat.com \
--cc=paulros@microsoft.com \
--cc=peterz@infradead.org \
--cc=robh@kernel.org \
--cc=shivamurthy.shastri@linutronix.de \
--cc=shradhagupta@linux.microsoft.com \
--cc=shradhagupta@microsoft.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).