coresight: tmc: Explicit type conversions to prevent integer overflow
authorRuidong Tian <tianruidong@linux.alibaba.com>
Fri, 4 Aug 2023 08:15:14 +0000 (16:15 +0800)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Fri, 4 Aug 2023 09:52:32 +0000 (10:52 +0100)
commitfd380097cdb305582b7a1f9476391330299d2c59
treebb1602058ea6bf216140ff1d965a9461d6a274b7
parentc00701125cf379f8ce9a4c98cb3cbf9edc3a5672
coresight: tmc: Explicit type conversions to prevent integer overflow

Perf cs_etm session executed unexpectedly when AUX buffer > 1G.

  perf record -C 0 -m ,2G -e cs_etm// -- <workload>
  [ perf record: Captured and wrote 2.615 MB perf.data ]

Perf only collect about 2M perf data rather than 2G. This is becasuse
the operation, "nr_pages << PAGE_SHIFT", in coresight tmc driver, will
overflow when nr_pages >= 0x80000(correspond to 1G AUX buffer). The
overflow cause buffer allocation to fail, and TMC driver will alloc
minimal buffer size(1M). You can just get about 2M perf data(1M AUX
buffer + perf data header) at least.

Explicit convert nr_pages to 64 bit to avoid overflow.

Fixes: 22f429f19c41 ("coresight: etm-perf: Add support for ETR backend")
Fixes: 99443ea19e8b ("coresight: Add generic TMC sg table framework")
Fixes: 2e499bbc1a92 ("coresight: tmc: implementing TMC-ETF AUX space API")
Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20230804081514.120171-2-tianruidong@linux.alibaba.com
drivers/hwtracing/coresight/coresight-tmc-etf.c
drivers/hwtracing/coresight/coresight-tmc-etr.c
drivers/hwtracing/coresight/coresight-tmc.h