Re: [PATCH 5/7] x86: Introduce x86_merge_dr6()

2023-10-28 Thread Jinoh Kang
On 9/25/23 19:20, Jinoh Kang wrote: > As an outsider's perspective, I think this kind of thing is where selftests > really shine. I got the impression that Xen will need to rely on numerous > other > platform oddities, the documentation of which are often unavailable. > &

Re: [PATCH 5/7] x86: Introduce x86_merge_dr6()

2023-09-25 Thread Jinoh Kang
ee paths forward here: 1. Reference the most relevant paragraph in SDM/APM, but don't quote it. Keep the current explanation, and state that the manual is vague anyway. 2. Acknowledge that SDM/APM is incomplete, and completely abandon the manual as the *authoritative* source of information. Perhaps embed a sample test program that demonstrates the behavior, if it isn't too long. 3. Actually assert in runtime that DR6 behaves as expected. > > Jan -- Sincerely, Jinoh Kang

Re: [PATCH 4/7] x86/pv: Drop priv_op_ctxt.bpmatch and use pending_dbg instead

2023-09-16 Thread Jinoh Kang
On 9/16/23 23:00, Andrew Cooper wrote: > On 16/09/2023 8:36 am, Jinoh Kang wrote: (snip) >> These two hunks look like a behavioral change in singlestep mode. >> >> This is actually a fix, assuming the emulator previously did not handle >> 'rep {in,out}s' i

Re: [PATCH 7/7] x86/pv: Rewrite %dr6 handling

2023-09-16 Thread Jinoh Kang
that.  DR6 is > just one of many registers we need to context switch for the vCPU. > > PV guests, being ring-deprivieged, trap into Xen for every DR access, > and Xen handles every one of their #DB exceptions.  This is one reason > why I split the work into several parts.  PV guests are easier to get > sorted properly, and patch 1,2,5,6 are all common improvements relevant > to HVM too. That confirms my knowledge. Honestly if I got such a foolish remark I would question the reviewer's understanding of PV mode (not that you did anything wrong). Sorry for wasting your time. > > ~Andrew -- Sincerely, Jinoh Kang

Re: [PATCH 7/7] x86/pv: Rewrite %dr6 handling

2023-09-16 Thread Jinoh Kang
ent in the common case, but retain the prior behaviour if a debugger is > attached. > > Signed-off-by: Andrew Cooper > --- > CC: Jan Beulich > CC: Roger Pau Monné > CC: Wei Liu > CC: Jinoh Kang > > v2: > * Split pieces out into an earlier patch. > * Extend do_d

Re: [PATCH 6/7] x86: Extend x86_event with a pending_dbg field

2023-09-16 Thread Jinoh Kang
> > Signed-off-by: Andrew Cooper > --- > CC: Jan Beulich > CC: Roger Pau Monné > CC: Wei Liu > CC: Jinoh Kang > > v2: > * Split out of prior patch. > --- > xen/arch/x86/include/asm/domain.h | 18 -- > xen/arch/x86/include/asm/hvm/hvm.

Re: [PATCH 4/7] x86/pv: Drop priv_op_ctxt.bpmatch and use pending_dbg instead

2023-09-16 Thread Jinoh Kang
that. (Ideally all the HWBP handling should be part of the emulator logic, but I don't see an easy way to generalize the PV-specific logic. It could be its own patch anyway.) -- Sincerely, Jinoh Kang

Re: [PATCH 3/5] x86/emul: Add a pending_dbg field to x86_emulate_ctxt.retire

2023-09-15 Thread Jinoh Kang
On 9/15/23 21:20, Jinoh Kang wrote: > On 9/13/23 08:21, Andrew Cooper wrote: >> diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h >> b/xen/arch/x86/x86_emulate/x86_emulate.h >> index 698750267a90..f0e74d23c378 100644 >> --- a/xen/arch/x86/x86_emulate/x86_emul

Re: [PATCH 3/5] x86/emul: Add a pending_dbg field to x86_emulate_ctxt.retire

2023-09-15 Thread Jinoh Kang
t; bool sti:1; /* Instruction sets STI irq shadow. */ > bool unblock_nmi:1; /* Instruction clears NMI blocking. */ > -bool singlestep:1; /* Singlestepping was active. */ > +bool singlestep:1; /* Singlestepping was active. (TODO, merge > into pending_dbg) */ > }; > } retire; > -- Sincerely, Jinoh Kang

Re: [PATCH v2 2/8] x86/hvm: Only populate info->cr2 for #PF in hvm_get_pending_event()

2023-08-30 Thread Jinoh Kang
On 8/30/23 22:41, Jan Beulich wrote: > On 24.08.2023 17:25, Jinoh Kang wrote: >> Prepare for an upcoming patch that overloads the 'cr2' field for #DB. > > Seeing the subsequent change and the fact that earlier on Andrew didn't > need such an adjustment, I'

[PATCH v2 7/8] x86: Fix merging of new status bits into %dr6

2023-08-24 Thread Jinoh Kang
: Andrew Cooper Reviewed-by: Roger Pau Monné Reviewed-by: Jan Beulich [ jinoh: Rebase onto staging, move constants to x86-defns.h ] Signed-off-by: Jinoh Kang --- CC: Andrew Cooper CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Jun Nakajima CC: Kevin Tian v1 -> v2: [S-o-b fi

[PATCH v2 8/8] x86/dbg: Cleanup of legacy dr6 constants

2023-08-24 Thread Jinoh Kang
From: Andrew Cooper Replace the few remaining uses with X86_DR6_* constants. Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné Acked-by: Jan Beulich [ jinoh: Rebase onto staging ] Signed-off-by: Jinoh Kang --- CC: Andrew Cooper CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné v1

[PATCH v2 6/8] x86/hvm: Add comments about #DB exception behavior to {svm,vmx}_inject_event()

2023-08-24 Thread Jinoh Kang
From: Andrew Cooper Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné Extracted comments only, and then s/from emulation/from monitor/; originally "x86/hvm: RFC - PROBABLY BROKEN - Defer all debugging/monitor actions to {svm,vmx}_inject_event()" Signed-off-by: Jinoh Ka

[PATCH v2 4/8] x86/emul: Populate pending_dbg field of x86_event from {svm,vmx}_get_pending_event()

2023-08-24 Thread Jinoh Kang
Ensure that we pass the correct pending_dbg value to hvm_monitor_interrupt(). Signed-off-by: Jinoh Kang --- CC: Andrew Cooper CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Jun Nakajima CC: Kevin Tian CC: Tamas K Lengyel CC: Alexandru Isaila CC: Petre Pircalabu v1 -> v2: new pa

[PATCH v2 3/8] x86/emul: Add pending_dbg field to x86_event

2023-08-24 Thread Jinoh Kang
viewed-by: Roger Pau Monné Reviewed-by: Jan Beulich [ jinoh: Rebase onto staging, forward declare struct vcpu ] Signed-off-by: Jinoh Kang --- CC: Andrew Cooper CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Jun Nakajima CC: Kevin Tian CC: Tim Deegan CC: Tamas K Lengyel CC: Alexand

[PATCH v2 2/8] x86/hvm: Only populate info->cr2 for #PF in hvm_get_pending_event()

2023-08-24 Thread Jinoh Kang
Prepare for an upcoming patch that overloads the 'cr2' field for #DB. Signed-off-by: Jinoh Kang --- CC: Andrew Cooper CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Tamas K Lengyel CC: Alexandru Isaila CC: Petre Pircalabu --- xen/arch/x86/hvm/hvm.c | 9 +++-- 1 file

[PATCH v2 1/8] x86: Fix calculation of %dr6/7 reserved bits

2023-08-24 Thread Jinoh Kang
e the guest maximum policy, which will be more permissive with respect to the RTM feature. Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monné [ jinoh: Rebase onto staging, along with some fixes ] Signed-off-by: Jinoh Kang --- CC: Andrew Cooper CC: Jan Beulich CC: Wei Liu CC: Roger Pau

[PATCH v2 0/8] Fixes to debugging facilities

2023-08-24 Thread Jinoh Kang
ernel mode - Commit message fixes Andrew Cooper (5): x86: Fix calculation of %dr6/7 reserved bits x86/emul: Add pending_dbg field to x86_event x86/hvm: Add comments about #DB exception behavior to {svm,vmx}_inject_event() x86: Fix merging of new status bits into %dr6 x86/dbg: Cleanup

Re: [PATCH 1/5] x86: Fix calculation of %dr6/7 reserved bits

2023-08-22 Thread Jinoh Kang
to take care of them. Somehow I assumed that Andrew's branch had already contained the relevant updates, which was clearly wrong and was a sloppy thinking on my part. Also, rushing to submission didn't _really_ help. Again, apologies for wasting your time. -- Sincerely, Jinoh Kang

Re: [PATCH 1/5] x86: Fix calculation of %dr6/7 reserved bits

2023-08-22 Thread Jinoh Kang
On 8/22/23 23:54, Jan Beulich wrote: > On 21.08.2023 18:12, Jinoh Kang wrote: >> On 8/22/23 00:56, Jinoh Kang wrote: >>> From: Andrew Cooper >>> >>> The reserved bit calculations for %dr6 and %dr7 depend on whether the VM has >>> the Restricted Tr

Re: [PATCH 0/5] Fixes to debugging facilities

2023-08-22 Thread Jinoh Kang
thing else w.r.t. tagging rules. > > Jan -- Sincerely, Jinoh Kang

Re: [PATCH 3/5] x86/hvm: RFC - PROBABLY BROKEN - Defer all debugging/monitor actions to {svm,vmx}_inject_event()

2023-08-22 Thread Jinoh Kang
On 8/22/23 01:34, Tamas K Lengyel wrote: > On Mon, Aug 21, 2023 at 5:57 PM Jinoh Kang wrote: >> This is RFC because it probably breaks introspection, as injection replies >> from the introspection engine will (probably, but I haven't confirmed) >> trigger >> ne

Re: [PATCH 1/5] x86: Fix calculation of %dr6/7 reserved bits

2023-08-21 Thread Jinoh Kang
On 8/22/23 00:56, Jinoh Kang wrote: > From: Andrew Cooper > > The reserved bit calculations for %dr6 and %dr7 depend on whether the VM has > the Restricted Transnational Memory feature available. s/Transnational/Transactional/. It was in the original review, but I missed the change

[PATCH 2/5] x86/emul: Add pending_dbg field to x86_event

2023-08-21 Thread Jinoh Kang
of RTM and reserved fields. For PV guests, move the ad-hoc updating of %dr6 into pv_inject_event(). This in principle breaks the handing of RTM in do_debug(), but PV guests can't actually enable MSR_DEBUGCTL.RTM yet, so this doesn't matter in practice. Signed-off-by: Jinoh Kang --- CC:

[PATCH 4/5] x86: Fix merging of new status bits into %dr6

2023-08-21 Thread Jinoh Kang
: Jinoh Kang --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Jun Nakajima CC: Kevin Tian --- xen/arch/x86/hvm/svm/svm.c | 3 ++- xen/arch/x86/hvm/vmx/vmx.c | 3 ++- xen/arch/x86/include/asm/debugreg.h | 30 +++- xen/arch/x86/include/asm

[PATCH 5/5] x86/dbg: Cleanup of legacy dr6 constants

2023-08-21 Thread Jinoh Kang
From: Andrew Cooper Replace the few remaining uses with X86_DR6_* constants. Signed-off-by: Jinoh Kang --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/include/asm/debugreg.h | 17 - xen/arch/x86/pv/emul-priv

[PATCH 3/5] x86/hvm: RFC - PROBABLY BROKEN - Defer all debugging/monitor actions to {svm,vmx}_inject_event()

2023-08-21 Thread Jinoh Kang
level, and everything implemented at the injection level. Amongst other things, this means that the monitor subsystem will pick up debug actions from emulated events. Signed-off-by: Jinoh Kang --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Jun Nakajima CC: Kevin Tian CC: Razvan

[PATCH 1/5] x86: Fix calculation of %dr6/7 reserved bits

2023-08-21 Thread Jinoh Kang
guest maximum policy, which will be more permissive with respect to the RTM feature. Signed-off-by: Jinoh Kang --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- xen/arch/x86/domain.c | 7 +++-- xen/arch/x86/hvm/hvm.c | 6 ++-- xen/arch/x86/include/asm

[PATCH 0/5] Fixes to debugging facilities

2023-08-21 Thread Jinoh Kang
This is a rebased version of Andrew Cooper's debugging facilities patch: https://lore.kernel.org/xen-devel/1528120755-17455-1-git-send-email-andrew.coop...@citrix.com/ > So this started as a small fix for the vmentry failure (penultimate patch), > and has snowballed... > > I'm fairly confident tha

Re: [PATCH 0/6] x86/debug: fix guest dr6 value for single stepping and HW breakpoints

2023-08-19 Thread Jinoh Kang
ne something wrong, your debug-fixes-v1 when rebased to master seems to fix my problem, so I guess your patchset is the superset. -- Sincerely, Jinoh Kang

Re: [PATCH 3/6] x86: don't assume #DB is always caused by singlestep if EFLAGS.TF is set

2023-08-18 Thread Jinoh Kang
On 8/19/23 00:47, Jinoh Kang wrote: > Today, when a HVM (or PVH) guest triggers a hardware breakpoint while > EFLAGS.TF is set, Xen incorrectly assumes that this is a single stepping > exception and sets DR_STEP in dr6 in addition to DR_TRAP. > > This causes problems with Linu

[PATCH] x86/svm: invert valid condition in svm_get_pending_event()

2023-08-18 Thread Jinoh Kang
Fixes: 9864841914c2 ("x86/vm_event: add support for VM_EVENT_REASON_INTERRUPT") Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/svm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 01dd592d9b83..be

[PATCH 6/6] x86/debug: actually plumb pending_dbg through the monitor and devicemodel interfaces

2023-08-18 Thread Jinoh Kang
Commit 21867648033d ("x86/debug: Plumb pending_dbg through the monitor and devicemodel interfaces") introduced pending_dbg, but did not actually populate or use the field. Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/svm/svm.c | 34 +++--- xen/arch/x

[PATCH 5/6] x86/pv: factor out single-step debug trap injection

2023-08-18 Thread Jinoh Kang
Add pv_inject_debug_exception() helper and use it wherever applicable. This helper corresponds to hvm_inject_debug_exception() in HVM. Signed-off-by: Jinoh Kang --- xen/arch/x86/include/asm/domain.h | 12 xen/arch/x86/pv/emulate.c | 5 + xen/arch/x86/pv/ro-page

[PATCH 3/6] x86: don't assume #DB is always caused by singlestep if EFLAGS.TF is set

2023-08-18 Thread Jinoh Kang
nt. Fixes: 8b831f4189 ("x86: single step after instruction emulation") Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/emulate.c | 3 ++- xen/arch/x86/hvm/svm/svm.c | 6 +++--- xen/arch/x86/hvm/vmx/vmx.c | 6 +++--- xen/arch/x86/include/as

[PATCH 4/6] x86/pv: set DR_STEP if single-stepping after ro page fault emulation

2023-08-18 Thread Jinoh Kang
Signed-off-by: Jinoh Kang --- xen/arch/x86/pv/ro-page-fault.c | 4 1 file changed, 4 insertions(+) diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c index cad28ef928ad..238bfbeb4ac4 100644 --- a/xen/arch/x86/pv/ro-page-fault.c +++ b/xen/arch/x86/pv/ro-page

[PATCH 2/6] x86emul: rename field 'cr2' of struct x86_event to 'extra'

2023-08-18 Thread Jinoh Kang
n preparation for an upcoming patch that uses it to actually populate dr6. Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/arch/x86/hvm/svm/nestedsvm.c | 2 +- xen/arch/x86/hvm/svm/svm.c

[PATCH 1/6] x86/hvm: only populate info->cr2 for #PF in hvm_get_pending_event()

2023-08-18 Thread Jinoh Kang
Prepare for an upcoming patch that overloads the 'cr2' field for #DB. Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/hvm.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 3a99c0ff20be..48a77524f198 10

[PATCH 0/6] x86/debug: fix guest dr6 value for single stepping and HW breakpoints

2023-08-18 Thread Jinoh Kang
KEUSER, pid, (void *)offsetof(struct user, u_debugreg[7]), (void *)0L)); /* Continue execution to let child process exit */ ABORT_ON_ERR(ptrace(PTRACE_CONT, pid, NULL, (unsigned long)0)); if (waitpid(pid, &wstatus, 0) != pid) abort(); if (!(WIFEXITED(wstatus) && WEXITST