[PATCH v2 02/11] xen: return proper type for guest access functions

Oleksii Kurochko posted 11 patches 3 hours ago
[PATCH v2 02/11] xen: return proper type for guest access functions
Posted by Oleksii Kurochko 3 hours ago
The copy_to_guest_phys_cb function pointer declaration was based on Arm
code. However, guest access functions use copy_guest(), which should
return an unsigned int as it returns either 0 or len which is unsigned int,
so it does not make sense to return unsigned long.

Update other functions that use copy_guest() to return unsigned int, to
match its return type.

Also update guest access functions for other architectures, as their
declarations/definitions are likely copied from the Arm implementation,
so update them as well to keep everything in sync.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in v2:
 - New patch.
---
 xen/arch/arm/guestcopy.c                  | 24 +++++++++++------------
 xen/arch/arm/include/asm/guest_access.h   | 18 ++++++++---------
 xen/arch/ppc/include/asm/guest_access.h   | 10 +++++-----
 xen/arch/riscv/include/asm/guest_access.h |  6 +++---
 xen/arch/riscv/stubs.c                    |  8 ++++----
 xen/include/xen/fdt-domain-build.h        |  8 ++++----
 6 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c
index fdb06422b8e9..11ad80320f4c 100644
--- a/xen/arch/arm/guestcopy.c
+++ b/xen/arch/arm/guestcopy.c
@@ -53,8 +53,8 @@ static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,
     return page;
 }
 
-static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
-                                copy_info_t info, unsigned int flags)
+static unsigned int copy_guest(void *buf, uint64_t addr, unsigned int len,
+                               copy_info_t info, unsigned int flags)
 {
     /* XXX needs to handle faults */
     unsigned int offset = addr & ~PAGE_MASK;
@@ -107,36 +107,36 @@ static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
     return 0;
 }
 
-unsigned long raw_copy_to_guest(void *to, const void *from, unsigned int len)
+unsigned int raw_copy_to_guest(void *to, const void *from, unsigned int len)
 {
     return copy_guest((void *)from, (vaddr_t)to, len,
                       GVA_INFO(current), COPY_to_guest | COPY_linear);
 }
 
-unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
-                                             unsigned int len)
+unsigned int raw_copy_to_guest_flush_dcache(void *to, const void *from,
+                                            unsigned int len)
 {
     return copy_guest((void *)from, (vaddr_t)to, len, GVA_INFO(current),
                       COPY_to_guest | COPY_flush_dcache | COPY_linear);
 }
 
-unsigned long raw_clear_guest(void *to, unsigned int len)
+unsigned int raw_clear_guest(void *to, unsigned int len)
 {
     return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(current),
                       COPY_to_guest | COPY_linear);
 }
 
-unsigned long raw_copy_from_guest(void *to, const void __user *from,
-                                  unsigned int len)
+unsigned int raw_copy_from_guest(void *to, const void __user *from,
+                                 unsigned int len)
 {
     return copy_guest(to, (vaddr_t)from, len, GVA_INFO(current),
                       COPY_from_guest | COPY_linear);
 }
 
-unsigned long copy_to_guest_phys_flush_dcache(struct domain *d,
-                                              paddr_t gpa,
-                                              void *buf,
-                                              unsigned int len)
+unsigned int copy_to_guest_phys_flush_dcache(struct domain *d,
+                                             paddr_t gpa,
+                                             void *buf,
+                                             unsigned int len)
 {
     return copy_guest(buf, gpa, len, GPA_INFO(d),
                       COPY_to_guest | COPY_ipa | COPY_flush_dcache);
diff --git a/xen/arch/arm/include/asm/guest_access.h b/xen/arch/arm/include/asm/guest_access.h
index 18c88b70d7ec..a1a4b1c36269 100644
--- a/xen/arch/arm/include/asm/guest_access.h
+++ b/xen/arch/arm/include/asm/guest_access.h
@@ -4,17 +4,17 @@
 #include <xen/errno.h>
 #include <xen/sched.h>
 
-unsigned long raw_copy_to_guest(void *to, const void *from, unsigned int len);
-unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
-                                             unsigned int len);
-unsigned long raw_copy_from_guest(void *to, const void *from, unsigned int len);
-unsigned long raw_clear_guest(void *to, unsigned int len);
+unsigned int raw_copy_to_guest(void *to, const void *from, unsigned int len);
+unsigned int raw_copy_to_guest_flush_dcache(void *to, const void *from,
+                                            unsigned int len);
+unsigned int raw_copy_from_guest(void *to, const void *from, unsigned int len);
+unsigned int raw_clear_guest(void *to, unsigned int len);
 
 /* Copy data to guest physical address, then clean the region. */
-unsigned long copy_to_guest_phys_flush_dcache(struct domain *d,
-                                              paddr_t gpa,
-                                              void *buf,
-                                              unsigned int len);
+unsigned int copy_to_guest_phys_flush_dcache(struct domain *d,
+                                             paddr_t gpa,
+                                             void *buf,
+                                             unsigned int len);
 
 int access_guest_memory_by_gpa(struct domain *d, paddr_t gpa, void *buf,
                                uint32_t size, bool is_write);
diff --git a/xen/arch/ppc/include/asm/guest_access.h b/xen/arch/ppc/include/asm/guest_access.h
index 654693191106..922848032604 100644
--- a/xen/arch/ppc/include/asm/guest_access.h
+++ b/xen/arch/ppc/include/asm/guest_access.h
@@ -6,34 +6,34 @@
 
 /* TODO */
 
-static inline unsigned long raw_copy_to_guest(
+static inline unsigned int raw_copy_to_guest(
     void *to,
     const void *from,
     unsigned int len)
 {
     BUG_ON("unimplemented");
 }
-static inline unsigned long raw_copy_to_guest_flush_dcache(
+static inline unsigned int raw_copy_to_guest_flush_dcache(
     void *to,
     const void *from,
     unsigned int len)
 {
     BUG_ON("unimplemented");
 }
-static inline unsigned long raw_copy_from_guest(
+static inline unsigned int raw_copy_from_guest(
     void *to,
     const void *from,
     unsigned int len)
 {
     BUG_ON("unimplemented");
 }
-static inline unsigned long raw_clear_guest(void *to, unsigned int len)
+static inline unsigned int raw_clear_guest(void *to, unsigned int len)
 {
     BUG_ON("unimplemented");
 }
 
 /* Copy data to guest physical address, then clean the region. */
-static inline unsigned long copy_to_guest_phys_flush_dcache(
+static inline unsigned int copy_to_guest_phys_flush_dcache(
     struct domain *d,
     paddr_t gpa,
     void *buf,
diff --git a/xen/arch/riscv/include/asm/guest_access.h b/xen/arch/riscv/include/asm/guest_access.h
index 7cd51fbbdead..3f4c68e4da20 100644
--- a/xen/arch/riscv/include/asm/guest_access.h
+++ b/xen/arch/riscv/include/asm/guest_access.h
@@ -2,9 +2,9 @@
 #ifndef ASM__RISCV__GUEST_ACCESS_H
 #define ASM__RISCV__GUEST_ACCESS_H
 
-unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len);
-unsigned long raw_copy_from_guest(void *to, const void *from, unsigned len);
-unsigned long raw_clear_guest(void *to, unsigned int len);
+unsigned int raw_copy_to_guest(void *to, const void *from, unsigned len);
+unsigned int raw_copy_from_guest(void *to, const void *from, unsigned len);
+unsigned int raw_clear_guest(void *to, unsigned int len);
 
 #define __raw_copy_to_guest raw_copy_to_guest
 #define __raw_copy_from_guest raw_copy_from_guest
diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c
index acbb5b9123ea..d1f78b7c59fa 100644
--- a/xen/arch/riscv/stubs.c
+++ b/xen/arch/riscv/stubs.c
@@ -201,13 +201,13 @@ int __init parse_arch_dom0_param(const char *s, const char *e)
 
 /* guestcopy.c */
 
-unsigned long raw_copy_to_guest(void *to, const void *from, unsigned int len)
+unsigned int raw_copy_to_guest(void *to, const void *from, unsigned int len)
 {
     BUG_ON("unimplemented");
 }
 
-unsigned long raw_copy_from_guest(void *to, const void __user *from,
-                                  unsigned int len)
+unsigned int raw_copy_from_guest(void *to, const void __user *from,
+                                 unsigned int len)
 {
     BUG_ON("unimplemented");
 }
@@ -266,7 +266,7 @@ void udelay(unsigned long usecs)
 
 /* guest_access.h */
 
-static inline unsigned long raw_clear_guest(void *to, unsigned int len)
+static inline unsigned int raw_clear_guest(void *to, unsigned int len)
 {
     BUG_ON("unimplemented");
 }
diff --git a/xen/include/xen/fdt-domain-build.h b/xen/include/xen/fdt-domain-build.h
index 886a85381651..194d69303f56 100644
--- a/xen/include/xen/fdt-domain-build.h
+++ b/xen/include/xen/fdt-domain-build.h
@@ -44,10 +44,10 @@ static inline int get_allocation_size(paddr_t size)
     return get_order_from_bytes(size + 1) - 1;
 }
 
-typedef unsigned long (*copy_to_guest_phys_cb)(struct domain *d,
-                                               paddr_t gpa,
-                                               void *buf,
-                                               unsigned int len);
+typedef unsigned int (*copy_to_guest_phys_cb)(struct domain *d,
+                                              paddr_t gpa,
+                                              void *buf,
+                                              unsigned int len);
 
 void initrd_load(struct kernel_info *kinfo,
                  copy_to_guest_phys_cb cb);
-- 
2.53.0