RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Subsystems (5)
Wei Hu
maintainerPATCH v4 1/1 RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
The change calls some public APIs in mana ethernet driver to allocate EQs and other resources. Ehe EQ process routine is also shared by mana ethernet and mana ib drivers.
---
v2: Use ibdev_dbg to print error messages and return -ENOMEN
when kzalloc fails.
v3: Check return value on mana_ib_gd_destroy_dma_region(). Remove most
debug prints.
v4: Fix couple nits and performed thorough test in production evn.
drivers/infiniband/hw/mana/cq.c | 35 ++++- drivers/infiniband/hw/mana/main.c | 84 +++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 4 + drivers/infiniband/hw/mana/qp.c | 79 ++++++++++- .../net/ethernet/microsoft/mana/gdma_main.c | 131 ++++++++++-------- drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + include/net/mana/gdma.h | 9 +- 7 files changed, 278 insertions(+), 65 deletions(-)
drivers/infiniband/hw/mana/cq.c +33 -2
@@ -12,13 +12,20 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,struct ib_device *ibdev = ibcq->device;struct mana_ib_create_cq ucmd = {};struct mana_ib_dev *mdev; +struct gdma_context *gc; +struct gdma_dev *gd;int err; mdev = container_of(ibdev, struct mana_ib_dev, ib_dev); + gd = mdev->gdma_dev; + gc = gd->gdma_context;if (udata->inlen <sizeof (ucmd))return -EINVAL ; + cq->comp_vector = attr->comp_vector > gc->max_num_queues ? +0 : attr->comp_vector; + err =ib_copy_from_udata (&ucmd, udata,min (sizeof (ucmd), udata->inlen));if (err) { ibdev_dbg(ibdev,
@@ -69,11 +76,35 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);struct ib_device *ibdev = ibcq->device;struct mana_ib_dev *mdev; +struct gdma_context *gc; +struct gdma_dev *gd; +int err; + mdev = container_of(ibdev, struct mana_ib_dev, ib_dev); + gd = mdev->gdma_dev; + gc = gd->gdma_context; + -mana_ib_gd_destroy_dma_region (mdev, cq->gdma_region); -ib_umem_release (cq->umem); + +if (atomic_read (&ibcq->usecnt) ==0 ) { + err =mana_ib_gd_destroy_dma_region (mdev, cq->gdma_region); +if (err) { +ibdev_dbg (ibdev, +"Failed to destroy dma region, %d\n" , err); +return err; + } +kfree (gc->cq_table[cq->id]); + gc->cq_table[cq->id] =NULL ; +ib_umem_release (cq->umem); + }return 0 ; } + +void mana_ib_cq_handler (void *ctx,struct gdma_queue *gdma_cq) +{ +struct mana_ib_cq *cq = ctx; + + cq->ibcq.comp_handler (&cq->ibcq, cq->ibcq.cq_context); +}
drivers/infiniband/hw/mana/main.c +84 -0
103 lines not on this page · raw message
drivers/infiniband/hw/mana/mana_ib.h +4 -0
@@ -67,6 +67,7 @@ struct mana_ib_cq {int cqe;u64 gdma_region;u64 id; +u32 comp_vector; };struct mana_ib_qp {
@@ -86,6 +87,7 @@ struct mana_ib_qp {struct mana_ib_ucontext {struct ib_ucontext ibucontext;u32 doorbell; +struct mana_eq *eqs; };struct mana_ib_rwq_ind_table {
@@ -159,4 +161,6 @@ int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index,void mana_ib_disassociate_ucontext (struct ib_ucontext *ibcontext); +void mana_ib_cq_handler (void *ctx,struct gdma_queue *gdma_cq); +#endif
drivers/infiniband/hw/mana/qp.c +73 -6
162 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/gdma_main.c +76 -55
226 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
@@ -1156,6 +1156,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_allocated = false;for (i =0 ; i < gc->max_num_queues; i++) { err =mana_gd_create_mana_eq (gd, &spec, &ac->eqs[i].eq);
include/net/mana/gdma.h +7 -2
@@ -6,6 +6,7 @@#include <linux/dma-mapping.h> #include <linux/netdevice.h> +#include <linux/list.h> #include "shm_channel.h"
@@ -291,6 +292,8 @@ struct gdma_queue {u32 head;u32 tail; +struct list_head entry; +/* Extra fields specific to EQ/CQ. */ union { struct {
@@ -325,6 +328,8 @@ struct gdma_queue_spec {void *context;unsigned long log2_throttle_limit; +bool msix_allocated; +unsigned int msix_index; } eq;struct {
@@ -340,8 +345,8 @@ struct gdma_queue_spec {#define MANA_IRQ_NAME_SZ 32struct gdma_irq_context { -void (*handler)(void *arg); -void *arg; +void (*handler)(struct list_head *arg); +struct list_head eq_list;char name[MANA_IRQ_NAME_SZ ]; };
Signature · 1 line
2.25.1
Quoted 4 lines · Wei Hu
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
It seems strange that interrupts would be somehow linked to a ucontext? interrupts are highly limited, you can DOS the entire system if someone abuses this.
Generally I expect a properly functioning driver to use one interrupt per CPU core.
You should tie the CQ to a shared EQ belong to the core that the CQ wants to have affinity to.
Jason
Quoted 9 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 4 lines · Wei Hu
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
Quoted 5 lines
It seems strange that interrupts would be somehow linked to a ucontext? interrupts are highly limited, you can DOS the entire system if someone abuses this.
Generally I expect a properly functioning driver to use one interrupt per CPU core.
Yes, MANA uses one interrupt per CPU. One interrupt is shared among multiple EQs.
Quoted 3 lines
You should tie the CQ to a shared EQ belong to the core that the CQ wants to have affinity to.
The reason for using a separate EQ for a ucontext, is for preventing DOS. If we use a shared EQ, a single ucontext can storm this shared EQ affecting other users.
If one ucontext decides to abuse its own EQ, the hardware won't be able generate enough IRQs to storm the whole system.
Long
Quoted 9 lines · Long Li
Quoted 9 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 4 lines · Wei Hu
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
Quoted 8 lines
Quoted 5 lines
It seems strange that interrupts would be somehow linked to a ucontext? interrupts are highly limited, you can DOS the entire system if someone abuses this.
Generally I expect a properly functioning driver to use one interrupt per CPU core.
Yes, MANA uses one interrupt per CPU. One interrupt is shared among multiple EQs.
So you have another multiplexing layer between the interrupt and the EQ? That is alot of multiplexing layers..
Quoted 6 lines
Quoted 2 lines
You should tie the CQ to a shared EQ belong to the core that the CQ wants to have affinity to.
The reason for using a separate EQ for a ucontext, is for preventing DOS. If we use a shared EQ, a single ucontext can storm this shared EQ affecting other users.
With a proper design it should not be possible. The CQ adds an entry to the EQ and that should be rate limited by the ability of userspace to schedule to re-arm the CQ.
Jason
Quoted 29 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 9 lines · Long Li
Quoted 9 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 4 lines · Wei Hu
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
Quoted 5 lines
Quoted 5 lines
It seems strange that interrupts would be somehow linked to a ucontext? interrupts are highly limited, you can DOS the entire system if someone abuses this.
Generally I expect a properly functioning driver to use one interrupt per CPU
core.
Quoted 3 lines
Yes, MANA uses one interrupt per CPU. One interrupt is shared among multiple EQs.
So you have another multiplexing layer between the interrupt and the EQ? That is alot of multiplexing layers..
Quoted 3 lines
Quoted 2 lines
You should tie the CQ to a shared EQ belong to the core that the CQ wants to have affinity to.
Quoted 7 lines
Quoted 3 lines
The reason for using a separate EQ for a ucontext, is for preventing DOS. If we use a shared EQ, a single ucontext can storm this shared EQ affecting other users.
With a proper design it should not be possible. The CQ adds an entry to the EQ and that should be rate limited by the ability of userspace to schedule to re-arm the CQ.
I think DPDK user space can sometimes storm the EQ by arming the CQ from user-mode.
Please see the following code on arming the CQ from MLX4:
https://github.com/DPDK/dpdk/blob/12fcafcd62286933e6b167b14856d21f642efa5f/drivers/net/mlx4/mlx4_intr.c#L229
With a malicious DPDK user, this code can be abused to arm the CQ at extremely high rate.
Long
Quoted 33 lines · Long Li
Quoted 33 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 9 lines · Long Li
Quoted 9 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 4 lines · Wei Hu
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
Quoted 5 lines
Quoted 5 lines
It seems strange that interrupts would be somehow linked to a ucontext? interrupts are highly limited, you can DOS the entire system if someone abuses this.
Generally I expect a properly functioning driver to use one interrupt per CPU
core.
Quoted 3 lines
Yes, MANA uses one interrupt per CPU. One interrupt is shared among multiple EQs.
So you have another multiplexing layer between the interrupt and the EQ? That is alot of multiplexing layers..
Quoted 6 lines
Quoted 2 lines
You should tie the CQ to a shared EQ belong to the core that the CQ wants to have affinity to.
The reason for using a separate EQ for a ucontext, is for preventing DOS. If we use a shared EQ, a single ucontext can storm this shared EQ affecting other users.
Quoted 6 lines
Quoted 3 lines
With a proper design it should not be possible. The CQ adds an entry to the EQ and that should be rate limited by the ability of userspace to schedule to re-arm the CQ.
I think DPDK user space can sometimes storm the EQ by arming the CQ from user-mode.
Maybe maliciously you can do a blind re-arm, but nothing sane should do that.
Quoted 2 lines
With a malicious DPDK user, this code can be abused to arm the CQ at extremely high rate.
Again, the rate of CQ re-arm is limited by the ability of userspace to schedule, I'm reluctant to consider that a DOS vector. Doesn't your HW have EQ overflow recovery?
Frankly, stacking more layers of IRQ multiplexing doesn't seem like it should solve any problems, you are just shifting where the DOS can occure. Allowing userspace to create EQs is its own DOS direction, either you exhaust and DOS the number of EQs or you DOS the multiplexing layer between the interrupt and the EQ.
Jason
Quoted 38 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 34 lines · Long Li
Quoted 34 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 9 lines · Long Li
Quoted 9 lines
Subject: Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 4 lines · Wei Hu
Add EQ interrupt support for mana ib driver. Allocate EQs per ucontext to receive interrupt. Attach EQ when CQ is created. Call CQ interrupt handler when completion interrupt happens. EQs are destroyed when ucontext is deallocated.
Quoted 6 lines
Quoted 6 lines
It seems strange that interrupts would be somehow linked to a ucontext? interrupts are highly limited, you can DOS the entire system if someone abuses this.
Generally I expect a properly functioning driver to use one interrupt per CPU
core.
Quoted 3 lines
Yes, MANA uses one interrupt per CPU. One interrupt is shared among multiple EQs.
So you have another multiplexing layer between the interrupt and the EQ? That is alot of multiplexing layers..
Quoted 6 lines
Quoted 2 lines
You should tie the CQ to a shared EQ belong to the core that the CQ wants to have affinity to.
The reason for using a separate EQ for a ucontext, is for preventing DOS. If we use a shared EQ, a single ucontext can storm this shared EQ affecting other users.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
With a proper design it should not be possible. The CQ adds an entry to the EQ and that should be rate limited by the ability of userspace to schedule to re-arm the CQ.
I think DPDK user space can sometimes storm the EQ by arming the CQ from user-mode.
Maybe maliciously you can do a blind re-arm, but nothing sane should do that.
Yes, we don't expect a sane user would do that. But in a containerized cloud VM, we can't trust any user. The hardware/driver is designed to isolate the damage from those bad behaviors to their own environment.
Quoted 7 lines
Quoted 3 lines
With a malicious DPDK user, this code can be abused to arm the CQ at extremely high rate.
Again, the rate of CQ re-arm is limited by the ability of userspace to schedule, I'm reluctant to consider that a DOS vector. Doesn't your HW have EQ overflow recovery?
The HW supports detecting and recovery of EQ overflow, but it is on the slow path. A bad user can still affect other users if they use the same EQ and get into recovery mode from time to time.
Quoted 5 lines
Frankly, stacking more layers of IRQ multiplexing doesn't seem like it should solve any problems, you are just shifting where the DOS can occure. Allowing userspace to create EQs is its own DOS direction, either you exhaust and DOS the number of EQs or you DOS the multiplexing layer between the interrupt and the EQ.
The hardware is designed to support a very large number EQs. In practice, this hardware limit is unlikely to be reached before other resources are running out.
The driver interrupt code limits the CPU processing time of each EQ by reading a small batch of EQEs in this interrupt. It guarantees all the EQs are checked on this CPU, and limits the interrupt processing time for any given EQ. In this way, a bad EQ (which is stormed by a bad user doing unreasonable re-arming on the CQ) can't storm other EQs on this CPU.
Thanks,
Long
Quoted 6 lines · Long Li
The driver interrupt code limits the CPU processing time of each EQ by reading a small batch of EQEs in this interrupt. It guarantees all the EQs are checked on this CPU, and limits the interrupt processing time for any given EQ. In this way, a bad EQ (which is stormed by a bad user doing unreasonable re-arming on the CQ) can't storm other EQs on this CPU.
Of course it can, the bad use just creates a million EQs and pushes a bit of work through them constantly. How is that really any different from pushing more EQEs into a single EQ?
And how does your EQ multiplexing work anyhow? Do you poll every EQ on every interrupt? That itself is a DOS vector.
Jason
Quoted 13 lines · Jason Gunthorpe
Quoted 6 lines · Long Li
The driver interrupt code limits the CPU processing time of each EQ by reading a small batch of EQEs in this interrupt. It guarantees all the EQs are checked on this CPU, and limits the interrupt processing time for any given EQ. In this way, a bad EQ (which is stormed by a bad user doing unreasonable re-arming on the CQ) can't storm other EQs on this CPU.
Quoted 8 lines
Of course it can, the bad use just creates a million EQs and pushes a bit of work through them constantly. How is that really any different from pushing more EQEs into a single EQ?
And how does your EQ multiplexing work anyhow? Do you poll every EQ on every interrupt? That itself is a DOS vector.
Jason
User does not create eqs directly . EQ creation is by product of opening device ie allocating context. I am not sure if the same process is allowed to open device multiple times - must be some kind of lock implemented. So million eqs are probably far fetched . As for how the eq servicing is done - only those eq’s for which the interrupt is raised are checked. And each eq is tied only once and only to a single interrupt.
Ajay
Quoted 17 lines · Ajay Sharma
Quoted 17 lines · Jason Gunthorpe
Quoted 6 lines · Long Li
The driver interrupt code limits the CPU processing time of each EQ by reading a small batch of EQEs in this interrupt. It guarantees all the EQs are checked on this CPU, and limits the interrupt processing time for any given EQ. In this way, a bad EQ (which is stormed by a bad user doing unreasonable re-arming on the CQ) can't storm other EQs on this CPU.
Of course it can, the bad use just creates a million EQs and pushes a bit of work through them constantly. How is that really any different from pushing more EQEs into a single EQ?
Quoted 5 lines
Quoted 2 lines
And how does your EQ multiplexing work anyhow? Do you poll every EQ on every interrupt? That itself is a DOS vector.
User does not create eqs directly . EQ creation is by product of opening device ie allocating context.
Which is done directly by the user.
Quoted 2 lines
I am not sure if the same
process is allowed to open device multiple times
Of course it can.
Quoted 1 line
of lock implemented. So million eqs are probably far fetched .
Uh, how do you conclude that?
Quoted 3 lines
As for how the eq servicing is done - only those eq’s for which the
interrupt is raised are checked. And each eq is tied only once and only to a single interrupt.
So you iterate over a list of EQs in every interrupt?
Allowing userspace to increase the number of EQs on an interrupt is a direct DOS vector, no special fussing required.
If you want this to work properly you need to have your HW arrange things so there is only ever one EQE in the EQ for a given CQ at any time. Another EQE cannot be stuffed by the HW until the kernel reads the first EQE and acks it back.
You have almost got this right, the mistake is that userspace is the thing that allows the HW to generate a new EQE. If you care about DOS then this is the wrong design, the kernel and only the kernel must be able to trigger a new EQE for the CQ.
In effect you need two CQ doorbells, a userspace one that re-arms the CQ, and a kernel one that allows a CQ that triggered on ARM to generate an EQE.
Thus the kernel can strictly limit the flow of EQEs through the EQs such that an EQ can never overflow and a CQ can never consume more than one EQE.
You cannot really fix this hardware problem with a software solution. You will always have a DOS at some point.
Jason
Quoted 57 lines
Subject: Re: [EXTERNAL] Re: [PATCH v4 1/1] RDMA/mana_ib: Add EQ interrupt support to mana ib driver.
Quoted 17 lines · Ajay Sharma
Quoted 17 lines · Jason Gunthorpe
Quoted 6 lines · Long Li
The driver interrupt code limits the CPU processing time of each EQ by reading a small batch of EQEs in this interrupt. It guarantees all the EQs are checked on this CPU, and limits the interrupt processing time for any given EQ. In this way, a bad EQ (which is stormed by a bad user doing unreasonable re-arming on the CQ) can't storm other EQs on this CPU.
Of course it can, the bad use just creates a million EQs and pushes a bit of work through them constantly. How is that really any different from pushing more EQEs into a single EQ?
Quoted 5 lines
Quoted 2 lines
And how does your EQ multiplexing work anyhow? Do you poll every EQ on every interrupt? That itself is a DOS vector.
User does not create eqs directly . EQ creation is by product of opening device ie allocating context.
Which is done directly by the user.
Quoted 2 lines
I am not sure if the same
process is allowed to open device multiple timesOf course it can.
Quoted 1 line
of lock implemented. So million eqs are probably far fetched .
Uh, how do you conclude that?
Quoted 3 lines
As for how the eq servicing is done - only those eq’s for which the
interrupt is raised are checked. And each eq is tied only once and only to a single interrupt.So you iterate over a list of EQs in every interrupt?
Allowing userspace to increase the number of EQs on an interrupt is a direct DOS vector, no special fussing required.
If you want this to work properly you need to have your HW arrange things so there is only ever one EQE in the EQ for a given CQ at any time. Another EQE cannot be stuffed by the HW until the kernel reads the first EQE and acks it back.
You have almost got this right, the mistake is that userspace is the thing that allows the HW to generate a new EQE. If you care about DOS then this is the wrong design, the kernel and only the kernel must be able to trigger a new EQE for the CQ.
Quoted 8 lines
In effect you need two CQ doorbells, a userspace one that re-arms the CQ, and a kernel one that allows a CQ that triggered on ARM to generate an EQE.
Thus the kernel can strictly limit the flow of EQEs through the EQs such that an EQ can never overflow and a CQ can never consume more than one EQE.
You cannot really fix this hardware problem with a software solution. You will always have a DOS at some point.
We'll address the comments and send another patch.
Thanks,
Long