target-arm: Implement ARMv8.5-MemTag, user mode
v5 cover target-arm: Implement ARMv8.5-MemTag, user mode
The kernel abi was finally merged into 5.10.
Changes for v5:
* Actually include the revamp for TARGET_TAGGED_ADDRESSES,
which got lost at some point before posting v4.
Patches lacking review are only the new ones:
0011-exec-Introduce-cpu_untagged_addr.patch
0012-exec-Use-cpu_untagged_addr-in-g2h-split-out-g2h_u.patch
0013-linux-user-Explicitly-untag-memory-management-sys.patch
0014-linux-user-Use-guest_range_valid-in-access_ok.patch
0015-exec-Rename-guest_-addr-range-_valid-to-_untagged.patch
0016-linux-user-Use-cpu_untagged_addr-in-access_ok-spl.patch
0017-linux-user-Move-lock_user-et-al-out-of-line.patch
0018-linux-user-Fix-types-in-uaccess.c.patch
0019-linux-user-Handle-tags-in-lock_user-unlock_user.patchChanges for v4:
* Revamp "Add support for TARGET_TAGGED_ADDRESSES". There are now two sets of functions in include/exec/, one for tagged and one for untagged addresses. The former takes a CPUState, and does not assume current_cpu is a thing. So much for the generic bits... However, use of current_cpu remains, pushed down to lock_user. Changing everything that touches that, or get/put_user, is daunting.
* Fix tbi0 vs tbi1 for linux-user.
This had a number of cascading effects.
* Adjust when async errors are noticed.
Changes for v3:
* Split out type changes to separate patches.
* Add doc comments; tweak alloc so that the !PAGE_VALID case is clear.
* Do not overlap PAGE_TARGET_2 with PAGE_RESERVED.
* Use syndrome.h, arm_deliver_fault.
r~
Richard Henderson (31):
tcg: Introduce target-specific page data for user-only
linux-user: Introduce PAGE_ANON
exec: Use uintptr_t for guest_base
exec: Use uintptr_t in cpu_ldst.h
exec: Improve types for guest_addr_valid
linux-user: Check for overflow in access_ok
linux-user: Tidy VERIFY_READ/VERIFY_WRITE
bsd-user: Tidy VERIFY_READ/VERIFY_WRITE
linux-user: Do not use guest_addr_valid for h2g_valid
linux-user: Fix guest_addr_valid vs reserved_va
exec: Introduce cpu_untagged_addr
exec: Use cpu_untagged_addr in g2h; split out g2h_untagged
linux-user: Explicitly untag memory management syscalls
linux-user: Use guest_range_valid in access_ok
exec: Rename guest_{addr,range}_valid to *_untagged
linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged
linux-user: Move lock_user et al out of line
linux-user: Fix types in uaccess.c
linux-user: Handle tags in lock_user/unlock_user linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE target/arm: Improve gen_top_byte_ignore
target/arm: Use the proper TBI settings for linux-user linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG linux-user/aarch64: Implement PROT_MTE
target/arm: Split out syndrome.h from internals.h linux-user/aarch64: Pass syndrome to EXC_*_ABORT linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error target/arm: Add allocation tag storage for user mode target/arm: Enable MTE for user-only
tests/tcg/aarch64: Add mte smoke tests
bsd-user/qemu.h | 9 +- include/exec/cpu-all.h | 47 ++++- include/exec/cpu_ldst.h | 39 ++-- include/exec/exec-all.h | 2 +- linux-user/aarch64/target_signal.h | 3 + linux-user/aarch64/target_syscall.h | 13 ++ linux-user/qemu.h | 76 +++----- linux-user/syscall_defs.h | 1 + target/arm/cpu-param.h | 3 + target/arm/cpu.h | 32 ++++ target/arm/internals.h | 249 +------------------------ target/arm/syndrome.h | 273 ++++++++++++++++++++++++++++ tests/tcg/aarch64/mte.h | 60 ++++++ accel/tcg/translate-all.c | 32 +++- accel/tcg/user-exec.c | 57 +++--- bsd-user/main.c | 4 +- linux-user/aarch64/cpu_loop.c | 38 +++- linux-user/elfload.c | 18 +- linux-user/flatload.c | 2 +- linux-user/hppa/cpu_loop.c | 39 ++-- linux-user/i386/cpu_loop.c | 6 +- linux-user/i386/signal.c | 5 +- linux-user/main.c | 4 +- linux-user/mmap.c | 86 +++++---- linux-user/ppc/signal.c | 4 +- linux-user/syscall.c | 165 +++++++++++++---- linux-user/uaccess.c | 82 +++++++-- target/arm/cpu.c | 25 ++- target/arm/helper-a64.c | 4 +- target/arm/mte_helper.c | 39 +++- target/arm/tlb_helper.c | 15 +- target/arm/translate-a64.c | 25 +-- target/hppa/op_helper.c | 2 +- target/i386/tcg/mem_helper.c | 2 +- target/s390x/mem_helper.c | 4 +- tests/tcg/aarch64/mte-1.c | 28 +++ tests/tcg/aarch64/mte-2.c | 45 +++++ tests/tcg/aarch64/mte-3.c | 51 ++++++ tests/tcg/aarch64/mte-4.c | 45 +++++ tests/tcg/aarch64/pauth-2.c | 1 - tests/tcg/aarch64/Makefile.target | 6 + tests/tcg/configure.sh | 4 + 42 files changed, 1126 insertions(+), 519 deletions(-) create mode 100644 target/arm/syndrome.h create mode 100644 tests/tcg/aarch64/mte.h create mode 100644 tests/tcg/aarch64/mte-1.c create mode 100644 tests/tcg/aarch64/mte-2.c create mode 100644 tests/tcg/aarch64/mte-3.c create mode 100644 tests/tcg/aarch64/mte-4.c
Signature · 1 line
2.25.1
PATCH v5 1/31 tcg: Introduce target-specific page data for user-only
This data can be allocated by page_alloc_target_data() and released by page_set_flags(start, end, prot | PAGE_RESET).
This data will be used to hold tag memory for AArch64 MTE.
--- include/exec/cpu-all.h | 42 +++++++++++++++++++++++++++++++++------ accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++ linux-user/mmap.c | 4 +++- linux-user/syscall.c | 4 ++-- 4 files changed, 69 insertions(+), 9 deletions(-)
include/exec/cpu-all.h +36 -6
@@ -264,15 +264,21 @@ extern intptr_t qemu_host_page_mask;#define PAGE_EXEC 0x0004#define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)#define PAGE_VALID 0x0008 -/* original state of the write flag (used when tracking self-modifying -code */ +/* +* Original state of the write flag (used when tracking self-modifying code) +*/ #define PAGE_WRITE_ORG 0x0010 -/* Invalidate the TLB entry immediately, helpful for s390x -* Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() */ -#define PAGE_WRITE_INV 0x0040 +/* +* Invalidate the TLB entry immediately, helpful for s390x +* Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() +*/ +#define PAGE_WRITE_INV 0x0020 +/* For use with page_set_flags: page is being replaced; target_data cleared. */ +#define PAGE_RESET 0x0040 +#if defined(CONFIG_BSD ) && defined(CONFIG_USER_ONLY )/* FIXME: Code that sets/uses this is broken and needs to go away. */ -#define PAGE_RESERVED 0x0020 +#define PAGE_RESERVED 0x0100#endif /* Target-specific bits that will be used via page_get_flags(). */ #define PAGE_TARGET_1 0x0080
@@ -287,6 +293,30 @@ int walk_memory_regions(void *, walk_memory_regions_fn);int page_get_flags (target_ulong address);void page_set_flags (target_ulong start,target_ulong end,int flags);int page_check_range (target_ulong start,target_ulong len,int flags); + +/** +* page_alloc_target_data(address, size) +* @address: guest virtual address +* @size: size of data to allocate +* +* Allocate @size bytes of out-of-band data to associate with the +* guest page at @address. If the page is not mapped, NULL will +* be returned. If there is existing data associated with @address, +* no new memory will be allocated. +* +* The memory will be freed when the guest page is deallocated, +* e.g. with the munmap system call. +*/ +void *page_alloc_target_data (target_ulong address,size_t size); + +/** +* page_get_target_data(address) +* @address: guest virtual address +* +* Return any out-of-bound memory assocated with the guest page +* at @address, as per page_alloc_target_data. +*/ +void *page_get_target_data (target_ulong address);#endif CPUArchState *cpu_copy (CPUArchState *env);
accel/tcg/translate-all.c +28 -0
@@ -114,6 +114,7 @@ typedef struct PageDesc {unsigned int code_write_count;#else unsigned long flags; +void *target_data;#endif #ifndef CONFIG_USER_ONLY QemuSpin lock;
@@ -2740,6 +2741,7 @@ int page_get_flags(target_ulong address)void page_set_flags (target_ulong start,target_ulong end,int flags) {target_ulong addr, len; +bool reset_target_data;/* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates
@@ -2754,6 +2756,8 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)if (flags &PAGE_WRITE ) { flags |=PAGE_WRITE_ORG ; } + reset_target_data = !(flags &PAGE_VALID ) || (flags &PAGE_RESET ); + flags &= ~PAGE_RESET ; for (addr = start, len = end - start; len != 0;
@@ -2767,10 +2771,34 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) p->first_tb) {tb_invalidate_phys_page (addr,0 ); } +if (reset_target_data && p->target_data) { +g_free (p->target_data); + p->target_data =NULL ; + } p->flags = flags; } } +void *page_get_target_data (target_ulong address) +{ +PageDesc *p =page_find (address >>TARGET_PAGE_BITS ); +return p ? p->target_data :NULL ; +} + +void *page_alloc_target_data (target_ulong address,size_t size) +{ +PageDesc *p =page_find (address >>TARGET_PAGE_BITS ); +void *ret =NULL ; + +if (p->flags &PAGE_VALID ) { + ret = p->target_data; +if (!ret) { + p->target_data = ret =g_malloc0 (size); + } + } +return ret; +} +int page_check_range (target_ulong start,target_ulong len,int flags) {PageDesc *p;
linux-user/mmap.c +3 -1
@@ -599,6 +599,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } } the_end1: + page_flags |=PAGE_RESET ;page_set_flags (start, start + len, page_flags); the_end:trace_target_mmap_complete (start);
@@ -792,7 +793,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, new_addr =h2g (host_addr); prot =page_get_flags (old_addr);page_set_flags (old_addr, old_addr + old_size,0 ); -page_set_flags (new_addr, new_addr + new_size, prot |PAGE_VALID ); +page_set_flags (new_addr, new_addr + new_size, + prot |PAGE_VALID |PAGE_RESET ); }tb_invalidate_phys_range (new_addr, new_addr + new_size);mmap_unlock ();
linux-user/syscall.c +2 -2
@@ -4632,8 +4632,8 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, raddr=h2g ((unsigned long )host_raddr);page_set_flags (raddr, raddr + shm_info.shm_segsz, -PAGE_VALID |PAGE_READ | - ((shmflg &SHM_RDONLY )?0 :PAGE_WRITE )); +PAGE_VALID |PAGE_RESET |PAGE_READ | + (shmflg &SHM_RDONLY ?0 :PAGE_WRITE ));for (i =0 ; i <N_SHM_REGIONS ; i++) {if (!shm_regions[i].in_use) {
Signature · 1 line
2.25.1
PATCH v5 2/31 linux-user: Introduce PAGE_ANON
In reply to Richard HendersonRecord whether the backing page is anonymous, or if it has file backing. This will allow us to get close to the Linux AArch64 ABI for MTE, which allows tag memory only on ram-backed VMAs.
The real ABI allows tag memory on files, when those files are on ram-backed filesystems, such as tmpfs. We will not be able to implement that in QEMU linux-user.
Thankfully, anonymous memory for malloc arenas is the primary consumer of this feature, so this restricted version should still be of use.
--- include/exec/cpu-all.h | 2 ++ linux-user/mmap.c | 3 +++ 2 files changed, 5 insertions(+)
include/exec/cpu-all.h +2 -0
@@ -275,6 +275,8 @@ extern intptr_t qemu_host_page_mask;#define PAGE_WRITE_INV 0x0020/* For use with page_set_flags: page is being replaced; target_data cleared. */ #define PAGE_RESET 0x0040 +/* For linux-user, indicates that the page is MAP_ANON. */ +#define PAGE_ANON 0x0080#if defined(CONFIG_BSD ) && defined(CONFIG_USER_ONLY )/* FIXME: Code that sets/uses this is broken and needs to go away. */
linux-user/mmap.c +3 -0
@@ -599,6 +599,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } } the_end1: +if (flags &MAP_ANONYMOUS ) { + page_flags |=PAGE_ANON ; + } page_flags |=PAGE_RESET ;page_set_flags (start, start + len, page_flags); the_end:
Signature · 1 line
2.25.1
PATCH v5 3/31 exec: Use uintptr_t for guest_base
In reply to Richard HendersonThis is more descriptive than 'unsigned long'.
No functional change, since these match on all linux+bsd hosts.
--- include/exec/cpu-all.h | 2 +- bsd-user/main.c | 4 ++-- linux-user/elfload.c | 4 ++-- linux-user/main.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
include/exec/cpu-all.h +1 -1
@@ -158,7 +158,7 @@ static inline void tswap64s(uint64_t *s)/* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. */ -extern unsigned long guest_base; +extern uintptr_t guest_base;extern bool have_guest_base;extern unsigned long reserved_va;
bsd-user/main.c +2 -2
@@ -41,7 +41,7 @@int singlestep;unsigned long mmap_min_addr; -unsigned long guest_base; +uintptr_t guest_base;bool have_guest_base;unsigned long reserved_va;
@@ -965,7 +965,7 @@ int main(int argc, char **argv)g_free (target_environ);if (qemu_loglevel_mask (CPU_LOG_PAGE )) { -qemu_log ("guest_base 0x%lx\n" , guest_base); +qemu_log ("guest_base %p\n" , (void *)guest_base);log_page_dump ("binary load" );qemu_log ("start_brk 0x" TARGET_ABI_FMT_lx"\n" , info->start_brk);
linux-user/elfload.c +2 -2
@@ -2135,9 +2135,9 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,void *addr, *test;if (!QEMU_IS_ALIGNED (guest_base, align)) { -fprintf (stderr,"Requested guest base 0x%lx does not satisfy " +fprintf (stderr,"Requested guest base %p does not satisfy " "host minimum alignment (0x%lx)\n" , - guest_base, align); + (void *)guest_base, align);exit (EXIT_FAILURE ); }
linux-user/main.c +2 -2
@@ -58,7 +58,7 @@ static const char *cpu_model;static const char *cpu_type;static const char *seed_optarg;unsigned long mmap_min_addr; -unsigned long guest_base; +uintptr_t guest_base;bool have_guest_base;/*
@@ -819,7 +819,7 @@ int main(int argc, char **argv, char **envp)g_free (target_environ);if (qemu_loglevel_mask (CPU_LOG_PAGE )) { -qemu_log ("guest_base 0x%lx\n" , guest_base); +qemu_log ("guest_base %p\n" , (void *)guest_base);log_page_dump ("binary load" );qemu_log ("start_brk 0x" TARGET_ABI_FMT_lx"\n" , info->start_brk);
Signature · 1 line
2.25.1
Re: [PATCH v5 03/31] exec: Use uintptr_t for guest_base
Quoted 39 lines · Richard Henderson
This is more descriptive than 'unsigned long'.
No functional change, since these match on all linux+bsd hosts.Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 2 +- bsd-user/main.c | 4 ++-- linux-user/elfload.c | 4 ++-- linux-user/main.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)include/exec/cpu-all.h +1
-1@@ -158,7 +158,7 @@ static inline void tswap64s(uint64_t *s)/* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. */ -extern unsigned long guest_base; +extern uintptr_t guest_base;extern bool have_guest_base;extern unsigned long reserved_va;bsd-user/main.c +1
-1@@ -41,7 +41,7 @@int singlestep;unsigned long mmap_min_addr; -unsigned long guest_base; +uintptr_t guest_base;bool have_guest_base;unsigned long reserved_va;
bsd-user/main.c int main(int argc, char **argv) · line 968
Quoted 5 lines
bsd-user/main.c +1
-1@@ -965,7 +965,7 @@ int main(int argc, char **argv)g_free (target_environ);if (qemu_loglevel_mask (CPU_LOG_PAGE )) { -qemu_log ("guest_base 0x%lx\n" , guest_base); +qemu_log ("guest_base %p\n" , (void *)guest_base);
Why not use PRIxPTR?
Otherwise:
Re: [PATCH v5 03/31] exec: Use uintptr_t for guest_base
Quoted 39 lines · Philippe Mathieu-Daudé
Quoted 38 lines · Richard Henderson
This is more descriptive than 'unsigned long'.
No functional change, since these match on all linux+bsd hosts.Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 2 +- bsd-user/main.c | 4 ++-- linux-user/elfload.c | 4 ++-- linux-user/main.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)include/exec/cpu-all.h +1
-1@@ -158,7 +158,7 @@ static inline void tswap64s(uint64_t *s)/* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. */ -extern unsigned long guest_base; +extern uintptr_t guest_base;extern bool have_guest_base;extern unsigned long reserved_va;bsd-user/main.c +1
-1@@ -41,7 +41,7 @@int singlestep;unsigned long mmap_min_addr; -unsigned long guest_base; +uintptr_t guest_base;bool have_guest_base;unsigned long reserved_va;
Quoted 8 lines
bsd-user/main.c int main(int argc, char **argv) · line 968
Quoted 6 lines
bsd-user/main.c +1
-1@@ -965,7 +965,7 @@ int main(int argc, char **argv)g_free (target_environ);if (qemu_loglevel_mask (CPU_LOG_PAGE )) { -qemu_log ("guest_base 0x%lx\n" , guest_base); +qemu_log ("guest_base %p\n" , (void *)guest_base);Why not use PRIxPTR?
Didn't think of it. Worth a respin?
Quoted 4 lines
Otherwise:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH v5 03/31] exec: Use uintptr_t for guest_base
Quoted 43 lines · Richard Henderson
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 41 lines · Richard Henderson
This is more descriptive than 'unsigned long'.
No functional change, since these match on all linux+bsd hosts.Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu-all.h | 2 +- bsd-user/main.c | 4 ++-- linux-user/elfload.c | 4 ++-- linux-user/main.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)include/exec/cpu-all.h +1
-1@@ -158,7 +158,7 @@ static inline void tswap64s(uint64_t *s)/* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. */ -extern unsigned long guest_base; +extern uintptr_t guest_base;extern bool have_guest_base;extern unsigned long reserved_va;bsd-user/main.c +1
-1@@ -41,7 +41,7 @@int singlestep;unsigned long mmap_min_addr; -unsigned long guest_base; +uintptr_t guest_base;bool have_guest_base;unsigned long reserved_va;@@ -965,7 +965,7 @@ int main(int argc, char **argv)g_free (target_environ);
Quoted 7 lines
Quoted 5 lines
bsd-user/main.c int main(int argc, char **argv) · line 968
Quoted 3 lines
bsd-user/main.c +1
-1if (qemu_loglevel_mask (CPU_LOG_PAGE )) { -qemu_log ("guest_base 0x%lx\n" , guest_base); +qemu_log ("guest_base %p\n" , (void *)guest_base);Why not use PRIxPTR?
Didn't think of it. Worth a respin?
No, I was simply curious if it weren't possible for some reason.
Quoted 5 lines
Quoted 4 lines
Otherwise:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
PATCH v5 4/31 exec: Use uintptr_t in cpu_ldst.h
In reply to Richard HendersonThis is more descriptive than 'unsigned long'.
No functional change, since these match on all linux+bsd hosts.
--- include/exec/cpu_ldst.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/exec/cpu_ldst.h +3 -3
@@ -70,14 +70,14 @@ typedef uint64_t abi_ptr;#endif /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h (x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) +#define g2h (x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base))#if HOST_LONG_BITS <=TARGET_VIRT_ADDR_SPACE_BITS #define guest_addr_valid (x) (1)#else #define guest_addr_valid (x) ((x) <= GUEST_ADDR_MAX)#endif -#define h2g_valid (x) guest_addr_valid((unsigned long)(x) - guest_base) +#define h2g_valid (x) guest_addr_valid((uintptr_t)(x) - guest_base)static inline int guest_range_valid (unsigned long start,unsigned long len) {
@@ -85,7 +85,7 @@ static inline int guest_range_valid(unsigned long start, unsigned long len) }#define h2g_nocheck (x) ({ \ - unsigned long __ret = (unsigned long)(x) - guest_base; \ + uintptr_t __ret = (uintptr_t)(x) - guest_base; \ (abi_ptr)__ret; \ })
Signature · 1 line
2.25.1
PATCH v5 5/31 exec: Improve types for guest_addr_valid
In reply to Richard HendersonReturn bool not int; pass abi_ulong not 'unsigned long'. All callers use abi_ulong already, so the change in type has no effect.
--- include/exec/cpu_ldst.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu_ldst.h +1 -1
@@ -79,7 +79,7 @@ typedef uint64_t abi_ptr;#endif #define h2g_valid (x) guest_addr_valid((uintptr_t)(x) - guest_base) -static inline int guest_range_valid (unsigned long start,unsigned long len) +static inline bool guest_range_valid (abi_ulong start,abi_ulong len) {return len -1 <=GUEST_ADDR_MAX && start <=GUEST_ADDR_MAX - len +1 ; }
Signature · 1 line
2.25.1
PATCH v5 6/31 linux-user: Check for overflow in access_ok
In reply to Richard HendersonVerify that addr + size - 1 does not wrap around.
--- linux-user/qemu.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
linux-user/qemu.h +12 -5
@@ -491,12 +491,19 @@ extern unsigned long guest_stack_size;#define VERIFY_READ 0#define VERIFY_WRITE 1/* implies read access */ -static inline int access_ok (int type,abi_ulong addr,abi_ulong size) +static inline bool access_ok (int type,abi_ulong addr,abi_ulong size) { -return guest_addr_valid (addr) && - (size ==0 ||guest_addr_valid (addr + size -1 )) && -page_check_range ((target_ulong )addr, size, - (type ==VERIFY_READ ) ?PAGE_READ : (PAGE_READ |PAGE_WRITE )) ==0 ; +if (!guest_addr_valid (addr)) { +return false; + } +if (size !=0 && + (addr + size -1 < addr || + !guest_addr_valid (addr + size -1 ))) { +return false; + } +return page_check_range ((target_ulong )addr, size, + (type ==VERIFY_READ ) ?PAGE_READ : + (PAGE_READ |PAGE_WRITE )) ==0 ; }/* NOTE __get_user and __put_user use host pointers and don't check access.
Signature · 1 line
2.25.1
PATCH v5 7/31 linux-user: Tidy VERIFY_READ/VERIFY_WRITE
In reply to Richard HendersonThese constants are only ever used with access_ok, and friends. Rather than translating them to PAGE_* bits, let them equal the PAGE_* bits to begin.
--- linux-user/qemu.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
linux-user/qemu.h +3 -5
@@ -488,8 +488,8 @@ extern unsigned long guest_stack_size;/* user access */ -#define VERIFY_READ 0 -#define VERIFY_WRITE 1/* implies read access */ +#define VERIFY_READ PAGE_READ +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)static inline bool access_ok (int type,abi_ulong addr,abi_ulong size) {
@@ -501,9 +501,7 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) !guest_addr_valid(addr + size - 1))) {return false; } -return page_check_range ((target_ulong )addr, size, - (type ==VERIFY_READ ) ?PAGE_READ : - (PAGE_READ |PAGE_WRITE )) ==0 ; +return page_check_range ((target_ulong )addr, size, type) ==0 ; }/* NOTE __get_user and __put_user use host pointers and don't check access.
Signature · 1 line
2.25.1
PATCH v5 8/31 bsd-user: Tidy VERIFY_READ/VERIFY_WRITE
In reply to Richard HendersonThese constants are only ever used with access_ok, and friends. Rather than translating them to PAGE_* bits, let them equal the PAGE_* bits to begin.
--- bsd-user/qemu.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
bsd-user/qemu.h +4 -5
@@ -218,13 +218,12 @@ extern unsigned long x86_stack_size;/* user access */ -#define VERIFY_READ 0 -#define VERIFY_WRITE 1/* implies read access */ +#define VERIFY_READ PAGE_READ +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) -static inline int access_ok (int type,abi_ulong addr,abi_ulong size) +static inline bool access_ok (int type,abi_ulong addr,abi_ulong size) { -return page_check_range ((target_ulong )addr, size, - (type ==VERIFY_READ ) ?PAGE_READ : (PAGE_READ |PAGE_WRITE )) ==0 ; +return page_check_range ((target_ulong )addr, size, type) ==0 ; }/* NOTE __get_user and __put_user use host pointers and don't check access. */
Signature · 1 line
2.25.1
PATCH v5 9/31 linux-user: Do not use guest_addr_valid for h2g_valid
In reply to Richard HendersonThis is the only use of guest_addr_valid that does not begin with a guest address, but a host address being transformed to a guest address.
We will shortly adjust guest_addr_valid to handle guest memory tags, and the host address should not be subjected to that.
Move h2g_valid adjacent to the other h2g macros.
--- include/exec/cpu_ldst.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/exec/cpu_ldst.h +4 -1
@@ -77,13 +77,16 @@ typedef uint64_t abi_ptr;#else #define guest_addr_valid (x) ((x) <= GUEST_ADDR_MAX)#endif -#define h2g_valid (x) guest_addr_valid((uintptr_t)(x) - guest_base)static inline bool guest_range_valid (abi_ulong start,abi_ulong len) {return len -1 <=GUEST_ADDR_MAX && start <=GUEST_ADDR_MAX - len +1 ; } +#define h2g_valid (x) \ + (HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS || \ + (uintptr_t)(x) - guest_base <= GUEST_ADDR_MAX) +#define h2g_nocheck (x) ({ \ uintptr_t __ret = (uintptr_t)(x) - guest_base; \ (abi_ptr)__ret; \
Signature · 1 line
2.25.1
PATCH v5 10/31 linux-user: Fix guest_addr_valid vs reserved_va
In reply to Richard HendersonWe must always use GUEST_ADDR_MAX, because even 32-bit hosts can use -R <reserved_va> to restrict the memory address of the guest.
--- include/exec/cpu_ldst.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
include/exec/cpu_ldst.h +4 -5
@@ -72,11 +72,10 @@ typedef uint64_t abi_ptr;/* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h (x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) -#if HOST_LONG_BITS <=TARGET_VIRT_ADDR_SPACE_BITS -#define guest_addr_valid (x) (1) -#else -#define guest_addr_valid (x) ((x) <= GUEST_ADDR_MAX) -#endif +static inline bool guest_addr_valid (abi_ulong x) +{ +return x <=GUEST_ADDR_MAX ; +}static inline bool guest_range_valid (abi_ulong start,abi_ulong len) {
Signature · 1 line
2.25.1
PATCH v5 11/31 exec: Introduce cpu_untagged_addr
In reply to Richard HendersonProvide an identity fallback for target that do not use tagged addresses.
--- include/exec/cpu_ldst.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/exec/cpu_ldst.h +7 -0
@@ -69,6 +69,13 @@ typedef uint64_t abi_ptr;#define TARGET_ABI_FMT_ptr "%"PRIx64#endif +#ifndef TARGET_TAGGED_ADDRESSES +static inline abi_ptr cpu_untagged_addr (CPUState *cs,abi_ptr x) +{ +return x; +} +#endif +/* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h (x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base))
Signature · 1 line
2.25.1
Re: [PATCH v5 11/31] exec: Introduce cpu_untagged_addr
Quoted 8 lines · Richard Henderson
Provide an identity fallback for target that do not use tagged addresses.
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu_ldst.h | 7 +++++++ 1 file changed, 7 insertions(+)
thanks
-- PMM
PATCH v5 12/31 exec: Use cpu_untagged_addr in g2h; split out g2h_untagged
In reply to Richard HendersonUse g2h_untagged in contexts that have no cpu, e.g. the binary loaders that operate before the primary cpu is created. As a collolary, target_mmap and friends must use untagged addresses, since they are used by the loaders.
Use g2h_untagged on values returned from target_mmap, as the kernel never applies a tag itself.
Use g2h_untagged on all pc values. The only current user of tags, aarch64, removes tags from code addresses upon branch, so "pc" is always untagged.
Use g2h with the cpu context on hand whereever possible.
Use g2h_untagged in lock_user, which will be updated soon.
--- include/exec/cpu_ldst.h | 12 +++++- include/exec/exec-all.h | 2 +- linux-user/qemu.h | 6 +-- accel/tcg/translate-all.c | 4 +- accel/tcg/user-exec.c | 48 ++++++++++++------------ linux-user/elfload.c | 12 +++--- linux-user/flatload.c | 2 +- linux-user/hppa/cpu_loop.c | 31 ++++++++-------- linux-user/i386/cpu_loop.c | 4 +- linux-user/mmap.c | 45 +++++++++++----------- linux-user/ppc/signal.c | 4 +- linux-user/syscall.c | 72 +++++++++++++++++++----------------- target/arm/helper-a64.c | 4 +- target/hppa/op_helper.c | 2 +- target/i386/tcg/mem_helper.c | 2 +- target/s390x/mem_helper.c | 4 +- 16 files changed, 135 insertions(+), 119 deletions(-)
include/exec/cpu_ldst.h +10 -2
@@ -77,7 +77,15 @@ static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)#endif /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h (x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) +static inline void *g2h_untagged (abi_ptr x) +{ +return (void *)((uintptr_t )(x) + guest_base); +} + +static inline void *g2h (CPUState *cs,abi_ptr x) +{ +return g2h_untagged (cpu_untagged_addr (cs, x)); +}static inline bool guest_addr_valid (abi_ulong x) {
@@ -448,7 +456,7 @@ static inline int cpu_ldsw_code(CPUArchState *env, abi_ptr addr)static inline void *tlb_vaddr_to_host (CPUArchState *env,abi_ptr addr,MMUAccessType access_type,int mmu_idx) { -return g2h (addr); +return g2h (env_cpu (env), addr); }#else void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr,
include/exec/exec-all.h +1 -1
@@ -616,7 +616,7 @@ static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, void **hostp) {if (hostp) { - *hostp =g2h (addr); + *hostp =g2h_untagged (addr); }return addr; }
linux-user/qemu.h +3 -3
@@ -652,7 +652,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy return addr; }#else -return g2h (guest_addr); +return g2h_untagged (guest_addr);#endif }
@@ -666,10 +666,10 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,#ifdef DEBUG_REMAP if (!host_ptr)return ; -if (host_ptr ==g2h (guest_addr)) +if (host_ptr ==g2h_untagged (guest_addr))return ;if (len >0 ) -memcpy (g2h (guest_addr), host_ptr, len); +memcpy (g2h_untagged (guest_addr), host_ptr, len);g_free (host_ptr);#endif }
accel/tcg/translate-all.c +2 -2
@@ -1762,7 +1762,7 @@ static inline void tb_page_add(PageDesc *p, TranslationBlock *tb, prot |= p2->flags; p2->flags &= ~PAGE_WRITE ; } -mprotect (g2h (page_addr), qemu_host_page_size, +mprotect (g2h_untagged (page_addr), qemu_host_page_size, (prot &PAGE_BITS ) & ~PAGE_WRITE );if (DEBUG_TB_INVALIDATE_GATE ) {printf ("protecting code page: 0x" TB_PAGE_ADDR_FMT "\n" , page_addr);
@@ -2912,7 +2912,7 @@ int page_unprotect(target_ulong address, uintptr_t pc) }#endif } -mprotect ((void *)g2h (host_start), qemu_host_page_size, +mprotect ((void *)g2h_untagged (host_start), qemu_host_page_size, prot &PAGE_BITS ); }mmap_unlock ();
accel/tcg/user-exec.c +24 -24
192 lines not on this page · raw message
linux-user/elfload.c +6 -6
@@ -389,7 +389,7 @@ enum {static bool init_guest_commpage (void ) { -void *want =g2h (ARM_COMMPAGE & -qemu_host_page_size); +void *want =g2h_untagged (ARM_COMMPAGE & -qemu_host_page_size);void *addr =mmap (want, qemu_host_page_size,PROT_READ |PROT_WRITE ,MAP_ANONYMOUS |MAP_PRIVATE |MAP_FIXED ,-1 ,0 );
@@ -402,7 +402,7 @@ static bool init_guest_commpage(void) }/* Set kernel helper versions; rest of page is 0. */ -__put_user (5 , (uint32_t *)g2h (0xffff0ffcu )); +__put_user (5 , (uint32_t *)g2h_untagged (0xffff0ffcu ));if (mprotect (addr, qemu_host_page_size,PROT_READ )) {perror ("Protecting guest commpage" );
@@ -1872,8 +1872,8 @@ static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot)here is still actually needed. For now, continue with it, but merge it with the "normal" mmap that would allocate the bss. */ - host_start = (uintptr_t )g2h (elf_bss); - host_end = (uintptr_t )g2h (last_bss); + host_start = (uintptr_t )g2h_untagged (elf_bss); + host_end = (uintptr_t )g2h_untagged (last_bss); host_map_start =REAL_HOST_PAGE_ALIGN (host_start);if (host_map_start < host_end) {
@@ -2171,7 +2171,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, }/* Reserve the address space for the binary, or reserved_va. */ - test =g2h (guest_loaddr); + test =g2h_untagged (guest_loaddr); addr =mmap (test, guest_hiaddr - guest_loaddr,PROT_NONE , flags,-1 ,0 );if (test != addr) {pgb_fail_in_use (image_name);
@@ -2393,7 +2393,7 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr,/* Reserve the memory on the host. */ assert (guest_base !=0 ); - test =g2h (0 ); + test =g2h_untagged (0 ); addr =mmap (test, reserved_va,PROT_NONE , flags,-1 ,0 );if (addr ==MAP_FAILED || addr != test) { error_report("Unable to reserve 0x%lx bytes of virtual address "
linux-user/flatload.c +1 -1
@@ -668,7 +668,7 @@ static int load_flat_file(struct linux_binprm * bprm, }/* zero the BSS. */ -memset (g2h (datapos + data_len),0 , bss_len); +memset (g2h_untagged (datapos + data_len),0 , bss_len);return 0 ; }
linux-user/hppa/cpu_loop.c +16 -15
@@ -23,6 +23,7 @@static abi_ulong hppa_lws (CPUHPPAState *env) { +CPUState *cs =env_cpu (env);uint32_t which = env->gr[20 ];abi_ulong addr = env->gr[26 ];abi_ulong old = env->gr[25 ];
@@ -39,7 +40,7 @@ static abi_ulong hppa_lws(CPUHPPAState *env) } old =tswap32 (old); new =tswap32 (new); - ret =qatomic_cmpxchg ((uint32_t *)g2h (addr), old, new); + ret =qatomic_cmpxchg ((uint32_t *)g2h (cs, addr), old, new); ret =tswap32 (ret);break ;
@@ -58,38 +59,38 @@ static abi_ulong hppa_lws(CPUHPPAState *env)can be host-endian as well. */ switch (size) {case 0 : - old = *(uint8_t *)g2h (old); - new = *(uint8_t *)g2h (new); - ret =qatomic_cmpxchg ((uint8_t *)g2h (addr), old, new); + old = *(uint8_t *)g2h (cs, old); + new = *(uint8_t *)g2h (cs, new); + ret =qatomic_cmpxchg ((uint8_t *)g2h (cs, addr), old, new); ret = ret != old;break ;case 1 : - old = *(uint16_t *)g2h (old); - new = *(uint16_t *)g2h (new); - ret =qatomic_cmpxchg ((uint16_t *)g2h (addr), old, new); + old = *(uint16_t *)g2h (cs, old); + new = *(uint16_t *)g2h (cs, new); + ret =qatomic_cmpxchg ((uint16_t *)g2h (cs, addr), old, new); ret = ret != old;break ;case 2 : - old = *(uint32_t *)g2h (old); - new = *(uint32_t *)g2h (new); - ret =qatomic_cmpxchg ((uint32_t *)g2h (addr), old, new); + old = *(uint32_t *)g2h (cs, old); + new = *(uint32_t *)g2h (cs, new); + ret =qatomic_cmpxchg ((uint32_t *)g2h (cs, addr), old, new); ret = ret != old;break ;case 3 : {uint64_t o64, n64, r64; - o64 = *(uint64_t *)g2h (old); - n64 = *(uint64_t *)g2h (new); + o64 = *(uint64_t *)g2h (cs, old); + n64 = *(uint64_t *)g2h (cs, new);#ifdef CONFIG_ATOMIC64 - r64 =qatomic_cmpxchg__nocheck ((uint64_t *)g2h (addr), + r64 =qatomic_cmpxchg__nocheck ((uint64_t *)g2h (cs, addr), o64, n64); ret = r64 != o64;#else start_exclusive (); - r64 = *(uint64_t *)g2h (addr); + r64 = *(uint64_t *)g2h (cs, addr); ret =1 ;if (r64 == o64) { - *(uint64_t *)g2h (addr) = n64; + *(uint64_t *)g2h (cs, addr) = n64; ret =0 ; }end_exclusive ();
linux-user/i386/cpu_loop.c +2 -2
@@ -379,7 +379,7 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) env->idt.base =target_mmap (0 ,sizeof (uint64_t ) * (env->idt.limit +1 ),PROT_READ |PROT_WRITE ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); - idt_table =g2h (env->idt.base); + idt_table =g2h_untagged (env->idt.base);set_idt (0 ,0 );set_idt (1 ,0 );set_idt (2 ,0 );
@@ -409,7 +409,7 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)PROT_READ |PROT_WRITE , MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); env->gdt.limit =sizeof (uint64_t ) *TARGET_GDT_ENTRIES -1 ; - gdt_table =g2h (env->gdt.base); + gdt_table =g2h_untagged (env->gdt.base);#ifdef TARGET_ABI32 write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
linux-user/mmap.c +24 -21
148 lines not on this page · raw message
linux-user/ppc/signal.c +2 -2
@@ -365,7 +365,7 @@ static void restore_user_regs(CPUPPCState *env,uint64_t v_addr;/* 64-bit needs to recover the pointer to the vectors from the frame */ __get_user (v_addr, &frame->v_regs); - v_regs =g2h (v_addr); + v_regs =g2h (env_cpu (env), v_addr);#else v_regs = (ppc_avr_t *)frame->mc_vregs.altivec;#endif
@@ -552,7 +552,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,if (get_ppc64_abi (image) <2 ) {/* ELFv1 PPC64 function pointers are pointers to OPD entries. */ struct target_func_ptr *handler = - (struct target_func_ptr *)g2h (ka->_sa_handler); + (struct target_func_ptr *)g2h (env_cpu (env), ka->_sa_handler); env->nip =tswapl (handler->entry); env->gpr[2 ] =tswapl (handler->toc); }else {
linux-user/syscall.c +38 -34
209 lines not on this page · raw message
target/arm/helper-a64.c +2 -2
@@ -542,7 +542,7 @@ uint64_t HELPER(paired_cmpxchg64_le)(CPUARMState *env, uint64_t addr,#ifdef CONFIG_USER_ONLY /* ??? Enforce alignment. */ -uint64_t *haddr =g2h (addr); +uint64_t *haddr =g2h (env_cpu (env), addr);set_helper_retaddr (ra); o0 =ldq_le_p (haddr +0 );
@@ -612,7 +612,7 @@ uint64_t HELPER(paired_cmpxchg64_be)(CPUARMState *env, uint64_t addr,#ifdef CONFIG_USER_ONLY /* ??? Enforce alignment. */ -uint64_t *haddr =g2h (addr); +uint64_t *haddr =g2h (env_cpu (env), addr);set_helper_retaddr (ra); o1 =ldq_be_p (haddr +0 );
target/hppa/op_helper.c +1 -1
@@ -63,7 +63,7 @@ static void atomic_store_3(CPUHPPAState *env, target_ulong addr, uint32_t val,#ifdef CONFIG_USER_ONLY uint32_t old, new, cmp; -uint32_t *haddr =g2h (addr -1 ); +uint32_t *haddr =g2h (env_cpu (env), addr -1 ); old = *haddr;while (1 ) { new = (old & ~mask) | (val & mask);
target/i386/tcg/mem_helper.c +1 -1
@@ -66,7 +66,7 @@ void helper_cmpxchg8b(CPUX86State *env, target_ulong a0)#ifdef CONFIG_USER_ONLY { -uint64_t *haddr =g2h (a0); +uint64_t *haddr =g2h (env_cpu (env), a0); cmpv =cpu_to_le64 (cmpv); newv =cpu_to_le64 (newv); oldv =qatomic_cmpxchg__nocheck (haddr, cmpv, newv);
target/s390x/mem_helper.c +2 -2
@@ -1780,7 +1780,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,if (parallel) {#ifdef CONFIG_USER_ONLY -uint32_t *haddr =g2h (a1); +uint32_t *haddr =g2h (env_cpu (env), a1); ov =qatomic_cmpxchg__nocheck (haddr, cv, nv);#else TCGMemOpIdx oi =make_memop_idx (MO_TEUL |MO_ALIGN , mem_idx);
@@ -1804,7 +1804,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,if (parallel) {#ifdef CONFIG_ATOMIC64 # ifdef CONFIG_USER_ONLY -uint64_t *haddr =g2h (a1); +uint64_t *haddr =g2h (env_cpu (env), a1); ov =qatomic_cmpxchg__nocheck (haddr, cv, nv);# else TCGMemOpIdx oi =make_memop_idx (MO_TEQ |MO_ALIGN , mem_idx);
Signature · 1 line
2.25.1
Re: [PATCH v5 12/31] exec: Use cpu_untagged_addr in g2h; split out g2h_untagged
Quoted 4 lines · Richard Henderson
Use
g2h_untaggedin contexts that have no cpu, e.g. the binary loaders that operate before the primary cpu is created. As a collolary,target_mmapand friends must use untagged addresses,
"corollary"
Quoted 10 lines
since they are used by the loaders.
Use
g2h_untaggedon values returned fromtarget_mmap, as the kernel never applies a tag itself.Use
g2h_untaggedon all pc values. The only current user of tags, aarch64, removes tags from code addresses upon branch, so "pc" is always untagged.Use g2h with the cpu context on hand whereever possible.
"wherever"
Quoted 4 lines
Use
g2h_untaggedinlock_user, which will be updated soon.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v5 13/31 linux-user: Explicitly untag memory management syscalls
In reply to Richard HendersonWe define target_mmap et al as untagged, so that they can be used from the binary loaders. Explicitly call cpu_untagged_addr for munmap, mprotect, mremap syscall entry points.
Add a few comments for the syscalls that are exempted by the kernel's tagged-address-abi.rst.
--- linux-user/syscall.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
linux-user/syscall.c +11 -0
@@ -889,6 +889,8 @@ abi_long do_brk(abi_ulong new_brk)abi_long mapped_addr;abi_ulong new_alloc_size; +/* brk pointers are always untagged */ +DEBUGF_BRK ("do_brk(" TARGET_ABI_FMT_lx") -> " , new_brk);if (!new_brk) {
@@ -4588,6 +4590,8 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,int i,ret;abi_ulong shmlba; +/* shmat pointers are always untagged */ +/* find out the length of the shared memory segment */ ret =get_errno (shmctl (shmid,IPC_STAT , &shm_info));if (is_error (ret)) {
@@ -4655,6 +4659,8 @@ static inline abi_long do_shmdt(abi_ulong shmaddr)int i;abi_long rv; +/* shmdt pointers are always untagged */ +mmap_lock ();for (i =0 ; i <N_SHM_REGIONS ; ++i) {
@@ -9691,6 +9697,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, v5, v6)); }#else +/* mmap pointers are always untagged */ ret = get_errno(target_mmap(arg1, arg2, arg3, target_to_host_bitmask(arg4, mmap_flags_tbl), arg5,
@@ -9709,8 +9716,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,return get_errno (ret);#endif case TARGET_NR_munmap: + arg1 =cpu_untagged_addr (cpu, arg1);return get_errno (target_munmap (arg1, arg2));case TARGET_NR_mprotect: + arg1 =cpu_untagged_addr (cpu, arg1); {TaskState *ts = cpu->opaque;/* Special hack to detect libc making the stack executable. */
@@ -9725,6 +9734,8 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,return get_errno (target_mprotect (arg1, arg2, arg3));#ifdef TARGET_NR_mremapcase TARGET_NR_mremap: + arg1 =cpu_untagged_addr (cpu, arg1); +/* mremap new_addr (arg5) is always untagged */ return get_errno (target_mremap (arg1, arg2, arg3, arg4, arg5));#endif /* ??? msync/mlock/munlock are broken for softmmu. */
Signature · 1 line
2.25.1
Re: [PATCH v5 13/31] linux-user: Explicitly untag memory management syscalls
Quoted 18 lines · Richard Henderson
We define
target_mmapet al as untagged, so that they can be used from the binary loaders. Explicitly callcpu_untagged_addrfor munmap, mprotect, mremap syscall entry points.Add a few comments for the syscalls that are exempted by the kernel's
tagged-address-abi.rst.Signed-off-by Richard Henderson <[email protected]>--- linux-user/syscall.c | 11 +++++++++++ 1 file changed, 11 insertions(+)linux-user/syscall.c +0
-0
linux-user/syscall.c abi_long do_brk(abi_ulong new_brk) · line 896
Quoted 8 lines
linux-user/syscall.c +2
-0@@ -889,6 +889,8 @@ abi_long do_brk(abi_ulong new_brk)abi_long mapped_addr;abi_ulong new_alloc_size; +/* brk pointers are always untagged */ +DEBUGF_BRK ("do_brk(" TARGET_ABI_FMT_lx") -> " , new_brk);if (!new_brk) {
It's not clear to me from
https://www.kernel.org/doc/Documentation/arm64/tagged-address-abi.rst
whether brk() pointers are "always untagged", or only "always untagged when at stage 1 of relaxation"... Unlike shmat and shmdt pointers, they aren't listed in the section 3 "must be untagged regardless of the ABI relaxation" part of the doc. I've asked the kernel folks for clarification.
Same applies to mmap() and mremap() new_address.
thanks
-- PMM
Peter Maydell
Reviewed-byRe: [PATCH v5 13/31] linux-user: Explicitly untag memory management syscalls
Quoted 38 lines · Peter Maydell
Quoted 18 lines · Richard Henderson
We define
target_mmapet al as untagged, so that they can be used from the binary loaders. Explicitly callcpu_untagged_addrfor munmap, mprotect, mremap syscall entry points.Add a few comments for the syscalls that are exempted by the kernel's
tagged-address-abi.rst.Signed-off-by Richard Henderson <[email protected]>--- linux-user/syscall.c | 11 +++++++++++ 1 file changed, 11 insertions(+)linux-user/syscall.c +0
-0linux-user/syscall.c abi_long do_brk(abi_ulong new_brk) · line 896
Quoted 8 lines
linux-user/syscall.c +2
-0@@ -889,6 +889,8 @@ abi_long do_brk(abi_ulong new_brk)abi_long mapped_addr;abi_ulong new_alloc_size; +/* brk pointers are always untagged */ +DEBUGF_BRK ("do_brk(" TARGET_ABI_FMT_lx") -> " , new_brk);if (!new_brk) {It's not clear to me from
https://www.kernel.org/doc/Documentation/arm64/tagged-address-abi.rst
whetherbrk()pointers are "always untagged", or only "always untagged when at stage 1 of relaxation"... Unlike shmat and shmdt pointers, they aren't listed in the section 3 "must be untagged regardless of the ABI relaxation" part of the doc. I've asked the kernel folks for clarification.
Quoted 1 line
Same applies to
mmap()andmremap()new_address.
I got back the clarification: these should have been added to the section 3 "always untagged" list (and they'll update the kernel docs). So this patch is correct.
thanks
-- PMM
PATCH v5 14/31 linux-user: Use guest_range_valid in access_ok
In reply to Richard HendersonWe're currently open-coding the range check in access_ok; use guest_range_valid when size != 0.
--- linux-user/qemu.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
linux-user/qemu.h +3 -6
@@ -493,12 +493,9 @@ extern unsigned long guest_stack_size;static inline bool access_ok (int type,abi_ulong addr,abi_ulong size) { -if (!guest_addr_valid (addr)) { -return false; - } -if (size !=0 && - (addr + size -1 < addr || - !guest_addr_valid (addr + size -1 ))) { +if (size ==0 + ? !guest_addr_valid (addr) + : !guest_range_valid (addr, size)) {return false; }return page_check_range ((target_ulong )addr, size, type) ==0 ;
Signature · 1 line
2.25.1
Re: [PATCH v5 14/31] linux-user: Use guest_range_valid in access_ok
Quoted 14 lines · Richard Henderson
We're currently open-coding the range check in
access_ok; useguest_range_validwhen size != 0.Signed-off-by Richard Henderson <[email protected]>--- linux-user/qemu.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)linux-user/qemu.h +0
-0
linux-user/qemu.h extern unsigned long guest_stack_size; · line 493
Quoted 1 line
linux-user/qemu.h +0
-0@@ -493,12 +493,9 @@ extern unsigned long guest_stack_size;
thanks
-- PMM
PATCH v5 15/31 exec: Rename guest_{addr,range}_valid to *_untagged
In reply to Richard HendersonThe places that use these are better off using untagged addresses, so do not provide a tagged versions. Rename to make it clear about the address type.
--- include/exec/cpu_ldst.h | 4 ++-- linux-user/qemu.h | 4 ++-- accel/tcg/user-exec.c | 9 ++++++--- linux-user/mmap.c | 12 ++++++------ linux-user/syscall.c | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-)
include/exec/cpu_ldst.h +2 -2
@@ -87,12 +87,12 @@ static inline void *g2h(CPUState *cs, abi_ptr x)return g2h_untagged (cpu_untagged_addr (cs, x)); } -static inline bool guest_addr_valid (abi_ulong x) +static inline bool guest_addr_valid_untagged (abi_ulong x) {return x <=GUEST_ADDR_MAX ; } -static inline bool guest_range_valid (abi_ulong start,abi_ulong len) +static inline bool guest_range_valid_untagged (abi_ulong start,abi_ulong len) {return len -1 <=GUEST_ADDR_MAX && start <=GUEST_ADDR_MAX - len +1 ; }
linux-user/qemu.h +2 -2
@@ -494,8 +494,8 @@ extern unsigned long guest_stack_size;static inline bool access_ok (int type,abi_ulong addr,abi_ulong size) {if (size ==0 - ? !guest_addr_valid (addr) - : !guest_range_valid (addr, size)) { + ? !guest_addr_valid_untagged (addr) + : !guest_range_valid_untagged (addr, size)) {return false; }return page_check_range ((target_ulong )addr, size, type) ==0 ;
accel/tcg/user-exec.c +6 -3
@@ -191,10 +191,11 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info,g_assert_not_reached (); } -static int probe_access_internal (CPUArchState *env,target_ulong addr, +static int probe_access_internal (CPUArchState *env,target_ulong addr_tagged,int fault_size,MMUAccessType access_type,bool nonfault,uintptr_t ra) { +target_ulong addr;int flags;switch (access_type) {
@@ -211,13 +212,15 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,g_assert_not_reached (); } -if (!guest_addr_valid (addr) ||page_check_range (addr,1 , flags) <0 ) { + addr =cpu_untagged_addr (env_cpu (env), addr_tagged); +if (!guest_addr_valid_untagged (addr) || +page_check_range (addr,1 , flags) <0 ) {if (nonfault) {return TLB_INVALID_MASK ; }else {CPUState *cpu =env_cpu (env);CPUClass *cc =CPU_GET_CLASS (cpu); - cc->tlb_fill (cpu, addr, fault_size, access_type, + cc->tlb_fill (cpu, addr_tagged, fault_size, access_type,MMU_USER_IDX , false, ra);g_assert_not_reached (); }
linux-user/mmap.c +6 -6
@@ -119,7 +119,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) } len =TARGET_PAGE_ALIGN (len); end = start + len; -if (!guest_range_valid (start, len)) { +if (!guest_range_valid_untagged (start, len)) {return -TARGET_ENOMEM ; }if (len ==0 ) {
@@ -528,7 +528,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,* It can fail only on 64-bit host with 32-bit target. * On any other target/host host mmap() handles this error correctly. */ -if (end < start || !guest_range_valid (start, len)) { +if (end < start || !guest_range_valid_untagged (start, len)) { errno =ENOMEM ; goto fail; }
@@ -669,7 +669,7 @@ int target_munmap(abi_ulong start, abi_ulong len)if (start & ~TARGET_PAGE_MASK )return -TARGET_EINVAL ; len =TARGET_PAGE_ALIGN (len); -if (len ==0 || !guest_range_valid (start, len)) { +if (len ==0 || !guest_range_valid_untagged (start, len)) {return -TARGET_EINVAL ; }
@@ -727,9 +727,9 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,int prot;void *host_addr; -if (!guest_range_valid (old_addr, old_size) || +if (!guest_range_valid_untagged (old_addr, old_size) || ((flags &MREMAP_FIXED ) && - !guest_range_valid (new_addr, new_size))) { + !guest_range_valid_untagged (new_addr, new_size))) { errno =ENOMEM ;return -1 ; }
@@ -777,7 +777,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,if (host_addr !=MAP_FAILED ) {/* Check if address fits target address space */ -if (!guest_range_valid (h2g (host_addr), new_size)) { +if (!guest_range_valid_untagged (h2g (host_addr), new_size)) {/* Revert mremap() changes */ host_addr =mremap (g2h_untagged (old_addr), new_size, old_size, flags);
linux-user/syscall.c +1 -1
@@ -4608,7 +4608,7 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,return -TARGET_EINVAL ; } } -if (!guest_range_valid (shmaddr, shm_info.shm_segsz)) { +if (!guest_range_valid_untagged (shmaddr, shm_info.shm_segsz)) {return -TARGET_EINVAL ; }
Signature · 1 line
2.25.1
Re: [PATCH v5 15/31] exec: Rename guest_{addr, range}_valid to *_untagged
Quoted 16 lines · Richard Henderson
The places that use these are better off using untagged addresses, so do not provide a tagged versions. Rename to make it clear about the address type.
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu_ldst.h | 4 ++-- linux-user/qemu.h | 4 ++-- accel/tcg/user-exec.c | 9 ++++++--- linux-user/mmap.c | 12 ++++++------ linux-user/syscall.c | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-)
accel/tcg/user-exec.c static int probe_access_internal(CPUArchState *env, target_ulong addr, · line 215
Quoted 5 lines
accel/tcg/user-exec.c +1
-1@@ -211,13 +212,15 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,g_assert_not_reached (); } -if (!guest_addr_valid (addr) ||page_check_range (addr,1 , flags) <0 ) { + addr =cpu_untagged_addr (env_cpu (env), addr_tagged);
This change isn't part of a simple function-rename and should presumably be in a different patch?
Otherwise
thanks
-- PMM
PATCH v5 16/31 linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged
In reply to Richard HendersonProvide both tagged and untagged versions of access_ok. In a few places use thread_cpu, as the user is several callees removed from do_syscall1.
--- linux-user/qemu.h | 11 +++++++++-- linux-user/elfload.c | 2 +- linux-user/hppa/cpu_loop.c | 8 ++++---- linux-user/i386/cpu_loop.c | 2 +- linux-user/i386/signal.c | 5 +++-- linux-user/syscall.c | 9 ++++++--- 6 files changed, 24 insertions(+), 13 deletions(-)
linux-user/qemu.h +9 -2
@@ -491,7 +491,7 @@ extern unsigned long guest_stack_size;#define VERIFY_READ PAGE_READ#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) -static inline bool access_ok (int type,abi_ulong addr,abi_ulong size) +static inline bool access_ok_untagged (int type,abi_ulong addr,abi_ulong size) { if (size == 0 ? !guest_addr_valid_untagged(addr)
@@ -501,6 +501,12 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)return page_check_range ((target_ulong )addr, size, type) ==0 ; } +static inline bool access_ok (CPUState *cpu,int type, +abi_ulong addr,abi_ulong size) +{ +return access_ok_untagged (type,cpu_untagged_addr (cpu, addr), size); +} +/* NOTE __get_user and __put_user use host pointers and don't check access. These are usually used to access struct data members once the struct has been locked - usually with lock_user_struct. */
@@ -636,8 +642,9 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);host area will have the same contents as the guest. */ static inline void *lock_user (int type,abi_ulong guest_addr,long len,int copy) { -if (!access_ok (type, guest_addr, len)) +if (!access_ok_untagged (type, guest_addr, len)) {return NULL ; + }#ifdef DEBUG_REMAP {void *addr;
linux-user/elfload.c +1 -1
@@ -3500,7 +3500,7 @@ static int vma_get_mapping_count(const struct mm_struct *mm)static abi_ulong vma_dump_size (const struct vm_area_struct *vma) {/* if we cannot even read the first page, skip it */ -if (!access_ok (VERIFY_READ , vma->vma_start,TARGET_PAGE_SIZE )) +if (!access_ok_untagged (VERIFY_READ , vma->vma_start,TARGET_PAGE_SIZE ))return (0 );/*
linux-user/hppa/cpu_loop.c +4 -4
@@ -35,7 +35,7 @@ static abi_ulong hppa_lws(CPUHPPAState *env)return -TARGET_ENOSYS ;case 0 :/* elf32 atomic 32bit cmpxchg */ -if ((addr &3 ) || !access_ok (VERIFY_WRITE , addr,4 )) { +if ((addr &3 ) || !access_ok (cs,VERIFY_WRITE , addr,4 )) {return -TARGET_EFAULT ; } old =tswap32 (old);
@@ -50,9 +50,9 @@ static abi_ulong hppa_lws(CPUHPPAState *env)return -TARGET_ENOSYS ; }if (((addr | old | new) & ((1 << size) -1 )) - || !access_ok (VERIFY_WRITE , addr,1 << size) - || !access_ok (VERIFY_READ , old,1 << size) - || !access_ok (VERIFY_READ , new,1 << size)) { + || !access_ok (cs,VERIFY_WRITE , addr,1 << size) + || !access_ok (cs,VERIFY_READ , old,1 << size) + || !access_ok (cs,VERIFY_READ , new,1 << size)) {return -TARGET_EFAULT ; }/* Note that below we use host-endian loads so that the cmpxchg
linux-user/i386/cpu_loop.c +1 -1
@@ -99,7 +99,7 @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len)* For all the vsyscalls, NULL means "don't write anything" not * "write it at address 0". */ -if (addr ==0 ||access_ok (VERIFY_WRITE , addr, len)) { +if (addr ==0 ||access_ok (env_cpu (env),VERIFY_WRITE , addr, len)) {return true; }
linux-user/i386/signal.c +3 -2
@@ -513,9 +513,10 @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) fpstate_addr =tswapl (sc->fpstate);if (fpstate_addr !=0 ) { -if (!access_ok (VERIFY_READ , fpstate_addr, -sizeof (struct target_fpstate ))) +if (!access_ok (env_cpu (env),VERIFY_READ , fpstate_addr, +sizeof (struct target_fpstate ))) { goto badframe; + }#ifndef TARGET_X86_64 cpu_x86_frstor (env, fpstate_addr,1 );#else
linux-user/syscall.c +6 -3
@@ -3515,8 +3515,9 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,return -TARGET_EINVAL ; } -if (!access_ok (VERIFY_WRITE , target_addr, addrlen)) +if (!access_ok (thread_cpu,VERIFY_WRITE , target_addr, addrlen)) {return -TARGET_EFAULT ; + } addr =alloca (addrlen);
@@ -3546,8 +3547,9 @@ static abi_long do_getpeername(int fd, abi_ulong target_addr,return -TARGET_EINVAL ; } -if (!access_ok (VERIFY_WRITE , target_addr, addrlen)) +if (!access_ok (thread_cpu,VERIFY_WRITE , target_addr, addrlen)) {return -TARGET_EFAULT ; + } addr =alloca (addrlen);
@@ -3577,8 +3579,9 @@ static abi_long do_getsockname(int fd, abi_ulong target_addr,return -TARGET_EINVAL ; } -if (!access_ok (VERIFY_WRITE , target_addr, addrlen)) +if (!access_ok (thread_cpu,VERIFY_WRITE , target_addr, addrlen)) {return -TARGET_EFAULT ; + } addr =alloca (addrlen);
Signature · 1 line
2.25.1
Re: [PATCH v5 16/31] linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged
Quoted 7 lines · Richard Henderson
Provide both tagged and untagged versions of
access_ok. In a few places usethread_cpu, as the user is several callees removed fromdo_syscall1.Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v5 17/31 linux-user: Move lock_user et al out of line
In reply to Richard HendersonThese functions are not small, except for unlock_user without debugging enabled. Move them out of line, and add missing braces on the way.
--- linux-user/qemu.h | 45 ++++++------------------------------------- linux-user/uaccess.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 39 deletions(-)
linux-user/qemu.h +6 -39
@@ -640,57 +640,24 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);/* Lock an area of guest memory into the host. If copy is true then the host area will have the same contents as the guest. */ -static inline void *lock_user (int type,abi_ulong guest_addr,long len,int copy) -{ -if (!access_ok_untagged (type, guest_addr, len)) { -return NULL ; - } -#ifdef DEBUG_REMAP - { -void *addr; - addr =g_malloc (len); -if (copy) -memcpy (addr,g2h (guest_addr), len); -else -memset (addr,0 , len); -return addr; - } -#else -return g2h_untagged (guest_addr); -#endif -} +void *lock_user (int type,abi_ulong guest_addr,long len,int copy);/* Unlock an area of guest memory. The first LEN bytes must be flushed back to guest memory. host_ptr = NULL is explicitly allowed and does nothing. */ -static inline void unlock_user (void *host_ptr,abi_ulong guest_addr, -long len) -{ -#ifdef DEBUG_REMAP -if (!host_ptr) -return ; -if (host_ptr ==g2h_untagged (guest_addr)) -return ; -if (len >0 ) -memcpy (g2h_untagged (guest_addr), host_ptr, len); -g_free (host_ptr); +static inline void unlock_user (void *host_ptr,abi_ulong guest_addr,long len) +{ } +#else +void unlock_user (void *host_ptr,abi_ulong guest_addr,long len);#endif -}/* Return the length of a string in target memory or -TARGET_EFAULT if access error. */ abi_long target_strlen (abi_ulong gaddr);/* Like lock_user but for null terminated strings. */ -static inline void *lock_user_string (abi_ulong guest_addr) -{ -abi_long len; - len =target_strlen (guest_addr); -if (len <0 ) -return NULL ; -return lock_user (VERIFY_READ , guest_addr, (long )(len +1 ),1 ); -} +void *lock_user_string (abi_ulong guest_addr);/* Helper macros for locking/unlocking a target struct. */ #define lock_user_struct (type, host_ptr, guest_addr, copy) \
linux-user/uaccess.c +46 -0
52 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 17/31] linux-user: Move lock_user et al out of line
Quoted 5 lines · Richard Henderson
These functions are not small, except for
unlock_userwithout debugging enabled. Move them out of line, and add missing braces on the way.
thanks
-- PMM
PATCH v5 18/31 linux-user: Fix types in uaccess.c
In reply to Richard HendersonFor copy_*_user, only 0 and -TARGET_EFAULT are returned; no need to involve abi_long. Use size_t for lengths. Use bool for the lock_user copy argument. Use ssize_t for target_strlen, because we can't overflow the host memory space.
--- linux-user/qemu.h | 14 ++++++-------- linux-user/uaccess.c | 43 ++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 29 deletions(-)
linux-user/qemu.h +6 -8
@@ -7,8 +7,6 @@#include "exec/cpu_ldst.h" #undef DEBUG_REMAP -#ifdef DEBUG_REMAP -#endif /* DEBUG_REMAP */ #include "exec/user/abitypes.h"
@@ -629,8 +627,8 @@ static inline bool access_ok(CPUState *cpu, int type,* buffers between the target and host. These internally perform * locking/unlocking of the memory. */ -abi_long copy_from_user (void *hptr,abi_ulong gaddr,size_t len); -abi_long copy_to_user (abi_ulong gaddr,void *hptr,size_t len); +int copy_from_user (void *hptr,abi_ulong gaddr,size_t len); +int copy_to_user (abi_ulong gaddr,void *hptr,size_t len);/* Functions for accessing guest memory. The tget and tput functions read/write single values, byteswapping as necessary. The lock_user function
@@ -640,13 +638,13 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);/* Lock an area of guest memory into the host. If copy is true then the host area will have the same contents as the guest. */ -void *lock_user (int type,abi_ulong guest_addr,long len,int copy); +void *lock_user (int type,abi_ulong guest_addr,size_t len,bool copy);/* Unlock an area of guest memory. The first LEN bytes must be flushed back to guest memory. host_ptr = NULL is explicitly allowed and does nothing. */ -#ifdef DEBUG_REMAP -static inline void unlock_user (void *host_ptr,abi_ulong guest_addr,long len) +#ifndef DEBUG_REMAP +static inline void unlock_user (void *host_ptr,abi_ulong guest_addr,size_t len) { }#else void unlock_user (void *host_ptr,abi_ulong guest_addr,long len);
@@ -654,7 +652,7 @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);/* Return the length of a string in target memory or -TARGET_EFAULT if access error. */ -abi_long target_strlen (abi_ulong gaddr); +ssize_t target_strlen (abi_ulong gaddr);/* Like lock_user but for null terminated strings. */ void *lock_user_string (abi_ulong guest_addr);
linux-user/uaccess.c +22 -21
100 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 18/31] linux-user: Fix types in uaccess.c
Quoted 7 lines · Richard Henderson
For copy_*_user, only 0 and -TARGET_EFAULT are returned; no need to involve
abi_long. Usesize_tfor lengths. Use bool for thelock_usercopy argument. Usessize_tfortarget_strlen, because we can't overflow the host memory space.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v5 19/31 linux-user: Handle tags in lock_user/unlock_user
In reply to Richard HendersonResolve the untagged address once, using thread_cpu. Tidy the DEBUG_REMAP code using glib routines.
--- linux-user/uaccess.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
linux-user/uaccess.c +15 -14
@@ -6,36 +6,37 @@void *lock_user (int type,abi_ulong guest_addr,size_t len,bool copy) { +void *host_addr; + + guest_addr =cpu_untagged_addr (thread_cpu, guest_addr);if (!access_ok_untagged (type, guest_addr, len)) {return NULL ; } + host_addr =g2h_untagged (guest_addr);#ifdef DEBUG_REMAP - { -void *addr; - addr =g_malloc (len); -if (copy) { -memcpy (addr,g2h (guest_addr), len); - }else { -memset (addr,0 , len); - } -return addr; +if (copy) { + host_addr =g_memdup (host_addr, len); + }else { + host_addr =g_malloc0 (len); } -#else -return g2h_untagged (guest_addr);#endif +return host_addr; }#ifdef DEBUG_REMAP void unlock_user (void *host_ptr,abi_ulong guest_addr,size_t len); { +void *host_ptr_conv; +if (!host_ptr) {return ; } -if (host_ptr ==g2h_untagged (guest_addr)) { + host_ptr_conv =g2h (thread_cpu, guest_addr); +if (host_ptr == host_ptr_conv) {return ; } -if (len >0 ) { -memcpy (g2h_untagged (guest_addr), host_ptr, len); +if (len !=0 ) { +memcpy (host_ptr_conv, host_ptr, len); }g_free (host_ptr); }
Signature · 1 line
2.25.1
Re: [PATCH v5 19/31] linux-user: Handle tags in lock_user/unlock_user
Quoted 53 lines · Richard Henderson
Resolve the untagged address once, using
thread_cpu. Tidy theDEBUG_REMAPcode using glib routines.Signed-off-by Richard Henderson <[email protected]>--- linux-user/uaccess.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)linux-user/uaccess.c +11
-11@@ -6,36 +6,37 @@void *lock_user (int type,abi_ulong guest_addr,size_t len,bool copy) { +void *host_addr; + + guest_addr =cpu_untagged_addr (thread_cpu, guest_addr);if (!access_ok_untagged (type, guest_addr, len)) {return NULL ; } + host_addr =g2h_untagged (guest_addr);#ifdef DEBUG_REMAP - { -void *addr; - addr =g_malloc (len); -if (copy) { -memcpy (addr,g2h (guest_addr), len); - }else { -memset (addr,0 , len); - } -return addr; +if (copy) { + host_addr =g_memdup (host_addr, len); + }else { + host_addr =g_malloc0 (len); } -#else -return g2h_untagged (guest_addr);#endif +return host_addr; }#ifdef DEBUG_REMAP void unlock_user (void *host_ptr,abi_ulong guest_addr,size_t len); { +void *host_ptr_conv; +if (!host_ptr) {return ; }
linux-user/uaccess.c line 40
Quoted 10 lines
linux-user/uaccess.c +4
-3-if (host_ptr ==g2h_untagged (guest_addr)) { + host_ptr_conv =g2h (thread_cpu, guest_addr); +if (host_ptr == host_ptr_conv) {return ; } -if (len >0 ) { -memcpy (g2h_untagged (guest_addr), host_ptr, len); +if (len !=0 ) { +memcpy (host_ptr_conv, host_ptr, len); }
Why the change from checking >0 to checking !=0 ? I'd rather not have to go through and audit all the callsites to confirm none of them pass a "length-or-negative-errno" value here...
thanks
-- PMM
Re: [PATCH v5 19/31] linux-user: Handle tags in lock_user/unlock_user
Quoted 1 line · Peter Maydell
Quoted 1 line
void
unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len);
....
Quoted 9 lines
linux-user/uaccess.c line 40
Quoted 5 lines
linux-user/uaccess.c +2
-2-if (len >0 ) { -memcpy (g2h_untagged (guest_addr), host_ptr, len); +if (len !=0 ) { +memcpy (host_ptr_conv, host_ptr, len); }Why the change from checking >0 to checking !=0 ? I'd rather not have to go through and audit all the callsites to confirm none of them pass a "length-or-negative-errno" value here...
The comparison change should have happened with the type change to unsigned in the previous patch.
r~
PATCH v5 20/31 linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE
In reply to Richard HendersonThis is the prctl bit that controls whether syscalls accept tagged addresses. See Documentation/arm64/tagged-address-abi.rst in the linux kernel.
--- linux-user/aarch64/target_syscall.h | 4 ++++ target/arm/cpu-param.h | 3 +++ target/arm/cpu.h | 31 +++++++++++++++++++++++++++++ linux-user/syscall.c | 24 ++++++++++++++++++++++ 4 files changed, 62 insertions(+)
linux-user/aarch64/target_syscall.h +4 -0
@@ -30,4 +30,8 @@ struct target_pt_regs {# define TARGET_PR_PAC_APDBKEY (1 << 3)# define TARGET_PR_PAC_APGAKEY (1 << 4) +#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 +#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 +# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) +#endif /* AARCH64_TARGET_SYSCALL_H */
target/arm/cpu-param.h +3 -0
@@ -20,6 +20,9 @@#ifdef CONFIG_USER_ONLY #define TARGET_PAGE_BITS 12 +# ifdef TARGET_AARCH64 +# define TARGET_TAGGED_ADDRESSES +# endif #else /* * ARMv7 and later CPUs have 4K pages minimum, but ARMv5 and v6
target/arm/cpu.h +31 -0
@@ -721,6 +721,11 @@ typedef struct CPUARMState {const struct arm_boot_info *boot_info;/* Store GICv3CPUState to access from this struct */ void *gicv3state; + +#ifdef TARGET_TAGGED_ADDRESSES +/* Linux syscall tagged address support */ +bool tagged_addr_enable; +#endif } CPUARMState;static inline void set_feature (CPUARMState *env,int feature)
@@ -3602,6 +3607,32 @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)*/ #define PAGE_BTI PAGE_TARGET_1 +#ifdef TARGET_TAGGED_ADDRESSES +/** +* cpu_untagged_addr: +* @cs: CPU context +* @x: tagged address +* +* Remove any address tag from @x. This is explicitly related to the +* linux syscall TIF_TAGGED_ADDR setting, not TBI in general. +* +* There should be a better place to put this, but we need this in +* include/exec/cpu_ldst.h, and not some place linux-user specific. +*/ +static inline target_ulong cpu_untagged_addr (CPUState *cs,target_ulong x) +{ +ARMCPU *cpu =ARM_CPU (cs); +if (cpu->env.tagged_addr_enable) { +/* +* TBI is enabled for userspace but not kernelspace addresses. +* Only clear the tag if bit 55 is clear. +*/ + x &=sextract64 (x,0 ,56 ); + } +return x; +} +#endif +/* * Naming convention for isar_feature functions: * Functions which test 32-bit ID registers should have _aa32_ in
linux-user/syscall.c +24 -0
@@ -10981,6 +10981,30 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } }return -TARGET_EINVAL ; +case TARGET_PR_SET_TAGGED_ADDR_CTRL : + { +abi_ulong valid_mask =TARGET_PR_TAGGED_ADDR_ENABLE ; +CPUARMState *env = cpu_env; + +if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { +return -TARGET_EINVAL ; + } + env->tagged_addr_enable = arg2 &TARGET_PR_TAGGED_ADDR_ENABLE ; +return 0 ; + } +case TARGET_PR_GET_TAGGED_ADDR_CTRL : + { +abi_long ret =0 ; +CPUARMState *env = cpu_env; + +if (arg2 || arg3 || arg4 || arg5) { +return -TARGET_EINVAL ; + } +if (env->tagged_addr_enable) { + ret |=TARGET_PR_TAGGED_ADDR_ENABLE ; + } +return ret; + }#endif /* AARCH64 */ case PR_GET_SECCOMP :case PR_SET_SECCOMP :
Signature · 1 line
2.25.1
PATCH v5 21/31 target/arm: Improve gen_top_byte_ignore
In reply to Richard HendersonUse simple arithmetic instead of a conditional
move when tbi0 != tbi1.
--- target/arm/translate-a64.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
target/arm/translate-a64.c +14 -11
@@ -183,17 +183,20 @@ static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst,/* Sign-extend from bit 55. */ tcg_gen_sextract_i64 (dst, src,0 ,56 ); -if (tbi !=3 ) { -TCGv_i64 tcg_zero =tcg_const_i64 (0 ); - -/* -* The two TBI bits differ. -* If tbi0, then !tbi1: only use the extension if positive. -* if !tbi0, then tbi1: only use the extension if negative. -*/ -tcg_gen_movcond_i64 (tbi ==1 ?TCG_COND_GE :TCG_COND_LT , - dst, dst, tcg_zero, dst, src); -tcg_temp_free_i64 (tcg_zero); +switch (tbi) { +case 1 : +/* tbi0 but !tbi1: only use the extension if positive */ +tcg_gen_and_i64 (dst, dst, src); +break ; +case 2 : +/* !tbi0 but tbi1: only use the extension if negative */ +tcg_gen_or_i64 (dst, dst, src); +break ; +case 3 : +/* tbi0 and tbi1: always use the extension */ +break ; +default : +g_assert_not_reached (); } } }
Signature · 1 line
2.25.1
PATCH v5 22/31 target/arm: Use the proper TBI settings for linux-user
In reply to Richard HendersonWe were fudging TBI1 enabled to speed up the generated code. Now that we've improved the code generation, remove this. Also, tidy the comment to reflect the current code.
The pauth test was testing a kernel address (-1) and making incorrect assumptions about TBI1; stick to userland addresses.
--- target/arm/internals.h | 4 ++-- target/arm/cpu.c | 10 +++------- tests/tcg/aarch64/pauth-2.c | 1 - 3 files changed, 5 insertions(+), 10 deletions(-)
target/arm/internals.h +2 -2
@@ -1413,9 +1413,9 @@ static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag)*/ static inline uint64_t useronly_clean_ptr (uint64_t ptr) { -/* TBI is known to be enabled. */ #ifdef CONFIG_USER_ONLY - ptr =sextract64 (ptr,0 ,56 ); +/* TBI0 is known to be enabled, while TBI1 is disabled. */ + ptr &=sextract64 (ptr,0 ,56 );#endif return ptr; }
target/arm/cpu.c +3 -7
@@ -200,14 +200,10 @@ static void arm_cpu_reset(DeviceState *dev) env->vfp.zcr_el[1] = MIN(cpu->sve_max_vq - 1, 3); }/* -* Enable TBI0 and TBI1. While the real kernel only enables TBI0, -* turning on both here will produce smaller code and otherwise -* make no difference to the user-level emulation. -* -* In sve_probe_page, we assume that this is set. -* Do not modify this without other changes. +* Enable TBI0 but not TBI1. +* Note that this must match useronly_clean_ptr. */ - env->cp15.tcr_el[1 ].raw_tcr = (3ULL <<37 ); + env->cp15.tcr_el[1 ].raw_tcr = (1ULL <<37 );#else /* Reset into the highest available EL */ if (arm_feature (env,ARM_FEATURE_EL3 )) {
tests/tcg/aarch64/pauth-2.c +0 -1
@@ -53,7 +53,6 @@ void do_test(uint64_t value)int main () {do_test (0 ); -do_test (-1 );do_test (0xda004acedeadbeefull );return 0 ; }
Signature · 1 line
2.25.1
PATCH v5 23/31 linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG
In reply to Richard HendersonThese prctl fields are required for the function of MTE.
--- linux-user/aarch64/target_syscall.h | 9 ++++++ linux-user/syscall.c | 43 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
linux-user/aarch64/target_syscall.h +9 -0
@@ -33,5 +33,14 @@ struct target_pt_regs {#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) +/* MTE tag check fault modes */ +# define TARGET_PR_MTE_TCF_SHIFT 1 +# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT) +/* MTE tag inclusion mask */ +# define TARGET_PR_MTE_TAG_SHIFT 3 +# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT)#endif /* AARCH64_TARGET_SYSCALL_H */
linux-user/syscall.c +43 -0
66 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 24/31 linux-user/aarch64: Implement PROT_MTE
In reply to Richard HendersonRemember the PROT_MTE bit as PAGE_MTE/PAGE_TARGET_2. Otherwise this does not yet have effect.
--- include/exec/cpu-all.h | 1 + linux-user/syscall_defs.h | 1 + target/arm/cpu.h | 1 + linux-user/mmap.c | 22 ++++++++++++++-------- 4 files changed, 17 insertions(+), 8 deletions(-)
include/exec/cpu-all.h +1 -0
@@ -284,6 +284,7 @@ extern intptr_t qemu_host_page_mask;#endif /* Target-specific bits that will be used via page_get_flags(). */ #define PAGE_TARGET_1 0x0080 +#define PAGE_TARGET_2 0x0200#if defined(CONFIG_USER_ONLY )void page_dump (FILE *f);
linux-user/syscall_defs.h +1 -0
@@ -1311,6 +1311,7 @@ struct target_winsize {#ifdef TARGET_AARCH64 #define TARGET_PROT_BTI 0x10 +#define TARGET_PROT_MTE 0x20#endif /* Common */
target/arm/cpu.h +1 -0
@@ -3606,6 +3606,7 @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)* AArch64 usage of the PAGE_TARGET_* bits for linux-user. */ #define PAGE_BTI PAGE_TARGET_1 +#define PAGE_MTE PAGE_TARGET_2#ifdef TARGET_TAGGED_ADDRESSES /**
linux-user/mmap.c +14 -8
@@ -84,18 +84,24 @@ static int validate_prot_to_pageflags(int *host_prot, int prot) | (prot & PROT_EXEC ? PROT_READ : 0);#ifdef TARGET_AARCH64 -/* -* The PROT_BTI bit is only accepted if the cpu supports the feature. -* Since this is the unusual case, don't bother checking unless -* the bit has been requested. If set and valid, record the bit -* within QEMU's page_flags. -*/ -if (prot &TARGET_PROT_BTI ) { + {ARMCPU *cpu =ARM_CPU (thread_cpu); -if (cpu_isar_feature (aa64_bti, cpu)) { + +/* +* The PROT_BTI bit is only accepted if the cpu supports the feature. +* Since this is the unusual case, don't bother checking unless +* the bit has been requested. If set and valid, record the bit +* within QEMU's page_flags. +*/ +if ((prot &TARGET_PROT_BTI ) &&cpu_isar_feature (aa64_bti, cpu)) { valid |=TARGET_PROT_BTI ; page_flags |=PAGE_BTI ; } +/* Similarly for the PROT_MTE bit. */ +if ((prot &TARGET_PROT_MTE ) &&cpu_isar_feature (aa64_mte, cpu)) { + valid |=TARGET_PROT_MTE ; + page_flags |=PAGE_MTE ; + } }#endif
Signature · 1 line
2.25.1
PATCH v5 25/31 target/arm: Split out syndrome.h from internals.h
In reply to Richard HendersonMove everything related to syndromes to a new file, which can be shared with linux-user.
--- target/arm/internals.h | 245 +----------------------------------- target/arm/syndrome.h | 273 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 274 insertions(+), 244 deletions(-) create mode 100644 target/arm/syndrome.h
target/arm/internals.h +1 -244
@@ -26,6 +26,7 @@#define TARGET_ARM_INTERNALS_H #include "hw/registerfields.h" +#include "syndrome.h" /* register banks for CPU modes */ #define BANK_USRSYS 0
@@ -256,250 +257,6 @@ static inline bool extended_addresses_enabled(CPUARMState *env) (arm_feature (env,ARM_FEATURE_LPAE ) && (tcr->raw_tcr &TTBCR_EAE )); } -/* Valid Syndrome Register EC field values */ -enum arm_exception_class { -EC_UNCATEGORIZED =0x00 , -EC_WFX_TRAP =0x01 , -EC_CP15RTTRAP =0x03 , -EC_CP15RRTTRAP =0x04 , -EC_CP14RTTRAP =0x05 , -EC_CP14DTTRAP =0x06 , -EC_ADVSIMDFPACCESSTRAP =0x07 , -EC_FPIDTRAP =0x08 , -EC_PACTRAP =0x09 , -EC_CP14RRTTRAP =0x0c , -EC_BTITRAP =0x0d , -EC_ILLEGALSTATE =0x0e , -EC_AA32_SVC =0x11 , -EC_AA32_HVC =0x12 , -EC_AA32_SMC =0x13 , -EC_AA64_SVC =0x15 , -EC_AA64_HVC =0x16 , -EC_AA64_SMC =0x17 , -EC_SYSTEMREGISTERTRAP =0x18 , -EC_SVEACCESSTRAP =0x19 , -EC_INSNABORT =0x20 , -EC_INSNABORT_SAME_EL =0x21 , -EC_PCALIGNMENT =0x22 , -EC_DATAABORT =0x24 , -EC_DATAABORT_SAME_EL =0x25 , -EC_SPALIGNMENT =0x26 , -EC_AA32_FPTRAP =0x28 , -EC_AA64_FPTRAP =0x2c , -EC_SERROR =0x2f , -EC_BREAKPOINT =0x30 , -EC_BREAKPOINT_SAME_EL =0x31 , -EC_SOFTWARESTEP =0x32 , -EC_SOFTWARESTEP_SAME_EL =0x33 , -EC_WATCHPOINT =0x34 , -EC_WATCHPOINT_SAME_EL =0x35 , -EC_AA32_BKPT =0x38 , -EC_VECTORCATCH =0x3a , -EC_AA64_BKPT =0x3c , -}; - -#define ARM_EL_EC_SHIFT 26 -#define ARM_EL_IL_SHIFT 25 -#define ARM_EL_ISV_SHIFT 24 -#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) -#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) - -static inline uint32_t syn_get_ec (uint32_t syn) -{ -return syn >>ARM_EL_EC_SHIFT ; -} - -/* Utility functions for constructing various kinds of syndrome value. -* Note that in general we follow the AArch64 syndrome values; in a -* few cases the value in HSR for exceptions taken to AArch32 Hyp -* mode differs slightly, and we fix this up when populating HSR in -* arm_cpu_do_interrupt_aarch32_hyp(). -* The exception is FP/SIMD access traps -- these report extra information -* when taking an exception to AArch32. For those we include the extra coproc -* and TA fields, and mask them out when taking the exception to AArch64. -*/ -static inline uint32_t syn_uncategorized (void ) -{ -return (EC_UNCATEGORIZED <<ARM_EL_EC_SHIFT ) |ARM_EL_IL ; -} - -static inline uint32_t syn_aa64_svc (uint32_t imm16) -{ -return (EC_AA64_SVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); -} - -static inline uint32_t syn_aa64_hvc (uint32_t imm16) -{ -return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); -} - -static inline uint32_t syn_aa64_smc (uint32_t imm16) -{ -return (EC_AA64_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); -} - -static inline uint32_t syn_aa32_svc (uint32_t imm16,bool is_16bit) -{ -return (EC_AA32_SVC <<ARM_EL_EC_SHIFT ) | (imm16 &0xffff ) - | (is_16bit ?0 :ARM_EL_IL ); -} - -static inline uint32_t syn_aa32_hvc (uint32_t imm16) -{ -return (EC_AA32_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); -} - -static inline uint32_t syn_aa32_smc (void ) -{ -return (EC_AA32_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL ; -} - -static inline uint32_t syn_aa64_bkpt (uint32_t imm16) -{ -return (EC_AA64_BKPT <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); -} - -static inline uint32_t syn_aa32_bkpt (uint32_t imm16,bool is_16bit) -{ -return (EC_AA32_BKPT <<ARM_EL_EC_SHIFT ) | (imm16 &0xffff ) - | (is_16bit ?0 :ARM_EL_IL ); -} - -static inline uint32_t syn_aa64_sysregtrap (int op0,int op1,int op2, -int crn,int crm,int rt, -int isread) -{ -return (EC_SYSTEMREGISTERTRAP <<ARM_EL_EC_SHIFT ) |ARM_EL_IL - | (op0 <<20 ) | (op2 <<17 ) | (op1 <<14 ) | (crn <<10 ) | (rt <<5 ) - | (crm <<1 ) | isread; -} - -static inline uint32_t syn_cp14_rt_trap (int cv,int cond,int opc1,int opc2, -int crn,int crm,int rt,int isread, -bool is_16bit) -{ -return (EC_CP14RTTRAP <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - | (cv <<24 ) | (cond <<20 ) | (opc2 <<17 ) | (opc1 <<14 ) - | (crn <<10 ) | (rt <<5 ) | (crm <<1 ) | isread; -} - -static inline uint32_t syn_cp15_rt_trap (int cv,int cond,int opc1,int opc2, -int crn,int crm,int rt,int isread, -bool is_16bit) -{ -return (EC_CP15RTTRAP <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - | (cv <<24 ) | (cond <<20 ) | (opc2 <<17 ) | (opc1 <<14 ) - | (crn <<10 ) | (rt <<5 ) | (crm <<1 ) | isread; -} - -static inline uint32_t syn_cp14_rrt_trap (int cv,int cond,int opc1,int crm, -int rt,int rt2,int isread, -bool is_16bit) -{ -return (EC_CP14RRTTRAP <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - | (cv <<24 ) | (cond <<20 ) | (opc1 <<16 ) - | (rt2 <<10 ) | (rt <<5 ) | (crm <<1 ) | isread; -} - -static inline uint32_t syn_cp15_rrt_trap (int cv,int cond,int opc1,int crm, -int rt,int rt2,int isread, -bool is_16bit) -{ -return (EC_CP15RRTTRAP <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - | (cv <<24 ) | (cond <<20 ) | (opc1 <<16 ) - | (rt2 <<10 ) | (rt <<5 ) | (crm <<1 ) | isread; -} - -static inline uint32_t syn_fp_access_trap (int cv,int cond,bool is_16bit) -{ -/* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */ -return (EC_ADVSIMDFPACCESSTRAP <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - | (cv <<24 ) | (cond <<20 ) |0xa ; -} - -static inline uint32_t syn_simd_access_trap (int cv,int cond,bool is_16bit) -{ -/* AArch32 SIMD trap: TA == 1 coproc == 0 */ -return (EC_ADVSIMDFPACCESSTRAP <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - | (cv <<24 ) | (cond <<20 ) | (1 <<5 ); -} - -static inline uint32_t syn_sve_access_trap (void ) -{ -return EC_SVEACCESSTRAP <<ARM_EL_EC_SHIFT ; -} - -static inline uint32_t syn_pactrap (void ) -{ -return EC_PACTRAP <<ARM_EL_EC_SHIFT ; -} - -static inline uint32_t syn_btitrap (int btype) -{ -return (EC_BTITRAP <<ARM_EL_EC_SHIFT ) | btype; -} - -static inline uint32_t syn_insn_abort (int same_el,int ea,int s1ptw,int fsc) -{ -return (EC_INSNABORT <<ARM_EL_EC_SHIFT ) | (same_el <<ARM_EL_EC_SHIFT ) - |ARM_EL_IL | (ea <<9 ) | (s1ptw <<7 ) | fsc; -} - -static inline uint32_t syn_data_abort_no_iss (int same_el,int fnv, -int ea,int cm,int s1ptw, -int wnr,int fsc) -{ -return (EC_DATAABORT <<ARM_EL_EC_SHIFT ) | (same_el <<ARM_EL_EC_SHIFT ) - |ARM_EL_IL - | (fnv <<10 ) | (ea <<9 ) | (cm <<8 ) | (s1ptw <<7 ) - | (wnr <<6 ) | fsc; -} - -static inline uint32_t syn_data_abort_with_iss (int same_el, -int sas,int sse,int srt, -int sf,int ar, -int ea,int cm,int s1ptw, -int wnr,int fsc, -bool is_16bit) -{ -return (EC_DATAABORT <<ARM_EL_EC_SHIFT ) | (same_el <<ARM_EL_EC_SHIFT ) - | (is_16bit ?0 :ARM_EL_IL ) - |ARM_EL_ISV | (sas <<22 ) | (sse <<21 ) | (srt <<16 ) - | (sf <<15 ) | (ar <<14 ) - | (ea <<9 ) | (cm <<8 ) | (s1ptw <<7 ) | (wnr <<6 ) | fsc; -} - -static inline uint32_t syn_swstep (int same_el,int isv,int ex) -{ -return (EC_SOFTWARESTEP <<ARM_EL_EC_SHIFT ) | (same_el <<ARM_EL_EC_SHIFT ) - |ARM_EL_IL | (isv <<24 ) | (ex <<6 ) |0x22 ; -} - -static inline uint32_t syn_watchpoint (int same_el,int cm,int wnr) -{ -return (EC_WATCHPOINT <<ARM_EL_EC_SHIFT ) | (same_el <<ARM_EL_EC_SHIFT ) - |ARM_EL_IL | (cm <<8 ) | (wnr <<6 ) |0x22 ; -} - -static inline uint32_t syn_breakpoint (int same_el) -{ -return (EC_BREAKPOINT <<ARM_EL_EC_SHIFT ) | (same_el <<ARM_EL_EC_SHIFT ) - |ARM_EL_IL |0x22 ; -} - -static inline uint32_t syn_wfx (int cv,int cond,int ti,bool is_16bit) -{ -return (EC_WFX_TRAP <<ARM_EL_EC_SHIFT ) | - (is_16bit ?0 : (1 <<ARM_EL_IL_SHIFT )) | - (cv <<24 ) | (cond <<20 ) | ti; -} -/* Update a QEMU watchpoint based on the information the guest has set in the * DBGWCR<n>_EL1 and DBGWVR<n>_EL1 registers. */
target/arm/syndrome.h new file +273 -0
273 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 26/31 linux-user/aarch64: Pass syndrome to EXC_*_ABORT
In reply to Richard HendersonA proper syndrome is required to fill in the proper si_code. Use page_get_flags to determine permission vs translation for user-only.
--- linux-user/aarch64/cpu_loop.c | 24 +++++++++++++++++++++--- target/arm/tlb_helper.c | 15 +++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-)
linux-user/aarch64/cpu_loop.c +21 -3
@@ -23,6 +23,7 @@#include "cpu_loop-common.h" #include "qemu/guest-random.h" #include "hw/semihosting/common-semi.h" +#include "target/arm/syndrome.h" #define get_user_code_u32 (x, gaddr, env) \ ({ abi_long __r = get_user_u32((x), (gaddr)); \
@@ -76,7 +77,7 @@void cpu_loop (CPUARMState *env) {CPUState *cs =env_cpu (env); -int trapnr; +int trapnr, ec, fsc;abi_long ret;target_siginfo_t info;
@@ -117,9 +118,26 @@ void cpu_loop(CPUARMState *env)case EXCP_DATA_ABORT : info.si_signo =TARGET_SIGSEGV ; info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; info._sifields._sigfault._addr = env->exception.vaddress; + +/* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ + ec =syn_get_ec (env->exception.syndrome); +assert (ec ==EC_DATAABORT || ec ==EC_INSNABORT ); + +/* Both EC have the same format for FSC, or close enough. */ + fsc =extract32 (env->exception.syndrome,0 ,6 ); +switch (fsc) { + case 0x04 ... 0x07: /* Translation fault, level {0-3} */ + info.si_code =TARGET_SEGV_MAPERR ; +break ; + case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ + case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ + info.si_code =TARGET_SEGV_ACCERR ; +break ; +default : +g_assert_not_reached (); + } +queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info);break ;case EXCP_DEBUG :
target/arm/tlb_helper.c +9 -6
@@ -154,21 +154,24 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, bool probe, uintptr_t retaddr) {ARMCPU *cpu =ARM_CPU (cs); +ARMMMUFaultInfo fi = {};#ifdef CONFIG_USER_ONLY - cpu->env.exception.vaddress = address; -if (access_type ==MMU_INST_FETCH ) { - cs->exception_index =EXCP_PREFETCH_ABORT ; +int flags =page_get_flags (useronly_clean_ptr (address)); +if (flags &PAGE_VALID ) { + fi.type = ARMFault_Permission; }else { - cs->exception_index =EXCP_DATA_ABORT ; + fi.type = ARMFault_Translation; } -cpu_loop_exit_restore (cs, retaddr); + +/* now we have a real cpu fault */ +cpu_restore_state (cs, retaddr, true); +arm_deliver_fault (cpu, address, access_type, mmu_idx, &fi);#else hwaddr phys_addr;target_ulong page_size;int prot, ret;MemTxAttrs attrs = {}; -ARMMMUFaultInfo fi = {};ARMCacheAttrs cacheattrs = {};/*
Signature · 1 line
2.25.1
PATCH v5 27/31 linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault
In reply to Richard Henderson--- linux-user/aarch64/target_signal.h | 2 ++ linux-user/aarch64/cpu_loop.c | 3 +++ 2 files changed, 5 insertions(+)
linux-user/aarch64/target_signal.h +2 -0
@@ -21,5 +21,7 @@ typedef struct target_sigaltstack {#include "../generic/signal.h" +#define TARGET_SEGV_MTESERR 9/* Synchronous ARM MTE exception */ +#define TARGET_ARCH_HAS_SETUP_FRAME #endif /* AARCH64_TARGET_SIGNAL_H */
linux-user/aarch64/cpu_loop.c +3 -0
@@ -134,6 +134,9 @@ void cpu_loop(CPUARMState *env) case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ info.si_code =TARGET_SEGV_ACCERR ;break ; +case 0x11 :/* Synchronous Tag Check Fault */ + info.si_code =TARGET_SEGV_MTESERR ; +break ;default :g_assert_not_reached (); }
Signature · 1 line
2.25.1
PATCH v5 28/31 linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error
In reply to Richard HendersonThe real kernel collects _TIF_MTE_ASYNC_FAULT into the current thread's state on any kernel entry (interrupt, exception etc), and then delivers the signal in advance of resuming the thread.
This means that while the signal won't be delivered immediately, it will not be delayed forever -- at minimum it will be delivered after the next clock interrupt.
We don't have a clock interrupt in linux-user, so we issue a cpu_kick to signal a return to the main loop at the end of the current TB.
--- linux-user/aarch64/target_signal.h | 1 + linux-user/aarch64/cpu_loop.c | 11 +++++++++++ target/arm/mte_helper.c | 10 ++++++++++ 3 files changed, 22 insertions(+)
linux-user/aarch64/target_signal.h +1 -0
@@ -21,6 +21,7 @@ typedef struct target_sigaltstack {#include "../generic/signal.h" +#define TARGET_SEGV_MTEAERR 8/* Asynchronous ARM MTE error */ #define TARGET_SEGV_MTESERR 9/* Synchronous ARM MTE exception */ #define TARGET_ARCH_HAS_SETUP_FRAME
linux-user/aarch64/cpu_loop.c +11 -0
@@ -164,6 +164,17 @@ void cpu_loop(CPUARMState *env)EXCP_DUMP (env,"qemu: unhandled CPU exception 0x%x - aborting\n" , trapnr);abort (); } + +/* Check for MTE asynchronous faults */ +if (unlikely (env->cp15.tfsr_el[0 ])) { + env->cp15.tfsr_el[0 ] =0 ; + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; + info._sifields._sigfault._addr =0 ; + info.si_code =TARGET_SEGV_MTEAERR ; +queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); + } +process_pending_signals (env);/* Exception return on AArch64 always clears the exclusive monitor, * so any return to running guest code implies this.
target/arm/mte_helper.c +10 -0
@@ -565,6 +565,16 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc, select =0 ; } env->cp15.tfsr_el[el] |=1 << select; +#ifdef CONFIG_USER_ONLY +/* +* Stand in for a timer irq, setting _TIF_MTE_ASYNC_FAULT, +* which then sends a SIGSEGV when the thread is next scheduled. +* This cpu will return to the main loop at the end of the TB, +* which is rather sooner than "normal". But the alternative +* is waiting until the next syscall. +*/ +qemu_cpu_kick (env_cpu (env)); +#endif break ;default :
Signature · 1 line
2.25.1
PATCH v5 29/31 target/arm: Add allocation tag storage for user mode
In reply to Richard HendersonUse the now-saved PAGE_ANON and PAGE_MTE bits,
and the per-page saved data.
--- target/arm/mte_helper.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
target/arm/mte_helper.c +27 -2
@@ -78,8 +78,33 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, int tag_size, uintptr_t ra) {#ifdef CONFIG_USER_ONLY -/* Tag storage not implemented. */ -return NULL ; +uint64_t clean_ptr =useronly_clean_ptr (ptr); +int flags =page_get_flags (clean_ptr); +uint8_t *tags; +uintptr_t index; + +if (!(flags & (ptr_access ==MMU_DATA_STORE ?PAGE_WRITE :PAGE_READ ))) { +/* SIGSEGV */ +arm_cpu_tlb_fill (env_cpu (env), ptr, ptr_size, ptr_access, + ptr_mmu_idx, false, ra); +g_assert_not_reached (); + } + +/* Require both MAP_ANON and PROT_MTE for the page. */ +if (!(flags &PAGE_ANON ) || !(flags &PAGE_MTE )) { +return NULL ; + } + + tags =page_get_target_data (clean_ptr); +if (tags ==NULL ) { +size_t alloc_size =TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE +1 ); + tags =page_alloc_target_data (clean_ptr, alloc_size); +assert (tags !=NULL ); + } + + index =extract32 (ptr,LOG2_TAG_GRANULE +1 , +TARGET_PAGE_BITS -LOG2_TAG_GRANULE -1 ); +return tags + index;#else uintptr_t index;CPUIOTLBEntry *iotlbentry;
Signature · 1 line
2.25.1
PATCH v5 30/31 target/arm: Enable MTE for user-only
In reply to Richard Henderson--- target/arm/cpu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
target/arm/cpu.c +15 -0
@@ -204,6 +204,21 @@ static void arm_cpu_reset(DeviceState *dev)* Note that this must match useronly_clean_ptr. */ env->cp15.tcr_el[1 ].raw_tcr = (1ULL <<37 ); + +/* Enable MTE */ +if (cpu_isar_feature (aa64_mte, cpu)) { +/* Enable tag access, but leave TCF0 as No Effect (0). */ + env->cp15.sctlr_el[1 ] |=SCTLR_ATA0 ; +/* +* Exclude all tags, so that tag 0 is always used. +* This corresponds to Linux current->thread.gcr_incl = 0. +* +* Set RRND, so that helper_irg() will generate a seed later. +* Here in cpu_reset(), the crypto subsystem has not yet been +* initialized. +*/ + env->cp15.gcr_el1 =0x1ffff ; + }#else /* Reset into the highest available EL */ if (arm_feature (env,ARM_FEATURE_EL3 )) {
Signature · 1 line
2.25.1
PATCH v5 31/31 tests/tcg/aarch64: Add mte smoke tests
In reply to Richard Henderson--- tests/tcg/aarch64/mte.h | 60 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/mte-1.c | 28 +++++++++++++++ tests/tcg/aarch64/mte-2.c | 45 +++++++++++++++++++++++ tests/tcg/aarch64/mte-3.c | 51 ++++++++++++++++++++++++++ tests/tcg/aarch64/mte-4.c | 45 +++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 6 ++++ tests/tcg/configure.sh | 4 +++ 7 files changed, 239 insertions(+) create mode 100644 tests/tcg/aarch64/mte.h create mode 100644 tests/tcg/aarch64/mte-1.c create mode 100644 tests/tcg/aarch64/mte-2.c create mode 100644 tests/tcg/aarch64/mte-3.c create mode 100644 tests/tcg/aarch64/mte-4.c
tests/tcg/aarch64/mte.h new file +60 -0
@@ -0,0 +1,60 @@ +/* +* Linux kernel fallback API definitions for MTE and test helpers. +* +* Copyright (c) 2021 Linaro Ltd +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include <assert.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <signal.h> +#include <sys/mman.h> +#include <sys/prctl.h> + +#ifndef PR_SET_TAGGED_ADDR_CTRL +# define PR_SET_TAGGED_ADDR_CTRL 55 +#endif +#ifndef PR_TAGGED_ADDR_ENABLE +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) +#endif +#ifndef PR_MTE_TCF_SHIFT +# define PR_MTE_TCF_SHIFT 1 +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TAG_SHIFT 3 +#endif + +#ifndef PROT_MTE +# define PROT_MTE 0x20 +#endif + +#ifndef SEGV_MTEAERR +# define SEGV_MTEAERR 8 +# define SEGV_MTESERR 9 +#endif + +static void enable_mte (int tcf) +{ +int r =prctl (PR_SET_TAGGED_ADDR_CTRL , +PR_TAGGED_ADDR_ENABLE | tcf | (0xfffe <<PR_MTE_TAG_SHIFT ), +0 ,0 ,0 ); +if (r <0 ) { +perror ("PR_SET_TAGGED_ADDR_CTRL" ); +exit (2 ); + } +} + +static void *alloc_mte_mem (size_t size) +{ +void *p =mmap (NULL , size,PROT_READ |PROT_WRITE |PROT_MTE , +MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); +if (p ==MAP_FAILED ) { +perror ("mmap PROT_MTE" ); +exit (2 ); + } +return p; +}
tests/tcg/aarch64/mte-1.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Memory tagging, basic pass cases. +* +* Copyright (c) 2021 Linaro Ltd +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "mte.h" + +int main (int ac,char **av) +{ +int *p0, *p1, *p2; +long c; + +enable_mte (PR_MTE_TCF_NONE ); + p0 =alloc_mte_mem (sizeof (*p0)); + + asm("irg %0,%1,%2" :"=r" (p1) :"r" (p0),"r" (1 )); +assert (p1 != p0); + asm("subp %0,%1,%2" :"=r" (c) :"r" (p0),"r" (p1)); +assert (c ==0 ); + + asm("stg %0, [%0]" : :"r" (p1)); + asm("ldg %0, [%1]" :"=r" (p2) :"r" (p0),"0" (p0)); +assert (p1 == p2); + +return 0 ; +}
tests/tcg/aarch64/mte-2.c new file +45 -0
45 lines not on this page · raw message
tests/tcg/aarch64/mte-3.c new file +51 -0
51 lines not on this page · raw message
tests/tcg/aarch64/mte-4.c new file +45 -0
45 lines not on this page · raw message
tests/tcg/aarch64/Makefile.target +6 -0
@@ -35,6 +35,12 @@ endif # bti-2 tests PROT_BTI, so no special compiler support required. AARCH64_TESTS += bti-2 +# MTE Tests +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_MTE),) +AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 +mte-%: CFLAGS += -march=armv8.5-a+memtag +endif + # Semihosting smoke test for linux-user AARCH64_TESTS += semihosting run-semihosting: semihosting
tests/tcg/configure.sh +4 -0
@@ -244,6 +244,10 @@ for target in $target_list; do -mbranch-protection=standard -o $TMPE $TMPC; then echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak fi + if do_compiler "$target_compiler" $target_compiler_cflags \ + -march=armv8.5-a+memtag -o $TMPE $TMPC; then + echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak + fi ;; esac
Signature · 1 line
2.25.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH v5 00/31] target-arm: Implement ARMv8.5-MemTag, user mode
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
99ae0cd..1ed9228 master -> master - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
9e18fe8 tests/tcg/aarch64: Add mte smoke tests
1343d13 target/arm: Enable MTE for user-only
b0637f9 target/arm: Add allocation tag storage for user mode 7dbe8ae linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error a8a9e4b linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault 8a46469 linux-user/aarch64: Pass syndrome to EXC_*_ABORT
0bdd89c target/arm: Split out syndrome.h from internals.h 1413717 linux-user/aarch64: Implement PROT_MTE
b121145 linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG 9fabfe6 target/arm: Use the proper TBI settings for linux-user 0d277c2 target/arm: Improve gen_top_byte_ignore
8dab68f linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE 8859ad9 linux-user: Handle tags in lock_user/unlock_user
cffec9c linux-user: Fix types in uaccess.c
b927a1f linux-user: Move lock_user et al out of line
9fe72ac linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged cc06f39 exec: Rename guest_{addr,range}_valid to *_untagged 6f6a813 linux-user: Use guest_range_valid in access_ok
dd4ad16 linux-user: Explicitly untag memory management syscalls 152f923 exec: Use cpu_untagged_addr in g2h; split out g2h_untagged 871d472 exec: Introduce cpu_untagged_addr
d413972 linux-user: Fix guest_addr_valid vs reserved_va
3734711 linux-user: Do not use guest_addr_valid for h2g_valid f972c0f bsd-user: Tidy VERIFY_READ/VERIFY_WRITE
4b41ae7 linux-user: Tidy VERIFY_READ/VERIFY_WRITE
9598219 linux-user: Check for overflow in access_ok
3fd7719 exec: Improve types for guest_addr_valid
78b573c exec: Use uintptr_t in cpu_ldst.h
17e666c exec: Use uintptr_t for guest_base
c4d6188 linux-user: Introduce PAGE_ANON
a131719 tcg: Introduce target-specific page data for user-only
=== OUTPUT BEGIN ===
1/31 Checking commit a1317196bf48 (tcg: Introduce target-specific page data for user-only) 2/31 Checking commit c4d6188c23c1 (linux-user: Introduce PAGE_ANON)
3/31 Checking commit 17e666c400ce (exec: Use uintptr_t for guest_base)
4/31 Checking commit 78b573ca012e (exec: Use uintptr_t in cpu_ldst.h)
5/31 Checking commit 3fd7719254c6 (exec: Improve types for guest_addr_valid) 6/31 Checking commit 9598219b9a92 (linux-user: Check for overflow in access_ok) 7/31 Checking commit 4b41ae7fbd9a (linux-user: Tidy VERIFY_READ/VERIFY_WRITE) 8/31 Checking commit f972c0fa3acd (bsd-user: Tidy VERIFY_READ/VERIFY_WRITE)
9/31 Checking commit 3734711323de (linux-user: Do not use guest_addr_valid for h2g_valid) 10/31 Checking commit d41397266800 (linux-user: Fix guest_addr_valid vs reserved_va) 11/31 Checking commit 871d472c35da (exec: Introduce cpu_untagged_addr)
12/31 Checking commit 152f9231963a (exec: Use cpu_untagged_addr in g2h; split out g2h_untagged)
ERROR: braces {} are necessary for all arms of this statement
#535: FILE: linux-user/mmap.c:222:
+ if (pread(fd, g2h_untagged(start), end - start, offset) == -1)
[...]
ERROR: braces {} are necessary for all arms of this statement #697: FILE: linux-user/qemu.h:669:
+ if (host_ptr == g2h_untagged(guest_addr))
[...]
total: 2 errors, 0 warnings, 814 lines checked
Patch 12/31 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
13/31 Checking commit dd4ad1690343 (linux-user: Explicitly untag memory management syscalls) 14/31 Checking commit 6f6a813a06db (linux-user: Use guest_range_valid in access_ok) 15/31 Checking commit cc06f39dff6d (exec: Rename guest_{addr,range}_valid to *_untagged) 16/31 Checking commit 9fe72acec2fc (linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged)
ERROR: braces {} are necessary for all arms of this statement
#31: FILE: linux-user/elfload.c:3503:
+ if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE))
[...]
total: 1 errors, 0 warnings, 108 lines checked
Patch 16/31 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
17/31 Checking commit b927a1f15e1b (linux-user: Move lock_user et al out of line)
ERROR: externs should be avoided in .c files
#116: FILE: linux-user/uaccess.c:29:
+void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
total: 1 errors, 0 warnings, 115 lines checked
Patch 17/31 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
18/31 Checking commit cffec9c75fbb (linux-user: Fix types in uaccess.c)
ERROR: externs should be avoided in .c files
#87: FILE: linux-user/uaccess.c:29:
+void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len);
total: 1 errors, 0 warnings, 142 lines checked
Patch 18/31 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
19/31 Checking commit 8859ad90d24a (linux-user: Handle tags in lock_user/unlock_user) 20/31 Checking commit 8dab68fc73ef (linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE) 21/31 Checking commit 0d277c229ee7 (target/arm: Improve gen_top_byte_ignore) 22/31 Checking commit 9fabfe6269c8 (target/arm: Use the proper TBI settings for linux-user) 23/31 Checking commit b1211455cdde (linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG) 24/31 Checking commit 141371770278 (linux-user/aarch64: Implement PROT_MTE) 25/31 Checking commit 0bdd89c67062 (target/arm: Split out syndrome.h from internals.h)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #282:
new file mode 100644
total: 0 errors, 1 warnings, 530 lines checked
Patch 25/31 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
26/31 Checking commit 8a464692dd13 (linux-user/aarch64: Pass syndrome to EXC_*_ABORT) 27/31 Checking commit a8a9e4ba68a2 (linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault) 28/31 Checking commit 7dbe8ae490db (linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error) 29/31 Checking commit b0637f953e22 (target/arm: Add allocation tag storage for user mode) 30/31 Checking commit 1343d132c7b2 (target/arm: Enable MTE for user-only)
31/31 Checking commit 9e18fe86d431 (tests/tcg/aarch64: Add mte smoke tests)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#38:
new file mode 100644
ERROR: trailing statements should be on next line
#177: FILE: tests/tcg/aarch64/mte-3.c:50:
+ while (1);
ERROR: braces {} are necessary for all arms of this statement #177: FILE: tests/tcg/aarch64/mte-3.c:50:
+ while (1);
[...]
ERROR: use qemu_real_host_page_size instead of getpagesize() #215: FILE: tests/tcg/aarch64/mte-4.c:31:
+ size_t size = getpagesize() * 4;
total: 3 errors, 1 warnings, 251 lines checked
Patch 31/31 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]