xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: boris.ostrovsky@oracle.com,
	Roger Pau Monne <roger.pau@citrix.com>,
	konrad.wilk@oracle.com
Subject: [PATCH v5 5/9] x86/hvm: add vcpu parameter to guest memory copy function
Date: Thu, 19 Jan 2017 17:29:37 +0000	[thread overview]
Message-ID: <20170119172941.65642-6-roger.pau@citrix.com> (raw)
In-Reply-To: <20170119172941.65642-1-roger.pau@citrix.com>

Current __hvm_copy assumes that the destination memory belongs to the current
vcpu, but this is not always the case since for PVHv2 Dom0 build hvm copy
functions are used with current being the idle vcpu. Add a new vcpu parameter
to hvm copy in order to solve that. Note that only hvm_copy_to_guest_phys_vcpu
is introduced, because that's the only one at the moment that's required in
order to build a PVHv2 Dom0.

While there, also assert that the passed vcpu belongs to a HVM guest.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v4:
 - New in the series.
---
 xen/arch/x86/hvm/hvm.c            | 40 ++++++++++++++++++++++++---------------
 xen/include/asm-x86/hvm/support.h |  2 ++
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 41a44c9..600a04d 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3077,15 +3077,16 @@ void hvm_task_switch(
 #define HVMCOPY_linear     (1u<<2)
 static enum hvm_copy_result __hvm_copy(
     void *buf, paddr_t addr, int size, unsigned int flags, uint32_t pfec,
-    pagefault_info_t *pfinfo)
+    pagefault_info_t *pfinfo, struct vcpu *vcpu)
 {
-    struct vcpu *curr = current;
     unsigned long gfn;
     struct page_info *page;
     p2m_type_t p2mt;
     char *p;
     int count, todo = size;
 
+    ASSERT(has_hvm_container_vcpu(vcpu));
+
     /*
      * XXX Disable for 4.1.0: PV-on-HVM drivers will do grant-table ops
      * such as query_size. Grant-table code currently does copy_to/from_guest
@@ -3110,7 +3111,7 @@ static enum hvm_copy_result __hvm_copy(
 
         if ( flags & HVMCOPY_linear )
         {
-            gfn = paging_gva_to_gfn(curr, addr, &pfec);
+            gfn = paging_gva_to_gfn(vcpu, addr, &pfec);
             if ( gfn == gfn_x(INVALID_GFN) )
             {
                 if ( pfec & PFEC_page_paged )
@@ -3137,12 +3138,12 @@ static enum hvm_copy_result __hvm_copy(
          * - 32-bit WinXP (& older Windows) on AMD CPUs for LAPIC accesses,
          * - newer Windows (like Server 2012) for HPET accesses.
          */
-        if ( !nestedhvm_vcpu_in_guestmode(curr)
-             && is_hvm_vcpu(curr)
+        if ( !nestedhvm_vcpu_in_guestmode(vcpu)
+             && is_hvm_vcpu(vcpu)
              && hvm_mmio_internal(gpa) )
             return HVMCOPY_bad_gfn_to_mfn;
 
-        page = get_page_from_gfn(curr->domain, gfn, &p2mt, P2M_UNSHARE);
+        page = get_page_from_gfn(vcpu->domain, gfn, &p2mt, P2M_UNSHARE);
 
         if ( !page )
             return HVMCOPY_bad_gfn_to_mfn;
@@ -3150,7 +3151,7 @@ static enum hvm_copy_result __hvm_copy(
         if ( p2m_is_paging(p2mt) )
         {
             put_page(page);
-            p2m_mem_paging_populate(curr->domain, gfn);
+            p2m_mem_paging_populate(vcpu->domain, gfn);
             return HVMCOPY_gfn_paged_out;
         }
         if ( p2m_is_shared(p2mt) )
@@ -3172,9 +3173,9 @@ static enum hvm_copy_result __hvm_copy(
             {
                 static unsigned long lastpage;
                 if ( xchg(&lastpage, gfn) != gfn )
-                    gdprintk(XENLOG_DEBUG, "guest attempted write to read-only"
+                    printk(XENLOG_DEBUG, "%pv guest attempted write to read-only"
                              " memory page. gfn=%#lx, mfn=%#lx\n",
-                             gfn, page_to_mfn(page));
+                             vcpu->domain, gfn, page_to_mfn(page));
             }
             else
             {
@@ -3182,7 +3183,7 @@ static enum hvm_copy_result __hvm_copy(
                     memcpy(p, buf, count);
                 else
                     memset(p, 0, count);
-                paging_mark_dirty(curr->domain, _mfn(page_to_mfn(page)));
+                paging_mark_dirty(vcpu->domain, _mfn(page_to_mfn(page)));
             }
         }
         else
@@ -3202,18 +3203,25 @@ static enum hvm_copy_result __hvm_copy(
     return HVMCOPY_okay;
 }
 
+enum hvm_copy_result hvm_copy_to_guest_phys_vcpu(
+    paddr_t paddr, void *buf, size_t size, struct vcpu *vcpu)
+{
+    return __hvm_copy(buf, paddr, size,
+                      HVMCOPY_to_guest | HVMCOPY_phys, 0, NULL, vcpu);
+}
+
 enum hvm_copy_result hvm_copy_to_guest_phys(
     paddr_t paddr, void *buf, int size)
 {
     return __hvm_copy(buf, paddr, size,
-                      HVMCOPY_to_guest | HVMCOPY_phys, 0, NULL);
+                      HVMCOPY_to_guest | HVMCOPY_phys, 0, NULL, current);
 }
 
 enum hvm_copy_result hvm_copy_from_guest_phys(
     void *buf, paddr_t paddr, int size)
 {
     return __hvm_copy(buf, paddr, size,
-                      HVMCOPY_from_guest | HVMCOPY_phys, 0, NULL);
+                      HVMCOPY_from_guest | HVMCOPY_phys, 0, NULL, current);
 }
 
 enum hvm_copy_result hvm_copy_to_guest_linear(
@@ -3222,7 +3230,8 @@ enum hvm_copy_result hvm_copy_to_guest_linear(
 {
     return __hvm_copy(buf, addr, size,
                       HVMCOPY_to_guest | HVMCOPY_linear,
-                      PFEC_page_present | PFEC_write_access | pfec, pfinfo);
+                      PFEC_page_present | PFEC_write_access | pfec, pfinfo,
+                      current);
 }
 
 enum hvm_copy_result hvm_copy_from_guest_linear(
@@ -3231,7 +3240,7 @@ enum hvm_copy_result hvm_copy_from_guest_linear(
 {
     return __hvm_copy(buf, addr, size,
                       HVMCOPY_from_guest | HVMCOPY_linear,
-                      PFEC_page_present | pfec, pfinfo);
+                      PFEC_page_present | pfec, pfinfo, current);
 }
 
 enum hvm_copy_result hvm_fetch_from_guest_linear(
@@ -3240,7 +3249,8 @@ enum hvm_copy_result hvm_fetch_from_guest_linear(
 {
     return __hvm_copy(buf, addr, size,
                       HVMCOPY_from_guest | HVMCOPY_linear,
-                      PFEC_page_present | PFEC_insn_fetch | pfec, pfinfo);
+                      PFEC_page_present | PFEC_insn_fetch | pfec, pfinfo,
+                      current);
 }
 
 unsigned long copy_to_user_hvm(void *to, const void *from, unsigned int len)
diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/support.h
index ba5899c..1a34d35 100644
--- a/xen/include/asm-x86/hvm/support.h
+++ b/xen/include/asm-x86/hvm/support.h
@@ -71,6 +71,8 @@ enum hvm_copy_result hvm_copy_to_guest_phys(
     paddr_t paddr, void *buf, int size);
 enum hvm_copy_result hvm_copy_from_guest_phys(
     void *buf, paddr_t paddr, int size);
+enum hvm_copy_result hvm_copy_to_guest_phys_vcpu(
+    paddr_t paddr, void *buf, size_t size, struct vcpu *vcpu);
 
 /*
  * Copy to/from a guest linear address. @pfec should include PFEC_user_mode
-- 
2.10.1 (Apple Git-78)


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

  parent reply	other threads:[~2017-01-19 17:30 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 17:29 [PATCH v5 0/9] Initial PVHv2 Dom0 support Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 1/9] xen/x86: remove XENFEAT_hvm_pirqs for PVHv2 guests Roger Pau Monne
2017-01-20 18:41   ` Andrew Cooper
2017-01-23 12:28     ` Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 2/9] x86/iommu: add IOMMU entries for p2m_mmio_direct pages Roger Pau Monne
2017-01-20  6:41   ` Tian, Kevin
2017-01-20 10:28     ` Roger Pau Monne
2017-01-20 18:44   ` Andrew Cooper
2017-01-22  4:45     ` Tian, Kevin
2017-01-19 17:29 ` [PATCH v5 3/9] xen/x86: split Dom0 build into PV and PVHv2 Roger Pau Monne
2017-01-20 19:03   ` Andrew Cooper
2017-01-23 12:58     ` Roger Pau Monne
2017-01-23 12:59       ` Andrew Cooper
2017-01-20 19:13   ` Boris Ostrovsky
2017-01-20 19:27     ` Andrew Cooper
2017-01-26 11:43   ` Jan Beulich
2017-01-26 16:36     ` Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 4/9] xen/x86: populate PVHv2 Dom0 physical memory map Roger Pau Monne
2017-01-20 19:41   ` Andrew Cooper
2017-01-23 11:23     ` Jan Beulich
2017-01-23 14:11   ` Boris Ostrovsky
2017-01-23 14:43     ` Roger Pau Monne
2017-01-26 12:41   ` Jan Beulich
2017-01-27 11:14     ` Tim Deegan
2017-01-27 12:37       ` Roger Pau Monne
2017-01-27 12:51       ` Andrew Cooper
2017-01-27 13:20         ` Tim Deegan
2017-01-27 13:46           ` Andrew Cooper
2017-01-27 14:01             ` Tim Deegan
2017-01-27 14:35               ` Andrew Cooper
2017-01-27 19:43                 ` Tim Deegan
2017-01-30 10:43                   ` Jan Beulich
2017-01-30 11:06                     ` Andrew Cooper
2017-01-27 16:40           ` Jan Beulich
2017-01-27 18:06             ` Andrew Cooper
2017-02-03 13:57               ` Jan Beulich
2017-01-27 19:48             ` Tim Deegan
2017-02-02 15:38               ` Jan Beulich
2017-01-27 12:23     ` Roger Pau Monne
2017-01-27 15:11       ` Jan Beulich
2017-01-27 16:04         ` Roger Pau Monne
2017-01-27 16:29           ` Jan Beulich
2017-01-19 17:29 ` Roger Pau Monne [this message]
2017-01-20 19:45   ` [PATCH v5 5/9] x86/hvm: add vcpu parameter to guest memory copy function Andrew Cooper
2017-01-23 13:50     ` Roger Pau Monne
2017-01-26 12:51   ` Jan Beulich
2017-01-26 13:33   ` Jan Beulich
2017-01-27 14:55     ` Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 6/9] xen/x86: parse Dom0 kernel for PVHv2 Roger Pau Monne
2017-01-26 13:37   ` Jan Beulich
2017-01-27 17:22     ` Roger Pau Monne
2017-01-27 17:28       ` Roger Pau Monne
2017-01-30 10:20         ` Jan Beulich
2017-01-27 18:03       ` Roger Pau Monne
2017-01-30 10:14       ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 7/9] x86/PVHv2: fix dom0_max_vcpus so it's capped to 128 for PVHv2 Dom0 Roger Pau Monne
2017-01-19 17:32   ` Andrew Cooper
2017-01-26 13:39   ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 8/9] xen/x86: Setup PVHv2 Dom0 CPUs Roger Pau Monne
2017-01-26 13:46   ` Jan Beulich
2017-02-08 12:48     ` Roger Pau Monne
2017-02-08 13:02       ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 9/9] xen/x86: setup PVHv2 Dom0 ACPI tables Roger Pau Monne
2017-01-26 14:16   ` Jan Beulich
2017-02-08 15:10     ` Roger Pau Monne
2017-02-08 15:50       ` Jan Beulich
2017-02-08 15:58         ` Roger Pau Monne
2017-02-08 16:03           ` Jan Beulich

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=20170119172941.65642-6-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=konrad.wilk@oracle.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).