Unaligned access for user only
v4 cover Unaligned access for user only
Version 3 was way back in August:
https://lore.kernel.org/qemu-devel/[email protected]/
Quite a few of the patches in there have been merged, but not all.
Based-on: <[email protected]>
There are follow-on patch sets for arm, mips, and sparc, which I will be refreshing soon. Xuerui, I believe that tcg/loongarch should be as simple as one of these five.
r~
Richard Henderson (7):
tcg/i386: Support raising sigbus for user-only tcg/aarch64: Support raising sigbus for user-only tcg/ppc: Support raising sigbus for user-only tcg/riscv: Support raising sigbus for user-only tcg/s390x: Support raising sigbus for user-only tcg/tci: Support raising sigbus for user-only tests/tcg/multiarch: Add sigbus.c
tcg/aarch64/tcg-target.h | 2 - tcg/i386/tcg-target.h | 2 - tcg/ppc/tcg-target.h | 2 - tcg/riscv/tcg-target.h | 2 - tcg/s390x/tcg-target.h | 2 - tcg/tci.c | 20 +++++-- tests/tcg/multiarch/sigbus.c | 68 +++++++++++++++++++++++ tcg/aarch64/tcg-target.c.inc | 91 +++++++++++++++++++++++++------ tcg/i386/tcg-target.c.inc | 103 +++++++++++++++++++++++++++++++++-- tcg/ppc/tcg-target.c.inc | 98 ++++++++++++++++++++++++++++++--- tcg/riscv/tcg-target.c.inc | 63 ++++++++++++++++++++- tcg/s390x/tcg-target.c.inc | 59 +++++++++++++++++++- 12 files changed, 462 insertions(+), 50 deletions(-) create mode 100644 tests/tcg/multiarch/sigbus.c
Signature · 1 line
2.25.1
PATCH v4 1/7 tcg/i386: Support raising sigbus for user-only
--- tcg/i386/tcg-target.h | 2 - tcg/i386/tcg-target.c.inc | 103 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 7 deletions(-)
tcg/i386/tcg-target.h +0 -2
@@ -232,9 +232,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_HAS_MEMORY_BSWAP have_movbe -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #endif
tcg/i386/tcg-target.c.inc +98 -5
163 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 2/7 tcg/aarch64: Support raising sigbus for user-only
In reply to Richard Henderson--- tcg/aarch64/tcg-target.h | 2 - tcg/aarch64/tcg-target.c.inc | 91 +++++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 19 deletions(-)
tcg/aarch64/tcg-target.h +0 -2
@@ -151,9 +151,7 @@ typedef enum {void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t ); -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #endif /* AARCH64_TCG_TARGET_H */
tcg/aarch64/tcg-target.c.inc +74 -17
164 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v4 2/7] tcg/aarch64: Support raising sigbus for user-only
Quoted 3 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v4 3/7 tcg/ppc: Support raising sigbus for user-only
In reply to Richard Henderson--- tcg/ppc/tcg-target.h | 2 - tcg/ppc/tcg-target.c.inc | 98 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 90 insertions(+), 10 deletions(-)
tcg/ppc/tcg-target.h +0 -2
@@ -182,9 +182,7 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #endif
tcg/ppc/tcg-target.c.inc +90 -8
171 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 4/7 tcg/riscv: Support raising sigbus for user-only
In reply to Richard Henderson--- tcg/riscv/tcg-target.h | 2 -- tcg/riscv/tcg-target.c.inc | 63 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-)
tcg/riscv/tcg-target.h +0 -2
@@ -165,9 +165,7 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_DEFAULT_MO (0) -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0
tcg/riscv/tcg-target.c.inc +61 -2
105 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 5/7 tcg/s390x: Support raising sigbus for user-only
In reply to Richard Henderson--- tcg/s390x/tcg-target.h | 2 -- tcg/s390x/tcg-target.c.inc | 59 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-)
tcg/s390x/tcg-target.h +0 -2
@@ -178,9 +178,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx, /* no need to flush icache explicitly */ } -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #endif
tcg/s390x/tcg-target.c.inc +57 -2
97 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 6/7 tcg/tci: Support raising sigbus for user-only
In reply to Richard Henderson--- tcg/tci.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
tcg/tci.c +14 -6
@@ -292,11 +292,11 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)static uint64_t tci_qemu_ld (CPUArchState *env,target_ulong taddr,MemOpIdx oi,const void *tb_ptr) { -MemOp mop =get_memop (oi) & (MO_BSWAP |MO_SSIZE ); +MemOp mop =get_memop (oi);uintptr_t ra = (uintptr_t )tb_ptr;#ifdef CONFIG_SOFTMMU -switch (mop) { +switch (mop & (MO_BSWAP |MO_SSIZE )) {case MO_UB :return helper_ret_ldub_mmu (env, taddr, oi, ra);case MO_SB :
@@ -326,10 +326,14 @@ static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr, }#else void *haddr =g2h (env_cpu (env), taddr); +unsigned a_mask = (1u <<get_alignment_bits (mop)) -1 ;uint64_t ret;set_helper_retaddr (ra); -switch (mop) { +if (taddr & a_mask) { +helper_unaligned_ld (env, taddr); + } +switch (mop & (MO_BSWAP |MO_SSIZE )) {case MO_UB : ret =ldub_p (haddr);break ;
@@ -377,11 +381,11 @@ static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,static void tci_qemu_st (CPUArchState *env,target_ulong taddr,uint64_t val,MemOpIdx oi,const void *tb_ptr) { -MemOp mop =get_memop (oi) & (MO_BSWAP |MO_SSIZE ); +MemOp mop =get_memop (oi);uintptr_t ra = (uintptr_t )tb_ptr;#ifdef CONFIG_SOFTMMU -switch (mop) { +switch (mop & (MO_BSWAP |MO_SIZE )) {case MO_UB :helper_ret_stb_mmu (env, taddr, val, oi, ra);break ;
@@ -408,9 +412,13 @@ static void tci_qemu_st(CPUArchState *env, target_ulong taddr, uint64_t val, }#else void *haddr =g2h (env_cpu (env), taddr); +unsigned a_mask = (1u <<get_alignment_bits (mop)) -1 ;set_helper_retaddr (ra); -switch (mop) { +if (taddr & a_mask) { +helper_unaligned_st (env, taddr); + } +switch (mop & (MO_BSWAP |MO_SIZE )) {case MO_UB :stb_p (haddr, val);break ;
Signature · 1 line
2.25.1
Re: [PATCH v4 6/7] tcg/tci: Support raising sigbus for user-only
Quoted 4 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/tci.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
PATCH v4 7/7 tests/tcg/multiarch: Add sigbus.c
In reply to Richard HendersonA mostly generic test for unaligned access raising SIGBUS.
--- tests/tcg/multiarch/sigbus.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/tcg/multiarch/sigbus.c
tests/tcg/multiarch/sigbus.c new file +68 -0
@@ -0,0 +1,68 @@ +#define _GNU_SOURCE 1 + +#include <assert.h> +#include <stdlib.h> +#include <signal.h> +#include <endian.h> + + +unsigned long long x =0x8877665544332211ull ; +void *volatile p = (void *)&x +1 ; + +void sigbus (int sig,siginfo_t *info,void *uc) +{ +assert (sig ==SIGBUS ); +assert (info->si_signo ==SIGBUS ); +#ifdef BUS_ADRALN +assert (info->si_code ==BUS_ADRALN ); +#endif +assert (info->si_addr == p); +exit (EXIT_SUCCESS ); +} + +int main () +{ +struct sigaction sa = { + .sa_sigaction = sigbus, + .sa_flags =SA_SIGINFO + }; +int allow_fail =0 ; +int tmp; + + tmp =sigaction (SIGBUS , &sa,NULL ); +assert (tmp ==0 ); + +/* +* Select an operation that's likely to enforce alignment. +* On many guests that support unaligned accesses by default, +* this is often an atomic operation. +*/ +#if defined(__aarch64__) + asmvolatile ("ldxr %w0,[%1]" :"=r" (tmp) :"r" (p) :"memory" ); +#elif defined(__alpha__) + asmvolatile ("ldl_l %0,0(%1)" :"=r" (tmp) :"r" (p) :"memory" ); +#elif defined(__arm__) + asmvolatile ("ldrex %0,[%1]" :"=r" (tmp) :"r" (p) :"memory" ); +#elif defined(__powerpc__) + asmvolatile ("lwarx %0,0,%1" :"=r" (tmp) :"r" (p) :"memory" ); +#elif defined(__riscv_atomic) + asmvolatile ("lr.w %0,(%1)" :"=r" (tmp) :"r" (p) :"memory" ); +#else +/* No insn known to fault unaligned -- try for a straight load. */ + allow_fail =1 ; + tmp = *(volatile int *)p; +#endif + +assert (allow_fail); + +/* +* We didn't see a signal. +* We might as well validate the unaligned load worked. +*/ +if (BYTE_ORDER ==LITTLE_ENDIAN ) { +assert (tmp ==0x55443322 ); + }else { +assert (tmp ==0x77665544 ); + } +return EXIT_SUCCESS ; +}
Signature · 1 line
2.25.1
Re: [PATCH v4 7/7] tests/tcg/multiarch: Add sigbus.c
Quoted 8 lines · Richard Henderson
A mostly generic test for unaligned access raising SIGBUS.
Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tests/tcg/multiarch/sigbus.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)create mode 100644
tests/tcg/multiarch/sigbus.c
Re: [PATCH v4 7/7] tests/tcg/multiarch: Add sigbus.c
In reply to Richard HendersonQuoted 4 lines · Richard Henderson
A mostly generic test for unaligned access raising SIGBUS.
Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Signature · 1 line
Alex Bennée
Hi Richard,
Quoted 11 lines · Richard Henderson
Version 3 was way back in August:
https://lore.kernel.org/qemu-devel/[email protected]/
Quite a few of the patches in there have been merged, but not all.
Based-on: <[email protected]>
There are follow-on patch sets for arm, mips, and sparc, which I will be refreshing soon. Xuerui, I believe that tcg/loongarch should be as simple as one of these five.
Thanks for the heads-up; I'll take care of implementing the loongarch64 part in this week (or maybe next week in case of $DAY_JOB).
Quoted 29 lines
r~
Richard Henderson (7):
tcg/i386: Support raising sigbus for user-only tcg/aarch64: Support raising sigbus for user-only tcg/ppc: Support raising sigbus for user-only tcg/riscv: Support raising sigbus for user-only tcg/s390x: Support raising sigbus for user-only tcg/tci: Support raising sigbus for user-only tests/tcg/multiarch: Addsigbus.ctcg/aarch64/tcg-target.h | 2 - tcg/i386/tcg-target.h | 2 - tcg/ppc/tcg-target.h | 2 - tcg/riscv/tcg-target.h | 2 - tcg/s390x/tcg-target.h | 2 - tcg/tci.c | 20 +++++-- tests/tcg/multiarch/sigbus.c | 68 +++++++++++++++++++++++ tcg/aarch64/tcg-target.c.inc | 91 +++++++++++++++++++++++++------ tcg/i386/tcg-target.c.inc | 103 +++++++++++++++++++++++++++++++++-- tcg/ppc/tcg-target.c.inc | 98 ++++++++++++++++++++++++++++++--- tcg/riscv/tcg-target.c.inc | 63 ++++++++++++++++++++- tcg/s390x/tcg-target.c.inc | 59 +++++++++++++++++++- 12 files changed, 462 insertions(+), 50 deletions(-)create mode 100644
tests/tcg/multiarch/sigbus.c