Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jan 2021 12:48:41 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: f301a7de8b76 - stable/11 - MFC daa150aaa30f: Properly handle case where firmware dump returns more registers on second pass in mlx5core.
Message-ID:  <202101221248.10MCmfYA019970@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/11 has been updated by hselasky:

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

commit f301a7de8b764923aaba16dad6814936e3c80ac5
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-01-08 10:52:44 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-01-22 12:36:20 +0000

    MFC daa150aaa30f:
    Properly handle case where firmware dump returns more registers on second pass
    in mlx5core.
    
    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 25aaf16147c1..0eb816bf17fd 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);
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101221248.10MCmfYA019970>