IB/hfi1: Update RMT size calculation

[ Upstream commit 892ede5a77 ]

Fix possible RMT overflow:  Use the correct netdev size.
Don't allow adjusted user contexts to go negative.

Fix QOS calculation: Send kernel context count as an argument since
dd->n_krcv_queues is not yet set up in earliest call.  Do not include
the control context in the QOS calculation.  Use the same sized
variable to find the max of krcvq[] entries.

Update the RMT count explanation to make more sense.

Signed-off-by: Dean Luick <dean.luick@cornelisnetworks.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Link: https://lore.kernel.org/r/167329106946.1472990.18385495251650939054.stgit@awfm-02.cornelisnetworks.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Dean Luick 2023-01-09 14:04:29 -05:00 коммит произвёл Greg Kroah-Hartman
Родитель 5a47bb71b1
Коммит 77d567091e
1 изменённых файлов: 32 добавлений и 27 удалений

Просмотреть файл

@ -1055,7 +1055,7 @@ static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
static void handle_temp_err(struct hfi1_devdata *dd); static void handle_temp_err(struct hfi1_devdata *dd);
static void dc_shutdown(struct hfi1_devdata *dd); static void dc_shutdown(struct hfi1_devdata *dd);
static void dc_start(struct hfi1_devdata *dd); static void dc_start(struct hfi1_devdata *dd);
static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, static int qos_rmt_entries(unsigned int n_krcv_queues, unsigned int *mp,
unsigned int *np); unsigned int *np);
static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd); static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms); static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms);
@ -13361,7 +13361,6 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
int ret; int ret;
unsigned ngroups; unsigned ngroups;
int rmt_count; int rmt_count;
int user_rmt_reduced;
u32 n_usr_ctxts; u32 n_usr_ctxts;
u32 send_contexts = chip_send_contexts(dd); u32 send_contexts = chip_send_contexts(dd);
u32 rcv_contexts = chip_rcv_contexts(dd); u32 rcv_contexts = chip_rcv_contexts(dd);
@ -13420,28 +13419,34 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
(num_kernel_contexts + n_usr_ctxts), (num_kernel_contexts + n_usr_ctxts),
&node_affinity.real_cpu_mask); &node_affinity.real_cpu_mask);
/* /*
* The RMT entries are currently allocated as shown below: * RMT entries are allocated as follows:
* 1. QOS (0 to 128 entries); * 1. QOS (0 to 128 entries)
* 2. FECN (num_kernel_context - 1 + num_user_contexts + * 2. FECN (num_kernel_context - 1 [a] + num_user_contexts +
* num_netdev_contexts); * num_netdev_contexts [b])
* 3. netdev (num_netdev_contexts). * 3. netdev (NUM_NETDEV_MAP_ENTRIES)
* It should be noted that FECN oversubscribe num_netdev_contexts *
* entries of RMT because both netdev and PSM could allocate any receive * Notes:
* context between dd->first_dyn_alloc_text and dd->num_rcv_contexts, * [a] Kernel contexts (except control) are included in FECN if kernel
* and PSM FECN must reserve an RMT entry for each possible PSM receive * TID_RDMA is active.
* context. * [b] Netdev and user contexts are randomly allocated from the same
* context pool, so FECN must cover all contexts in the pool.
*/ */
rmt_count = qos_rmt_entries(dd, NULL, NULL) + (num_netdev_contexts * 2); rmt_count = qos_rmt_entries(num_kernel_contexts - 1, NULL, NULL)
if (HFI1_CAP_IS_KSET(TID_RDMA)) + (HFI1_CAP_IS_KSET(TID_RDMA) ? num_kernel_contexts - 1
rmt_count += num_kernel_contexts - 1; : 0)
if (rmt_count + n_usr_ctxts > NUM_MAP_ENTRIES) { + n_usr_ctxts
user_rmt_reduced = NUM_MAP_ENTRIES - rmt_count; + num_netdev_contexts
dd_dev_err(dd, + NUM_NETDEV_MAP_ENTRIES;
"RMT size is reducing the number of user receive contexts from %u to %d\n", if (rmt_count > NUM_MAP_ENTRIES) {
n_usr_ctxts, int over = rmt_count - NUM_MAP_ENTRIES;
user_rmt_reduced); /* try to squish user contexts, minimum of 1 */
/* recalculate */ if (over >= n_usr_ctxts) {
n_usr_ctxts = user_rmt_reduced; dd_dev_err(dd, "RMT overflow: reduce the requested number of contexts\n");
return -EINVAL;
}
dd_dev_err(dd, "RMT overflow: reducing # user contexts from %u to %u\n",
n_usr_ctxts, n_usr_ctxts - over);
n_usr_ctxts -= over;
} }
/* the first N are kernel contexts, the rest are user/netdev contexts */ /* the first N are kernel contexts, the rest are user/netdev contexts */
@ -14298,15 +14303,15 @@ static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
} }
/* return the number of RSM map table entries that will be used for QOS */ /* return the number of RSM map table entries that will be used for QOS */
static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, static int qos_rmt_entries(unsigned int n_krcv_queues, unsigned int *mp,
unsigned int *np) unsigned int *np)
{ {
int i; int i;
unsigned int m, n; unsigned int m, n;
u8 max_by_vl = 0; uint max_by_vl = 0;
/* is QOS active at all? */ /* is QOS active at all? */
if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS || if (n_krcv_queues < MIN_KERNEL_KCTXTS ||
num_vls == 1 || num_vls == 1 ||
krcvqsset <= 1) krcvqsset <= 1)
goto no_qos; goto no_qos;
@ -14364,7 +14369,7 @@ static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
if (!rmt) if (!rmt)
goto bail; goto bail;
rmt_entries = qos_rmt_entries(dd, &m, &n); rmt_entries = qos_rmt_entries(dd->n_krcv_queues - 1, &m, &n);
if (rmt_entries == 0) if (rmt_entries == 0)
goto bail; goto bail;
qpns_per_vl = 1 << m; qpns_per_vl = 1 << m;