v7.0-rc2+ Fixes for mpam driver
James Morse
maintainercover v7.0-rc2+ Fixes for mpam driver
Hi Will, Catalin,
How do you want to handle fixes for the mpam driver? Currently its hidden behind CONFIG_EXPERT as there is no user-interface to it yet, but these are the issues that can be hit with mainline today.
The first fixes a dereference of an uninitialised variable when restoring state following cpuhp. The other two are warnings in the kunit code. (which I wouldn't send now without the first one).
If its helpful, there is a signed tag with some verbage here:git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/fixes/v7.0-rc2
---
mpam driver fixes for v7.0
- Fix dereference of an uninitialised variable when restoring state.
- Fix a pre-empt warning in kunit tests.
- Fix a sparse warning in kunit tests.
---
Let me know if a proper pull request is the right way to go.
Thanks,
James
Ben Horgan (2):
arm_mpam: Fix null pointer dereference when restoring bandwidth
counters
arm_mpam: Disable preemption when making accesses to fake MSC in kunit
test
Krzysztof Kozlowski (1):
arm_mpam: Force __iomem casts
drivers/resctrl/mpam_devices.c | 2 ++ drivers/resctrl/test_mpam_devices.c | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-)
Signature · 1 line
2.51.0
James Morse
maintainerPATCH 1/3 arm_mpam: Fix null pointer dereference when restoring bandwidth counters
From: Ben Horgan <[email protected]>
When an MSC supporting memory bandwidth monitoring is brought offline and then online, mpam_restore_mbwu_state() calls __ris_msmon_read() via ipi to restore the configuration of the bandwidth counters. It doesn't care about the value read, mbwu_arg.val, and doesn't set it leading to a null pointer dereference when __ris_msmon_read() adds to it. This results in a kernel oops with a call trace such as:
Call trace: __ris_msmon_read+0x19c/0x64c (P) mpam_restore_mbwu_state+0xa0/0xe8 smp_call_on_cpu_callback+0x1c/0x38 process_one_work+0x154/0x4b4 worker_thread+0x188/0x310 kthread+0x11c/0x130 ret_from_fork+0x10/0x20
Provide a local variable for val to avoid __ris_msmon_read() dereferencing a null pointer when adding to val.
--- drivers/resctrl/mpam_devices.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/resctrl/mpam_devices.c +2 -0
@@ -1428,6 +1428,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,static int mpam_restore_mbwu_state (void *_ris) {int i; +u64 val;struct mon_read mwbu_arg;struct mpam_msc_ris *ris = _ris;struct mpam_class *class = ris->vmsc->comp->class;
@@ -1437,6 +1438,7 @@ static int mpam_restore_mbwu_state(void *_ris) mwbu_arg.ris = ris; mwbu_arg.ctx = &ris->mbwu_state[i].cfg; mwbu_arg.type =mpam_msmon_choose_counter (class); + mwbu_arg.val = &val;__ris_msmon_read (&mwbu_arg); }
Signature · 1 line
2.51.0
James Morse
maintainerPATCH 2/3 arm_mpam: Disable preemption when making accesses to fake MSC in kunit test
In reply to James MorseFrom: Ben Horgan <[email protected]>
Accesses to MSC must be made from a cpu that is affine to that MSC and the driver checks this in __mpam_write_reg() using smp_processor_id(). A fake in-memory MSC is used for testing. When using that, it doesn't matter which cpu we access it from but calling smp_processor_id() from a preemptible context gives warnings when running with CONFIG_DEBUG_PREEMPT.
Add a test helper that wraps mpam_reset_msc_bitmap() with preemption disabled to ensure all (fake) MSC accesses are made with preemption disabled.
--- drivers/resctrl/test_mpam_devices.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/resctrl/test_mpam_devices.c +13 -5
@@ -322,6 +322,14 @@ static void test_mpam_enable_merge_features(struct kunit *test)mutex_unlock (&mpam_list_lock); } +static void __test_mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) +{ +/* Avoid warnings when running with CONFIG_DEBUG_PREEMPT */ +guard (preempt)(); + +mpam_reset_msc_bitmap (msc, reg, wd); +} +static void test_mpam_reset_msc_bitmap (struct kunit *test) {char __iomem *buf =kunit_kzalloc (test,SZ_16K ,GFP_KERNEL );
@@ -341,31 +349,31 @@ static void test_mpam_reset_msc_bitmap(struct kunit *test) test_result = (u32 *)(buf +MPAMCFG_CPBM ); -mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,0 ); +__test_mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,0 );KUNIT_EXPECT_EQ (test, test_result[0 ],0 );KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); test_result[0 ] =0 ; test_result[1 ] =0 ; -mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,1 ); +__test_mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,1 );KUNIT_EXPECT_EQ (test, test_result[0 ],1 );KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); test_result[0 ] =0 ; test_result[1 ] =0 ; -mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,16 ); +__test_mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,16 );KUNIT_EXPECT_EQ (test, test_result[0 ],0xffff );KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); test_result[0 ] =0 ; test_result[1 ] =0 ; -mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,32 ); +__test_mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,32 );KUNIT_EXPECT_EQ (test, test_result[0 ],0xffffffff );KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); test_result[0 ] =0 ; test_result[1 ] =0 ; -mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,33 ); +__test_mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,33 );KUNIT_EXPECT_EQ (test, test_result[0 ],0xffffffff );KUNIT_EXPECT_EQ (test, test_result[1 ],1 ); test_result[0 ] =0 ;
Signature · 1 line
2.51.0
James Morse
maintainerPATCH 3/3 arm_mpam: Force __iomem casts
In reply to James MorseFrom: Krzysztof Kozlowski <[email protected]>
Code allocates standard kernel memory to pass to the MPAM, which expects __iomem. The code is safe, because __iomem accessors should work fine on kernel mapped memory, however leads to sparse warnings:
test_mpam_devices.c:327:42: warning: incorrect type in initializer (different address spaces)
test_mpam_devices.c:327:42: expected char [noderef] __iomem *buf
test_mpam_devices.c:327:42: got void *
test_mpam_devices.c:342:24: warning: cast removes address space '__iomem' of expression
Cast the pointer to memory via __force to silence them.
--- drivers/resctrl/test_mpam_devices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/resctrl/test_mpam_devices.c +2 -2
@@ -332,7 +332,7 @@ static void __test_mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)static void test_mpam_reset_msc_bitmap (struct kunit *test) { -char __iomem *buf =kunit_kzalloc (test,SZ_16K ,GFP_KERNEL ); +char __iomem *buf = (__force char __iomem *)kunit_kzalloc (test,SZ_16K ,GFP_KERNEL );struct mpam_msc fake_msc = {};u32 *test_result;
@@ -347,7 +347,7 @@ static void test_mpam_reset_msc_bitmap(struct kunit *test)mutex_init (&fake_msc.part_sel_lock);mutex_lock (&fake_msc.part_sel_lock); - test_result = (u32 *)(buf +MPAMCFG_CPBM ); + test_result = (__force u32 *)(buf +MPAMCFG_CPBM );__test_mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,0 );KUNIT_EXPECT_EQ (test, test_result[0 ],0 );
Signature · 1 line
2.51.0
Will Deacon
AppliedQuoted 9 lines · James Morse
How do you want to handle fixes for the mpam driver? Currently its hidden behind
CONFIG_EXPERTas there is no user-interface to it yet, but these are the issues that can be hit with mainline today.The first fixes a dereference of an uninitialised variable when restoring state following cpuhp. The other two are warnings in the kunit code. (which I wouldn't send now without the first one).
[...]
Applied to arm64 (for-next/fixes), thanks!
[1/3] arm_mpam: Fix null pointer dereference when restoring bandwidth counters
https://git.kernel.org/arm64/c/4ad79c874e53 [2/3] arm_mpam: Disable preemption when making accesses to fake MSC in kunit test https://git.kernel.org/arm64/c/c1376f1ff3f0 [3/3] arm_mpam: Force __iomem casts https://git.kernel.org/arm64/c/fb75437b4478
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev