]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
arm64: mpam: Add cpu_pm notifier to restore MPAM sysregs
authorJames Morse <james.morse@arm.com>
Fri, 13 Mar 2026 14:45:47 +0000 (14:45 +0000)
committerJames Morse <james.morse@arm.com>
Fri, 27 Mar 2026 15:28:54 +0000 (15:28 +0000)
The MPAM system registers will be lost if the CPU is reset during PSCI's
CPU_SUSPEND.

Add a PM notifier to restore them.

mpam_thread_switch(current) can't be used as this won't make any changes if
the in-memory copy says the register already has the correct value. In
reality the system register is UNKNOWN out of reset.

Tested-by: Gavin Shan <gshan@redhat.com>
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com>
Tested-by: Jesse Chick <jessechick@os.amperecomputing.com>
Reviewed-by: Zeng Heng <zengheng4@huawei.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Co-developed-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
arch/arm64/kernel/mpam.c

index e6feff2324acb10f7948bc5fed583cf6ea69cbb5..48ec0ffd59997cb3670438fa65c779d1e09a531d 100644 (file)
@@ -4,6 +4,7 @@
 #include <asm/mpam.h>
 
 #include <linux/arm_mpam.h>
+#include <linux/cpu_pm.h>
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 
@@ -13,12 +14,44 @@ DEFINE_PER_CPU(u64, arm64_mpam_current);
 
 u64 arm64_mpam_global_default;
 
+static int mpam_pm_notifier(struct notifier_block *self,
+                           unsigned long cmd, void *v)
+{
+       u64 regval;
+       int cpu = smp_processor_id();
+
+       switch (cmd) {
+       case CPU_PM_EXIT:
+               /*
+                * Don't use mpam_thread_switch() as the system register
+                * value has changed under our feet.
+                */
+               regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
+               write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
+               isb();
+
+               write_sysreg_s(regval, SYS_MPAM0_EL1);
+
+               return NOTIFY_OK;
+       default:
+               return NOTIFY_DONE;
+       }
+}
+
+static struct notifier_block mpam_pm_nb = {
+       .notifier_call = mpam_pm_notifier,
+};
+
 static int __init arm64_mpam_register_cpus(void)
 {
        u64 mpamidr = read_sanitised_ftr_reg(SYS_MPAMIDR_EL1);
        u16 partid_max = FIELD_GET(MPAMIDR_EL1_PARTID_MAX, mpamidr);
        u8 pmg_max = FIELD_GET(MPAMIDR_EL1_PMG_MAX, mpamidr);
 
+       if (!system_supports_mpam())
+               return 0;
+
+       cpu_pm_register_notifier(&mpam_pm_nb);
        return mpam_register_requestor(partid_max, pmg_max);
 }
 /* Must occur before mpam_msc_driver_init() from subsys_initcall() */