xen/arm: guest_copy: Extend the prototype to pass the vCPU
authorJulien Grall <julien.grall@linaro.org>
Tue, 12 Dec 2017 19:02:01 +0000 (19:02 +0000)
committerStefano Stabellini <sstabellini@kernel.org>
Tue, 12 Dec 2017 19:58:10 +0000 (11:58 -0800)
Currently, guest_copy assumes the copy will only be done for the current
vCPU. copy_guest is meant to be vCPU agnostic, so extend the prototype
to pass the vCPU.

At the same time, encapsulate the vCPU in an union to allow extension
for copying from a guest domain (ipa case) in the future.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/arch/arm/guestcopy.c

index ff7d15380f0c4879be7dbaa70434ddef7cfaf532..7e92e27beb91f0782f5ec0a3fcbb417f07a8a1d0 100644 (file)
@@ -9,8 +9,18 @@
 #define COPY_from_guest     (0U << 1)
 #define COPY_to_guest       (1U << 1)
 
+typedef union
+{
+    struct
+    {
+        struct vcpu *v;
+    } gva;
+} copy_info_t;
+
+#define GVA_INFO(vcpu) ((copy_info_t) { .gva = { vcpu } })
+
 static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
-                                unsigned int flags)
+                                copy_info_t info, unsigned int flags)
 {
     /* XXX needs to handle faults */
     unsigned offset = addr & ~PAGE_MASK;
@@ -23,7 +33,7 @@ static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
         unsigned size = min(len, (unsigned)PAGE_SIZE - offset);
         struct page_info *page;
 
-        page = get_page_from_gva(current, addr,
+        page = get_page_from_gva(info.gva.v, addr,
                                  (flags & COPY_to_guest) ? GV2M_WRITE : GV2M_READ);
         if ( page == NULL )
             return len;
@@ -64,24 +74,27 @@ static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
 
 unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len)
 {
-    return copy_guest((void *)from, (vaddr_t)to, len, COPY_to_guest);
+    return copy_guest((void *)from, (vaddr_t)to, len,
+                      GVA_INFO(current), COPY_to_guest);
 }
 
 unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
                                              unsigned len)
 {
-    return copy_guest((void *)from, (vaddr_t)to, len,
+    return copy_guest((void *)from, (vaddr_t)to, len, GVA_INFO(current),
                       COPY_to_guest | COPY_flush_dcache);
 }
 
 unsigned long raw_clear_guest(void *to, unsigned len)
 {
-    return copy_guest(NULL, (vaddr_t)to, len, COPY_to_guest);
+    return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(current),
+                      COPY_to_guest);
 }
 
 unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len)
 {
-    return copy_guest(to, (vaddr_t)from, len, COPY_from_guest);
+    return copy_guest(to, (vaddr_t)from, len, GVA_INFO(current),
+                      COPY_from_guest);
 }
 
 /*