Re: drivers/resctrl/mpam_devices.c:1860:35-38: WARNING: Suspicious code. resource_size is maybe missing with msc_res

From: Ben Horgan

Date: Thu Sep 03 2026 - 09:29:54 EST


Hi Ilpo,

On 03/09/2026 12:02, Ilpo Järvinen wrote:
> On Thu, 3 Sep 2026, kernel test robot wrote:
>
>> Hi Ben,
>>
>> First bad commit (maybe != root cause):
>>
>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>> head: 89a312991dc6e638a36adc43ccb91dbc25504c04
>> commit: c544f00a473239835d22e7109b403314d8b85974 arm64: mpam: Drop the CONFIG_EXPERT restriction
>> date: 5 months ago
>> config: arm64-randconfig-r051-20260902 (https://download.01.org/0day-ci/archive/20260903/202609030809.ObirDhR3-lkp@xxxxxxxxx/config)
>> compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 2c2cffa015e9549aafba9e514384b08204c7cc4b)
>>
>> 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
>> | Fixes: c544f00a4732 ("arm64: mpam: Drop the CONFIG_EXPERT restriction")
>> | Reported-by: kernel test robot <lkp@xxxxxxxxx>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202609030809.ObirDhR3-lkp@xxxxxxxxx/
>>
>> cocci warnings: (new ones prefixed by >>)
>>>> drivers/resctrl/mpam_devices.c:1860:35-38: WARNING: Suspicious code. resource_size is maybe missing with msc_res
>>
>> vim +1860 drivers/resctrl/mpam_devices.c
>>
>> f04046f2577a5c James Morse 2025-11-19 @1860 msc->mapped_hwpage_sz = msc_res->end - msc_res->start;
>
>> :::::: The code at line 1860 was first introduced by commit
>> :::::: f04046f2577a5c76167333ca99d3903ee5331ba0 arm_mpam: Add probe/remove for mpam msc driver and kbuild boiler plate
>>
>> :::::: TO: James Morse <james.morse@xxxxxxx>
>> :::::: CC: Catalin Marinas <catalin.marinas@xxxxxxx>
>
> Hi all,
>
> This report has some validity but the code doesn't look buggy as is, just
> off-by-one errors correcting each other. The variable is called "..._sz"
> (~ size), but the resource size calculation is off-by-one because trying Arm A-profile Architecture Hi
> to do it by hand instead of using the resource_size() helper.
>
> The mapped_hwpage_sz value is only used for register write offset
> sanity checks, which use > countering the off-by-one error.

Ah, yes, thanks for pointing this out. mapped_hwpage_sz is a misleading name as it really indicates
the last byte mapped and so it is functionally correct when used with >.

>
> IMO, it would be better to use resource_size() and change those sanity
> checks to use >= instead of > but this doesn't look a major problem by
> any means.

Agreed. Looking back I fixed the functional bug in v6 (changed >= to >) of the original mpam driver
posting but left it in a confusing state.

Thanks,

Ben

>