RE: [PATCH] net: mana: add msix index sharing between EQs

From: Long Li
Date: Mon Dec 11 2023 - 21:51:59 EST


> @@ -502,12 +512,19 @@ 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];
> - gic->handler = NULL;
> - gic->arg = NULL;
> -
> spin_lock_irqsave(&r->lock, flags);
> - bitmap_clear(r->map, msix_index, 1);
> + gic = &gc->irq_contexts[msix_index];
> + list_for_each_entry_rcu(eq, &gic->eq_list, entry) {
> + if (queue == eq) {
> + list_del_rcu(&eq->entry);
> + synchronize_rcu();

The usage of RCU is questionable in an atomic context. This code needs to be tested with multiple EQs.

Long

> + break;
> + }
> + }
> + if (list_empty(&gic->eq_list)) {
> + gic->handler = NULL;
> + bitmap_clear(r->map, msix_index, 1);
> + }
> spin_unlock_irqrestore(&r->lock, flags);
>
> queue->eq.msix_index = INVALID_PCI_MSIX_INDEX; @@ -587,7 +604,8
> @@ static int mana_gd_create_eq(struct gdma_dev *gd,
> u32 log2_num_entries;
> int err;
>
> - queue->eq.msix_index = INVALID_PCI_MSIX_INDEX;
> + queue->eq.msix_index = spec->eq.msix_index;
> + queue->id = INVALID_QUEUE_ID;
>
> log2_num_entries = ilog2(queue->queue_size / GDMA_EQE_SIZE);
>
> @@ -819,6 +837,7 @@ free_q:
> kfree(queue);
> return err;
> }
> +EXPORT_SYMBOL_NS(mana_gd_create_mana_eq, NET_MANA);
>
> int mana_gd_create_mana_wq_cq(struct gdma_dev *gd,
> const struct gdma_queue_spec *spec, @@ -895,6
> +914,7 @@ void mana_gd_destroy_queue(struct gdma_context *gc, struct
> gdma_queue *queue)
> mana_gd_free_memory(gmi);
> kfree(queue);
> }
> +EXPORT_SYMBOL_NS(mana_gd_destroy_queue, NET_MANA);
>
> int mana_gd_verify_vf_version(struct pci_dev *pdev) { @@ -1217,9 +1237,14
> @@ int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int
> num_cqe) static irqreturn_t mana_gd_intr(int irq, void *arg) {
> struct gdma_irq_context *gic = arg;
> + struct list_head *eq_list = &gic->eq_list;
> + struct gdma_queue *eq;
>
> - if (gic->handler)
> - gic->handler(gic->arg);
> + if (gic->handler) {
> + list_for_each_entry_rcu(eq, eq_list, entry) {
> + gic->handler(eq);
> + }
> + }
>
> return IRQ_HANDLED;
> }
> @@ -1272,7 +1297,7 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev)
> for (i = 0; i < nvec; i++) {
> gic = &gc->irq_contexts[i];
> gic->handler = NULL;
> - gic->arg = NULL;
> + INIT_LIST_HEAD(&gic->eq_list);
>
> if (!i)
> snprintf(gic->name, MANA_IRQ_NAME_SZ,
> "mana_hwc@pci:%s", diff --git
> a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> index 9d1cd3b..0a5fc39 100644
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> @@ -300,6 +300,7 @@ static int mana_hwc_create_gdma_eq(struct
> hw_channel_context *hwc,
> spec.eq.context = ctx;
> spec.eq.callback = cb;
> spec.eq.log2_throttle_limit =
> DEFAULT_LOG2_THROTTLING_FOR_ERROR_EQ;
> + spec.eq.msix_index = INVALID_PCI_MSIX_INDEX;
>
> return mana_gd_create_hwc_queue(hwc->gdma_dev, &spec, queue); }
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c
> b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index fc3d290..8718c04 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
> @@ -1242,6 +1242,7 @@ static int mana_create_eq(struct mana_context *ac)
> spec.eq.callback = NULL;
> spec.eq.context = ac->eqs;
> spec.eq.log2_throttle_limit = LOG2_EQ_THROTTLE;
> + spec.eq.msix_index = INVALID_PCI_MSIX_INDEX;
>
> for (i = 0; i < gc->max_num_queues; i++) {
> err = mana_gd_create_mana_eq(gd, &spec, &ac->eqs[i].eq); diff
> --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index
> 88b6ef7..8d6569d 100644
> --- a/include/net/mana/gdma.h
> +++ b/include/net/mana/gdma.h
> @@ -293,6 +293,7 @@ struct gdma_queue {
>
> u32 head;
> u32 tail;
> + struct list_head entry;
>
> /* Extra fields specific to EQ/CQ. */
> union {
> @@ -328,6 +329,7 @@ struct gdma_queue_spec {
> void *context;
>
> unsigned long log2_throttle_limit;
> + unsigned int msix_index;
> } eq;
>
> struct {
> @@ -344,7 +346,7 @@ struct gdma_queue_spec {
>
> struct gdma_irq_context {
> void (*handler)(void *arg);
> - void *arg;
> + struct list_head eq_list;
> char name[MANA_IRQ_NAME_SZ];
> };
>
> --
> 2.43.0