lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <0cc551b72dadada1f6c98881dc5cbdd535aade29.1761704862.git.kuhanh.murugasen.krishnan@altera.com>
Date: Tue,  4 Nov 2025 10:09:27 +0800
From: Kuhanh Murugasen Krishnan <kuhanh.murugasen.krishnan@...era.com>
To: Moritz Fischer <mdf@...nel.org>,
	Xu Yilun <yilun.xu@...el.com>,
	Tom Rix <trix@...hat.com>,
	linux-fpga@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Kuhanh Murugasen Krishnan <kuhanh.murugasen.krishnan@...era.com>
Subject: [PATCH 1/1] fpga: altera-cvp: Add recovery retry mechanism for teardown failures

From: "Murugasen Krishnan, Kuhanh" <kuhanh.murugasen.krishnan@...era.com>

When an incorrect bitstream is sent during configuration, the teardown
sequence may fail and leave the CVP hardware in an undefined or
unrecoverable state. This prevents subsequent configuration attempts
from succeeding without a full PCIe reset.

To improve reliability, introduce a recovery mechanism that retries
the teardown operation up to 10 times. Each teardown failure triggers
a cleanup sequence that resets the CVP_MODE_CTRL register by clearing
the CVP_MODE and HIP_CLK_SEL bits before retrying. This ensures the
hardware is returned to a known idle state between attempts.

A new macro, CVP_TEARDOWN_MAX_RETRY, defines the maximum number of
teardown retry attempts. The recovery routine is integrated into both
the write initialization and completion paths to ensure consistent
error handling and improved robustness across configuration cycles.

This change prevents the driver from remaining in an unrecoverable
state and enables safe retry attempts without requiring a full PCIe
re-enumeration.

Signed-off-by: Ang Tien Sung <tien.sung.ang@...era.com>
Signed-off-by: Murugasen Krishnan, Kuhanh <kuhanh.murugasen.krishnan@...era.com>

---
 drivers/fpga/altera-cvp.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c
index 5af0bd33890c..5c4f4a5bae76 100644
--- a/drivers/fpga/altera-cvp.c
+++ b/drivers/fpga/altera-cvp.c
@@ -66,6 +66,8 @@
 #define ALTERA_CVP_V1_SIZE	4
 #define ALTERA_CVP_V2_SIZE	4096
 
+/* Tear-down retry */
+#define CVP_TEARDOWN_MAX_RETRY 10
 /* Optional CvP config error status check for debugging */
 static bool altera_cvp_chkcfg;
 
@@ -308,12 +310,34 @@ static int altera_cvp_teardown(struct fpga_manager *mgr,
 	/* STEP 15 - poll CVP_CONFIG_READY bit for 0 with 10us timeout */
 	ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, 0,
 				     conf->priv->poll_time_us);
-	if (ret)
+	if (ret) {
 		dev_err(&mgr->dev, "CFG_RDY == 0 timeout\n");
+		/* reset CVP_MODE and HIP_CLK_SEL bit */
+		altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val);
+		val &= ~VSE_CVP_MODE_CTRL_HIP_CLK_SEL;
+		val &= ~VSE_CVP_MODE_CTRL_CVP_MODE;
+		altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val);
 
+		return -EAGAIN;
+	}
 	return ret;
 }
 
+static int altera_cvp_recovery(struct fpga_manager *mgr,
+			       struct fpga_image_info *info)
+{
+	int ret, retry;
+
+	for (retry = 0; retry < CVP_TEARDOWN_MAX_RETRY; retry++) {
+		ret = altera_cvp_teardown(mgr, info);
+		if (!ret)
+			break;
+		dev_warn(&mgr->dev,
+			 "%s: [%d] Tear-down failed. Retrying\n",
+			  __func__, retry);
+	}
+	return ret;
+}
 static int altera_cvp_write_init(struct fpga_manager *mgr,
 				 struct fpga_image_info *info,
 				 const char *buf, size_t count)
@@ -346,7 +370,7 @@ static int altera_cvp_write_init(struct fpga_manager *mgr,
 
 	if (val & VSE_CVP_STATUS_CFG_RDY) {
 		dev_warn(&mgr->dev, "CvP already started, tear down first\n");
-		ret = altera_cvp_teardown(mgr, info);
+		ret = altera_cvp_recovery(mgr, info);
 		if (ret)
 			return ret;
 	}
@@ -487,7 +511,7 @@ static int altera_cvp_write_complete(struct fpga_manager *mgr,
 	u32 mask, val;
 	int ret;
 
-	ret = altera_cvp_teardown(mgr, info);
+	ret = altera_cvp_recovery(mgr, info);
 	if (ret)
 		return ret;
 
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ