Re: [peterz-queue:perf/core] [perf/x86/rapl] 90942140bb: UBSAN:array-index-out-of-bounds_in_arch/x86/events/rapl.c

From: Peter Zijlstra
Date: Wed Sep 11 2024 - 05:45:56 EST


On Wed, Sep 11, 2024 at 04:32:13PM +0800, kernel test robot wrote:
>
>
> Hello,
>
> kernel test robot noticed "UBSAN:array-index-out-of-bounds_in_arch/x86/events/rapl.c" on:
>
> commit: 90942140bb6cc7e9a41d5927c7617ee522896f7a ("perf/x86/rapl: Move the pmu allocation out of CPU hotplug")
> https://git.kernel.org/cgit/linux/kernel/git/peterz/queue.git perf/core
>
> in testcase: boot
>
> compiler: clang-18
> test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G
>
> (please refer to attached dmesg/kmsg for entire log/backtrace)
>
>
> +-----------------------------------------------------------+------------+------------+
> | | c206df6d69 | 90942140bb |
> +-----------------------------------------------------------+------------+------------+
> | UBSAN:array-index-out-of-bounds_in_arch/x86/events/rapl.c | 0 | 12 |
> +-----------------------------------------------------------+------------+------------+
>
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <oliver.sang@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-lkp/202409111521.c7c6d56f-lkp@xxxxxxxxx
>
>
> [ 22.115286][ T1] ------------[ cut here ]------------
> [ 22.115957][ T1] UBSAN: array-index-out-of-bounds in arch/x86/events/rapl.c:685:3

That is:

rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu;

Which is scaled like:

int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package();

And that isn't new in that patch, just moved around.

Kan, as it happens these two patches got zapped by Ingo because they
conflict with that rapl patch from perf/urgent and he merged perf/urgent
into perf/core.

I was going to rebase these two patches on top, but given the above, can
you have a look instead?