[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] target/arm: allow DC CVA[D]P in user mode emulation
From: |
Zhuojia Shen |
Subject: |
[PATCH v2] target/arm: allow DC CVA[D]P in user mode emulation |
Date: |
Wed, 17 May 2023 10:31:06 -0700 |
DC CVAP and DC CVADP instructions can be executed in EL0 on Linux,
either directly when SCTLR_EL1.UCI == 1 or emulated by the kernel (see
user_cache_maint_handler() in arch/arm64/kernel/traps.c).
This patch enables execution of the two instructions in user mode
emulation.
Signed-off-by: Zhuojia Shen <chaosdefinition@hotmail.com>
---
target/arm/helper.c | 6 ++--
tests/tcg/aarch64/Makefile.target | 11 ++++++++
tests/tcg/aarch64/dcpodp-1.c | 47 +++++++++++++++++++++++++++++++
tests/tcg/aarch64/dcpodp-2.c | 47 +++++++++++++++++++++++++++++++
tests/tcg/aarch64/dcpop-1.c | 47 +++++++++++++++++++++++++++++++
tests/tcg/aarch64/dcpop-2.c | 47 +++++++++++++++++++++++++++++++
6 files changed, 201 insertions(+), 4 deletions(-)
create mode 100644 tests/tcg/aarch64/dcpodp-1.c
create mode 100644 tests/tcg/aarch64/dcpodp-2.c
create mode 100644 tests/tcg/aarch64/dcpop-1.c
create mode 100644 tests/tcg/aarch64/dcpop-2.c
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 0b7fd2e7e6..d4bee43bd0 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -7405,7 +7405,6 @@ static const ARMCPRegInfo rndr_reginfo[] = {
.access = PL0_R, .readfn = rndr_readfn },
};
-#ifndef CONFIG_USER_ONLY
static void dccvap_writefn(CPUARMState *env, const ARMCPRegInfo *opaque,
uint64_t value)
{
@@ -7420,6 +7419,7 @@ static void dccvap_writefn(CPUARMState *env, const
ARMCPRegInfo *opaque,
/* This won't be crossing page boundaries */
haddr = probe_read(env, vaddr, dline_size, mem_idx, GETPC());
if (haddr) {
+#ifndef CONFIG_USER_ONLY
ram_addr_t offset;
MemoryRegion *mr;
@@ -7430,6 +7430,7 @@ static void dccvap_writefn(CPUARMState *env, const
ARMCPRegInfo *opaque,
if (mr) {
memory_region_writeback(mr, offset, dline_size);
}
+#endif /*CONFIG_USER_ONLY*/
}
}
@@ -7448,7 +7449,6 @@ static const ARMCPRegInfo dcpodp_reg[] = {
.fgt = FGT_DCCVADP,
.accessfn = aa64_cacheop_poc_access, .writefn = dccvap_writefn },
};
-#endif /*CONFIG_USER_ONLY*/
static CPAccessResult access_aa64_tid5(CPUARMState *env, const ARMCPRegInfo
*ri,
bool isread)
@@ -9092,7 +9092,6 @@ void register_cp_regs_for_features(ARMCPU *cpu)
if (cpu_isar_feature(aa64_tlbios, cpu)) {
define_arm_cp_regs(cpu, tlbios_reginfo);
}
-#ifndef CONFIG_USER_ONLY
/* Data Cache clean instructions up to PoP */
if (cpu_isar_feature(aa64_dcpop, cpu)) {
define_one_arm_cp_reg(cpu, dcpop_reg);
@@ -9101,7 +9100,6 @@ void register_cp_regs_for_features(ARMCPU *cpu)
define_one_arm_cp_reg(cpu, dcpodp_reg);
}
}
-#endif /*CONFIG_USER_ONLY*/
/*
* If full MTE is enabled, add all of the system registers.
diff --git a/tests/tcg/aarch64/Makefile.target
b/tests/tcg/aarch64/Makefile.target
index 0315795487..714a30355d 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -21,12 +21,23 @@ config-cc.mak: Makefile
$(quiet-@)( \
$(call cc-option,-march=armv8.1-a+sve, CROSS_CC_HAS_SVE); \
$(call cc-option,-march=armv8.1-a+sve2, CROSS_CC_HAS_SVE2);
\
+ $(call cc-option,-march=armv8.2-a,
CROSS_CC_HAS_ARMV8_2); \
$(call cc-option,-march=armv8.3-a,
CROSS_CC_HAS_ARMV8_3); \
+ $(call cc-option,-march=armv8.5-a,
CROSS_CC_HAS_ARMV8_5); \
$(call cc-option,-mbranch-protection=standard,
CROSS_CC_HAS_ARMV8_BTI); \
$(call cc-option,-march=armv8.5-a+memtag,
CROSS_CC_HAS_ARMV8_MTE); \
$(call cc-option,-march=armv9-a+sme,
CROSS_CC_HAS_ARMV9_SME)) 3> config-cc.mak
-include config-cc.mak
+ifneq ($(CROSS_CC_HAS_ARMV8_2),)
+AARCH64_TESTS += dcpop-1 dcpop-2
+dcpop-1 dcpop-2: CFLAGS += -march=armv8.2-a
+endif
+ifneq ($(CROSS_CC_HAS_ARMV8_5),)
+AARCH64_TESTS += dcpodp-1 dcpodp-2
+dcpodp-1 dcpodp-2: CFLAGS += -march=armv8.5-a
+endif
+
# Pauth Tests
ifneq ($(CROSS_CC_HAS_ARMV8_3),)
AARCH64_TESTS += pauth-1 pauth-2 pauth-4 pauth-5
diff --git a/tests/tcg/aarch64/dcpodp-1.c b/tests/tcg/aarch64/dcpodp-1.c
new file mode 100644
index 0000000000..47c466a9bf
--- /dev/null
+++ b/tests/tcg/aarch64/dcpodp-1.c
@@ -0,0 +1,47 @@
+/* Test execution of DC CVADP instruction */
+
+#include <asm/hwcap.h>
+#include <sys/auxv.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef HWCAP2_DCPODP
+#define HWCAP2_DCPODP (1 << 0)
+#endif
+
+static void signal_handler(int sig)
+{
+ exit(EXIT_FAILURE);
+}
+
+static int do_dc_cvadp(void)
+{
+ struct sigaction sa = {
+ .sa_handler = signal_handler,
+ };
+
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+ if (sigaction(SIGSEGV, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+
+ asm volatile("dc cvadp, %0\n\t" :: "r"(&sa));
+
+ return EXIT_SUCCESS;
+}
+
+int main(void)
+{
+ if (getauxval(AT_HWCAP) & HWCAP2_DCPODP) {
+ return do_dc_cvadp();
+ } else {
+ printf("SKIP: no HWCAP2_DCPODP on this system\n");
+ return EXIT_SUCCESS;
+ }
+}
diff --git a/tests/tcg/aarch64/dcpodp-2.c b/tests/tcg/aarch64/dcpodp-2.c
new file mode 100644
index 0000000000..3245d7883d
--- /dev/null
+++ b/tests/tcg/aarch64/dcpodp-2.c
@@ -0,0 +1,47 @@
+/* Test execution of DC CVADP instruction on unmapped address */
+
+#include <asm/hwcap.h>
+#include <sys/auxv.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef HWCAP2_DCPODP
+#define HWCAP2_DCPODP (1 << 0)
+#endif
+
+static void signal_handler(int sig)
+{
+ exit(EXIT_SUCCESS);
+}
+
+static int do_dc_cvadp(void)
+{
+ struct sigaction sa = {
+ .sa_handler = signal_handler,
+ };
+
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+ if (sigaction(SIGSEGV, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+
+ asm volatile("dc cvadp, %0\n\t" :: "r"(NULL));
+
+ return EXIT_FAILURE;
+}
+
+int main(void)
+{
+ if (getauxval(AT_HWCAP) & HWCAP2_DCPODP) {
+ return do_dc_cvadp();
+ } else {
+ printf("SKIP: no HWCAP2_DCPODP on this system\n");
+ return EXIT_SUCCESS;
+ }
+}
diff --git a/tests/tcg/aarch64/dcpop-1.c b/tests/tcg/aarch64/dcpop-1.c
new file mode 100644
index 0000000000..c9fc5b7e57
--- /dev/null
+++ b/tests/tcg/aarch64/dcpop-1.c
@@ -0,0 +1,47 @@
+/* Test execution of DC CVAP instruction */
+
+#include <asm/hwcap.h>
+#include <sys/auxv.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef HWCAP_DCPOP
+#define HWCAP_DCPOP (1 << 16)
+#endif
+
+static void signal_handler(int sig)
+{
+ exit(EXIT_FAILURE);
+}
+
+static int do_dc_cvap(void)
+{
+ struct sigaction sa = {
+ .sa_handler = signal_handler,
+ };
+
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+ if (sigaction(SIGSEGV, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+
+ asm volatile("dc cvap, %0\n\t" :: "r"(&sa));
+
+ return EXIT_SUCCESS;
+}
+
+int main(void)
+{
+ if (getauxval(AT_HWCAP) & HWCAP_DCPOP) {
+ return do_dc_cvap();
+ } else {
+ printf("SKIP: no HWCAP_DCPOP on this system\n");
+ return EXIT_SUCCESS;
+ }
+}
diff --git a/tests/tcg/aarch64/dcpop-2.c b/tests/tcg/aarch64/dcpop-2.c
new file mode 100644
index 0000000000..8f8ed81720
--- /dev/null
+++ b/tests/tcg/aarch64/dcpop-2.c
@@ -0,0 +1,47 @@
+/* Test execution of DC CVAP instruction on unmapped address */
+
+#include <asm/hwcap.h>
+#include <sys/auxv.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef HWCAP_DCPOP
+#define HWCAP_DCPOP (1 << 16)
+#endif
+
+static void signal_handler(int sig)
+{
+ exit(EXIT_SUCCESS);
+}
+
+static int do_dc_cvap(void)
+{
+ struct sigaction sa = {
+ .sa_handler = signal_handler,
+ };
+
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+ if (sigaction(SIGSEGV, &sa, NULL) < 0) {
+ perror("sigaction");
+ return EXIT_FAILURE;
+ }
+
+ asm volatile("dc cvap, %0\n\t" :: "r"(NULL));
+
+ return EXIT_FAILURE;
+}
+
+int main(void)
+{
+ if (getauxval(AT_HWCAP) & HWCAP_DCPOP) {
+ return do_dc_cvap();
+ } else {
+ printf("SKIP: no HWCAP_DCPOP on this system\n");
+ return EXIT_SUCCESS;
+ }
+}
--
2.40.1
- [PATCH v2] target/arm: allow DC CVA[D]P in user mode emulation,
Zhuojia Shen <=