From: Vered Yavniely vered.yavniely@intel.com
[ Upstream commit b4fd8e56c9a3b614370fde2d45aec1032eb67ddd ]
Change the BMON_CR register value back to its original state before enabling, so that BMON does not continue to collect information after being disabled.
Signed-off-by: Vered Yavniely vered.yavniely@intel.com Reviewed-by: Koby Elbaz koby.elbaz@intel.com Signed-off-by: Koby Elbaz koby.elbaz@intel.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES - `gaudi2_config_bmon()` writes the user-supplied enable bits into `mmBMON_CR` when activating the monitor (`drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c:2409`). With the pre-fix code, the disable path overwrote the control register with `0x0F000077`, a value that leaves collection logic active, so the hardware kept sampling even after we told userspace the monitor was disabled (`drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c` history via `git blame`, original value added in de88aa67af94). The patch restores the register to the hardware reset value `0x41` (`drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c:2429`), matching the state observed before enablement and preventing post-disable bus sampling. - This bug is user-visible: disabling a BMON instance via the debug ioctl leaves residual capture running, corrupting later measurements and wasting bandwidth/trace resources. No alternative workaround exists in older kernels because the driver unconditionally writes the wrong value. - The fix is tiny, self-contained, and hardware-specific; it touches only the Gaudi2 BMON disable path and aligns with how the Gaudi (non-2) driver already restores the control register to its idle value. There are no functional dependencies beyond the longstanding code added with the original Gaudi2 profiler support, so the change backports cleanly even to older trees that still house the file under `drivers/misc/habanalabs/gaudi2`. Risk of regression is minimal because the new constant matches the documented idle state and only executes on the disable path.
Given the clear bug fix, minimal scope, and relevance to existing users of the Gaudi2 debug interface, this commit meets the stable tree backport criteria.
drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c b/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c index 2423620ff358f..bc3c57bda5cda 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c @@ -2426,7 +2426,7 @@ static int gaudi2_config_bmon(struct hl_device *hdev, struct hl_debug_params *pa WREG32(base_reg + mmBMON_ADDRH_E3_OFFSET, 0); WREG32(base_reg + mmBMON_REDUCTION_OFFSET, 0); WREG32(base_reg + mmBMON_STM_TRC_OFFSET, 0x7 | (0xA << 8)); - WREG32(base_reg + mmBMON_CR_OFFSET, 0x77 | 0xf << 24); + WREG32(base_reg + mmBMON_CR_OFFSET, 0x41); }
return 0;