From: Zayd Qumsieh <zayd_qumsieh@apple.com>
To: zayd_qumsieh@apple.com
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Mark Brown <broonie@kernel.org>,
Ard Biesheuvel <ardb@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mateusz Guzik <mjguzik@gmail.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Marc Zyngier <maz@kernel.org>,
Oliver Upton <oliver.upton@linux.dev>,
Miguel Luis <miguel.luis@oracle.com>,
Joey Gouly <joey.gouly@arm.com>,
Christoph Paasch <cpaasch@apple.com>,
Kees Cook <keescook@chromium.org>,
Sami Tolvanen <samitolvanen@google.com>,
Baoquan He <bhe@redhat.com>,
Lecopzer Chen <lecopzer.chen@mediatek.com>,
Joel Granados <j.granados@samsung.com>,
Dawei Li <dawei.li@shingroup.cn>,
Andrew Morton <akpm@linux-foundation.org>,
Florent Revest <revest@chromium.org>,
David Hildenbrand <david@redhat.com>,
Stefan Roesch <shr@devkernel.io>,
Andy Chiu <andy.chiu@sifive.com>,
Josh Triplett <josh@joshtriplett.org>,
Oleg Nesterov <oleg@redhat.com>, Helge Deller <deller@gmx.de>,
Zev Weiss <zev@bewilderbeest.net>,
Ondrej Mosnacek <omosnace@redhat.com>,
Miguel Ojeda <ojeda@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 1/3] tso: aarch64: allow linux kernel to read/write ACTLR.TSOEN
Date: Wed, 10 Apr 2024 14:16:39 -0700 [thread overview]
Message-ID: <20240410211652.16640-2-zayd_qumsieh@apple.com> (raw)
In-Reply-To: <20240410211652.16640-1-zayd_qumsieh@apple.com>
Create a couple simplistic functions that can read / modify the
ACTLR.TSOEN bit on Apple Silicon. Setting this bit to 1 will change
the CPU's memory model to x86-64's TSO memory model. Clearing it will
set the CPU's memory model to the standard ARM64 memory model.
Signed-off-by: Zayd Qumsieh <zayd_qumsieh@apple.com>
---
arch/arm64/Kconfig | 13 +++++++++
arch/arm64/include/asm/sysreg.h | 7 +++++
arch/arm64/include/asm/tso.h | 17 +++++++++++
arch/arm64/kernel/Makefile | 2 +-
arch/arm64/kernel/tso.c | 52 +++++++++++++++++++++++++++++++++
5 files changed, 90 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/include/asm/tso.h
create mode 100644 arch/arm64/kernel/tso.c
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 7b11c98b3e84..35162e5a0705 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
+# Copyright © 2024 Apple Inc. All rights reserved.
config ARM64
def_bool y
select ACPI_APMT if ACPI
@@ -2079,6 +2080,18 @@ config ARM64_MTE
Documentation/arch/arm64/memory-tagging-extension.rst.
+config ARM64_TSO
+ bool "ARM64 Apple Silicon TSO support"
+ default y
+ help
+ Apple Silicon TSO mode allows the CPU's memory model to be
+ dynamically switched between the default ARM64 memory model
+ and x86_64's memory model (TSO).
+
+ Selecting this option allows the feature to be detected at
+ runtime. If the CPU doesn't implement TSO mode, then this
+ feature will be disabled.
+
endmenu # "ARMv8.5 architectural features"
menu "ARMv8.7 architectural features"
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 9e8999592f3a..5464217c6bfd 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -4,6 +4,8 @@
*
* Copyright (C) 2014 ARM Ltd.
* Author: Catalin Marinas <catalin.marinas@arm.com>
+ *
+ * Copyright © 2024 Apple Inc. All rights reserved.
*/
#ifndef __ASM_SYSREG_H
@@ -277,6 +279,9 @@
#define SYS_REVIDR_EL1 sys_reg(3, 0, 0, 0, 6)
#define SYS_ACTLR_EL1 sys_reg(3, 0, 1, 0, 1)
+#define SYS_ACTLR_EL1_TSOEN_SHIFT 1
+#define SYS_ACTLR_EL1_TSOEN_MASK (1 << SYS_ACTLR_EL1_TSOEN_SHIFT)
+
#define SYS_RGSR_EL1 sys_reg(3, 0, 1, 0, 5)
#define SYS_GCR_EL1 sys_reg(3, 0, 1, 0, 6)
@@ -394,6 +399,8 @@
#define SYS_CNTKCTL_EL1 sys_reg(3, 0, 14, 1, 0)
#define SYS_AIDR_EL1 sys_reg(3, 1, 0, 0, 7)
+#define SYS_AIDR_EL1_TSO_SHIFT 9
+#define SYS_AIDR_EL1_TSO_MASK (1 << SYS_AIDR_EL1_TSO_SHIFT)
#define SYS_RNDR_EL0 sys_reg(3, 3, 2, 4, 0)
#define SYS_RNDRRS_EL0 sys_reg(3, 3, 2, 4, 1)
diff --git a/arch/arm64/include/asm/tso.h b/arch/arm64/include/asm/tso.h
new file mode 100644
index 000000000000..d9e1a7602c44
--- /dev/null
+++ b/arch/arm64/include/asm/tso.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright © 2024 Apple Inc. All rights reserved.
+ */
+
+#ifndef __ASM_TSO_H
+#define __ASM_TSO_H
+
+#ifdef CONFIG_ARM64_TSO
+
+#include <linux/sched.h>
+#include <linux/types.h>
+
+int modify_tso_enable(bool tso_enable);
+
+#endif /* CONFIG_ARM64_TSO */
+#endif /* __ASM_TSO_H */
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 763824963ed1..a2a7c74fb00d 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -33,7 +33,7 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \
return_address.o cpuinfo.o cpu_errata.o \
cpufeature.o alternative.o cacheinfo.o \
smp.o smp_spin_table.o topology.o smccc-call.o \
- syscall.o proton-pack.o idle.o patching.o pi/
+ syscall.o proton-pack.o idle.o patching.o tso.o pi/ \
obj-$(CONFIG_COMPAT) += sys32.o signal32.o \
sys_compat.o
diff --git a/arch/arm64/kernel/tso.c b/arch/arm64/kernel/tso.c
new file mode 100644
index 000000000000..b3964db7aa66
--- /dev/null
+++ b/arch/arm64/kernel/tso.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright © 2024 Apple Inc. All rights reserved.
+ */
+
+#include <linux/types.h>
+
+#include <asm/cputype.h>
+#include <asm/processor.h>
+#include <asm/sysreg.h>
+#include <asm/tso.h>
+
+#ifdef CONFIG_ARM64_TSO
+
+static bool tso_supported(void)
+{
+ unsigned int cpuid_implementor = read_cpuid_implementor();
+ u64 aidr = read_sysreg(aidr_el1);
+
+ return (cpuid_implementor == ARM_CPU_IMP_APPLE) &&
+ (aidr & SYS_AIDR_EL1_TSO_MASK);
+}
+
+static int tso_enabled(void)
+{
+ if (!tso_supported())
+ return -EOPNOTSUPP;
+
+ u64 actlr_el1 = read_sysreg(actlr_el1);
+
+ return !!(actlr_el1 & SYS_ACTLR_EL1_TSOEN_MASK);
+}
+
+int modify_tso_enable(bool tso_enable)
+{
+ if (!tso_supported())
+ return -EOPNOTSUPP;
+
+ u64 actlr_el1_old = read_sysreg(actlr_el1);
+ u64 actlr_el1_new =
+ (actlr_el1_old & ~SYS_ACTLR_EL1_TSOEN_MASK) |
+ (tso_enable << SYS_ACTLR_EL1_TSOEN_SHIFT);
+
+ write_sysreg(actlr_el1_new, actlr_el1);
+
+ if (tso_enabled() != tso_enable)
+ return -EOPNOTSUPP;
+
+ return 0;
+}
+
+#endif /* CONFIG_ARM64_TSO */
--
2.39.3 (Apple Git-146)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-10 21:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-10 21:16 [PATCH 0/3] tso: aarch64: Expose TSO for virtualized linux on Apple Silicon Zayd Qumsieh
2024-04-10 21:16 ` Zayd Qumsieh [this message]
2024-04-10 21:16 ` [PATCH 2/3] tso: aarch64: context-switch tso bit on thread switch Zayd Qumsieh
2024-04-10 21:16 ` [PATCH 3/3] tso: aarch64: allow userspace to set tso bit using prctl Zayd Qumsieh
2024-04-10 23:23 ` [PATCH 0/3] tso: aarch64: Expose TSO for virtualized linux on Apple Silicon Hector Martin
2024-04-11 13:37 ` Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240410211652.16640-2-zayd_qumsieh@apple.com \
--to=zayd_qumsieh@apple.com \
--cc=akpm@linux-foundation.org \
--cc=andy.chiu@sifive.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=bhe@redhat.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=cpaasch@apple.com \
--cc=david@redhat.com \
--cc=dawei.li@shingroup.cn \
--cc=deller@gmx.de \
--cc=j.granados@samsung.com \
--cc=joey.gouly@arm.com \
--cc=josh@joshtriplett.org \
--cc=keescook@chromium.org \
--cc=lecopzer.chen@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mcgrof@kernel.org \
--cc=miguel.luis@oracle.com \
--cc=mjguzik@gmail.com \
--cc=ojeda@kernel.org \
--cc=oleg@redhat.com \
--cc=oliver.upton@linux.dev \
--cc=omosnace@redhat.com \
--cc=revest@chromium.org \
--cc=samitolvanen@google.com \
--cc=shr@devkernel.io \
--cc=will@kernel.org \
--cc=zev@bewilderbeest.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox