Skip to content

Commit ee7f6af

Browse files
aeglbp3tk0v
authored andcommitted
fs/resctrl: Move allocation/free of closid_num_dirty_rmid[]
closid_num_dirty_rmid[] and rmid_ptrs[] are allocated together during resctrl initialization and freed together during resctrl exit. Telemetry events are enumerated on resctrl mount so only at resctrl mount will the number of RMID supported by all monitoring resources and needed as size for rmid_ptrs[] be known. Separate closid_num_dirty_rmid[] and rmid_ptrs[] allocation and free in preparation for rmid_ptrs[] to be allocated on resctrl mount. Keep the rdtgroup_mutex protection around the allocation and free of closid_num_dirty_rmid[] as ARM needs this to guarantee memory ordering. Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://lore.kernel.org/20251217172121.12030-1-tony.luck@intel.com
1 parent 67640e3 commit ee7f6af

1 file changed

Lines changed: 51 additions & 28 deletions

File tree

fs/resctrl/monitor.c

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -906,36 +906,14 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long del
906906
static int dom_data_init(struct rdt_resource *r)
907907
{
908908
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
909-
u32 num_closid = resctrl_arch_get_num_closid(r);
910909
struct rmid_entry *entry = NULL;
911910
int err = 0, i;
912911
u32 idx;
913912

914913
mutex_lock(&rdtgroup_mutex);
915-
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
916-
u32 *tmp;
917-
918-
/*
919-
* If the architecture hasn't provided a sanitised value here,
920-
* this may result in larger arrays than necessary. Resctrl will
921-
* use a smaller system wide value based on the resources in
922-
* use.
923-
*/
924-
tmp = kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL);
925-
if (!tmp) {
926-
err = -ENOMEM;
927-
goto out_unlock;
928-
}
929-
930-
closid_num_dirty_rmid = tmp;
931-
}
932914

933915
rmid_ptrs = kcalloc(idx_limit, sizeof(struct rmid_entry), GFP_KERNEL);
934916
if (!rmid_ptrs) {
935-
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
936-
kfree(closid_num_dirty_rmid);
937-
closid_num_dirty_rmid = NULL;
938-
}
939917
err = -ENOMEM;
940918
goto out_unlock;
941919
}
@@ -971,11 +949,6 @@ static void dom_data_exit(struct rdt_resource *r)
971949
if (!r->mon_capable)
972950
goto out_unlock;
973951

974-
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
975-
kfree(closid_num_dirty_rmid);
976-
closid_num_dirty_rmid = NULL;
977-
}
978-
979952
kfree(rmid_ptrs);
980953
rmid_ptrs = NULL;
981954

@@ -1814,6 +1787,45 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,
18141787
return ret ?: nbytes;
18151788
}
18161789

1790+
static int closid_num_dirty_rmid_alloc(struct rdt_resource *r)
1791+
{
1792+
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
1793+
u32 num_closid = resctrl_arch_get_num_closid(r);
1794+
u32 *tmp;
1795+
1796+
/* For ARM memory ordering access to closid_num_dirty_rmid */
1797+
mutex_lock(&rdtgroup_mutex);
1798+
1799+
/*
1800+
* If the architecture hasn't provided a sanitised value here,
1801+
* this may result in larger arrays than necessary. Resctrl will
1802+
* use a smaller system wide value based on the resources in
1803+
* use.
1804+
*/
1805+
tmp = kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL);
1806+
if (!tmp) {
1807+
mutex_unlock(&rdtgroup_mutex);
1808+
return -ENOMEM;
1809+
}
1810+
1811+
closid_num_dirty_rmid = tmp;
1812+
1813+
mutex_unlock(&rdtgroup_mutex);
1814+
}
1815+
1816+
return 0;
1817+
}
1818+
1819+
static void closid_num_dirty_rmid_free(void)
1820+
{
1821+
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
1822+
mutex_lock(&rdtgroup_mutex);
1823+
kfree(closid_num_dirty_rmid);
1824+
closid_num_dirty_rmid = NULL;
1825+
mutex_unlock(&rdtgroup_mutex);
1826+
}
1827+
}
1828+
18171829
/**
18181830
* resctrl_l3_mon_resource_init() - Initialise global monitoring structures.
18191831
*
@@ -1834,10 +1846,16 @@ int resctrl_l3_mon_resource_init(void)
18341846
if (!r->mon_capable)
18351847
return 0;
18361848

1837-
ret = dom_data_init(r);
1849+
ret = closid_num_dirty_rmid_alloc(r);
18381850
if (ret)
18391851
return ret;
18401852

1853+
ret = dom_data_init(r);
1854+
if (ret) {
1855+
closid_num_dirty_rmid_free();
1856+
return ret;
1857+
}
1858+
18411859
if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) {
18421860
mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable = true;
18431861
resctrl_file_fflags_init("mbm_total_bytes_config",
@@ -1880,5 +1898,10 @@ void resctrl_l3_mon_resource_exit(void)
18801898
{
18811899
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
18821900

1901+
if (!r->mon_capable)
1902+
return;
1903+
1904+
closid_num_dirty_rmid_free();
1905+
18831906
dom_data_exit(r);
18841907
}

0 commit comments

Comments
 (0)