[XEN PATCH v2] x86/emul: Fix misaligned IO breakpoint behaviour in PV guests

Matthew Barnes posted 1 patch 3 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/4219d12fcd075635c8c2548c5d14471642af3038.1723045077.git.matthew.barnes@cloud.com
xen/arch/x86/pv/emul-priv-op.c | 2 ++
1 file changed, 2 insertions(+)
[XEN PATCH v2] x86/emul: Fix misaligned IO breakpoint behaviour in PV guests
Posted by Matthew Barnes 3 months, 2 weeks ago
When hardware breakpoints are configured on misaligned IO ports, the
hardware will mask the addresses based on the breakpoint width during
comparison.

For PV guests, misaligned IO breakpoints do not behave the same way, and
therefore yield different results.

This patch tweaks the emulation of IO breakpoints for PV guests such
that they reproduce the same behaviour as hardware.

Fixes: bec9e3205018 ("x86: emulate I/O port access breakpoints")
Signed-off-by: Matthew Barnes <matthew.barnes@cloud.com>
---
Changes in v2:
- Refactor breakpoint port masking to be more succinct
- Add 'Fixes' line to commit message
---
 xen/arch/x86/pv/emul-priv-op.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index f101510a1bab..aa11ecadaac0 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -346,6 +346,8 @@ static unsigned int check_guest_io_breakpoint(struct vcpu *v,
         case DR_LEN_8: width = 8; break;
         }
 
+        start &= ~(width - 1UL);
+
         if ( (start < (port + len)) && ((start + width) > port) )
             match |= 1u << i;
     }
-- 
2.34.1
Re: [XEN PATCH v2] x86/emul: Fix misaligned IO breakpoint behaviour in PV guests
Posted by Jan Beulich 3 months, 2 weeks ago
On 07.08.2024 17:39, Matthew Barnes wrote:
> When hardware breakpoints are configured on misaligned IO ports, the
> hardware will mask the addresses based on the breakpoint width during
> comparison.
> 
> For PV guests, misaligned IO breakpoints do not behave the same way, and
> therefore yield different results.
> 
> This patch tweaks the emulation of IO breakpoints for PV guests such
> that they reproduce the same behaviour as hardware.
> 
> Fixes: bec9e3205018 ("x86: emulate I/O port access breakpoints")
> Signed-off-by: Matthew Barnes <matthew.barnes@cloud.com>

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