File 5b9784d2-x86-HVM-add-known_gla-helper.patch of Package xen.26348
References: bsc#1094508
# Commit 9f232721deaeb9f56eeffb555c4b7ecd62708667
# Date 2018-09-11 11:03:14 +0200
# Author Jan Beulich <jbeulich@suse.com>
# Committer Jan Beulich <jbeulich@suse.com>
x86/HVM: add known_gla() emulation helper
... as a central place to do respective checking for whether the
translation for the linear address is available as well as usable.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -752,6 +752,26 @@ static inline int hvmemul_linear_mmio_wr
pfec, hvmemul_ctxt, translate);
}
+static bool_t known_gla(unsigned long addr, unsigned int bytes, uint32_t pfec)
+{
+ const struct hvm_vcpu_io *vio = ¤t->arch.hvm_vcpu.hvm_io;
+
+ if ( pfec & PFEC_write_access )
+ {
+ if ( !vio->mmio_access.write_access )
+ return 0;
+ }
+ else if ( pfec & PFEC_insn_fetch )
+ {
+ if ( !vio->mmio_access.insn_fetch )
+ return 0;
+ }
+ else if ( !vio->mmio_access.read_access )
+ return 0;
+
+ return vio->mmio_gva == (addr & PAGE_MASK);
+}
+
static int __hvmemul_read(
enum x86_segment seg,
unsigned long offset,
@@ -760,10 +780,8 @@ static int __hvmemul_read(
enum hvm_access_type access_type,
struct hvm_emulate_ctxt *hvmemul_ctxt)
{
- struct vcpu *curr = current;
unsigned long addr, reps = 1;
uint32_t pfec = PFEC_page_present;
- struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
int rc;
if ( access_type == hvm_access_insn_fetch )
@@ -773,10 +791,7 @@ static int __hvmemul_read(
seg, offset, bytes, &reps, access_type, hvmemul_ctxt, &addr);
if ( rc != X86EMUL_OKAY || !bytes )
return rc;
- if ( ((access_type != hvm_access_insn_fetch
- ? vio->mmio_access.read_access
- : vio->mmio_access.insn_fetch)) &&
- (vio->mmio_gva == (addr & PAGE_MASK)) )
+ if ( known_gla(addr, bytes, pfec) )
return hvmemul_linear_mmio_read(addr, bytes, p_data, pfec, hvmemul_ctxt, 1);
if ( (seg != x86_seg_none) &&
@@ -880,10 +895,8 @@ static int hvmemul_write(
{
struct hvm_emulate_ctxt *hvmemul_ctxt =
container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
- struct vcpu *curr = current;
unsigned long addr, reps = 1;
uint32_t pfec = PFEC_page_present | PFEC_write_access;
- struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
int rc;
rc = hvmemul_virtual_to_linear(
@@ -891,8 +904,7 @@ static int hvmemul_write(
if ( rc != X86EMUL_OKAY || !bytes )
return rc;
- if ( vio->mmio_access.write_access &&
- (vio->mmio_gva == (addr & PAGE_MASK)) )
+ if ( known_gla(addr, bytes, pfec) )
return hvmemul_linear_mmio_write(addr, bytes, p_data, pfec, hvmemul_ctxt, 1);
if ( (seg != x86_seg_none) &&