[PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()

Babu Moger posted 23 patches 1 year ago
There is a newer version of this series
[PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Posted by Babu Moger 1 year ago
resctrl_late_init() has the __init attribute, but some of the functions
called from it do not have the __init attribute.

Add the __init attribute to all the functions in the call sequences to
maintain consistency throughout.

Fixes: 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")
Fixes: def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")
Fixes: bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v11: No changes.

v10: Text changes.
     Added __init attribute to cache_alloc_hsw_probe()
     Followed function prototype rules (preferred order is storage
     class before return type).

v9: Moved the patch to the begining of the series.
    Fixed all the call sequences. Added additional Fixed tags.

v8: New patch.
---
 arch/x86/kernel/cpu/resctrl/core.c     | 10 +++++-----
 arch/x86/kernel/cpu/resctrl/internal.h |  2 +-
 arch/x86/kernel/cpu/resctrl/monitor.c  |  4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 3d1735ed8d1f..f0a331287979 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -145,7 +145,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)
  * is always 20 on hsw server parts. The minimum cache bitmask length
  * allowed for HSW server is always 2 bits. Hardcode all of them.
  */
-static inline void cache_alloc_hsw_probe(void)
+static inline __init void cache_alloc_hsw_probe(void)
 {
 	struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3];
 	struct rdt_resource *r  = &hw_res->r_resctrl;
@@ -277,7 +277,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
 	return true;
 }
 
-static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
+static __init void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	union cpuid_0x10_1_eax eax;
@@ -296,7 +296,7 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
 	r->alloc_capable = true;
 }
 
-static void rdt_get_cdp_config(int level)
+static __init void rdt_get_cdp_config(int level)
 {
 	/*
 	 * By default, CDP is disabled. CDP can be enabled by mount parameter
@@ -306,12 +306,12 @@ static void rdt_get_cdp_config(int level)
 	rdt_resources_all[level].r_resctrl.cdp_capable = true;
 }
 
-static void rdt_get_cdp_l3_config(void)
+static __init void rdt_get_cdp_l3_config(void)
 {
 	rdt_get_cdp_config(RDT_RESOURCE_L3);
 }
 
-static void rdt_get_cdp_l2_config(void)
+static __init void rdt_get_cdp_l2_config(void)
 {
 	rdt_get_cdp_config(RDT_RESOURCE_L2);
 }
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index 20c898f09b7e..05358e78147b 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -634,7 +634,7 @@ int closids_supported(void);
 void closid_free(int closid);
 int alloc_rmid(u32 closid);
 void free_rmid(u32 closid, u32 rmid);
-int rdt_get_mon_l3_config(struct rdt_resource *r);
+int __init rdt_get_mon_l3_config(struct rdt_resource *r);
 void __exit rdt_put_mon_l3_config(void);
 bool __init rdt_cpu_has(int flag);
 void mon_event_count(void *info);
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index 94a1d9780461..1c7b574bf0cd 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -979,7 +979,7 @@ void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long delay_
 		schedule_delayed_work_on(cpu, &dom->mbm_over, delay);
 }
 
-static int dom_data_init(struct rdt_resource *r)
+static __init int dom_data_init(struct rdt_resource *r)
 {
 	u32 idx_limit = resctrl_arch_system_num_rmid_idx();
 	u32 num_closid = resctrl_arch_get_num_closid(r);
@@ -1077,7 +1077,7 @@ static struct mon_evt mbm_local_event = {
  * because as per the SDM the total and local memory bandwidth
  * are enumerated as part of L3 monitoring.
  */
-static void l3_mon_evt_init(struct rdt_resource *r)
+static __init void l3_mon_evt_init(struct rdt_resource *r)
 {
 	INIT_LIST_HEAD(&r->evt_list);
 
-- 
2.34.1
Re: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Posted by Dave Martin 11 months, 3 weeks ago
Hi,

On Wed, Jan 22, 2025 at 02:20:09PM -0600, Babu Moger wrote:
> resctrl_late_init() has the __init attribute, but some of the functions
> called from it do not have the __init attribute.
> 
> Add the __init attribute to all the functions in the call sequences to
> maintain consistency throughout.

(BTW, did you just find these cases by inspection, or were you getting
build warnings?

Even with CONFIG_DEBUG_SECTION_MISMATCH=y, I struggle to get build
warnings about section mismatches on inlined functions.  Even building
with -fno-inline doesn't flag them all up (though I don't think this
suppresses all inlining).

If you have a way of tracking these cases down automatically, I'd be
interested to know so that I can apply it elsewhere.)

Cheers
---Dave


> 
> Fixes: 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")
> Fixes: def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")
> Fixes: bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")
> Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---

[...]

> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 3d1735ed8d1f..f0a331287979 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -145,7 +145,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)
>   * is always 20 on hsw server parts. The minimum cache bitmask length
>   * allowed for HSW server is always 2 bits. Hardcode all of them.
>   */
> -static inline void cache_alloc_hsw_probe(void)
> +static inline __init void cache_alloc_hsw_probe(void)
>  {
>  	struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3];
>  	struct rdt_resource *r  = &hw_res->r_resctrl;
> @@ -277,7 +277,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)

[...]
Re: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Posted by Moger, Babu 11 months, 3 weeks ago
Hi Dave,

On 2/19/25 07:28, Dave Martin wrote:
> Hi,
> 
> On Wed, Jan 22, 2025 at 02:20:09PM -0600, Babu Moger wrote:
>> resctrl_late_init() has the __init attribute, but some of the functions
>> called from it do not have the __init attribute.
>>
>> Add the __init attribute to all the functions in the call sequences to
>> maintain consistency throughout.
> 
> (BTW, did you just find these cases by inspection, or were you getting
> build warnings?
> 
> Even with CONFIG_DEBUG_SECTION_MISMATCH=y, I struggle to get build
> warnings about section mismatches on inlined functions.  Even building
> with -fno-inline doesn't flag them all up (though I don't think this
> suppresses all inlining).
> 
> If you have a way of tracking these cases down automatically, I'd be
> interested to know so that I can apply it elsewhere.)

It is mostly by code inspection at this point.

You can refer to this commit [1].

We used to see section mismatch warnings when non-init functions call
__init functions.

MODPOST Module.symvers
WARNING: modpost: vmlinux: section mismatch in reference:
rdt_get_mon_l3_config+0x2b5 (section: .text) -> rdt_cpu_has (section:
.init.text)
WARNING: modpost: vmlinux: section mismatch in reference:
rdt_get_mon_l3_config+0x408 (section: .text) -> rdt_cpu_has (section:
.init.text)


1.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.14-rc3&id=bd334c86b5d70e5d1c6169991802e62c828d6f38

> 
> Cheers
> ---Dave
> 
> 
>>
>> Fixes: 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")
>> Fixes: def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")
>> Fixes: bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")
>> Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
> 
> [...]
> 
>> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
>> index 3d1735ed8d1f..f0a331287979 100644
>> --- a/arch/x86/kernel/cpu/resctrl/core.c
>> +++ b/arch/x86/kernel/cpu/resctrl/core.c
>> @@ -145,7 +145,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)
>>   * is always 20 on hsw server parts. The minimum cache bitmask length
>>   * allowed for HSW server is always 2 bits. Hardcode all of them.
>>   */
>> -static inline void cache_alloc_hsw_probe(void)
>> +static inline __init void cache_alloc_hsw_probe(void)
>>  {
>>  	struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3];
>>  	struct rdt_resource *r  = &hw_res->r_resctrl;
>> @@ -277,7 +277,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
> 
> [...]
> 

-- 
Thanks
Babu Moger
Re: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Posted by Dave Martin 11 months, 3 weeks ago
Hi,

On Wed, Feb 19, 2025 at 10:53:41AM -0600, Moger, Babu wrote:
> Hi Dave,
> 
> On 2/19/25 07:28, Dave Martin wrote:
> > Hi,
> > 
> > On Wed, Jan 22, 2025 at 02:20:09PM -0600, Babu Moger wrote:
> >> resctrl_late_init() has the __init attribute, but some of the functions
> >> called from it do not have the __init attribute.
> >>
> >> Add the __init attribute to all the functions in the call sequences to
> >> maintain consistency throughout.
> > 
> > (BTW, did you just find these cases by inspection, or were you getting
> > build warnings?
> > 
> > Even with CONFIG_DEBUG_SECTION_MISMATCH=y, I struggle to get build
> > warnings about section mismatches on inlined functions.  Even building
> > with -fno-inline doesn't flag them all up (though I don't think this
> > suppresses all inlining).
> > 
> > If you have a way of tracking these cases down automatically, I'd be
> > interested to know so that I can apply it elsewhere.)
> 
> It is mostly by code inspection at this point.
> 
> You can refer to this commit [1].
> 
> We used to see section mismatch warnings when non-init functions call
> __init functions.
> 
> MODPOST Module.symvers
> WARNING: modpost: vmlinux: section mismatch in reference:
> rdt_get_mon_l3_config+0x2b5 (section: .text) -> rdt_cpu_has (section:
> .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> rdt_get_mon_l3_config+0x408 (section: .text) -> rdt_cpu_has (section:
> .init.text)
> 
> 
> 1.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.14-rc3&id=bd334c86b5d70e5d1c6169991802e62c828d6f38

Right.

No problem with this patch, but I'll bear in mind for the future that
CONFIG_DEBUG_SECTION_MISMATCH has limitations...

Cheers
---Dave
Re: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Posted by Reinette Chatre 1 year ago
Hi Babu,

On 1/22/25 12:20 PM, Babu Moger wrote:
> resctrl_late_init() has the __init attribute, but some of the functions
> called from it do not have the __init attribute.
> 
> Add the __init attribute to all the functions in the call sequences to
> maintain consistency throughout.
> 
> Fixes: 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")
> Fixes: def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")
> Fixes: bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")
> Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---

Thank you.

Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>

Reinette