git: daa150aaa30f - main - Properly handle case where firmware dump returns more registers on second pass in mlx5core.

Hans Petter Selasky hselasky at FreeBSD.org
Fri Jan 8 11:36:53 UTC 2021


The branch main has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=daa150aaa30fad8187da8bcbce0880c5075fdda7

commit daa150aaa30fad8187da8bcbce0880c5075fdda7
Author:     Hans Petter Selasky <hselasky at FreeBSD.org>
AuthorDate: 2021-01-08 10:52:44 +0000
Commit:     Hans Petter Selasky <hselasky at FreeBSD.org>
CommitDate: 2021-01-08 11:35:54 +0000

    Properly handle case where firmware dump returns more registers on second pass
    in mlx5core.
    
    Submitted by: kib@
    MFC after: 1 week
    Sponsored by: Mellanox Technologies // NVIDIA Networking
---
 sys/dev/mlx5/mlx5_core/mlx5_fwdump.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c b/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
index d633333cb80d..09e8f9f7660a 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
@@ -115,11 +115,15 @@ mlx5_fwdump_prep(struct mlx5_core_dev *mdev)
 		mlx5_core_warn(mdev, "no output from scan space\n");
 		goto unlock_vsc;
 	}
-	mdev->dump_rege = malloc(sz * sizeof(struct mlx5_crspace_regmap),
+
+	/*
+	 * We add a sentinel element at the end of the array to
+	 * terminate the read loop in mlx5_fwdump(), so allocate sz + 1.
+	 */
+	mdev->dump_rege = malloc((sz + 1) * sizeof(struct mlx5_crspace_regmap),
 	    M_MLX5_DUMP, M_WAITOK | M_ZERO);
 
 	for (i = 0, addr = 0;;) {
-		MPASS(i < sz);
 		mdev->dump_rege[i].cnt++;
 		MLX5_VSC_SET(vsc_addr, &in, address, addr);
 		pci_write_config(dev, vsc_addr + MLX5_VSC_ADDR_OFFSET, in, 4);
@@ -137,13 +141,21 @@ mlx5_fwdump_prep(struct mlx5_core_dev *mdev)
 		next_addr = MLX5_VSC_GET(vsc_addr, &out, address);
 		if (next_addr == 0 || next_addr == addr)
 			break;
-		if (next_addr != addr + 4)
-			mdev->dump_rege[++i].addr = next_addr;
+		if (next_addr != addr + 4) {
+			if (++i == sz) {
+				mlx5_core_err(mdev,
+		    "Inconsistent hw crspace reads (1): sz %u i %u addr %#lx",
+				    sz, i, (unsigned long)addr);
+				break;
+			}
+			mdev->dump_rege[i].addr = next_addr;
+		}
 		addr = next_addr;
 	}
-	if (i + 1 != sz) {
+	/* i == sz case already reported by loop above */
+	if (i + 1 != sz && i != sz) {
 		mlx5_core_err(mdev,
-		    "Inconsistent hw crspace reads: sz %u i %u addr %#lx",
+		    "Inconsistent hw crspace reads (2): sz %u i %u addr %#lx",
 		    sz, i, (unsigned long)addr);
 	}
 


More information about the dev-commits-src-all mailing list