Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly
@ 2023-12-11 19:27 Robin Murphy
  2023-12-12  2:21 ` Ilkka Koskinen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Robin Murphy @ 2023-12-11 19:27 UTC (permalink / raw)
  To: will
  Cc: mark.rutland, linux-arm-kernel, linux-kernel, jeremy.linton,
	ilkka, renyu.zj

Calling arm_cmn_event_clear() before all DTC indices are allocated is
wrong, and can lead to arm_cmn_event_add() erroneously clearing live
counters from full DTCs where allocation fails. Since the DTC counters
are only updated by arm_cmn_init_counter() after all DTC and DTM
allocations succeed, nothing actually needs cleaning up in this case
anyway, and it should just return directly as it did before.

Fixes: 7633ec2c262f ("perf/arm-cmn: Rework DTC counters (again)")
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/perf/arm-cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c
index 86d970e74129..c584165b13ba 100644
--- a/drivers/perf/arm-cmn.c
+++ b/drivers/perf/arm-cmn.c
@@ -1816,7 +1816,7 @@ static int arm_cmn_event_add(struct perf_event *event, int flags)
 			idx = 0;
 			while (cmn->dtc[j].counters[idx])
 				if (++idx == CMN_DT_NUM_COUNTERS)
-					goto free_dtms;
+					return -ENOSPC;
 		}
 		hw->dtc_idx[j] = idx;
 	}
-- 
2.39.2.101.g768bb238c484.dirty


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly
  2023-12-11 19:27 [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly Robin Murphy
@ 2023-12-12  2:21 ` Ilkka Koskinen
  2023-12-12  9:16 ` Will Deacon
  2023-12-12 17:22 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Ilkka Koskinen @ 2023-12-12  2:21 UTC (permalink / raw)
  To: Robin Murphy
  Cc: will, mark.rutland, linux-arm-kernel, linux-kernel, jeremy.linton,
	ilkka, renyu.zj


On Mon, 11 Dec 2023, Robin Murphy wrote:
> Calling arm_cmn_event_clear() before all DTC indices are allocated is
> wrong, and can lead to arm_cmn_event_add() erroneously clearing live
> counters from full DTCs where allocation fails. Since the DTC counters
> are only updated by arm_cmn_init_counter() after all DTC and DTM
> allocations succeed, nothing actually needs cleaning up in this case
> anyway, and it should just return directly as it did before.
>
> Fixes: 7633ec2c262f ("perf/arm-cmn: Rework DTC counters (again)")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

That's a good catch.

     Reviewed-by: Ilkka Koskinen <ilkka@os.amperecomputing.com>

Cheers, Ilkka

> ---
> drivers/perf/arm-cmn.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c
> index 86d970e74129..c584165b13ba 100644
> --- a/drivers/perf/arm-cmn.c
> +++ b/drivers/perf/arm-cmn.c
> @@ -1816,7 +1816,7 @@ static int arm_cmn_event_add(struct perf_event *event, int flags)
> 			idx = 0;
> 			while (cmn->dtc[j].counters[idx])
> 				if (++idx == CMN_DT_NUM_COUNTERS)
> -					goto free_dtms;
> +					return -ENOSPC;
> 		}
> 		hw->dtc_idx[j] = idx;
> 	}
> -- 
> 2.39.2.101.g768bb238c484.dirty
>
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly
  2023-12-11 19:27 [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly Robin Murphy
  2023-12-12  2:21 ` Ilkka Koskinen
@ 2023-12-12  9:16 ` Will Deacon
  2023-12-12 17:22 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2023-12-12  9:16 UTC (permalink / raw)
  To: Robin Murphy, catalin.marinas
  Cc: mark.rutland, linux-arm-kernel, linux-kernel, jeremy.linton,
	ilkka, renyu.zj

On Mon, Dec 11, 2023 at 07:27:28PM +0000, Robin Murphy wrote:
> Calling arm_cmn_event_clear() before all DTC indices are allocated is
> wrong, and can lead to arm_cmn_event_add() erroneously clearing live
> counters from full DTCs where allocation fails. Since the DTC counters
> are only updated by arm_cmn_init_counter() after all DTC and DTM
> allocations succeed, nothing actually needs cleaning up in this case
> anyway, and it should just return directly as it did before.
> 
> Fixes: 7633ec2c262f ("perf/arm-cmn: Rework DTC counters (again)")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/perf/arm-cmn.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c
> index 86d970e74129..c584165b13ba 100644
> --- a/drivers/perf/arm-cmn.c
> +++ b/drivers/perf/arm-cmn.c
> @@ -1816,7 +1816,7 @@ static int arm_cmn_event_add(struct perf_event *event, int flags)
>  			idx = 0;
>  			while (cmn->dtc[j].counters[idx])
>  				if (++idx == CMN_DT_NUM_COUNTERS)
> -					goto free_dtms;
> +					return -ENOSPC;
>  		}
>  		hw->dtc_idx[j] = idx;
>  	}
> -- 
> 2.39.2.101.g768bb238c484.dirty

Acked-by: Will Deacon <will@kernel.org>

Catalin -- please can you take this one as a fix?

Cheers,

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly
  2023-12-11 19:27 [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly Robin Murphy
  2023-12-12  2:21 ` Ilkka Koskinen
  2023-12-12  9:16 ` Will Deacon
@ 2023-12-12 17:22 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2023-12-12 17:22 UTC (permalink / raw)
  To: will, Robin Murphy
  Cc: mark.rutland, linux-arm-kernel, linux-kernel, jeremy.linton,
	ilkka, renyu.zj

On Mon, 11 Dec 2023 19:27:28 +0000, Robin Murphy wrote:
> Calling arm_cmn_event_clear() before all DTC indices are allocated is
> wrong, and can lead to arm_cmn_event_add() erroneously clearing live
> counters from full DTCs where allocation fails. Since the DTC counters
> are only updated by arm_cmn_init_counter() after all DTC and DTM
> allocations succeed, nothing actually needs cleaning up in this case
> anyway, and it should just return directly as it did before.
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] perf/arm-cmn: Fail DTC counter allocation correctly
      https://git.kernel.org/arm64/c/1892fe103c3a

-- 
Catalin


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-11 19:27 [PATCH] perf/arm-cmn: Fail DTC counter allocation correctly Robin Murphy
2023-12-12  2:21 ` Ilkka Koskinen
2023-12-12  9:16 ` Will Deacon
2023-12-12 17:22 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox