All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state
@ 2018-06-01 14:06 Andrew Cooper
  2018-06-01 14:09 ` Andrew Cooper
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Cooper @ 2018-06-01 14:06 UTC (permalink / raw)
  To: Xen-devel; +Cc: Juergen Gross, Andrew Cooper, Jan Beulich

c/s "x86/pv: Introduce and use x86emul_write_dr()" fixed a bug with IO shadow
handling, in that it remained stale and visible until %dr7.L/G got set again.

However, it neglected the -EPERM return inbetween these two hunks, introducing
a different bug in which a write to %dr7 which tries to set IO breakpoints
without %cr4.DE being set clobbers the IO state, rather than leaves it alone.

Instead, move the zeroing slightly later, which guarentees that the shadow
gets written exactly once, on a successful update to %dr7.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Juergen Gross <jgross@suse.com>

Although minor, this is a regression from Xen 4.10, so should be considered
for 4.11 at this point.  Given that PV debugging was basically completely
broken before the XSA-263 investigation work, the risk of further issues is
very small.
---
 xen/arch/x86/traps.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 8a99174..e79ca88 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -2123,9 +2123,6 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
         if ( value & DR_GENERAL_DETECT )
             return -EPERM;
 
-        /* Zero the IO shadow before recalculating the real %dr7 */
-        v->arch.debugreg[5] = 0;
-
         /* DR7.{G,L}E = 0 => debugging disabled for this domain. */
         if ( value & DR7_ACTIVE_MASK )
         {
@@ -2154,6 +2151,10 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
                  !(v->arch.debugreg[7] & DR7_ACTIVE_MASK) )
                 activate_debugregs(v);
         }
+        else
+            /* Zero the emulated controls if %dr7 isn't active. */
+            v->arch.debugreg[5] = 0;
+
         if ( v == curr )
             write_debugreg(7, value);
         break;
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state
  2018-06-01 14:06 [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state Andrew Cooper
@ 2018-06-01 14:09 ` Andrew Cooper
  2018-06-01 15:41 ` Jan Beulich
  2018-06-01 18:53 ` Juergen Gross
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Cooper @ 2018-06-01 14:09 UTC (permalink / raw)
  To: Xen-devel; +Cc: Juergen Gross, Jan Beulich

On 01/06/18 15:06, Andrew Cooper wrote:
> c/s "x86/pv: Introduce and use x86emul_write_dr()" fixed a bug with IO shadow
> handling, in that it remained stale and visible until %dr7.L/G got set again.
>
> However, it neglected the -EPERM return inbetween these two hunks, introducing
> a different bug in which a write to %dr7 which tries to set IO breakpoints
> without %cr4.DE being set clobbers the IO state, rather than leaves it alone.
>
> Instead, move the zeroing slightly later, which guarentees that the shadow
> gets written exactly once, on a successful update to %dr7.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Juergen Gross <jgross@suse.com>
>
> Although minor, this is a regression from Xen 4.10, so should be considered
> for 4.11 at this point.  Given that PV debugging was basically completely
> broken before the XSA-263 investigation work, the risk of further issues is
> very small.

Sorry - this is a bad way of phrasing what I meant to say.  The
behaviour of 4.11 is less bad than 4.10, but still wrong (and in a way
which is technically a regression from 4.10).

~Andrew

> ---
>  xen/arch/x86/traps.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
> index 8a99174..e79ca88 100644
> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -2123,9 +2123,6 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
>          if ( value & DR_GENERAL_DETECT )
>              return -EPERM;
>  
> -        /* Zero the IO shadow before recalculating the real %dr7 */
> -        v->arch.debugreg[5] = 0;
> -
>          /* DR7.{G,L}E = 0 => debugging disabled for this domain. */
>          if ( value & DR7_ACTIVE_MASK )
>          {
> @@ -2154,6 +2151,10 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
>                   !(v->arch.debugreg[7] & DR7_ACTIVE_MASK) )
>                  activate_debugregs(v);
>          }
> +        else
> +            /* Zero the emulated controls if %dr7 isn't active. */
> +            v->arch.debugreg[5] = 0;
> +
>          if ( v == curr )
>              write_debugreg(7, value);
>          break;


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state
  2018-06-01 14:06 [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state Andrew Cooper
  2018-06-01 14:09 ` Andrew Cooper
@ 2018-06-01 15:41 ` Jan Beulich
  2018-06-01 18:53 ` Juergen Gross
  2 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2018-06-01 15:41 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Juergen Gross, Xen-devel

>>> On 01.06.18 at 16:06, <andrew.cooper3@citrix.com> wrote:
> c/s "x86/pv: Introduce and use x86emul_write_dr()" fixed a bug with IO shadow
> handling, in that it remained stale and visible until %dr7.L/G got set again.
> 
> However, it neglected the -EPERM return inbetween these two hunks, introducing
> a different bug in which a write to %dr7 which tries to set IO breakpoints
> without %cr4.DE being set clobbers the IO state, rather than leaves it alone.
> 
> Instead, move the zeroing slightly later, which guarentees that the shadow
> gets written exactly once, on a successful update to %dr7.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state
  2018-06-01 14:06 [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state Andrew Cooper
  2018-06-01 14:09 ` Andrew Cooper
  2018-06-01 15:41 ` Jan Beulich
@ 2018-06-01 18:53 ` Juergen Gross
  2 siblings, 0 replies; 4+ messages in thread
From: Juergen Gross @ 2018-06-01 18:53 UTC (permalink / raw)
  To: Andrew Cooper, Xen-devel; +Cc: Jan Beulich

On 01/06/18 16:06, Andrew Cooper wrote:
> c/s "x86/pv: Introduce and use x86emul_write_dr()" fixed a bug with IO shadow
> handling, in that it remained stale and visible until %dr7.L/G got set again.
> 
> However, it neglected the -EPERM return inbetween these two hunks, introducing
> a different bug in which a write to %dr7 which tries to set IO breakpoints
> without %cr4.DE being set clobbers the IO state, rather than leaves it alone.
> 
> Instead, move the zeroing slightly later, which guarentees that the shadow
> gets written exactly once, on a successful update to %dr7.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Release-acked-by: Juergen Gross <jgross@suse.com>


Juergen

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-01 18:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-01 14:06 [PATCH for-4.11] x86/traps: Fix error handling of the pv %dr7 shadow state Andrew Cooper
2018-06-01 14:09 ` Andrew Cooper
2018-06-01 15:41 ` Jan Beulich
2018-06-01 18:53 ` Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.