mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-12 12:25:18 +02:00
IB/core: Implement a limit on UMAD receive List
[ Upstream commit ca0b44e20a
]
The existing behavior of ib_umad, which maintains received MAD
packets in an unbounded list, poses a risk of uncontrolled growth.
As user-space applications extract packets from this list, the rate
of extraction may not match the rate of incoming packets, leading
to potential list overflow.
To address this, we introduce a limit to the size of the list. After
considering typical scenarios, such as OpenSM processing, which can
handle approximately 100k packets per second, and the 1-second retry
timeout for most packets, we set the list size limit to 200k. Packets
received beyond this limit are dropped, assuming they are likely timed
out by the time they are handled by user-space.
Notably, packets queued on the receive list due to reasons like
timed-out sends are preserved even when the list is full.
Signed-off-by: Michael Guralnik <michaelgur@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Link: https://lore.kernel.org/r/7197cb58a7d9e78399008f25036205ceab07fbd5.1713268818.git.leon@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
c15bb7c940
commit
b8c5f63599
|
@ -63,6 +63,8 @@ MODULE_AUTHOR("Roland Dreier");
|
||||||
MODULE_DESCRIPTION("InfiniBand userspace MAD packet access");
|
MODULE_DESCRIPTION("InfiniBand userspace MAD packet access");
|
||||||
MODULE_LICENSE("Dual BSD/GPL");
|
MODULE_LICENSE("Dual BSD/GPL");
|
||||||
|
|
||||||
|
#define MAX_UMAD_RECV_LIST_SIZE 200000
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
IB_UMAD_MAX_PORTS = RDMA_MAX_PORTS,
|
IB_UMAD_MAX_PORTS = RDMA_MAX_PORTS,
|
||||||
IB_UMAD_MAX_AGENTS = 32,
|
IB_UMAD_MAX_AGENTS = 32,
|
||||||
|
@ -113,6 +115,7 @@ struct ib_umad_file {
|
||||||
struct mutex mutex;
|
struct mutex mutex;
|
||||||
struct ib_umad_port *port;
|
struct ib_umad_port *port;
|
||||||
struct list_head recv_list;
|
struct list_head recv_list;
|
||||||
|
atomic_t recv_list_size;
|
||||||
struct list_head send_list;
|
struct list_head send_list;
|
||||||
struct list_head port_list;
|
struct list_head port_list;
|
||||||
spinlock_t send_lock;
|
spinlock_t send_lock;
|
||||||
|
@ -180,24 +183,28 @@ static struct ib_mad_agent *__get_agent(struct ib_umad_file *file, int id)
|
||||||
return file->agents_dead ? NULL : file->agent[id];
|
return file->agents_dead ? NULL : file->agent[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int queue_packet(struct ib_umad_file *file,
|
static int queue_packet(struct ib_umad_file *file, struct ib_mad_agent *agent,
|
||||||
struct ib_mad_agent *agent,
|
struct ib_umad_packet *packet, bool is_recv_mad)
|
||||||
struct ib_umad_packet *packet)
|
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
mutex_lock(&file->mutex);
|
mutex_lock(&file->mutex);
|
||||||
|
|
||||||
|
if (is_recv_mad &&
|
||||||
|
atomic_read(&file->recv_list_size) > MAX_UMAD_RECV_LIST_SIZE)
|
||||||
|
goto unlock;
|
||||||
|
|
||||||
for (packet->mad.hdr.id = 0;
|
for (packet->mad.hdr.id = 0;
|
||||||
packet->mad.hdr.id < IB_UMAD_MAX_AGENTS;
|
packet->mad.hdr.id < IB_UMAD_MAX_AGENTS;
|
||||||
packet->mad.hdr.id++)
|
packet->mad.hdr.id++)
|
||||||
if (agent == __get_agent(file, packet->mad.hdr.id)) {
|
if (agent == __get_agent(file, packet->mad.hdr.id)) {
|
||||||
list_add_tail(&packet->list, &file->recv_list);
|
list_add_tail(&packet->list, &file->recv_list);
|
||||||
|
atomic_inc(&file->recv_list_size);
|
||||||
wake_up_interruptible(&file->recv_wait);
|
wake_up_interruptible(&file->recv_wait);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
unlock:
|
||||||
mutex_unlock(&file->mutex);
|
mutex_unlock(&file->mutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -224,7 +231,7 @@ static void send_handler(struct ib_mad_agent *agent,
|
||||||
if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
|
if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
|
||||||
packet->length = IB_MGMT_MAD_HDR;
|
packet->length = IB_MGMT_MAD_HDR;
|
||||||
packet->mad.hdr.status = ETIMEDOUT;
|
packet->mad.hdr.status = ETIMEDOUT;
|
||||||
if (!queue_packet(file, agent, packet))
|
if (!queue_packet(file, agent, packet, false))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
kfree(packet);
|
kfree(packet);
|
||||||
|
@ -284,7 +291,7 @@ static void recv_handler(struct ib_mad_agent *agent,
|
||||||
rdma_destroy_ah_attr(&ah_attr);
|
rdma_destroy_ah_attr(&ah_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue_packet(file, agent, packet))
|
if (queue_packet(file, agent, packet, true))
|
||||||
goto err2;
|
goto err2;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -409,6 +416,7 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
|
||||||
|
|
||||||
packet = list_entry(file->recv_list.next, struct ib_umad_packet, list);
|
packet = list_entry(file->recv_list.next, struct ib_umad_packet, list);
|
||||||
list_del(&packet->list);
|
list_del(&packet->list);
|
||||||
|
atomic_dec(&file->recv_list_size);
|
||||||
|
|
||||||
mutex_unlock(&file->mutex);
|
mutex_unlock(&file->mutex);
|
||||||
|
|
||||||
|
@ -421,6 +429,7 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
|
||||||
/* Requeue packet */
|
/* Requeue packet */
|
||||||
mutex_lock(&file->mutex);
|
mutex_lock(&file->mutex);
|
||||||
list_add(&packet->list, &file->recv_list);
|
list_add(&packet->list, &file->recv_list);
|
||||||
|
atomic_inc(&file->recv_list_size);
|
||||||
mutex_unlock(&file->mutex);
|
mutex_unlock(&file->mutex);
|
||||||
} else {
|
} else {
|
||||||
if (packet->recv_wc)
|
if (packet->recv_wc)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user