arm_mpam: Add support for the MPAM v0.1 architecture version
Subsystems (2)
James Morse
maintainerv3 cover arm_mpam: Add support for the MPAM v0.1 architecture version
This is a v3 of Zeng's series to add support for MPAM v0.1. Included are the changes Ben and I suggested, and a couple of bugs found while testing it.
I've put the bug fixes first as you can hit these with mainline. The patches for v0.1 enable MPAM on those platforms as this extra ID register was missed.
Based on v7.1-rc2, and can be retrieved from
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/arch_v0.1/v3
Thanks,
James
v2: https://patch.msgid.link/[email protected]
v1: https://lore.kernel.org/all/[email protected]/
James Morse (2):
arm_mpam: Fix false positive assert failure during mpam_disable()
arm_mpam: Check whether the config array is allocated before
destroying it
Zeng Heng (2):
arm64: cpufeature: Add support for the MPAM v0.1 architecture version
arm_mpam: Update architecture version check for MPAM MSC
arch/arm64/include/asm/cpufeature.h | 7 ++++++ arch/arm64/include/asm/el2_setup.h | 4 +++- arch/arm64/kernel/cpufeature.c | 15 ++++++++---- drivers/resctrl/mpam_devices.c | 36 +++++++++++++++++++++++++---- drivers/resctrl/mpam_internal.h | 1 + 5 files changed, 53 insertions(+), 10 deletions(-)
Signature · 1 line
2.53.0
James Morse
maintainerPATCH v3 1/4 arm_mpam: Fix false positive assert failure during mpam_disable()
mpam_assert_partid_sizes_fixed() is used to document that the caller doesn't expect the discovered PARTID size to change while it is walking a list sized by PARTID. Typically the MSC state is not written to until all the MSC have been discovered and this value is set.
However, if discovering the MSC fails and schedules mpam_disable(), then the MSC state is written to reset it. In this case the discovered PARTID size may be become smaller - but only PARTID 0 will be used once resctrl_exit() has been called.
Skip the WARN_ON_ONCE() if mpam_disable_reason has been set.
--- drivers/resctrl/mpam_devices.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +8 -2
@@ -164,11 +164,17 @@ static void mpam_free_garbage(void)/* * Once mpam is enabled, new requestors cannot further reduce the available * partid. Assert that the size is fixed, and new requestors will be turned -* away. +* away. This is needed when walking over structures sized by PARTID. +* +* During mpam_disable() these structures are not fixed, but the MSC state +* is still reset using whatever sizes have been discovered so far. As only +* PARTID 0 will be used after mpam_disable(), any race would be benign. +* Skip the check if a mpam_disable_reason has been set. */ static void mpam_assert_partid_sizes_fixed (void ) { -WARN_ON_ONCE (!partid_max_published); +if (!mpam_disable_reason) +WARN_ON_ONCE (!partid_max_published); }static u32 __mpam_read_reg (struct mpam_msc *msc,u16 reg)
Signature · 1 line
2.53.0
Re: [PATCH v3 1/4] arm_mpam: Fix false positive assert failure during mpam_disable()
Hi James,
Quoted 29 lines · James Morse
mpam_assert_partid_sizes_fixed()is used to document that the caller doesn't expect the discovered PARTID size to change while it is walking a list sized by PARTID. Typically the MSC state is not written to until all the MSC have been discovered and this value is set.However, if discovering the MSC fails and schedules
mpam_disable(), then the MSC state is written to reset it. In this case the discovered PARTID size may be become smaller - but only PARTID 0 will be used onceresctrl_exit()has been called.Skip the
WARN_ON_ONCE()ifmpam_disable_reasonhas been set.Fixes 3bd04fe7d807bb ("arm_mpam: Extend reset logic to allow devices to be reset at any time")Signed-off-by James Morse <[email protected]>--- drivers/resctrl/mpam_devices.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +2
-1@@ -164,11 +164,17 @@ static void mpam_free_garbage(void)/* * Once mpam is enabled, new requestors cannot further reduce the available * partid. Assert that the size is fixed, and new requestors will be turned -* away. +* away. This is needed when walking over structures sized by PARTID. +*
drivers/resctrl/mpam_devices.c static void mpam_free_garbage(void) · line 177
Quoted 10 lines
drivers/resctrl/mpam_devices.c +6
-1+* During mpam_disable() these structures are not fixed, but the MSC state +* is still reset using whatever sizes have been discovered so far. As only +* PARTID 0 will be used after mpam_disable(), any race would be benign. +* Skip the check if a mpam_disable_reason has been set. */ static void mpam_assert_partid_sizes_fixed (void ) { -WARN_ON_ONCE (!partid_max_published); +if (!mpam_disable_reason) +WARN_ON_ONCE (!partid_max_published);
A little bit nasty to use mpam_disable_reason this way but a simple better way eludes me.
Thanks,
Ben
Quoted 3 lines
drivers/resctrl/mpam_devices.c +0
-0}static u32 __mpam_read_reg (struct mpam_msc *msc,u16 reg)
James Morse
maintainerPATCH v3 2/4 arm_mpam: Check whether the config array is allocated before destroying it
In reply to James Morse__destroy_component_cfg() is called to free the configuration array. It uses the embedded 'garbage' structure, which means the array has to be allocated.
If __destroy_component_cfg() is called from mpam_disable() before the configuration was ever allocated, then a NULL pointer is dereferenced.
Check for this case and return early if the configuration is not allocated.
__destroy_component_cfg() also frees the mbwu_state as this is allocated by __allocate_component_cfg(). As the mbwu_state is allocated after comp->cfg is set, and is also under mpam_list_lock, only the first pointer needs checking.
--- drivers/resctrl/mpam_devices.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/resctrl/mpam_devices.c +3 -0
@@ -2591,6 +2591,9 @@ static void __destroy_component_cfg(struct mpam_component *comp)lockdep_assert_held (&mpam_list_lock); +if (!comp->cfg) +return ; +add_to_garbage (comp->cfg);list_for_each_entry (vmsc, &comp->vmsc, comp_list) { msc = vmsc->msc;
Signature · 1 line
2.53.0
Re: [PATCH v3 2/4] arm_mpam: Check whether the config array is allocated before destroying it
Hi James,
Quoted 10 lines · James Morse
__destroy_component_cfg()is called to free the configuration array. It uses the embedded 'garbage' structure, which means the array has to be allocated.If
__destroy_component_cfg()is called frommpam_disable()before the configuration was ever allocated, then a NULL pointer is dereferenced.Check for this case and return early if the configuration is not allocated.
Quoted 7 lines
__destroy_component_cfg()also frees thembwu_stateas this is allocated by__allocate_component_cfg(). As thembwu_stateis allocated aftercomp->cfgis set, and is also undermpam_list_lock, only the first pointer needs checking.Fixes 3bd04fe7d807bb ("arm_mpam: Extend reset logic to allow devices to be reset any time")Signed-off-by James Morse <[email protected]>
I checked on the FVP and with this and the previous patch and an early mpam_disable due to an unsupported MSC version doesn't cause any problems. Additionally, the kunit tests still run and pass.
Thanks,
Ben
James Morse
maintainerPATCH v3 3/4 arm64: cpufeature: Add support for the MPAM v0.1 architecture version
In reply to James MorseFrom: Zeng Heng <[email protected]>
According to the MPAM spec [1], the supported architecture versions are v1.0, v1.1 and v0.1. MPAM versions v0.1 and v1.1 are functionally identical, but v0.1 additionally supports the FORCE_NS feature.
ID_AA64PR | ID_AA64PR | MPAM Extension | Notes
F0_EL1. | F1_EL1. | Architecture |
MPAM | MPAM_frac | version |
---------------------------------------------------------------------------
0b0000 | 0b0001 | v0.1 | MPAM v0.1 is implemented.
| | | MPAM v0.1 is the same as MPAM v1.1
| | | with FORCE_NS which is
| | | incompatible with MPAM v1.0.
---------------------------------------------------------------------------
0b0001 | 0b0000 | v1.0 | MPAM v1.0 is implemented.
---------------------------------------------------------------------------
0b0001 | 0b0001 | v1.1 | MPAM v1.1 is implemented.
| | | MPAM v1.1 includes all features of
| | | MPAM v1.0.
| | | It must not include FORCE_NS.FORCE_NS is a feature that operates in EL3 mode. Consequently, the current Linux MPAM driver is also compatible with MPAM v0.1. To support v0.1, the existing driver which only checks ID_AA64PFR0_EL1.MPAM for the major version needs to examine ID_AA64PFR1_EL1.MPAM_frac for the minor version as well.
[1] https://developer.arm.com/documentation/ddi0598/db/?lang=en
--- arch/arm64/include/asm/cpufeature.h | 7 +++++++ arch/arm64/include/asm/el2_setup.h | 4 +++- arch/arm64/kernel/cpufeature.c | 15 +++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-)
arch/arm64/include/asm/cpufeature.h +7 -0
@@ -620,6 +620,13 @@ static inline bool id_aa64pfr0_mpam(u64 pfr0)return val >0 ; } +static inline bool id_aa64pfr1_mpamfrac (u64 pfr1) +{ +u32 val =cpuid_feature_extract_unsigned_field (pfr1, ID_AA64PFR1_EL1_MPAM_frac_SHIFT); + +return val >0 ; +} +static inline bool id_aa64pfr1_mte (u64 pfr1) {u32 val =cpuid_feature_extract_unsigned_field (pfr1,ID_AA64PFR1_EL1_MTE_SHIFT );
arch/arm64/include/asm/el2_setup.h +3 -1
@@ -510,7 +510,9 @@#endif .macro finalise_el2_state - check_override id_aa64pfr0, ID_AA64PFR0_EL1_MPAM_SHIFT, .Linit_mpam_\@, .Lskip_mpam_\@, x1, x2 + check_override id_aa64pfr0, ID_AA64PFR0_EL1_MPAM_SHIFT, .Linit_mpam_\@, .Lmpam_minor_\@, x1, x2 +.Lmpam_minor_\@: + check_override id_aa64pfr1, ID_AA64PFR1_EL1_MPAM_frac_SHIFT, .Linit_mpam_\@, .Lskip_mpam_\@, x1, x2 .Linit_mpam_\@: mov x0, #MPAM2_EL2_EnMPAMSM_MASK
arch/arm64/kernel/cpufeature.c +11 -4
@@ -1164,6 +1164,14 @@ static __init void detect_system_supports_pseudo_nmi(void)static inline void detect_system_supports_pseudo_nmi (void ) { }#endif +static bool detect_ftr_has_mpam (void ) +{ +u64 pfr0 =read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ); +u64 pfr1 =read_sanitised_ftr_reg (SYS_ID_AA64PFR1_EL1 ); + +return id_aa64pfr0_mpam (pfr0) ||id_aa64pfr1_mpamfrac (pfr1); +} +void __init init_cpu_features (struct cpuinfo_arm64 *info) {/* Before we start using the tables, make sure it is sorted */
@@ -1211,7 +1219,7 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info)cpacr_restore (cpacr); } -if (id_aa64pfr0_mpam (read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ))) { +if (detect_ftr_has_mpam ()) { info->reg_mpamidr =read_cpuid (MPAMIDR_EL1 );init_cpu_ftr_reg (SYS_MPAMIDR_EL1 , info->reg_mpamidr); }
@@ -1467,7 +1475,7 @@ void update_cpu_features(int cpu,cpacr_restore (cpacr); } -if (id_aa64pfr0_mpam (read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ))) { +if (detect_ftr_has_mpam ()) { info->reg_mpamidr =read_cpuid (MPAMIDR_EL1 ); taint |=check_update_ftr_reg (SYS_MPAMIDR_EL1 , cpu, info->reg_mpamidr, boot->reg_mpamidr);
@@ -2486,7 +2494,7 @@ cpucap_panic_on_conflict(const struct arm64_cpu_capabilities *cap)static bool test_has_mpam (const struct arm64_cpu_capabilities *entry,int scope) { -if (!has_cpuid_feature (entry, scope)) +if (!detect_ftr_has_mpam ())return false;/* Check firmware actually enabled MPAM on this cpu. */
@@ -3093,7 +3101,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .capability = ARM64_MPAM, .matches = test_has_mpam, .cpu_enable = cpu_enable_mpam, -ARM64_CPUID_FIELDS (ID_AA64PFR0_EL1 ,MPAM ,1 ) }, { .desc = "Memory Partitioning And Monitoring Virtualisation",
Signature · 1 line
2.53.0
Re: [PATCH v3 3/4] arm64: cpufeature: Add support for the MPAM v0.1 architecture version
Quoted 28 lines · James Morse
From: Zeng Heng <[email protected]>
According to the MPAM spec [1], the supported architecture versions are v1.0, v1.1 and v0.1. MPAM versions v0.1 and v1.1 are functionally identical, but v0.1 additionally supports the
FORCE_NSfeature.ID_AA64PR | ID_AA64PR | MPAM Extension | Notes F0_EL1. | F1_EL1. | Architecture | MPAM | MPAM_frac | version | --------------------------------------------------------------------------- 0b0000 | 0b0001 | v0.1 | MPAM v0.1 is implemented. | | | MPAM v0.1 is the same as MPAM v1.1 | | | with FORCE_NS which is | | | incompatible with MPAM v1.0. --------------------------------------------------------------------------- 0b0001 | 0b0000 | v1.0 | MPAM v1.0 is implemented. --------------------------------------------------------------------------- 0b0001 | 0b0001 | v1.1 | MPAM v1.1 is implemented. | | | MPAM v1.1 includes all features of | | | MPAM v1.0. | | | It must not include FORCE_NS.
FORCE_NSis a feature that operates in EL3 mode. Consequently, the current Linux MPAM driver is also compatible with MPAM v0.1. To support v0.1, the existing driver which only checks ID_AA64PFR0_EL1.MPAM for the major version needs to examine ID_AA64PFR1_EL1.MPAM_frac for the minor version as well.
Quoted 5 lines
[1] https://developer.arm.com/documentation/ddi0598/db/?lang=en
Signed-off-by Zeng Heng <[email protected]>Reviewed-by James Morse <[email protected]>Signed-off-by James Morse <[email protected]>
Not sure how this will go in for 7.2, so:
James Morse
maintainerPATCH v3 4/4 arm_mpam: Update architecture version check for MPAM MSC
In reply to James MorseFrom: Zeng Heng <[email protected]>
In addition to updating the CPU MPAM version check, the MPAM MSC version check also need to be updated. mpam_msc_check_aidr() is added to check the MSC AIDR register, ensuring that both the major and minor version numbers fall within the supported range of the MPAM architecture version.
--- drivers/resctrl/mpam_devices.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/resctrl/mpam_devices.c +20 -3
@@ -224,6 +224,24 @@ static inline void _mpam_write_monsel_reg(struct mpam_msc *msc, u16 reg, u32 val#define mpam_write_monsel_reg (msc, reg, val) _mpam_write_monsel_reg(msc, MSMON_##reg, val) +static bool mpam_msc_check_aidr (struct mpam_msc *msc) +{ +u32 aidr =__mpam_read_reg (msc,MPAMF_AIDR ); +u32 major =FIELD_GET (MPAMF_AIDR_ARCH_MAJOR_REV , aidr); +u32 minor =FIELD_GET (MPAMF_AIDR_ARCH_MINOR_REV , aidr); + +/* +* v0.0 and >v2.x aren't supported, but anything else should be backward +* compatible to v0.1 or v1.0. +*/ +if (!major && !minor) +return false; +if (major >1 ) +return false; + +return true; +} +static u64 mpam_msc_read_idr (struct mpam_msc *msc) {u64 idr_high =0 , idr_low;
@@ -951,9 +969,8 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)lockdep_assert_held (&msc->probe_lock); - idr =__mpam_read_reg (msc,MPAMF_AIDR ); -if ((idr &MPAMF_AIDR_ARCH_MAJOR_REV ) !=MPAM_ARCHITECTURE_V1 ) { -dev_err_once (dev,"MSC does not match MPAM architecture v1.x\n" ); +if (!mpam_msc_check_aidr (msc)) { +dev_err_once (dev,"MSC does not match architecture v1.x\n" );return -EIO ; }
Signature · 1 line
2.53.0
Re: [PATCH v3 4/4] arm_mpam: Update architecture version check for MPAM MSC
Hi James,
Quoted 44 lines · James Morse
From: Zeng Heng <[email protected]>
In addition to updating the CPU MPAM version check, the MPAM MSC version check also need to be updated.
mpam_msc_check_aidr()is added to check the MSC AIDR register, ensuring that both the major and minor version numbers fall within the supported range of the MPAM architecture version.Signed-off-by Zeng Heng <[email protected]>[ morse: changed mpam_msc_check_aidr() to accept versions like v1.2 ]Signed-off-by James Morse <[email protected]>--- drivers/resctrl/mpam_devices.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +18
-0@@ -224,6 +224,24 @@ static inline void _mpam_write_monsel_reg(struct mpam_msc *msc, u16 reg, u32 val#define mpam_write_monsel_reg (msc, reg, val) _mpam_write_monsel_reg(msc, MSMON_##reg, val) +static bool mpam_msc_check_aidr (struct mpam_msc *msc) +{ +u32 aidr =__mpam_read_reg (msc,MPAMF_AIDR ); +u32 major =FIELD_GET (MPAMF_AIDR_ARCH_MAJOR_REV , aidr); +u32 minor =FIELD_GET (MPAMF_AIDR_ARCH_MINOR_REV , aidr); + +/* +* v0.0 and >v2.x aren't supported, but anything else should be backward +* compatible to v0.1 or v1.0. +*/ +if (!major && !minor) +return false; +if (major >1 ) +return false; + +return true; +} +static u64 mpam_msc_read_idr (struct mpam_msc *msc) {u64 idr_high =0 , idr_low;
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 955
Quoted 5 lines
drivers/resctrl/mpam_devices.c +0
-2@@ -951,9 +969,8 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)lockdep_assert_held (&msc->probe_lock); - idr =__mpam_read_reg (msc,MPAMF_AIDR ); -if ((idr &MPAMF_AIDR_ARCH_MAJOR_REV ) !=MPAM_ARCHITECTURE_V1 ) {
nit: MPAM_ARCHITECTURE_V1 is now unused.
Thanks,
Ben
Quoted 6 lines
drivers/resctrl/mpam_devices.c +2
-1-dev_err_once (dev,"MSC does not match MPAM architecture v1.x\n" ); +if (!mpam_msc_check_aidr (msc)) { +dev_err_once (dev,"MSC does not match architecture v1.x\n" );return -EIO ; }
Re: [PATCH v3 4/4] arm_mpam: Update architecture version check for MPAM MSC
Hi all,
Quoted 25 lines · Ben Horgan
Hi James,
Quoted 22 lines · James Morse
From: Zeng Heng <[email protected]>
In addition to updating the CPU MPAM version check, the MPAM MSC version check also need to be updated.
mpam_msc_check_aidr()is added to check the MSC AIDR register, ensuring that both the major and minor version numbers fall within the supported range of the MPAM architecture version.Signed-off-by Zeng Heng <[email protected]>[ morse: changed mpam_msc_check_aidr() to accept versions like v1.2 ]Signed-off-by James Morse <[email protected]>--- drivers/resctrl/mpam_devices.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +0
-0@@ -224,6 +224,24 @@ static inline void _mpam_write_monsel_reg(struct mpam_msc *msc, u16 reg, u32 val#define mpam_write_monsel_reg (msc, reg, val) _mpam_write_monsel_reg(msc, MSMON_##reg, val)
Quoted 13 lines
drivers/resctrl/mpam_devices.c static inline void _mpam_write_monsel_reg(struct mpam_msc *msc, u16 reg, u32 val
Quoted 13 lines
drivers/resctrl/mpam_devices.c +13
-0+static bool mpam_msc_check_aidr (struct mpam_msc *msc) +{ +u32 aidr =__mpam_read_reg (msc,MPAMF_AIDR ); +u32 major =FIELD_GET (MPAMF_AIDR_ARCH_MAJOR_REV , aidr); +u32 minor =FIELD_GET (MPAMF_AIDR_ARCH_MINOR_REV , aidr); + +/* +* v0.0 and >v2.x aren't supported, but anything else should be backward +* compatible to v0.1 or v1.0. +*/ +if (!major && !minor) +return false; + if (major > 1) >> + return false;
Would it make sense to introduce a new macro that defines the maximum supported major version?
~~~
#define MPAM_ARCH_MAJOR_VERSION_MAX 0x1
if (major > MPAM_ARCH_MAJOR_VERSION_MAX)
return false;
~~~
Best regards,
Zeng Heng
Quoted 17 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 955
Quoted 13 lines
drivers/resctrl/mpam_devices.c +4
-2+ +return true; +} +static u64 mpam_msc_read_idr (struct mpam_msc *msc) {u64 idr_high =0 , idr_low;@@ -951,9 +969,8 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)lockdep_assert_held (&msc->probe_lock); - idr =__mpam_read_reg (msc,MPAMF_AIDR ); - if ((idr & MPAMF_AIDR_ARCH_MAJOR_REV) != MPAM_ARCHITECTURE_V1) { >nit:
MPAM_ARCHITECTURE_V1is now unused.Reviewed-by Ben Horgan <[email protected]>
Re: (subset) [PATCH v3 0/4] arm_mpam: Add support for the MPAM v0.1 architecture version
In reply to James MorseQuoted 9 lines · James Morse
This is a v3 of Zeng's series to add support for MPAM v0.1. Included are the changes Ben and I suggested, and a couple of bugs found while testing it.
I've put the bug fixes first as you can hit these with mainline. The patches for v0.1 enable MPAM on those platforms as this extra ID register was missed.
[...]
Applied to arm64 (for-next/fixes), thanks!
[1/4] arm_mpam: Fix false positive assert failure during mpam_disable()
https://git.kernel.org/arm64/c/f1caff3335ea [2/4] arm_mpam: Check whether the config array is allocated before destroying it https://git.kernel.org/arm64/c/6ccbb613b42a
I'll leave the other two patches adding MPAM 0.1 support for the next merging window.
Quoted 9 lines · James Morse
This is a v3 of Zeng's series to add support for MPAM v0.1. Included are the changes Ben and I suggested, and a couple of bugs found while testing it.
I've put the bug fixes first as you can hit these with mainline. The patches for v0.1 enable MPAM on those platforms as this extra ID register was missed.
[...]
Applied to arm64 (for-next/mpam), thanks!
[1/4] arm_mpam: Fix false positive assert failure during mpam_disable()
(no commit info)
[2/4] arm_mpam: Check whether the config array is allocated before destroying it
(no commit info)
[3/4] arm64: cpufeature: Add support for the MPAM v0.1 architecture version
https://git.kernel.org/arm64/c/5302bc1493be [4/4] arm_mpam: Update architecture version check for MPAM MSC https://git.kernel.org/arm64/c/50a42e03cdbd
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev