linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] perf/smmuv3: Don't cast parameter in bit operations
@ 2022-02-09 18:47 Andy Shevchenko
  2022-02-09 21:45 ` Robin Murphy
  2022-02-15 23:18 ` Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-02-09 18:47 UTC (permalink / raw)
  To: Will Deacon, linux-arm-kernel, linux-kernel; +Cc: Mark Rutland, Andy Shevchenko

While in this particular case it would not be a (critical) issue,
the pattern itself is bad and error prone in case somebody blindly
copies to their code.

Don't cast parameter to unsigned long pointer in the bit operations.
Instead copy to a local variable on stack of a proper type and use.

Note, new compilers might warn on this line for potential outbound access.

Fixes: 7d839b4b9e00 ("perf/smmuv3: Add arm64 smmuv3 pmu driver")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/perf/arm_smmuv3_pmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
index c49108a72865..00d4c45a8017 100644
--- a/drivers/perf/arm_smmuv3_pmu.c
+++ b/drivers/perf/arm_smmuv3_pmu.c
@@ -654,6 +654,7 @@ static int smmu_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
 static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data)
 {
 	struct smmu_pmu *smmu_pmu = data;
+	DECLARE_BITMAP(ovs, BITS_PER_TYPE(u64));
 	u64 ovsr;
 	unsigned int idx;
 
@@ -663,7 +664,8 @@ static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data)
 
 	writeq(ovsr, smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0);
 
-	for_each_set_bit(idx, (unsigned long *)&ovsr, smmu_pmu->num_counters) {
+	bitmap_from_u64(ovs, ovsr);
+	for_each_set_bit(idx, ovs, smmu_pmu->num_counters) {
 		struct perf_event *event = smmu_pmu->events[idx];
 		struct hw_perf_event *hwc;
 
-- 
2.34.1


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

* Re: [PATCH v1 1/1] perf/smmuv3: Don't cast parameter in bit operations
  2022-02-09 18:47 [PATCH v1 1/1] perf/smmuv3: Don't cast parameter in bit operations Andy Shevchenko
@ 2022-02-09 21:45 ` Robin Murphy
  2022-02-15 23:18 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2022-02-09 21:45 UTC (permalink / raw)
  To: Andy Shevchenko, Will Deacon, linux-arm-kernel, linux-kernel; +Cc: Mark Rutland

On 2022-02-09 18:47, Andy Shevchenko wrote:
> While in this particular case it would not be a (critical) issue,
> the pattern itself is bad and error prone in case somebody blindly
> copies to their code.
> 
> Don't cast parameter to unsigned long pointer in the bit operations.
> Instead copy to a local variable on stack of a proper type and use.

Seems reasonable, in fact in my build it appears to save a spill and 
reload from the stack so the code actually gets a teeny bit better. Not 
sure a cleanup warrants a "Fixes" tag, but either way,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Note, new compilers might warn on this line for potential outbound access.
> 
> Fixes: 7d839b4b9e00 ("perf/smmuv3: Add arm64 smmuv3 pmu driver")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/perf/arm_smmuv3_pmu.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
> index c49108a72865..00d4c45a8017 100644
> --- a/drivers/perf/arm_smmuv3_pmu.c
> +++ b/drivers/perf/arm_smmuv3_pmu.c
> @@ -654,6 +654,7 @@ static int smmu_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
>   static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data)
>   {
>   	struct smmu_pmu *smmu_pmu = data;
> +	DECLARE_BITMAP(ovs, BITS_PER_TYPE(u64));
>   	u64 ovsr;
>   	unsigned int idx;
>   
> @@ -663,7 +664,8 @@ static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data)
>   
>   	writeq(ovsr, smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0);
>   
> -	for_each_set_bit(idx, (unsigned long *)&ovsr, smmu_pmu->num_counters) {
> +	bitmap_from_u64(ovs, ovsr);
> +	for_each_set_bit(idx, ovs, smmu_pmu->num_counters) {
>   		struct perf_event *event = smmu_pmu->events[idx];
>   		struct hw_perf_event *hwc;
>   

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

* Re: [PATCH v1 1/1] perf/smmuv3: Don't cast parameter in bit operations
  2022-02-09 18:47 [PATCH v1 1/1] perf/smmuv3: Don't cast parameter in bit operations Andy Shevchenko
  2022-02-09 21:45 ` Robin Murphy
@ 2022-02-15 23:18 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2022-02-15 23:18 UTC (permalink / raw)
  To: linux-kernel, Andy Shevchenko, linux-arm-kernel
  Cc: catalin.marinas, kernel-team, Will Deacon, Mark Rutland

On Wed, 9 Feb 2022 20:47:58 +0200, Andy Shevchenko wrote:
> While in this particular case it would not be a (critical) issue,
> the pattern itself is bad and error prone in case somebody blindly
> copies to their code.
> 
> Don't cast parameter to unsigned long pointer in the bit operations.
> Instead copy to a local variable on stack of a proper type and use.
> 
> [...]

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] perf/smmuv3: Don't cast parameter in bit operations
      https://git.kernel.org/will/c/8ddf4eff71e1

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2022-02-15 23:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 18:47 [PATCH v1 1/1] perf/smmuv3: Don't cast parameter in bit operations Andy Shevchenko
2022-02-09 21:45 ` Robin Murphy
2022-02-15 23:18 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).