Skip to content

Commit f188a36

Browse files
James Morsectmarinas
authored andcommitted
arm_mpam: Reset MSC controls from cpuhp callbacks
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtied. e.g. Kexec. Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later. MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement. If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again. To reset, write the maximum values for all discovered controls. CC: Rohit Mathew <Rohit.Mathew@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Tested-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Hanjun Guo <guohanjun@huawei.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent c10ca83 commit f188a36

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

drivers/resctrl/mpam_devices.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/atomic.h>
88
#include <linux/arm_mpam.h>
99
#include <linux/bitfield.h>
10+
#include <linux/bitmap.h>
1011
#include <linux/cacheinfo.h>
1112
#include <linux/cpu.h>
1213
#include <linux/cpumask.h>
@@ -752,8 +753,104 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)
752753
return 0;
753754
}
754755

756+
static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)
757+
{
758+
u32 num_words, msb;
759+
u32 bm = ~0;
760+
int i;
761+
762+
lockdep_assert_held(&msc->part_sel_lock);
763+
764+
if (wd == 0)
765+
return;
766+
767+
/*
768+
* Write all ~0 to all but the last 32bit-word, which may
769+
* have fewer bits...
770+
*/
771+
num_words = DIV_ROUND_UP(wd, 32);
772+
for (i = 0; i < num_words - 1; i++, reg += sizeof(bm))
773+
__mpam_write_reg(msc, reg, bm);
774+
775+
/*
776+
* ....and then the last (maybe) partial 32bit word. When wd is a
777+
* multiple of 32, msb should be 31 to write a full 32bit word.
778+
*/
779+
msb = (wd - 1) % 32;
780+
bm = GENMASK(msb, 0);
781+
__mpam_write_reg(msc, reg, bm);
782+
}
783+
784+
static void mpam_reset_ris_partid(struct mpam_msc_ris *ris, u16 partid)
785+
{
786+
struct mpam_msc *msc = ris->vmsc->msc;
787+
struct mpam_props *rprops = &ris->props;
788+
789+
WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu)));
790+
791+
mutex_lock(&msc->part_sel_lock);
792+
__mpam_part_sel(ris->ris_idx, partid, msc);
793+
794+
if (mpam_has_feature(mpam_feat_cpor_part, rprops))
795+
mpam_reset_msc_bitmap(msc, MPAMCFG_CPBM, rprops->cpbm_wd);
796+
797+
if (mpam_has_feature(mpam_feat_mbw_part, rprops))
798+
mpam_reset_msc_bitmap(msc, MPAMCFG_MBW_PBM, rprops->mbw_pbm_bits);
799+
800+
if (mpam_has_feature(mpam_feat_mbw_min, rprops))
801+
mpam_write_partsel_reg(msc, MBW_MIN, 0);
802+
803+
if (mpam_has_feature(mpam_feat_mbw_max, rprops))
804+
mpam_write_partsel_reg(msc, MBW_MAX, MPAMCFG_MBW_MAX_MAX);
805+
806+
mutex_unlock(&msc->part_sel_lock);
807+
}
808+
809+
static void mpam_reset_ris(struct mpam_msc_ris *ris)
810+
{
811+
u16 partid, partid_max;
812+
813+
WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu)));
814+
815+
if (ris->in_reset_state)
816+
return;
817+
818+
spin_lock(&partid_max_lock);
819+
partid_max = mpam_partid_max;
820+
spin_unlock(&partid_max_lock);
821+
for (partid = 0; partid <= partid_max; partid++)
822+
mpam_reset_ris_partid(ris, partid);
823+
}
824+
825+
static void mpam_reset_msc(struct mpam_msc *msc, bool online)
826+
{
827+
struct mpam_msc_ris *ris;
828+
829+
list_for_each_entry_srcu(ris, &msc->ris, msc_list, srcu_read_lock_held(&mpam_srcu)) {
830+
mpam_reset_ris(ris);
831+
832+
/*
833+
* Set in_reset_state when coming online. The reset state
834+
* for non-zero partid may be lost while the CPUs are offline.
835+
*/
836+
ris->in_reset_state = online;
837+
}
838+
}
839+
755840
static int mpam_cpu_online(unsigned int cpu)
756841
{
842+
struct mpam_msc *msc;
843+
844+
guard(srcu)(&mpam_srcu);
845+
list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list,
846+
srcu_read_lock_held(&mpam_srcu)) {
847+
if (!cpumask_test_cpu(cpu, &msc->accessibility))
848+
continue;
849+
850+
if (atomic_fetch_inc(&msc->online_refs) == 0)
851+
mpam_reset_msc(msc, true);
852+
}
853+
757854
return 0;
758855
}
759856

@@ -792,6 +889,18 @@ static int mpam_discovery_cpu_online(unsigned int cpu)
792889

793890
static int mpam_cpu_offline(unsigned int cpu)
794891
{
892+
struct mpam_msc *msc;
893+
894+
guard(srcu)(&mpam_srcu);
895+
list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list,
896+
srcu_read_lock_held(&mpam_srcu)) {
897+
if (!cpumask_test_cpu(cpu, &msc->accessibility))
898+
continue;
899+
900+
if (atomic_dec_and_test(&msc->online_refs))
901+
mpam_reset_msc(msc, false);
902+
}
903+
795904
return 0;
796905
}
797906

drivers/resctrl/mpam_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define MPAM_INTERNAL_H
66

77
#include <linux/arm_mpam.h>
8+
#include <linux/atomic.h>
89
#include <linux/bitmap.h>
910
#include <linux/cpumask.h>
1011
#include <linux/io.h>
@@ -45,6 +46,7 @@ struct mpam_msc {
4546
enum mpam_msc_iface iface;
4647
u32 nrdy_usec;
4748
cpumask_t accessibility;
49+
atomic_t online_refs;
4850

4951
/*
5052
* probe_lock is only taken during discovery. After discovery these
@@ -198,6 +200,7 @@ struct mpam_msc_ris {
198200
u8 ris_idx;
199201
u64 idr;
200202
struct mpam_props props;
203+
bool in_reset_state;
201204

202205
cpumask_t affinity;
203206

0 commit comments

Comments
 (0)