* [PATCH v2 0/1] Use correct trap number for *BSD @ 2021-06-25 4:57 Warner Losh 2021-06-25 4:57 ` Warner Losh ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Warner Losh @ 2021-06-25 4:57 UTC (permalink / raw) To: qemu-devel; +Cc: pbonzini, riku.voipio, richard.henderson, Warner Losh This is a resend of a patch I sent back in March that was missing the proper includes due to a rebasing mistake. The issue is that all the BSDs use T_PAGEFLT to signal a page fault on x86, while linux uses 0xe. The patch harmonizes the different ways this can be spelled, as explained in the patch itself. Warner Losh (1): tcg: Use correct trap number for page faults on *BSD systems accel/tcg/user-exec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) -- 2.22.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 0/1] Use correct trap number for *BSD 2021-06-25 4:57 [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh @ 2021-06-25 4:57 ` Warner Losh 2021-06-25 4:57 ` [PATCH v2 1/1] tcg: Use correct trap number for page faults on *BSD systems Warner Losh 2021-06-25 5:09 ` [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh 2 siblings, 0 replies; 5+ messages in thread From: Warner Losh @ 2021-06-25 4:57 UTC (permalink / raw) To: qemu-devel; +Cc: pbonzini, riku.voipio, richard.henderson, Warner Losh This is a resend of a patch I sent back in March that was missing the proper includes due to a rebasing mistake. Warner Losh (1): tcg: Use correct trap number for page faults on *BSD systems accel/tcg/user-exec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) -- 2.22.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/1] tcg: Use correct trap number for page faults on *BSD systems 2021-06-25 4:57 [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh 2021-06-25 4:57 ` Warner Losh @ 2021-06-25 4:57 ` Warner Losh 2021-06-26 5:37 ` Richard Henderson 2021-06-25 5:09 ` [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh 2 siblings, 1 reply; 5+ messages in thread From: Warner Losh @ 2021-06-25 4:57 UTC (permalink / raw) To: qemu-devel Cc: riku.voipio, richard.henderson, Mark Johnston, pbonzini, Juergen Lock, Warner Losh The trap number for a page fault on BSD systems is T_PAGEFLT not 0xe. 0xe is used by Linux and represents the intel hardware trap vector. The BSD kernels, however, translate this to T_PAGEFLT in their Xpage, Xtrap0e, Xtrap14, etc fault handlers. This is true for i386 and x86_64, though the name of the trap hanlder can very on the flavor of BSD. As far as I can tell, Linux doesn't provide a define for this value. Invent a new one (PAGE_FAULT_TRAP) and use it instead to avoid uglier ifdefs. Signed-off-by: Mark Johnston <markj@FreeBSD.org> Signed-off-by: Juergen Lock <nox@FreeBSD.org> [ Rework to avoid ifdefs and expand it to i386 ] Signed-off-by: Warner Losh <imp@bsdimp.com> --- accel/tcg/user-exec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index fb2d43e6a9..e2d0165670 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -254,28 +254,35 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, #if defined(__NetBSD__) #include <ucontext.h> +#include <machine/trap.h> #define EIP_sig(context) ((context)->uc_mcontext.__gregs[_REG_EIP]) #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO]) #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR]) #define MASK_sig(context) ((context)->uc_sigmask) +#define PAGE_FAULT_TRAP T_PAGEFLT #elif defined(__FreeBSD__) || defined(__DragonFly__) #include <ucontext.h> +#include <machine/trap.h> #define EIP_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_eip)) #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno) #define ERROR_sig(context) ((context)->uc_mcontext.mc_err) #define MASK_sig(context) ((context)->uc_sigmask) +#define PAGE_FAULT_TRAP T_PAGEFLT #elif defined(__OpenBSD__) +#include <machine/trap.h> #define EIP_sig(context) ((context)->sc_eip) #define TRAP_sig(context) ((context)->sc_trapno) #define ERROR_sig(context) ((context)->sc_err) #define MASK_sig(context) ((context)->sc_mask) +#define PAGE_FAULT_TRAP T_PAGEFLT #else #define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP]) #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO]) #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR]) #define MASK_sig(context) ((context)->uc_sigmask) +#define PAGE_FAULT_TRAP 0xe #endif int cpu_signal_handler(int host_signum, void *pinfo, @@ -301,34 +308,42 @@ int cpu_signal_handler(int host_signum, void *pinfo, pc = EIP_sig(uc); trapno = TRAP_sig(uc); return handle_cpu_signal(pc, info, - trapno == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0, + trapno == PAGE_FAULT_TRAP ? + (ERROR_sig(uc) >> 1) & 1 : 0, &MASK_sig(uc)); } #elif defined(__x86_64__) #ifdef __NetBSD__ +#include <machine/trap.h> #define PC_sig(context) _UC_MACHINE_PC(context) #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO]) #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR]) #define MASK_sig(context) ((context)->uc_sigmask) +#define PAGE_FAULT_TRAP T_PAGEFLT #elif defined(__OpenBSD__) +#include <machine/trap.h> #define PC_sig(context) ((context)->sc_rip) #define TRAP_sig(context) ((context)->sc_trapno) #define ERROR_sig(context) ((context)->sc_err) #define MASK_sig(context) ((context)->sc_mask) +#define PAGE_FAULT_TRAP T_PAGEFLT #elif defined(__FreeBSD__) || defined(__DragonFly__) #include <ucontext.h> +#include <machine/trap.h> #define PC_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_rip)) #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno) #define ERROR_sig(context) ((context)->uc_mcontext.mc_err) #define MASK_sig(context) ((context)->uc_sigmask) +#define PAGE_FAULT_TRAP T_PAGEFLT #else #define PC_sig(context) ((context)->uc_mcontext.gregs[REG_RIP]) #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO]) #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR]) #define MASK_sig(context) ((context)->uc_sigmask) +#define PAGE_FAULT_TRAP 0xe #endif int cpu_signal_handler(int host_signum, void *pinfo, @@ -346,7 +361,8 @@ int cpu_signal_handler(int host_signum, void *pinfo, pc = PC_sig(uc); return handle_cpu_signal(pc, info, - TRAP_sig(uc) == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0, + TRAP_sig(uc) == PAGE_FAULT_TRAP ? + (ERROR_sig(uc) >> 1) & 1 : 0, &MASK_sig(uc)); } -- 2.22.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] tcg: Use correct trap number for page faults on *BSD systems 2021-06-25 4:57 ` [PATCH v2 1/1] tcg: Use correct trap number for page faults on *BSD systems Warner Losh @ 2021-06-26 5:37 ` Richard Henderson 0 siblings, 0 replies; 5+ messages in thread From: Richard Henderson @ 2021-06-26 5:37 UTC (permalink / raw) To: Warner Losh, qemu-devel Cc: pbonzini, riku.voipio, Juergen Lock, Mark Johnston On 6/24/21 9:57 PM, Warner Losh wrote: > The trap number for a page fault on BSD systems is T_PAGEFLT not 0xe. 0xe is > used by Linux and represents the intel hardware trap vector. The BSD kernels, > however, translate this to T_PAGEFLT in their Xpage, Xtrap0e, Xtrap14, etc fault > handlers. This is true for i386 and x86_64, though the name of the trap hanlder > can very on the flavor of BSD. As far as I can tell, Linux doesn't provide a > define for this value. Invent a new one (PAGE_FAULT_TRAP) and use it instead to > avoid uglier ifdefs. > > Signed-off-by: Mark Johnston<markj@FreeBSD.org> > Signed-off-by: Juergen Lock<nox@FreeBSD.org> > [ Rework to avoid ifdefs and expand it to i386 ] > Signed-off-by: Warner Losh<imp@bsdimp.com> > --- > accel/tcg/user-exec.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) Thanks, queued to tcg-next. r~ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/1] Use correct trap number for *BSD 2021-06-25 4:57 [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh 2021-06-25 4:57 ` Warner Losh 2021-06-25 4:57 ` [PATCH v2 1/1] tcg: Use correct trap number for page faults on *BSD systems Warner Losh @ 2021-06-25 5:09 ` Warner Losh 2 siblings, 0 replies; 5+ messages in thread From: Warner Losh @ 2021-06-25 5:09 UTC (permalink / raw) To: QEMU Developers; +Cc: Paolo Bonzini, Riku Voipio, Richard Henderson [-- Attachment #1: Type: text/plain, Size: 770 bytes --] On Thu, Jun 24, 2021 at 10:57 PM Warner Losh <imp@bsdimp.com> wrote: > This is a resend of a patch I sent back in March that was missing the > proper > includes due to a rebasing mistake. > > The issue is that all the BSDs use T_PAGEFLT to signal a page fault on x86, > while linux uses 0xe. The patch harmonizes the different ways this can be > spelled, as explained in the patch itself. > I forgot to mention that I've setup NetBSD and OpenBSD bhyve instances to compile and test these changes to make double sure that they will pass through the qemu CI. > Warner Losh (1): > tcg: Use correct trap number for page faults on *BSD systems > > accel/tcg/user-exec.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > -- > 2.22.1 > > [-- Attachment #2: Type: text/html, Size: 1311 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-06-26 5:37 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-06-25 4:57 [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh 2021-06-25 4:57 ` Warner Losh 2021-06-25 4:57 ` [PATCH v2 1/1] tcg: Use correct trap number for page faults on *BSD systems Warner Losh 2021-06-26 5:37 ` Richard Henderson 2021-06-25 5:09 ` [PATCH v2 0/1] Use correct trap number for *BSD Warner Losh
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).