From: Euan Harris <euan.harris@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: andrew.cooper3@citrix.com, kevin.tian@intel.com,
Euan Harris <euan.harris@citrix.com>,
jun.nakajima@intel.com, jbeulich@suse.com
Subject: [PATCH 8/9] x86/hvm: Add hvm_copy_{to, from}_guest_virt() helpers
Date: Thu, 26 Oct 2017 18:03:18 +0100 [thread overview]
Message-ID: <1509037399-48926-9-git-send-email-euan.harris@citrix.com> (raw)
In-Reply-To: <1509037399-48926-1-git-send-email-euan.harris@citrix.com>
hvm_copy_{to,from}_guest_virt() copy data to and from a guest, performing
segmentatino and paging checks on the provided seg:offset virtual address.
Signed-off-by: Euan Harris <euan.harris@citrix.com>
---
xen/arch/x86/hvm/hvm.c | 57 +++++++++++++++++++++++++++++++++++++++
xen/include/asm-x86/hvm/support.h | 12 +++++++++
2 files changed, 69 insertions(+)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 205b4cb685..5d2bdd6b2b 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3312,6 +3312,63 @@ unsigned long copy_from_user_hvm(void *to, const void *from, unsigned len)
return rc ? len : 0; /* fake a copy_from_user() return code */
}
+static int _hvm_copy_guest_virt(
+ enum x86_segment seg, unsigned long offset, void *buf, unsigned int bytes,
+ uint32_t pfec, unsigned int flags)
+{
+ struct vcpu *curr = current;
+ struct segment_register sreg, cs;
+ enum hvm_translation_result res;
+ pagefault_info_t pfinfo;
+ unsigned long linear;
+
+ ASSERT(is_x86_user_segment(seg));
+
+ hvm_get_segment_register(curr, seg, &sreg);
+ hvm_get_segment_register(curr, x86_seg_cs, &cs);
+
+ if ( !hvm_virtual_to_linear_addr(
+ seg, &sreg, offset, bytes,
+ flags & HVMCOPY_to_guest ? hvm_access_write : hvm_access_read,
+ &cs, &linear) )
+ {
+ hvm_inject_hw_exception(
+ (seg == x86_seg_ss) ? TRAP_stack_error : TRAP_gp_fault, 0);
+ return X86EMUL_EXCEPTION;
+ }
+
+ if ( flags & HVMCOPY_to_guest )
+ res = hvm_copy_to_guest_linear(linear, buf, bytes, pfec, &pfinfo);
+ else
+ res = hvm_copy_from_guest_linear(buf, linear, bytes, pfec, &pfinfo);
+
+ if ( res == HVMTRANS_bad_linear_to_gfn )
+ {
+ hvm_inject_page_fault(pfinfo.ec, pfinfo.linear);
+ return X86EMUL_EXCEPTION;
+ }
+ else if ( res )
+ return X86EMUL_RETRY;
+
+ return X86EMUL_OKAY;
+}
+
+int hvm_copy_to_guest_virt(
+ enum x86_segment seg, unsigned long offset, void *buf, unsigned int bytes,
+ uint32_t pfec)
+{
+ return _hvm_copy_guest_virt(seg, offset, buf, bytes, pfec,
+ HVMCOPY_to_guest);
+}
+
+int hvm_copy_from_guest_virt(
+ void *buf, enum x86_segment seg, unsigned long offset, unsigned int bytes,
+ uint32_t pfec)
+{
+ return _hvm_copy_guest_virt(seg, offset, buf, bytes, pfec,
+ HVMCOPY_from_guest);
+}
+
bool hvm_check_cpuid_faulting(struct vcpu *v)
{
const struct msr_vcpu_policy *vp = v->arch.msr;
diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/support.h
index d784fc1856..9af2ae77b7 100644
--- a/xen/include/asm-x86/hvm/support.h
+++ b/xen/include/asm-x86/hvm/support.h
@@ -115,6 +115,18 @@ enum hvm_translation_result hvm_translate_get_page(
pagefault_info_t *pfinfo, struct page_info **page_p,
gfn_t *gfn_p, p2m_type_t *p2mt_p);
+/*
+ * Copy data to and from a guest, performing segmentation and paging checks
+ * on the provided seg:offset virtual address.
+ * Returns X86EMUL_* and raises exceptions with the current vcpu.
+ */
+int hvm_copy_to_guest_virt(
+ enum x86_segment seg, unsigned long offset, void *buf, unsigned int bytes,
+ uint32_t pfec);
+int hvm_copy_from_guest_virt(
+ void *buf, enum x86_segment seg, unsigned long offset, unsigned int bytes,
+ uint32_t pfec);
+
#define HVM_HCALL_completed 0 /* hypercall completed - no further action */
#define HVM_HCALL_preempted 1 /* hypercall preempted - re-execute VMCALL */
int hvm_hypercall(struct cpu_user_regs *regs);
--
2.13.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-10-26 17:03 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-26 17:03 [PATCH 0/9] x86/vvmx: Read instruction operands correctly on VM exit Euan Harris
2017-10-26 17:03 ` [PATCH 1/9] x86/vvmx: Remove enum vmx_regs_enc Euan Harris
2017-10-26 17:03 ` [PATCH 2/9] x86/vvmx: Unify operands in struct vmx_inst_decoded Euan Harris
2017-10-26 17:03 ` [PATCH 3/9] x86/vvmx: Extract operand reading logic into operand_read() Euan Harris
2017-11-27 17:01 ` Jan Beulich
2017-11-27 18:08 ` Andrew Cooper
2017-11-28 8:40 ` Jan Beulich
2017-11-28 8:14 ` Jan Beulich
2017-10-26 17:03 ` [PATCH 4/9] x86/vvmx: Remove unnecessary VMX operand reads Euan Harris
2017-11-02 7:07 ` Tian, Kevin
2017-11-27 17:03 ` Jan Beulich
2017-10-26 17:03 ` [PATCH 5/9] x86/vvmx: Replace direct calls to reg_read() with operand_read() Euan Harris
2017-10-26 17:03 ` [PATCH 6/9] x86/vvmx: Remove operand reading from decode_vmx_inst() Euan Harris
2017-10-26 17:03 ` [PATCH 7/9] x86/vvmx: Use correct sizes when reading operands Euan Harris
2017-11-28 8:32 ` Jan Beulich
2017-12-01 18:45 ` Andrew Cooper
2017-12-04 8:55 ` Jan Beulich
2017-10-26 17:03 ` Euan Harris [this message]
2017-11-28 8:38 ` [PATCH 8/9] x86/hvm: Add hvm_copy_{to, from}_guest_virt() helpers Jan Beulich
2017-10-26 17:03 ` [PATCH 9/9] x86/vvmx: Use hvm_copy_{to, from}_guest_virt() to read operands Euan Harris
2017-11-28 8:49 ` Jan Beulich
2017-10-26 17:59 ` [PATCH 0/9] x86/vvmx: Read instruction operands correctly on VM exit Andrew Cooper
2017-11-02 7:23 ` Tian, Kevin
2017-11-02 18:39 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1509037399-48926-9-git-send-email-euan.harris@citrix.com \
--to=euan.harris@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).