From nobody Tue Dec 16 14:49:52 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 039891E1DFC for ; Fri, 5 Dec 2025 21:59:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764971987; cv=none; b=E/KRIs1R1he7d2PH7ZizvJg8eD925PSQZWoadHfF9xvkxPBXLTg9HskjJKe/k4u7M4PVfZ6rMDLDuUT2p8K7pAGH/hVuce/yKVI5p9Ub8FUSPXxemEa9N8YonJ20i6C99hIAj9nbok/kyq+SEDeBnH1JKX7PbNc/OOVtuCzrFhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764971987; c=relaxed/simple; bh=72orXuFTaz4a1JXCn/twJq8FRo8TgJm6qgBEBr7/5ro=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rxcnF1texOHneJ5VdUEFhECJxRBq7XDJxuWB82xMduSG6fBN099IReHHB68P7fp8Wrls5L50fx1ictmZ/bzqVAHgof96GR8M/JTidA2A9N3DcOoUvZZs2TBdEJt2Q80LjGAPmca2Wa6mlgFT432u4M6SgIDhGbQuR8ytOMMpXwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F147B1A25; Fri, 5 Dec 2025 13:59:36 -0800 (PST) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 93CEA3F740; Fri, 5 Dec 2025 13:59:40 -0800 (PST) From: James Morse To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Dave Martin , Koba Ko , Shanker Donthineni , fenghuay@nvidia.com, baisheng.gao@unisoc.com, Jonathan Cameron , Gavin Shan , Ben Horgan , rohit.mathew@arm.com, reinette.chatre@intel.com, Punit Agrawal Subject: [RFC PATCH 04/38] arm64: mpam: Add cpu_pm notifier to restore MPAM sysregs Date: Fri, 5 Dec 2025 21:58:27 +0000 Message-Id: <20251205215901.17772-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251205215901.17772-1-james.morse@arm.com> References: <20251205215901.17772-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: James Morse --- arch/arm64/kernel/mpam.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c index e6feff2324ac..dbe0a2d05abb 100644 --- a/arch/arm64/kernel/mpam.c +++ b/arch/arm64/kernel/mpam.c @@ -4,6 +4,7 @@ #include =20 #include +#include #include #include =20 @@ -13,12 +14,41 @@ DEFINE_PER_CPU(u64, arm64_mpam_current); =20 u64 arm64_mpam_global_default; =20 +static int mpam_pm_notifier(struct notifier_block *self, + unsigned long cmd, void *v) +{ + u64 regval; + int cpu =3D 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 =3D READ_ONCE(per_cpu(arm64_mpam_current, cpu)); + write_sysreg_s(regval, 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 =3D { + .notifier_call =3D mpam_pm_notifier, +}; + static int __init arm64_mpam_register_cpus(void) { u64 mpamidr =3D read_sanitised_ftr_reg(SYS_MPAMIDR_EL1); u16 partid_max =3D FIELD_GET(MPAMIDR_EL1_PARTID_MAX, mpamidr); u8 pmg_max =3D FIELD_GET(MPAMIDR_EL1_PMG_MAX, mpamidr); =20 + 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() */ --=20 2.39.5