target/arm: Implement ARMv8.5-BTI
v3 cover target/arm: Implement ARMv8.5-BTI
One fixup to the set of patches applied to target-arm.next. One adjustment to what is now patch 3 wrt EXCP_SEMIHOST.
r~
Richard Henderson (4):
fixup! target/arm: Cache the GP bit for a page in MemTxAttrs target/arm: Add x-guarded-pages cpu property for user-only linux-user/aarch64: Reset btype for syscalls and signals tests/tcg/aarch64: Add bti smoke test
target/arm/cpu.h | 4 ++ linux-user/aarch64/cpu_loop.c | 14 +++++++ target/arm/cpu64.c | 20 ++++++++++ target/arm/helper.c | 2 +- target/arm/translate-a64.c | 8 +++- tests/tcg/aarch64/bti-1.c | 61 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 ++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 7 +++- 8 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 tests/tcg/aarch64/bti-1.c create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
Signature · 1 line
2.17.2
PATCH v3 1/4 fixup! target/arm: Cache the GP bit for a page in MemTxAttrs
We talked about changing this, but missed when applying to target-arm.next.
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -10757,7 +10757,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, }/* Merge in attributes from table descriptors */ attrs |= nstable <<3 ;/* NS */ - guarded |=extract64 (descriptor,50 ,1 );/* GP */ + guarded =extract64 (descriptor,50 ,1 );/* GP */ if (param.hpd) {/* HPD disables all the table attributes except NSTable. */ break ;
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH v3 1/4] fixup! target/arm: Cache the GP bit for a page in MemTxAttrs
Quoted 5 lines · Richard Henderson
We talked about changing this, but missed when applying to target-arm.next.
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Yeah, I'd already caught this (also the initialization of guarded is no longer required), I just hadn't done the compile test to let me push it out to target-arm.next (now done).
thanks
-- PMM
PATCH v3 2/4 target/arm: Add x-guarded-pages cpu property for user-only
In reply to Richard HendersonWhile waiting for a proper userland ABI, allow static test cases to be written assuming that GP is set for all pages.
---
v2: Renamed the property with x- prefix
--- target/arm/cpu.h | 4 ++++ target/arm/cpu64.c | 20 ++++++++++++++++++++ target/arm/translate-a64.c | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-)
target/arm/cpu.h +4 -0
@@ -900,6 +900,10 @@ struct ARMCPU {*/ bool cfgend; +#ifdef CONFIG_USER_ONLY +bool guarded_pages; +#endif + QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks;
target/arm/cpu64.c +20 -0
@@ -281,6 +281,20 @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v, const char *name,error_propagate (errp, err); } +#ifdef CONFIG_USER_ONLY +static bool aarch64_cpu_get_guarded_pages (Object *obj,Error **errp) +{ +ARMCPU *cpu =ARM_CPU (obj); +return cpu->guarded_pages; +} + +static void aarch64_cpu_set_guarded_pages (Object *obj,bool val,Error **errp) +{ +ARMCPU *cpu =ARM_CPU (obj); + cpu->guarded_pages = val; +} +#endif +/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
@@ -360,6 +374,12 @@ static void aarch64_max_initfn(Object *obj)*/ cpu->ctr =0x80038003 ;/* 32 byte I and D cacheline size, VIPT icache */ cpu->dcz_blocksize =7 ;/* 512 bytes */ + +object_property_add_bool (obj,"x-guarded-pages" , + aarch64_cpu_get_guarded_pages, + aarch64_cpu_set_guarded_pages,NULL ); +object_property_set_description (obj,"x-guarded-pages" , +"Set on/off GuardPage bit for all pages" ,NULL );#endif cpu->sve_max_vq =ARM_MAX_VQ ;
target/arm/translate-a64.c +7 -1
@@ -13817,7 +13817,13 @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)static bool is_guarded_page (CPUARMState *env,DisasContext *s) {#ifdef CONFIG_USER_ONLY -return false;/* FIXME */ +/* +* FIXME: What is the userland ABI for this? +* For the moment this is controlled by an attribute: +* -cpu max,guarded_pages=on. +*/ +ARMCPU *cpu =arm_env_get_cpu (env); +return cpu->guarded_pages;#else uint64_t addr = s->base.pc_first;int mmu_idx =arm_to_core_mmu_idx (s->mmu_idx);
Signature · 1 line
2.17.2
PATCH v3 3/4 linux-user/aarch64: Reset btype for syscalls and signals
In reply to Richard HendersonThe value of btype for syscalls is CONSTRAINED UNPREDICTABLE, so we need to make sure that the value is 0 before clone, fork, or syscall return.
The value of btype for signals is defined, but it does not make sense for a SIGILL handler to enter with the btype set as for the indirect branch that caused the SIGILL.
Clearing the value early means that btype is zero within the pstate saved into the signal frame, and so is also zero on (normal) signal return, but also allows the signal handler to adjust the value as seen after the sigcontext restore.
This last is a guess at a future kernel's user-space ABI.
---
v3: Do not clear btype for semihost.
--- linux-user/aarch64/cpu_loop.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
linux-user/aarch64/cpu_loop.c +14 -0
@@ -83,8 +83,19 @@ void cpu_loop(CPUARMState *env)cpu_exec_end (cs);process_queued_cpu_work (cs); +/* +* The state of BTYPE on syscall and interrupt entry is CONSTRAINED +* UNPREDICTABLE. The real kernel will need to tidy this up as well. +* Do this before syscalls and signals, so that the value is correct +* both within signal handlers, and on return from syscall (especially +* clone & fork) and from signal handlers. +* +* The SIGILL signal handler, for BTITrap, can see the failing BTYPE +* within the ESR value in the signal frame. +*/ switch (trapnr) {case EXCP_SWI : + env->btype =0 ; ret = do_syscall(env, env->xregs[8], env->xregs[0],
@@ -104,6 +115,7 @@ void cpu_loop(CPUARMState *env)/* just indicate that signals should be handled asap */ break ;case EXCP_UDEF : + env->btype =0 ; info.si_signo =TARGET_SIGILL ; info.si_errno =0 ; info.si_code =TARGET_ILL_ILLOPN ;
@@ -112,6 +124,7 @@ void cpu_loop(CPUARMState *env)break ;case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT : + env->btype =0 ; info.si_signo =TARGET_SIGSEGV ; info.si_errno =0 ;/* XXX: check env->error_code */
@@ -121,6 +134,7 @@ void cpu_loop(CPUARMState *env)break ;case EXCP_DEBUG :case EXCP_BKPT : + env->btype =0 ; info.si_signo =TARGET_SIGTRAP ; info.si_errno =0 ; info.si_code =TARGET_TRAP_BRKPT ;
Signature · 1 line
2.17.2
PATCH v3 4/4 tests/tcg/aarch64: Add bti smoke test
In reply to Richard Henderson--- tests/tcg/aarch64/bti-1.c | 61 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 ++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 7 +++- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/bti-1.c create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
tests/tcg/aarch64/bti-1.c new file +61 -0
@@ -0,0 +1,61 @@ +/* +* Branch target identification, basic notskip cases. +*/ + +#include "bti-crt.inc.c" + +static void skip2_sigill (int sig,siginfo_t *info,ucontext_t *uc) +{ + uc->uc_mcontext.pc +=8 ; +} + +#define NOP "nop" +#define BTI_N "hint #32" +#define BTI_C "hint #34" +#define BTI_J "hint #36" +#define BTI_JC "hint #38" + +#define BTYPE_1 (DEST ) \ + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ + : "=r"(skipped) : : "x16") + +#define BTYPE_2 (DEST ) \ + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ + : "=r"(skipped) : : "x16", "x30") + +#define BTYPE_3 (DEST ) \ + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ + : "=r"(skipped) : : "x15") + +#define TEST (WHICH ,DEST ,EXPECT ) \ + do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0) + + +int main () +{ +int fail =0 ; +int skipped; + +/* Signal-like with SA_SIGINFO. */ +signal_info (SIGILL , skip2_sigill); + +TEST (BTYPE_1 ,NOP ,1 ); +TEST (BTYPE_1 ,BTI_N ,1 ); +TEST (BTYPE_1 ,BTI_C ,0 ); +TEST (BTYPE_1 ,BTI_J ,0 ); +TEST (BTYPE_1 ,BTI_JC ,0 ); + +TEST (BTYPE_2 ,NOP ,1 ); +TEST (BTYPE_2 ,BTI_N ,1 ); +TEST (BTYPE_2 ,BTI_C ,0 ); +TEST (BTYPE_2 ,BTI_J ,1 ); +TEST (BTYPE_2 ,BTI_JC ,0 ); + +TEST (BTYPE_3 ,NOP ,1 ); +TEST (BTYPE_3 ,BTI_N ,1 ); +TEST (BTYPE_3 ,BTI_C ,1 ); +TEST (BTYPE_3 ,BTI_J ,0 ); +TEST (BTYPE_3 ,BTI_JC ,0 ); + +return fail; +}
tests/tcg/aarch64/bti-crt.inc.c new file +51 -0
51 lines not on this page · raw message
tests/tcg/aarch64/Makefile.target +6 -1
@@ -8,10 +8,15 @@ VPATH += $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=$(filter-out $(ARM_TESTS), $(TESTS)) AARCH64_TESTS+=fcvt -TESTS:=$(AARCH64_TESTS) fcvt: LDFLAGS+=-lm run-fcvt: fcvt $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)") $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref) + +AARCH64_TESTS += bti-1 +bti-1: LDFLAGS += -nostartfiles -nodefaultlibs -nostdlib +run-bti-1: QEMU += -cpu max,x-guarded-pages=on + +TESTS:=$(AARCH64_TESTS)
Signature · 1 line
2.17.2