linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.10 01/30] IB/hfi1: Update RMT size calculation
@ 2023-03-03 21:46 Sasha Levin
  2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 02/30] iommu/amd: Fix error handling for pdev_pri_ats_enable() Sasha Levin
                   ` (28 more replies)
  0 siblings, 29 replies; 30+ messages in thread
From: Sasha Levin @ 2023-03-03 21:46 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Dean Luick, Dennis Dalessandro, Leon Romanovsky, Sasha Levin, linux-rdma

From: Dean Luick <dean.luick@cornelisnetworks.com>

[ Upstream commit 892ede5a77f337831609fb9c248ac60948061894 ]

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>
---
 drivers/infiniband/hw/hfi1/chip.c | 59 +++++++++++++++++--------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c
index 88476a1a601a4..4b41f35668b20 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -1097,7 +1097,7 @@ static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
 static void handle_temp_err(struct hfi1_devdata *dd);
 static void dc_shutdown(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);
 static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
 static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms);
@@ -13403,7 +13403,6 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
 	int ret;
 	unsigned ngroups;
 	int rmt_count;
-	int user_rmt_reduced;
 	u32 n_usr_ctxts;
 	u32 send_contexts = chip_send_contexts(dd);
 	u32 rcv_contexts = chip_rcv_contexts(dd);
@@ -13462,28 +13461,34 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
 					 (num_kernel_contexts + n_usr_ctxts),
 					 &node_affinity.real_cpu_mask);
 	/*
-	 * The RMT entries are currently allocated as shown below:
-	 * 1. QOS (0 to 128 entries);
-	 * 2. FECN (num_kernel_context - 1 + num_user_contexts +
-	 *    num_netdev_contexts);
-	 * 3. netdev (num_netdev_contexts).
-	 * It should be noted that FECN oversubscribe num_netdev_contexts
-	 * entries of RMT because both netdev and PSM could allocate any receive
-	 * context between dd->first_dyn_alloc_text and dd->num_rcv_contexts,
-	 * and PSM FECN must reserve an RMT entry for each possible PSM receive
-	 * context.
+	 * RMT entries are allocated as follows:
+	 * 1. QOS (0 to 128 entries)
+	 * 2. FECN (num_kernel_context - 1 [a] + num_user_contexts +
+	 *          num_netdev_contexts [b])
+	 * 3. netdev (NUM_NETDEV_MAP_ENTRIES)
+	 *
+	 * Notes:
+	 * [a] Kernel contexts (except control) are included in FECN if kernel
+	 *     TID_RDMA is active.
+	 * [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);
-	if (HFI1_CAP_IS_KSET(TID_RDMA))
-		rmt_count += num_kernel_contexts - 1;
-	if (rmt_count + n_usr_ctxts > NUM_MAP_ENTRIES) {
-		user_rmt_reduced = NUM_MAP_ENTRIES - rmt_count;
-		dd_dev_err(dd,
-			   "RMT size is reducing the number of user receive contexts from %u to %d\n",
-			   n_usr_ctxts,
-			   user_rmt_reduced);
-		/* recalculate */
-		n_usr_ctxts = user_rmt_reduced;
+	rmt_count = qos_rmt_entries(num_kernel_contexts - 1, NULL, NULL)
+		    + (HFI1_CAP_IS_KSET(TID_RDMA) ? num_kernel_contexts - 1
+						  : 0)
+		    + n_usr_ctxts
+		    + num_netdev_contexts
+		    + NUM_NETDEV_MAP_ENTRIES;
+	if (rmt_count > NUM_MAP_ENTRIES) {
+		int over = rmt_count - NUM_MAP_ENTRIES;
+		/* try to squish user contexts, minimum of 1 */
+		if (over >= n_usr_ctxts) {
+			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 */
@@ -14340,15 +14345,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 */
-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)
 {
 	int i;
 	unsigned int m, n;
-	u8 max_by_vl = 0;
+	uint max_by_vl = 0;
 
 	/* is QOS active at all? */
-	if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
+	if (n_krcv_queues < MIN_KERNEL_KCTXTS ||
 	    num_vls == 1 ||
 	    krcvqsset <= 1)
 		goto no_qos;
@@ -14406,7 +14411,7 @@ static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
 
 	if (!rmt)
 		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)
 		goto bail;
 	qpns_per_vl = 1 << m;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2023-03-03 23:04 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 21:46 [PATCH AUTOSEL 5.10 01/30] IB/hfi1: Update RMT size calculation Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 02/30] iommu/amd: Fix error handling for pdev_pri_ats_enable() Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 03/30] media: uvcvideo: Handle cameras with invalid descriptors Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 04/30] media: uvcvideo: Handle errors from calls to usb_string Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 05/30] media: uvcvideo: Quirk for autosuspend in Logitech B910 and C910 Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 06/30] media: uvcvideo: Silence memcpy() run-time false positive warnings Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 07/30] staging: emxx_udc: Add checks for dma_alloc_coherent() Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 08/30] tty: fix out-of-bounds access in tty_driver_lookup_tty() Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 09/30] tty: serial: fsl_lpuart: disable the CTS when send break signal Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 10/30] serial: sc16is7xx: setup GPIO controller later in probe Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 11/30] mei: bus-fixup:upon error print return values of send and receive Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 12/30] parport_pc: Set up mode and ECR masks for Oxford Semiconductor devices Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 13/30] tools/iio/iio_utils:fix memory leak Sasha Levin
2023-03-03 21:46 ` [PATCH AUTOSEL 5.10 14/30] iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_status_word() Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 15/30] iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word() Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 16/30] firmware: coreboot: framebuffer: Ignore reserved pixel color bits Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 17/30] PCI: loongson: Prevent LS7A MRRS increases Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 18/30] usb: host: xhci: mvebu: Iterate over array indexes instead of using pointer math Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 19/30] USB: ene_usb6250: Allocate enough memory for full object Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 20/30] usb: uvc: Enumerate valid values for color matching Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 21/30] usb: gadget: uvc: Make bSourceID read/write Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 22/30] PCI: Align extra resources for hotplug bridges properly Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 23/30] PCI: Take other bus devices into account when distributing resources Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 24/30] kernel/power/energy_model.c: fix memory leak with using debugfs_lookup() Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 25/30] kernel/fail_function: " Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 26/30] PCI: loongson: Add more devices that need MRRS quirk Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 27/30] PCI: Add ACS quirk for Wangxun NICs Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 28/30] phy: rockchip-typec: Fix unsigned comparison with less than zero Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 29/30] soundwire: cadence: Remove wasted space in response_buf Sasha Levin
2023-03-03 21:47 ` [PATCH AUTOSEL 5.10 30/30] soundwire: cadence: Drain the RX FIFO after an IO timeout Sasha Levin

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).