File 5b9784ad-x86-HVM-drop-hvm_fetch_from_guest_linear.patch of Package xen.23721

References: bsc#1094508

# Commit d9067986c93b14371056bd25507ac9606e86c962
# Date 2018-09-11 11:02:37 +0200
# Author Jan Beulich <jbeulich@suse.com>
# Committer Jan Beulich <jbeulich@suse.com>
x86/HVM: drop hvm_fetch_from_guest_linear()

It can easily be expressed through hvm_copy_from_guest_linear(), and in
two cases this even simplifies callers.

Suggested-by: Paul Durrant <paul.durrant@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -766,6 +766,9 @@ static int __hvmemul_read(
     struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
     int rc;
 
+    if ( access_type == hvm_access_insn_fetch )
+        pfec |= PFEC_insn_fetch;
+
     rc = hvmemul_virtual_to_linear(
         seg, offset, bytes, &reps, access_type, hvmemul_ctxt, &addr);
     if ( rc != X86EMUL_OKAY || !bytes )
@@ -780,9 +783,7 @@ static int __hvmemul_read(
          (hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl == 3) )
         pfec |= PFEC_user_mode;
 
-    rc = ((access_type == hvm_access_insn_fetch) ?
-          hvm_fetch_from_guest_virt(p_data, addr, bytes, pfec) :
-          hvm_copy_from_guest_virt(p_data, addr, bytes, pfec));
+    rc = hvm_copy_from_guest_virt(p_data, addr, bytes, pfec);
 
     switch ( rc )
     {
@@ -1760,9 +1761,9 @@ static int _hvm_emulate_one(struct hvm_e
                                         hvm_access_insn_fetch,
                                         hvmemul_ctxt->ctxt.addr_size,
                                         &addr) &&
-             hvm_fetch_from_guest_virt_nofault(hvmemul_ctxt->insn_buf, addr,
-                                               sizeof(hvmemul_ctxt->insn_buf),
-                                               pfec) == HVMCOPY_okay) ?
+             hvm_copy_from_guest_virt_nofault(hvmemul_ctxt->insn_buf, addr,
+                                              sizeof(hvmemul_ctxt->insn_buf),
+                                              pfec | PFEC_insn_fetch) == HVMCOPY_okay) ?
             sizeof(hvmemul_ctxt->insn_buf) : 0;
     }
     else
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3317,14 +3317,6 @@ enum hvm_copy_result hvm_copy_from_guest
                       PFEC_page_present | pfec);
 }
 
-enum hvm_copy_result hvm_fetch_from_guest_virt(
-    void *buf, unsigned long vaddr, int size, uint32_t pfec)
-{
-    return __hvm_copy(buf, vaddr, size,
-                      HVMCOPY_from_guest | HVMCOPY_fault | HVMCOPY_virt,
-                      PFEC_page_present | PFEC_insn_fetch | pfec);
-}
-
 enum hvm_copy_result hvm_copy_to_guest_virt_nofault(
     unsigned long vaddr, void *buf, int size, uint32_t pfec)
 {
@@ -3341,14 +3333,6 @@ enum hvm_copy_result hvm_copy_from_guest
                       PFEC_page_present | pfec);
 }
 
-enum hvm_copy_result hvm_fetch_from_guest_virt_nofault(
-    void *buf, unsigned long vaddr, int size, uint32_t pfec)
-{
-    return __hvm_copy(buf, vaddr, size,
-                      HVMCOPY_from_guest | HVMCOPY_no_fault | HVMCOPY_virt,
-                      PFEC_page_present | PFEC_insn_fetch | pfec);
-}
-
 unsigned long copy_to_user_hvm(void *to, const void *from, unsigned int len)
 {
     int rc;
@@ -4066,8 +4050,8 @@ void hvm_ud_intercept(struct cpu_user_re
                                         (hvm_long_mode_enabled(cur) &&
                                          cs.attr.fields.l) ? 64 :
                                         cs.attr.fields.db ? 32 : 16, &addr) &&
-             (hvm_fetch_from_guest_virt_nofault(sig, addr, sizeof(sig),
-                                                0) == HVMCOPY_okay) &&
+             (hvm_copy_from_guest_virt_nofault(sig, addr, sizeof(sig),
+                                               PFEC_insn_fetch) == HVMCOPY_okay) &&
              (memcmp(sig, "\xf\xbxen", sizeof(sig)) == 0) )
         {
             regs->eip += sizeof(sig);
--- a/xen/arch/x86/hvm/svm/emulate.c
+++ b/xen/arch/x86/hvm/svm/emulate.c
@@ -133,9 +133,10 @@ static const u8 *const opc_bytes[INSTR_M
 static bool_t fetch(const struct vmcb_struct *vmcb, u8 *buf,
                     unsigned long addr, unsigned int len)
 {
-    uint32_t pfec = (vmcb_get_cpl(vmcb) == 3) ? PFEC_user_mode : 0;
+    uint32_t pfec = ((vmcb_get_cpl(vmcb) == 3) ? PFEC_user_mode : 0) |
+                    PFEC_insn_fetch;
 
-    switch ( hvm_fetch_from_guest_virt(buf, addr, len, pfec) )
+    switch ( hvm_copy_from_guest_virt(buf, addr, len, pfec) )
     {
     case HVMCOPY_okay:
         break;
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -186,10 +186,9 @@ hvm_read(enum x86_segment seg,
     if ( rc || !bytes )
         return rc;
 
-    if ( access_type == hvm_access_insn_fetch )
-        rc = hvm_fetch_from_guest_virt(p_data, addr, bytes, 0);
-    else
-        rc = hvm_copy_from_guest_virt(p_data, addr, bytes, 0);
+    rc = hvm_copy_from_guest_virt(p_data, addr, bytes,
+                                  (access_type == hvm_access_insn_fetch
+                                   ? PFEC_insn_fetch : 0));
 
     switch ( rc )
     {
@@ -415,8 +414,9 @@ const struct x86_emulate_ops *shadow_ini
         (!hvm_translate_linear_addr(
             x86_seg_cs, regs->eip, sizeof(sh_ctxt->insn_buf),
             hvm_access_insn_fetch, sh_ctxt, &addr) &&
-         !hvm_fetch_from_guest_virt_nofault(
-             sh_ctxt->insn_buf, addr, sizeof(sh_ctxt->insn_buf), 0))
+         !hvm_copy_from_guest_virt_nofault(
+             sh_ctxt->insn_buf, addr, sizeof(sh_ctxt->insn_buf),
+             PFEC_insn_fetch))
         ? sizeof(sh_ctxt->insn_buf) : 0;
 
     return &hvm_shadow_emulator_ops;
@@ -443,8 +443,9 @@ void shadow_continue_emulation(struct sh
                 (!hvm_translate_linear_addr(
                     x86_seg_cs, regs->eip, sizeof(sh_ctxt->insn_buf),
                     hvm_access_insn_fetch, sh_ctxt, &addr) &&
-                 !hvm_fetch_from_guest_virt_nofault(
-                     sh_ctxt->insn_buf, addr, sizeof(sh_ctxt->insn_buf), 0))
+                 !hvm_copy_from_guest_virt_nofault(
+                     sh_ctxt->insn_buf, addr, sizeof(sh_ctxt->insn_buf),
+                     PFEC_insn_fetch))
                 ? sizeof(sh_ctxt->insn_buf) : 0;
             sh_ctxt->insn_buf_eip = regs->eip;
         }
--- a/xen/include/asm-x86/hvm/support.h
+++ b/xen/include/asm-x86/hvm/support.h
@@ -93,8 +93,6 @@ enum hvm_copy_result hvm_copy_to_guest_v
     unsigned long vaddr, void *buf, int size, uint32_t pfec);
 enum hvm_copy_result hvm_copy_from_guest_virt(
     void *buf, unsigned long vaddr, int size, uint32_t pfec);
-enum hvm_copy_result hvm_fetch_from_guest_virt(
-    void *buf, unsigned long vaddr, int size, uint32_t pfec);
 
 /*
  * As above (copy to/from a guest virtual address), but no fault is generated
@@ -104,8 +102,6 @@ enum hvm_copy_result hvm_copy_to_guest_v
     unsigned long vaddr, void *buf, int size, uint32_t pfec);
 enum hvm_copy_result hvm_copy_from_guest_virt_nofault(
     void *buf, unsigned long vaddr, int size, uint32_t pfec);
-enum hvm_copy_result hvm_fetch_from_guest_virt_nofault(
-    void *buf, unsigned long vaddr, int size, uint32_t pfec);
 
 #define HVM_HCALL_completed  0 /* hypercall completed - no further action */
 #define HVM_HCALL_preempted  1 /* hypercall preempted - re-execute VMCALL */
openSUSE Build Service is sponsored by