xen: Consolidate asm-*/guest_access.h in xen/guest_access.h
v2 cover xen: Consolidate asm-*/guest_access.h in xen/guest_access.h
From: Julien Grall <[email protected]>
Hi all,
A lot of the helpers implemented in asm-*/guest_access.h are implemented the same way. This series aims to avoid the duplication and implement them only once in xen/guest_access.h.
Cheers,
Julien Grall (7):
xen/guest_access: Add emacs magics
xen/arm: kernel: Re-order the includes
xen/arm: decode: Re-order the includes
xen/arm: guestcopy: Re-order the includes
xen: include xen/guest_access.h rather than asm/guest_access.h xen/guest_access: Consolidate guest access helpers in
xen/guest_access.h
xen/guest_access: Fix coding style in xen/guest_access.h
xen/arch/arm/decode.c | 7 +- xen/arch/arm/domain.c | 2 +- xen/arch/arm/guest_walk.c | 3 +- xen/arch/arm/guestcopy.c | 5 +- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/vgic-v3-its.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/common/libelf/libelf-loader.c | 2 +- xen/include/asm-arm/guest_access.h | 115 ----------------------- xen/include/asm-x86/guest_access.h | 116 ++---------------------- xen/include/xen/guest_access.h | 131 +++++++++++++++++++++++++++ xen/lib/x86/private.h | 2 +- 14 files changed, 161 insertions(+), 242 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/6 xen/arm: kernel: Re-order the includes
From: Julien Grall <[email protected]>
We usually have xen/ includes first and then asm/. They are also ordered alphabetically among themselves.
--- xen/arch/arm/kernel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/arm/kernel.c +5 -5
@@ -3,20 +3,20 @@* * Copyright (C) 2011 Citrix Systems, Inc. */ +#include <xen/domain_page.h> #include <xen/errno.h> +#include <xen/gunzip.h> #include <xen/init.h> #include <xen/lib.h> +#include <xen/libfdt/libfdt.h> #include <xen/mm.h> -#include <xen/domain_page.h> #include <xen/sched.h> -#include <asm/byteorder.h> -#include <asm/setup.h> -#include <xen/libfdt/libfdt.h> -#include <xen/gunzip.h> #include <xen/vmap.h> +#include <asm/byteorder.h> #include <asm/guest_access.h> #include <asm/kernel.h> +#include <asm/setup.h> #define UIMAGE_MAGIC 0x27051956#define UIMAGE_NMLEN 32
Signature · 1 line
2.17.1
PATCH v2 2/6 xen/arm: decode: Re-order the includes
In reply to Julien GrallFrom: Julien Grall <[email protected]>
We usually have xen/ includes first and then asm/. They are also ordered alphabetically among themselves.
--- xen/arch/arm/decode.c | 5 +++-- xen/arch/arm/kernel.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/arm/decode.c +3 -2
@@ -17,11 +17,12 @@* GNU General Public License for more details. */ -#include <xen/types.h> +#include <xen/lib.h> #include <xen/sched.h> +#include <xen/types.h> +#include <asm/current.h> #include <asm/guest_access.h> -#include <xen/lib.h> #include "decode.h"
xen/arch/arm/kernel.c +1 -1
@@ -5,6 +5,7 @@*/ #include <xen/domain_page.h> #include <xen/errno.h> +#include <xen/guest_access.h> #include <xen/gunzip.h> #include <xen/init.h> #include <xen/lib.h>
@@ -14,7 +15,6 @@#include <xen/vmap.h> #include <asm/byteorder.h> -#include <asm/guest_access.h> #include <asm/kernel.h> #include <asm/setup.h>
Signature · 1 line
2.17.1
PATCH v2 3/6 xen/arm: guestcopy: Re-order the includes
In reply to Julien GrallFrom: Julien Grall <[email protected]>
We usually have xen/ includes first and then asm/. They are also ordered alphabetically among themselves.
--- xen/arch/arm/guestcopy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/guestcopy.c +2 -1
@@ -1,7 +1,8 @@ -#include <xen/lib.h> #include <xen/domain_page.h> +#include <xen/lib.h> #include <xen/mm.h> #include <xen/sched.h> +#include <asm/current.h> #include <asm/guest_access.h>
Signature · 1 line
2.17.1
PATCH v2 4/6 xen: include xen/guest_access.h rather than asm/guest_access.h
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Only a few places are actually including asm/guest_access.h. While this is fine today, a follow-up patch will want to move most of the helpers from asm/guest_access.h to xen/guest_access.h.
To prepare the move, everyone should include xen/guest_access.h rather than asm/guest_access.h.
Interestingly, asm-arm/guest_access.h includes xen/guest_access.h. The inclusion is now removed as no-one but the latter should include the former.
---
Changes in v2:
- Remove some changes that weren't meant to be here.
--- xen/arch/arm/decode.c | 2 +- xen/arch/arm/domain.c | 2 +- xen/arch/arm/guest_walk.c | 3 ++- xen/arch/arm/guestcopy.c | 2 +- xen/arch/arm/vgic-v3-its.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/common/libelf/libelf-loader.c | 2 +- xen/include/asm-arm/guest_access.h | 1 - xen/lib/x86/private.h | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-)
xen/arch/arm/decode.c +1 -1
@@ -17,12 +17,12 @@* GNU General Public License for more details. */ +#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/types.h> #include <asm/current.h> -#include <asm/guest_access.h> #include "decode.h"
xen/arch/arm/domain.c +1 -1
@@ -12,6 +12,7 @@#include <xen/bitops.h> #include <xen/errno.h> #include <xen/grant_table.h> +#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/init.h> #include <xen/lib.h>
@@ -26,7 +27,6 @@#include <asm/current.h> #include <asm/event.h> #include <asm/gic.h> -#include <asm/guest_access.h> #include <asm/guest_atomics.h> #include <asm/irq.h> #include <asm/p2m.h>
xen/arch/arm/guest_walk.c +2 -1
@@ -16,8 +16,9 @@*/ #include <xen/domain_page.h> +#include <xen/guest_access.h> #include <xen/sched.h> -#include <asm/guest_access.h> +#include <asm/guest_walk.h> #include <asm/short-desc.h>
xen/arch/arm/guestcopy.c +1 -1
@@ -1,10 +1,10 @@#include <xen/domain_page.h> +#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/mm.h> #include <xen/sched.h> #include <asm/current.h> -#include <asm/guest_access.h> #define COPY_flush_dcache (1U << 0)#define COPY_from_guest (0U << 1)
xen/arch/arm/vgic-v3-its.c +1 -1
@@ -32,6 +32,7 @@#include <xen/bitops.h> #include <xen/config.h> #include <xen/domain_page.h> +#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/init.h> #include <xen/softirq.h>
@@ -39,7 +40,6 @@#include <xen/sched.h> #include <xen/sizes.h> #include <asm/current.h> -#include <asm/guest_access.h> #include <asm/mmio.h> #include <asm/gic_v3_defs.h> #include <asm/gic_v3_its.h>
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -16,6 +16,7 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/guest_access.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/trace.h>
@@ -34,7 +35,6 @@#include <asm/cpufeature.h> #include <asm/processor.h> #include <asm/amd.h> -#include <asm/guest_access.h> #include <asm/debugreg.h> #include <asm/msr.h> #include <asm/i387.h>
xen/arch/x86/hvm/viridian/viridian.c +1 -1
@@ -5,12 +5,12 @@* Hypervisor Top Level Functional Specification for more information. */ +#include <xen/guest_access.h> #include <xen/sched.h> #include <xen/version.h> #include <xen/hypercall.h> #include <xen/domain_page.h> #include <xen/param.h> -#include <asm/guest_access.h> #include <asm/guest/hyperv-tlfs.h> #include <asm/paging.h> #include <asm/p2m.h>
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -15,6 +15,7 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/guest_access.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/param.h>
@@ -31,7 +32,6 @@#include <asm/regs.h> #include <asm/cpufeature.h> #include <asm/processor.h> -#include <asm/guest_access.h> #include <asm/debugreg.h> #include <asm/msr.h> #include <asm/p2m.h>
xen/common/libelf/libelf-loader.c +1 -1
@@ -16,7 +16,7 @@*/ #ifdef __XEN__ -#include <asm/guest_access.h> +#include <xen/guest_access.h> #endif #include "libelf-private.h"
xen/include/asm-arm/guest_access.h +0 -1
@@ -1,7 +1,6 @@#ifndef __ASM_ARM_GUEST_ACCESS_H__#define __ASM_ARM_GUEST_ACCESS_H__ -#include <xen/guest_access.h> #include <xen/errno.h> #include <xen/sched.h>
xen/lib/x86/private.h +1 -1
@@ -4,12 +4,12 @@#ifdef __XEN__#include <xen/bitops.h> +#include <xen/guest_access.h> #include <xen/kernel.h> #include <xen/lib.h> #include <xen/nospec.h> #include <xen/types.h> -#include <asm/guest_access.h> #include <asm/msr-index.h> #define copy_to_buffer_offset copy_to_guest_offset
Signature · 1 line
2.17.1
PATCH v2 1/7 xen/guest_access: Add emacs magics
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Add emacs magics for xen/guest_access.h andasm-x86/guest_access.h.
---
Changes in v2:
- Remove the word "missing"
--- xen/include/asm-x86/guest_access.h | 8 ++++++++ xen/include/xen/guest_access.h | 8 ++++++++ 2 files changed, 16 insertions(+)
xen/include/asm-x86/guest_access.h +8 -0
@@ -160,3 +160,11 @@ })#endif /* __ASM_X86_GUEST_ACCESS_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/xen/guest_access.h +8 -0
@@ -33,3 +33,11 @@ char *safe_copy_string_from_guest(XEN_GUEST_HANDLE(char) u_buf, size_t size, size_t max_size);#endif /* __XEN_GUEST_ACCESS_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.17.1
PATCH v2 2/7 xen/arm: kernel: Re-order the includes
In reply to Julien GrallFrom: Julien Grall <[email protected]>
We usually have xen/ includes first and then asm/. They are also ordered alphabetically among themselves.
--- xen/arch/arm/kernel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/arm/kernel.c +5 -5
@@ -3,20 +3,20 @@* * Copyright (C) 2011 Citrix Systems, Inc. */ +#include <xen/domain_page.h> #include <xen/errno.h> +#include <xen/gunzip.h> #include <xen/init.h> #include <xen/lib.h> +#include <xen/libfdt/libfdt.h> #include <xen/mm.h> -#include <xen/domain_page.h> #include <xen/sched.h> -#include <asm/byteorder.h> -#include <asm/setup.h> -#include <xen/libfdt/libfdt.h> -#include <xen/gunzip.h> #include <xen/vmap.h> +#include <asm/byteorder.h> #include <asm/guest_access.h> #include <asm/kernel.h> +#include <asm/setup.h> #define UIMAGE_MAGIC 0x27051956#define UIMAGE_NMLEN 32
Signature · 1 line
2.17.1
PATCH v2 3/7 xen/arm: decode: Re-order the includes
In reply to Julien GrallFrom: Julien Grall <[email protected]>
We usually have xen/ includes first and then asm/. They are also ordered alphabetically among themselves.
--- xen/arch/arm/decode.c | 5 +++-- xen/arch/arm/kernel.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/arm/decode.c +3 -2
@@ -17,11 +17,12 @@* GNU General Public License for more details. */ -#include <xen/types.h> +#include <xen/lib.h> #include <xen/sched.h> +#include <xen/types.h> +#include <asm/current.h> #include <asm/guest_access.h> -#include <xen/lib.h> #include "decode.h"
xen/arch/arm/kernel.c +1 -1
@@ -5,6 +5,7 @@*/ #include <xen/domain_page.h> #include <xen/errno.h> +#include <xen/guest_access.h> #include <xen/gunzip.h> #include <xen/init.h> #include <xen/lib.h>
@@ -14,7 +15,6 @@#include <xen/vmap.h> #include <asm/byteorder.h> -#include <asm/guest_access.h> #include <asm/kernel.h> #include <asm/setup.h>
Signature · 1 line
2.17.1
PATCH v2 4/7 xen/arm: guestcopy: Re-order the includes
In reply to Julien GrallFrom: Julien Grall <[email protected]>
We usually have xen/ includes first and then asm/. They are also ordered alphabetically among themselves.
--- xen/arch/arm/guestcopy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/guestcopy.c +2 -1
@@ -1,7 +1,8 @@ -#include <xen/lib.h> #include <xen/domain_page.h> +#include <xen/lib.h> #include <xen/mm.h> #include <xen/sched.h> +#include <asm/current.h> #include <asm/guest_access.h>
Signature · 1 line
2.17.1
PATCH v2 5/6 xen/guest_access: Consolidate guest access helpers in xen/guest_access.h
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Most of the helpers to access guest memory are implemented the same way on Arm and x86. The only differences are:
- guest_handle_{from, to}_param(): while on x86 XEN_GUEST_HANDLE() and XEN_GUEST_HANDLE_PARAM() are the same, they are not on Arm. It is still fine to use the Arm implementation on x86.
- __clear_guest_offset(): Interestingly the prototype does not match between the x86 and Arm. However, the Arm one is bogus. So the x86 implementation can be used.
- guest_handle{,_subrange}_okay(): They are validly differing because Arm is only supporting auto-translated guest and therefore handles are always valid.
In the past, the ia64 and ppc64 port use a different model to access guest parameter. They have been long gone now.
Given Xen currently only support 2 archictures, it is too soon to have a directory asm-generic as it is not possible to differentiate it with the existing directory xen/. If/When there is a 3rd port, we can decide to create the new directory if that new port decide to use a different way to access guest parameter.
For now, consolidate it in xen/guest_access.h.
While it would be possible to adjust the coding style at the same, this is left for a follow-up patch so 'diff' can be used to check the consolidation was done correctly.
---
Changes in v2:
- Expand the commit message explaining why asm-generic is not created.
--- xen/include/asm-arm/guest_access.h | 114 --------------------------- xen/include/asm-x86/guest_access.h | 108 -------------------------- xen/include/xen/guest_access.h | 119 +++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 222 deletions(-)
xen/include/asm-arm/guest_access.h +0 -114
@@ -23,88 +23,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,#define __raw_copy_from_guest raw_copy_from_guest#define __raw_clear_guest raw_clear_guest -/* Remainder copied from x86 -- could be common? */ - -/* Is the guest handle a NULL reference? */ -#define guest_handle_is_null (hnd) ((hnd).p == NULL) - -/* Offset the given guest handle into the array it refers to. */ -#define guest_handle_add_offset (hnd, nr) ((hnd).p += (nr)) -#define guest_handle_subtract_offset (hnd, nr) ((hnd).p -= (nr)) - -/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM) -* to the specified type of XEN_GUEST_HANDLE_PARAM. */ -#define guest_handle_cast (hnd, type) ({ \ - type *_x = (hnd).p; \ - (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ -}) - -/* Convert a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */ -#define guest_handle_to_param (hnd, type) ({ \ - typeof((hnd).p) _x = (hnd).p; \ - XEN_GUEST_HANDLE_PARAM(type) _y = { _x }; \ -/* type checking: make sure that the pointers inside \ -* XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of \ -* the same type, then return hnd */ \ - (void )(&_x == &_y.p); \ - _y; \ -}) - -#define guest_handle_for_field (hnd, type, fld) \ - ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld }) - -#define guest_handle_from_ptr (ptr, type) \ - ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr }) -#define const_guest_handle_from_ptr (ptr, type) \ - ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr }) - -/* -* Copy an array of objects to guest context via a guest handle, -* specifying an offset into the guest array. -*/ -#define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(*(ptr)) *_s = (ptr); \ - char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ - /* Check that the handle is not for a const type */ \ - void *__maybe_unused _t = (hnd).p; \ - (void)((hnd).p == _s); \ - raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr)); \ -}) - -/* -* Clear an array of objects in guest context via a guest handle, -* specifying an offset into the guest array. -*/ -#define clear_guest_offset (hnd, off, nr) ({ \ - void *_d = (hnd).p; \ - raw_clear_guest(_d+(off), nr); \ -}) - -/* -* Copy an array of objects from guest context via a guest handle, -* specifying an offset into the guest array. -*/ -#define copy_from_guest_offset (ptr, hnd, off, nr) ({ \ - const typeof(*(ptr)) *_s = (hnd).p; \ - typeof(*(ptr)) *_d = (ptr); \ - raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\ -}) - -/* Copy sub-field of a structure to guest context via a guest handle. */ -#define copy_field_to_guest (hnd, ptr, field) ({ \ - const typeof(&(ptr)->field) _s = &(ptr)->field; \ - void *_d = &(hnd).p->field; \ - (void)(&(hnd).p->field == _s); \ - raw_copy_to_guest(_d, _s, sizeof(*_s)); \ -}) - -/* Copy sub-field of a structure from guest context via a guest handle. */ -#define copy_field_from_guest (ptr, hnd, field) ({ \ - const typeof(&(ptr)->field) _s = &(hnd).p->field; \ - typeof(&(ptr)->field) _d = &(ptr)->field; \ - raw_copy_from_guest(_d, _s, sizeof(*_d)); \ -}) -/* * Pre-validate a guest handle. * Allows use of faster __copy_* functions.
@@ -113,38 +31,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,#define guest_handle_okay (hnd, nr) (1)#define guest_handle_subrange_okay (hnd, first, last) (1) -#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(*(ptr)) *_s = (ptr); \ - char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ - /* Check that the handle is not for a const type */ \ - void *__maybe_unused _t = (hnd).p; \ - (void)((hnd).p == _s); \ - __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\ -}) - -#define __clear_guest_offset (hnd, off, ptr, nr) ({ \ - __raw_clear_guest(_d+(off), nr); \ -}) - -#define __copy_from_guest_offset (ptr, hnd, off, nr) ({ \ - const typeof(*(ptr)) *_s = (hnd).p; \ - typeof(*(ptr)) *_d = (ptr); \ - __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\ -}) - -#define __copy_field_to_guest (hnd, ptr, field) ({ \ - const typeof(&(ptr)->field) _s = &(ptr)->field; \ - void *_d = &(hnd).p->field; \ - (void)(&(hnd).p->field == _s); \ - __raw_copy_to_guest(_d, _s, sizeof(*_s)); \ -}) - -#define __copy_field_from_guest (ptr, hnd, field) ({ \ - const typeof(&(ptr)->field) _s = &(hnd).p->field; \ - typeof(&(ptr)->field) _d = &(ptr)->field; \ - __raw_copy_from_guest(_d, _s, sizeof(*_d)); \ -}) -#endif /* __ASM_ARM_GUEST_ACCESS_H__ */ /* * Local variables:
xen/include/asm-x86/guest_access.h +0 -108
120 lines not on this page · raw message
xen/include/xen/guest_access.h +119 -0
131 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 6/6 xen/guest_access: Fix coding style in xen/guest_access.h
In reply to Julien GrallFrom: Julien Grall <[email protected]>
* Add space before and after operator
* Align \
* Format comments
No functional changes expected.
--- xen/include/xen/guest_access.h | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-)
xen/include/xen/guest_access.h +20 -16
@@ -18,20 +18,24 @@#define guest_handle_add_offset (hnd, nr) ((hnd).p += (nr))#define guest_handle_subtract_offset (hnd, nr) ((hnd).p -= (nr)) -/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM) -* to the specified type of XEN_GUEST_HANDLE_PARAM. */ +/* +* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM) +* to the specified type of XEN_GUEST_HANDLE_PARAM. +*/ #define guest_handle_cast (hnd, type) ({ \ type *_x = (hnd).p; \ - (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ + (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ })/* Cast a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */ #define guest_handle_to_param (hnd, type) ({ \ typeof((hnd).p) _x = (hnd).p; \ XEN_GUEST_HANDLE_PARAM(type) _y = { _x }; \ -/* type checking: make sure that the pointers inside \ +/* \ +* type checking: make sure that the pointers inside \ * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of \ -* the same type, then return hnd */ \ +* the same type, then return hnd. \ +*/ \ (void )(&_x == &_y.p); \ _y; \ })
@@ -106,13 +110,13 @@* guest_handle_subrange_okay(). */ -#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(*(ptr)) *_s = (ptr); \ - char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ - /* Check that the handle is not for a const type */ \ - void *__maybe_unused _t = (hnd).p; \ - (void)((hnd).p == _s); \ - __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\ +#define __copy_to_guest_offset (hnd, off, ptr, nr) ({ \ + const typeof(*(ptr)) *_s = (ptr); \ + char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ +/* Check that the handle is not for a const type */ \ + void *__maybe_unused _t = (hnd).p; \ + (void )((hnd).p == _s); \ + __raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr));\ })#define __clear_guest_offset (hnd, off, nr) ({ \
@@ -120,10 +124,10 @@__raw_clear_guest (_d + (off), nr); \ }) -#define __copy_from_guest_offset (ptr, hnd, off, nr) ({ \ - const typeof(*(ptr)) *_s = (hnd).p; \ - typeof(*(ptr)) *_d = (ptr); \ - __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\ +#define __copy_from_guest_offset (ptr, hnd, off, nr) ({ \ + const typeof(*(ptr)) *_s = (hnd).p; \ + typeof(*(ptr)) *_d = (ptr); \ + __raw_copy_from_guest(_d, _s + (off), sizeof (*_d) * (nr)); \ })#define __copy_field_to_guest (hnd, ptr, field) ({ \
Signature · 1 line
2.17.1
PATCH v2 5/7 xen: include xen/guest_access.h rather than asm/guest_access.h
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Only a few places are actually including asm/guest_access.h. While this is fine today, a follow-up patch will want to move most of the helpers from asm/guest_access.h to xen/guest_access.h.
To prepare the move, everyone should include xen/guest_access.h rather than asm/guest_access.h.
Interestingly, asm-arm/guest_access.h includes xen/guest_access.h. The inclusion is now removed as no-one but the latter should include the former.
---
Changes in v2:
- Remove some changes that weren't meant to be here.
--- xen/arch/arm/decode.c | 2 +- xen/arch/arm/domain.c | 2 +- xen/arch/arm/guest_walk.c | 3 ++- xen/arch/arm/guestcopy.c | 2 +- xen/arch/arm/vgic-v3-its.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/common/libelf/libelf-loader.c | 2 +- xen/include/asm-arm/guest_access.h | 1 - xen/lib/x86/private.h | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-)
xen/arch/arm/decode.c +1 -1
@@ -17,12 +17,12 @@* GNU General Public License for more details. */ +#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/types.h> #include <asm/current.h> -#include <asm/guest_access.h> #include "decode.h"
xen/arch/arm/domain.c +1 -1
@@ -12,6 +12,7 @@#include <xen/bitops.h> #include <xen/errno.h> #include <xen/grant_table.h> +#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/init.h> #include <xen/lib.h>
@@ -26,7 +27,6 @@#include <asm/current.h> #include <asm/event.h> #include <asm/gic.h> -#include <asm/guest_access.h> #include <asm/guest_atomics.h> #include <asm/irq.h> #include <asm/p2m.h>
xen/arch/arm/guest_walk.c +2 -1
@@ -16,8 +16,9 @@*/ #include <xen/domain_page.h> +#include <xen/guest_access.h> #include <xen/sched.h> -#include <asm/guest_access.h> +#include <asm/guest_walk.h> #include <asm/short-desc.h>
xen/arch/arm/guestcopy.c +1 -1
@@ -1,10 +1,10 @@#include <xen/domain_page.h> +#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/mm.h> #include <xen/sched.h> #include <asm/current.h> -#include <asm/guest_access.h> #define COPY_flush_dcache (1U << 0)#define COPY_from_guest (0U << 1)
xen/arch/arm/vgic-v3-its.c +1 -1
@@ -32,6 +32,7 @@#include <xen/bitops.h> #include <xen/config.h> #include <xen/domain_page.h> +#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/init.h> #include <xen/softirq.h>
@@ -39,7 +40,6 @@#include <xen/sched.h> #include <xen/sizes.h> #include <asm/current.h> -#include <asm/guest_access.h> #include <asm/mmio.h> #include <asm/gic_v3_defs.h> #include <asm/gic_v3_its.h>
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -16,6 +16,7 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/guest_access.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/trace.h>
@@ -34,7 +35,6 @@#include <asm/cpufeature.h> #include <asm/processor.h> #include <asm/amd.h> -#include <asm/guest_access.h> #include <asm/debugreg.h> #include <asm/msr.h> #include <asm/i387.h>
xen/arch/x86/hvm/viridian/viridian.c +1 -1
@@ -5,12 +5,12 @@* Hypervisor Top Level Functional Specification for more information. */ +#include <xen/guest_access.h> #include <xen/sched.h> #include <xen/version.h> #include <xen/hypercall.h> #include <xen/domain_page.h> #include <xen/param.h> -#include <asm/guest_access.h> #include <asm/guest/hyperv-tlfs.h> #include <asm/paging.h> #include <asm/p2m.h>
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -15,6 +15,7 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/guest_access.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/param.h>
@@ -31,7 +32,6 @@#include <asm/regs.h> #include <asm/cpufeature.h> #include <asm/processor.h> -#include <asm/guest_access.h> #include <asm/debugreg.h> #include <asm/msr.h> #include <asm/p2m.h>
xen/common/libelf/libelf-loader.c +1 -1
@@ -16,7 +16,7 @@*/ #ifdef __XEN__ -#include <asm/guest_access.h> +#include <xen/guest_access.h> #endif #include "libelf-private.h"
xen/include/asm-arm/guest_access.h +0 -1
@@ -1,7 +1,6 @@#ifndef __ASM_ARM_GUEST_ACCESS_H__#define __ASM_ARM_GUEST_ACCESS_H__ -#include <xen/guest_access.h> #include <xen/errno.h> #include <xen/sched.h>
xen/lib/x86/private.h +1 -1
@@ -4,12 +4,12 @@#ifdef __XEN__#include <xen/bitops.h> +#include <xen/guest_access.h> #include <xen/kernel.h> #include <xen/lib.h> #include <xen/nospec.h> #include <xen/types.h> -#include <asm/guest_access.h> #include <asm/msr-index.h> #define copy_to_buffer_offset copy_to_guest_offset
Signature · 1 line
2.17.1
PATCH v2 6/7 xen/guest_access: Consolidate guest access helpers in xen/guest_access.h
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Most of the helpers to access guest memory are implemented the same way on Arm and x86. The only differences are:
- guest_handle_{from, to}_param(): while on x86 XEN_GUEST_HANDLE() and XEN_GUEST_HANDLE_PARAM() are the same, they are not on Arm. It is still fine to use the Arm implementation on x86.
- __clear_guest_offset(): Interestingly the prototype does not match between the x86 and Arm. However, the Arm one is bogus. So the x86 implementation can be used.
- guest_handle{,_subrange}_okay(): They are validly differing because Arm is only supporting auto-translated guest and therefore handles are always valid.
In the past, the ia64 and ppc64 port use a different model to access guest parameter. They have been long gone now.
Given Xen currently only support 2 archictures, it is too soon to have a directory asm-generic as it is not possible to differentiate it with the existing directory xen/. If/When there is a 3rd port, we can decide to create the new directory if that new port decide to use a different way to access guest parameter.
For now, consolidate it in xen/guest_access.h.
While it would be possible to adjust the coding style at the same, this is left for a follow-up patch so 'diff' can be used to check the consolidation was done correctly.
---
Changes in v2:
- Expand the commit message explaining why asm-generic is not created.
--- xen/include/asm-arm/guest_access.h | 114 --------------------------- xen/include/asm-x86/guest_access.h | 108 -------------------------- xen/include/xen/guest_access.h | 119 +++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 222 deletions(-)
xen/include/asm-arm/guest_access.h +0 -114
@@ -23,88 +23,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,#define __raw_copy_from_guest raw_copy_from_guest#define __raw_clear_guest raw_clear_guest -/* Remainder copied from x86 -- could be common? */ - -/* Is the guest handle a NULL reference? */ -#define guest_handle_is_null (hnd) ((hnd).p == NULL) - -/* Offset the given guest handle into the array it refers to. */ -#define guest_handle_add_offset (hnd, nr) ((hnd).p += (nr)) -#define guest_handle_subtract_offset (hnd, nr) ((hnd).p -= (nr)) - -/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM) -* to the specified type of XEN_GUEST_HANDLE_PARAM. */ -#define guest_handle_cast (hnd, type) ({ \ - type *_x = (hnd).p; \ - (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ -}) - -/* Convert a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */ -#define guest_handle_to_param (hnd, type) ({ \ - typeof((hnd).p) _x = (hnd).p; \ - XEN_GUEST_HANDLE_PARAM(type) _y = { _x }; \ -/* type checking: make sure that the pointers inside \ -* XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of \ -* the same type, then return hnd */ \ - (void )(&_x == &_y.p); \ - _y; \ -}) - -#define guest_handle_for_field (hnd, type, fld) \ - ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld }) - -#define guest_handle_from_ptr (ptr, type) \ - ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr }) -#define const_guest_handle_from_ptr (ptr, type) \ - ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr }) - -/* -* Copy an array of objects to guest context via a guest handle, -* specifying an offset into the guest array. -*/ -#define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(*(ptr)) *_s = (ptr); \ - char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ - /* Check that the handle is not for a const type */ \ - void *__maybe_unused _t = (hnd).p; \ - (void)((hnd).p == _s); \ - raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr)); \ -}) - -/* -* Clear an array of objects in guest context via a guest handle, -* specifying an offset into the guest array. -*/ -#define clear_guest_offset (hnd, off, nr) ({ \ - void *_d = (hnd).p; \ - raw_clear_guest(_d+(off), nr); \ -}) - -/* -* Copy an array of objects from guest context via a guest handle, -* specifying an offset into the guest array. -*/ -#define copy_from_guest_offset (ptr, hnd, off, nr) ({ \ - const typeof(*(ptr)) *_s = (hnd).p; \ - typeof(*(ptr)) *_d = (ptr); \ - raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\ -}) - -/* Copy sub-field of a structure to guest context via a guest handle. */ -#define copy_field_to_guest (hnd, ptr, field) ({ \ - const typeof(&(ptr)->field) _s = &(ptr)->field; \ - void *_d = &(hnd).p->field; \ - (void)(&(hnd).p->field == _s); \ - raw_copy_to_guest(_d, _s, sizeof(*_s)); \ -}) - -/* Copy sub-field of a structure from guest context via a guest handle. */ -#define copy_field_from_guest (ptr, hnd, field) ({ \ - const typeof(&(ptr)->field) _s = &(hnd).p->field; \ - typeof(&(ptr)->field) _d = &(ptr)->field; \ - raw_copy_from_guest(_d, _s, sizeof(*_d)); \ -}) -/* * Pre-validate a guest handle. * Allows use of faster __copy_* functions.
@@ -113,38 +31,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,#define guest_handle_okay (hnd, nr) (1)#define guest_handle_subrange_okay (hnd, first, last) (1) -#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(*(ptr)) *_s = (ptr); \ - char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ - /* Check that the handle is not for a const type */ \ - void *__maybe_unused _t = (hnd).p; \ - (void)((hnd).p == _s); \ - __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\ -}) - -#define __clear_guest_offset (hnd, off, ptr, nr) ({ \ - __raw_clear_guest(_d+(off), nr); \ -}) - -#define __copy_from_guest_offset (ptr, hnd, off, nr) ({ \ - const typeof(*(ptr)) *_s = (hnd).p; \ - typeof(*(ptr)) *_d = (ptr); \ - __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\ -}) - -#define __copy_field_to_guest (hnd, ptr, field) ({ \ - const typeof(&(ptr)->field) _s = &(ptr)->field; \ - void *_d = &(hnd).p->field; \ - (void)(&(hnd).p->field == _s); \ - __raw_copy_to_guest(_d, _s, sizeof(*_s)); \ -}) - -#define __copy_field_from_guest (ptr, hnd, field) ({ \ - const typeof(&(ptr)->field) _s = &(hnd).p->field; \ - typeof(&(ptr)->field) _d = &(ptr)->field; \ - __raw_copy_from_guest(_d, _s, sizeof(*_d)); \ -}) -#endif /* __ASM_ARM_GUEST_ACCESS_H__ */ /* * Local variables:
xen/include/asm-x86/guest_access.h +0 -108
120 lines not on this page · raw message
xen/include/xen/guest_access.h +119 -0
131 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 7/7 xen/guest_access: Fix coding style in xen/guest_access.h
In reply to Julien GrallFrom: Julien Grall <[email protected]>
* Add space before and after operator
* Align \
* Format comments
No functional changes expected.
--- xen/include/xen/guest_access.h | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-)
xen/include/xen/guest_access.h +20 -16
@@ -18,20 +18,24 @@#define guest_handle_add_offset (hnd, nr) ((hnd).p += (nr))#define guest_handle_subtract_offset (hnd, nr) ((hnd).p -= (nr)) -/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM) -* to the specified type of XEN_GUEST_HANDLE_PARAM. */ +/* +* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM) +* to the specified type of XEN_GUEST_HANDLE_PARAM. +*/ #define guest_handle_cast (hnd, type) ({ \ type *_x = (hnd).p; \ - (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ + (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ })/* Cast a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */ #define guest_handle_to_param (hnd, type) ({ \ typeof((hnd).p) _x = (hnd).p; \ XEN_GUEST_HANDLE_PARAM(type) _y = { _x }; \ -/* type checking: make sure that the pointers inside \ +/* \ +* type checking: make sure that the pointers inside \ * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of \ -* the same type, then return hnd */ \ +* the same type, then return hnd. \ +*/ \ (void )(&_x == &_y.p); \ _y; \ })
@@ -106,13 +110,13 @@* guest_handle_subrange_okay(). */ -#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(*(ptr)) *_s = (ptr); \ - char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ - /* Check that the handle is not for a const type */ \ - void *__maybe_unused _t = (hnd).p; \ - (void)((hnd).p == _s); \ - __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\ +#define __copy_to_guest_offset (hnd, off, ptr, nr) ({ \ + const typeof(*(ptr)) *_s = (ptr); \ + char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \ +/* Check that the handle is not for a const type */ \ + void *__maybe_unused _t = (hnd).p; \ + (void )((hnd).p == _s); \ + __raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr));\ })#define __clear_guest_offset (hnd, off, nr) ({ \
@@ -120,10 +124,10 @@__raw_clear_guest (_d + (off), nr); \ }) -#define __copy_from_guest_offset (ptr, hnd, off, nr) ({ \ - const typeof(*(ptr)) *_s = (hnd).p; \ - typeof(*(ptr)) *_d = (ptr); \ - __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\ +#define __copy_from_guest_offset (ptr, hnd, off, nr) ({ \ + const typeof(*(ptr)) *_s = (hnd).p; \ + typeof(*(ptr)) *_d = (ptr); \ + __raw_copy_from_guest(_d, _s + (off), sizeof (*_d) * (nr)); \ })#define __copy_field_to_guest (hnd, ptr, field) ({ \
Signature · 1 line
2.17.1
Hi all,
I have messed up this version. So I resend a new one.
Please ignore this version.
Cheers,
Quoted 36 lines · Julien Grall
From: Julien Grall <[email protected]>
Hi all,
A lot of the helpers implemented in
asm-*/guest_access.hare implemented the same way. This series aims to avoid the duplication and implement them only once inxen/guest_access.h.Cheers,
Julien Grall (7):
xen/guest_access: Add emacs magics
xen/arm: kernel: Re-order the includes
xen/arm: decode: Re-order the includes
xen/arm: guestcopy: Re-order the includes
xen: includexen/guest_access.hrather thanasm/guest_access.hxen/guest_access: Consolidate guest access helpers in
xen/guest_access.h
xen/guest_access: Fix coding style inxen/guest_access.hxen/arch/arm/decode.c | 7 +- xen/arch/arm/domain.c | 2 +- xen/arch/arm/guest_walk.c | 3 +- xen/arch/arm/guestcopy.c | 5 +- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/vgic-v3-its.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/common/libelf/libelf-loader.c | 2 +- xen/include/asm-arm/guest_access.h | 115 ----------------------- xen/include/asm-x86/guest_access.h | 116 ++---------------------- xen/include/xen/guest_access.h | 131 +++++++++++++++++++++++++++ xen/lib/x86/private.h | 2 +- 14 files changed, 161 insertions(+), 242 deletions(-)
Signature · 1 line
Julien Grall