[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen stable-4.9] x86/pv: Introduce and use x86emul_read_dr()
commit 52fa2f7d62090767b799d287c48a2146358a3953 Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Fri May 18 11:54:05 2018 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Fri May 18 11:54:05 2018 +0200 x86/pv: Introduce and use x86emul_read_dr() do_get_debugreg() has several bugs: * The %cr4.de condition is inverted. %dr4/5 should be accessible only when %cr4.de is disabled. * When %cr4.de is disabled, emulation should yield #UD rather than complete with zero. * Using -EINVAL for errors is a broken ABI, as it overlaps with valid values near the top of the address space. Introduce a common x86emul_read_dr() handler (as we will eventually want to add HVM support) which separates its success/failure indication from the data value, and have do_get_debugreg() call into the handler. The ABI of do_get_debugreg() remains broken, but switches from -EINVAL to -ENODEV for compatibility with the changes in the following patch. Take the opportunity to add a missing local variable block to x86_emulate.c Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Acked-by: Jan Beulich <jbeulich@xxxxxxxx> master commit: 881f8dc4314809293efc6f66f9af49734994bf0e master date: 2018-04-17 15:12:36 +0100 --- xen/arch/x86/traps.c | 33 +++-------------------- xen/arch/x86/x86_emulate.c | 49 ++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_emulate/x86_emulate.h | 3 +++ 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 938f7aeb85..1f3881e5b3 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -2494,19 +2494,6 @@ static int priv_op_write_cr(unsigned int reg, unsigned long val, return X86EMUL_UNHANDLEABLE; } -static int priv_op_read_dr(unsigned int reg, unsigned long *val, - struct x86_emulate_ctxt *ctxt) -{ - unsigned long res = do_get_debugreg(reg); - - if ( IS_ERR_VALUE(res) ) - return X86EMUL_UNHANDLEABLE; - - *val = res; - - return X86EMUL_OKAY; -} - static int priv_op_write_dr(unsigned int reg, unsigned long val, struct x86_emulate_ctxt *ctxt) { @@ -3023,7 +3010,7 @@ static const struct x86_emulate_ops priv_op_ops = { .read_segment = priv_op_read_segment, .read_cr = priv_op_read_cr, .write_cr = priv_op_write_cr, - .read_dr = priv_op_read_dr, + .read_dr = x86emul_read_dr, .write_dr = priv_op_write_dr, .read_msr = priv_op_read_msr, .write_msr = priv_op_write_msr, @@ -4300,22 +4287,10 @@ long do_set_debugreg(int reg, unsigned long value) unsigned long do_get_debugreg(int reg) { - struct vcpu *curr = current; - - switch ( reg ) - { - case 0 ... 3: - case 6: - return curr->arch.debugreg[reg]; - case 7: - return (curr->arch.debugreg[7] | - curr->arch.debugreg[5]); - case 4 ... 5: - return ((curr->arch.pv_vcpu.ctrlreg[4] & X86_CR4_DE) ? - curr->arch.debugreg[reg + 2] : 0); - } + unsigned long val; + int res = x86emul_read_dr(reg, &val, NULL); - return -EINVAL; + return res == X86EMUL_OKAY ? val : -ENODEV; } void asm_domain_crash_synchronous(unsigned long addr) diff --git a/xen/arch/x86/x86_emulate.c b/xen/arch/x86/x86_emulate.c index c7ba221d11..d3155a09d5 100644 --- a/xen/arch/x86/x86_emulate.c +++ b/xen/arch/x86/x86_emulate.c @@ -41,3 +41,52 @@ }) #include "x86_emulate/x86_emulate.c" + +/* Called with NULL ctxt in hypercall context. */ +int x86emul_read_dr(unsigned int reg, unsigned long *val, + struct x86_emulate_ctxt *ctxt) +{ + struct vcpu *curr = current; + + /* HVM support requires a bit more plumbing before it will work. */ + ASSERT(is_pv_vcpu(curr)); + + switch ( reg ) + { + case 0 ... 3: + case 6: + *val = curr->arch.debugreg[reg]; + break; + + case 7: + *val = (curr->arch.debugreg[7] | + curr->arch.debugreg[5]); + break; + + case 4 ... 5: + if ( !(curr->arch.pv_vcpu.ctrlreg[4] & X86_CR4_DE) ) + { + *val = curr->arch.debugreg[reg + 2]; + break; + } + + /* Fallthrough */ + default: + if ( ctxt ) + x86_emul_hw_exception(TRAP_invalid_op, X86_EVENT_NO_EC, ctxt); + + return X86EMUL_EXCEPTION; + } + + return X86EMUL_OKAY; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h b/xen/arch/x86/x86_emulate/x86_emulate.h index e5ec8a6122..1c9331c897 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -652,6 +652,9 @@ static inline void x86_emulate_free_state(struct x86_emulate_state *state) {} void x86_emulate_free_state(struct x86_emulate_state *state); #endif +int x86emul_read_dr(unsigned int reg, unsigned long *val, + struct x86_emulate_ctxt *ctxt); + #endif static inline void x86_emul_hw_exception( -- generated by git-patchbot for /home/xen/git/xen.git#stable-4.9 _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |