p2m: split mem_access into separate files
PATCH 1/1 p2m: split mem_access into separate files
This patch relocates mem_access components that are currently mixed with p2m code into separate files. This better aligns the code with similar subsystems, such as mem_sharing and mem_paging, which are already in separate files. There are no code-changes introduced, the patch is mechanical code movement.
On ARM we also relocate the static inline gfn_next_boundary function to p2m.h as it is a function the mem_access code needs access to.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Razvan Cojocaru <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
--- MAINTAINERS | 2 + xen/arch/arm/Makefile | 1 + xen/arch/arm/mem_access.c | 477 +++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 461 +------------------------------------ xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/mm/Makefile | 1 + xen/arch/x86/mm/mem_access.c | 463 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/p2m.c | 421 ---------------------------------- xen/arch/x86/vm_event.c | 1 + xen/common/mem_access.c | 3 +- xen/common/vm_event.c | 1 + xen/include/asm-arm/mem_access.h | 60 +++++ xen/include/asm-arm/p2m.h | 31 ++- xen/include/asm-x86/mem_access.h | 61 +++++ xen/include/asm-x86/p2m.h | 24 +- xen/include/xen/mem_access.h | 64 +++++- xen/include/xen/p2m-common.h | 52 ----- 18 files changed, 1142 insertions(+), 983 deletions(-) create mode 100644 xen/arch/arm/mem_access.c create mode 100644 xen/arch/x86/mm/mem_access.c create mode 100644 xen/include/asm-arm/mem_access.h create mode 100644 xen/include/asm-x86/mem_access.h
MAINTAINERS +2 -0
@@ -402,6 +402,8 @@ S: Supported F: tools/tests/xen-access F: xen/arch/*/monitor.c F: xen/arch/*/vm_event.c +F: xen/arch/arm/mem_access.c +F: xen/arch/x86/mm/mem_access.c F: xen/arch/x86/hvm/monitor.c F: xen/common/mem_access.c F: xen/common/monitor.c
xen/arch/arm/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-y += io.o obj-y += irq.o obj-y += kernel.o obj-$(CONFIG_LIVEPATCH) += livepatch.o +obj-y += mem_access.o obj-y += mm.o obj-y += monitor.o obj-y += p2m.o
xen/arch/arm/mem_access.c new file +477 -0
477 lines not on this page · raw message
xen/arch/arm/p2m.c +1 -460
497 lines not on this page · raw message
xen/arch/arm/traps.c +1 -0
@@ -43,6 +43,7 @@#include <asm/cpufeature.h> #include <asm/flushtlb.h> #include <asm/monitor.h> +#include <asm/mem_access.h> #include "decode.h" #include "vtimer.h"
xen/arch/x86/hvm/hvm.c +1 -0
@@ -73,6 +73,7 @@#include <public/vm_event.h> #include <public/arch-x86/cpuid.h> #include <asm/cpuid.h> +#include <asm/mem_access.h> bool_t __read_mostly hvm_enabled;
xen/arch/x86/mm/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-y += guest_walk_3.o obj-y += guest_walk_4.o obj-y += mem_paging.o obj-y += mem_sharing.o +obj-y += mem_access.o guest_walk_%.o: guest_walk.c Makefile $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
xen/arch/x86/mm/mem_access.c new file +463 -0
463 lines not on this page · raw message
xen/arch/x86/mm/p2m.c +0 -421
433 lines not on this page · raw message
xen/arch/x86/vm_event.c +1 -0
@@ -19,6 +19,7 @@*/ #include <asm/p2m.h> +#include <asm/mem_access.h> #include <asm/vm_event.h> /* Implicitly serialized by the domctl lock. */
xen/common/mem_access.c +2 -1
@@ -24,8 +24,9 @@#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/vm_event.h> +#include <xen/mem_access.h> #include <public/memory.h> -#include <asm/p2m.h> +#include <asm/mem_access.h> #include <xsm/xsm.h> int mem_access_memop(unsigned long cmd,
xen/common/vm_event.c +1 -0
@@ -28,6 +28,7 @@#include <asm/p2m.h> #include <asm/monitor.h> #include <asm/vm_event.h> +#include <asm/mem_access.h> #include <xsm/xsm.h> /* for public/io/ring.h macros */
xen/include/asm-arm/mem_access.h new file +60 -0
60 lines not on this page · raw message
xen/include/asm-arm/p2m.h +14 -17
@@ -4,6 +4,7 @@#include <xen/mm.h> #include <xen/radix-tree.h> #include <xen/rwlock.h> +#include <xen/mem_access.h> #include <public/vm_event.h> /* for vm_event_response_t */ #include <public/memory.h> #include <xen/p2m-common.h>
@@ -139,14 +140,6 @@ typedef enum { p2m_to_mask(p2m_map_foreign)))static inline -bool p2m_mem_access_emulate_check (struct vcpu *v, -const vm_event_response_t *rsp) -{ -/* Not supported on ARM. */ -return 0 ; -} - -static inline void p2m_altp2m_check (struct vcpu *v,uint16_t idx) {/* Not supported on ARM. */
@@ -343,22 +336,26 @@ static inline int get_page_and_type(struct page_info *page,/* get host p2m table */ #define p2m_get_hostp2m (d) (&(d)->arch.p2m) -/* vm_event and mem_access are supported on any ARM guest */ -static inline bool_t p2m_mem_access_sanity_check (struct domain *d) -{ -return 1 ; -} -static inline bool_t p2m_vm_event_sanity_check (struct domain *d) {return 1 ; }/* -* Send mem event based on the access. Boolean return value indicates if trap -* needs to be injected into guest. +* Return the start of the next mapping based on the order of the +* current one. */ -bool_t p2m_mem_access_check (paddr_t gpa,vaddr_t gla,const struct npfec npfec); +static inline gfn_t gfn_next_boundary (gfn_t gfn,unsigned int order) +{ +/* +* The order corresponds to the order of the mapping (or invalid +* range) in the page table. So we need to align the GFN before +* incrementing. +*/ + gfn =_gfn (gfn_x (gfn) & ~((1UL << order) -1 )); + +return gfn_add (gfn,1UL << order); +}#endif /* _XEN_P2M_H */
xen/include/asm-x86/mem_access.h new file +61 -0
61 lines not on this page · raw message
xen/include/asm-x86/p2m.h +1 -23
@@ -28,6 +28,7 @@#include <xen/config.h> #include <xen/paging.h> +#include <xen/mem_access.h> #include <xen/p2m-common.h> #include <asm/mem_sharing.h> #include <asm/page.h> /* for pagetable_t */
@@ -663,29 +664,6 @@ int p2m_mem_paging_prep(struct domain *d, unsigned long gfn, uint64_t buffer);/* Resume normal operation (in case a domain was paused) */ void p2m_mem_paging_resume (struct domain *d,vm_event_response_t *rsp); -/* -* Setup vm_event request based on the access (gla is -1ull if not available). -* Handles the rw2rx conversion. Boolean return value indicates if event type -* is syncronous (aka. requires vCPU pause). If the req_ptr has been populated, -* then the caller should use monitor_traps to send the event on the MONITOR -* ring. Once having released get_gfn* locks caller must also xfree the -* request. -*/ -bool_t p2m_mem_access_check (paddr_t gpa,unsigned long gla, -struct npfec npfec, -vm_event_request_t **req_ptr); - -/* Check for emulation and mark vcpu for skipping one instruction -* upon rescheduling if required. */ -bool p2m_mem_access_emulate_check (struct vcpu *v, -const vm_event_response_t *rsp); - -/* Sanity check for mem_access hardware support */ -static inline bool_t p2m_mem_access_sanity_check (struct domain *d) -{ -return is_hvm_domain (d) && cpu_has_vmx &&hap_enabled (d); -} -/* * Internal functions, only called by other p2m code */
xen/include/xen/mem_access.h +55 -9
84 lines not on this page · raw message
xen/include/xen/p2m-common.h +0 -52
62 lines not on this page · raw message
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 9 lines · Tamas K Lengyel
This patch relocates
mem_accesscomponents that are currently mixed with p2m code into separate files. This better aligns the code with similar subsystems, such asmem_sharingandmem_paging, which are already in separate files. There are no code-changes introduced, the patch is mechanical code movement.On ARM we also relocate the static inline
gfn_next_boundaryfunction top2m.has it is a function themem_accesscode needs access to.Signed-off-by Tamas K Lengyel <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
xen/arch/x86/mm/Makefile obj-y += guest_walk_3.o · line 12
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 23:57, <[email protected]> wrote:
xen/arch/x86/mm/Makefile +1
-0@@ -9,6 +9,7 @@ obj-y += guest_walk_3.o obj-y += guest_walk_4.o obj-y += mem_paging.o obj-y += mem_sharing.o +obj-y += mem_access.o
Please honor prior (mostly?) alphabetical ordering.
xen/common/mem_access.c line 30
Quoted 11 lines
xen/common/mem_access.c +2
-1@@ -24,8 +24,9 @@#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/vm_event.h> +#include <xen/mem_access.h> #include <public/memory.h> -#include <asm/p2m.h> +#include <asm/mem_access.h> #include <xsm/xsm.h>
Normally asm/ includes xen/ of the same name or the other way around, depending on how they relate to one another; you shouldn't ever need both includes, and I'd be surprised if the two headers really are (even conceptionally) completely independent of each other.
Otherwise this all looks like pure code motion (except for the adjustments described), but it would be nice if you could clarify that's indeed (intended to be) the case.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines · Jan Beulich
xen/arch/x86/mm/Makefile obj-y += guest_walk_3.o · line 12
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 23:57, <[email protected]> wrote:
xen/arch/x86/mm/Makefile +1
-0@@ -9,6 +9,7 @@ obj-y += guest_walk_3.o obj-y += guest_walk_4.o obj-y += mem_paging.o obj-y += mem_sharing.o +obj-y += mem_access.oPlease honor prior (mostly?) alphabetical ordering.
I don't think there is any alphabetical ordering here. The list begins with paging.o then goes to altp2m.o and then to guest_walk_2.o.. IMHO sorting the list is something that should be done in a separate patch.
Quoted 10 lines
Quoted 10 lines
xen/common/mem_access.c +1
-1@@ -24,8 +24,9 @@#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/vm_event.h> +#include <xen/mem_access.h> #include <public/memory.h> -#include <asm/p2m.h>
Quoted 8 lines
xen/common/mem_access.c line 30
Quoted 2 lines
xen/common/mem_access.c +1
-0+#include <asm/mem_access.h> #include <xsm/xsm.h> Normally asm/ includes xen/ of the same name or the other way around, depending on how they relate to one another; you shouldn't ever need both includes, and I'd be surprised if the two headers really are (even conceptionally) completely independent of each other.
Sure, xen/mem_access.h can include the asm specific one.
Quoted 4 lines
Otherwise this all looks like pure code motion (except for the adjustments described), but it would be nice if you could clarify that's indeed (intended to be) the case.
I do say in the commit message this is mechanical code motion: "There are no code-changes introduced, the patch is mechanical code movement."
Quoted 3 lines
Jan
Thanks,
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 09.12.16 at 19:38, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/arch/x86/mm/Makefile obj-y += guest_walk_3.o · line 12
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 23:57, <[email protected]> wrote:
xen/arch/x86/mm/Makefile +1
-0@@ -9,6 +9,7 @@ obj-y += guest_walk_3.o obj-y += guest_walk_4.o obj-y += mem_paging.o obj-y += mem_sharing.o +obj-y += mem_access.oPlease honor prior (mostly?) alphabetical ordering.
Quoted 3 lines
I don't think there is any alphabetical ordering here. The list begins with paging.o then goes to altp2m.o and then to guest_walk_2.o.. IMHO sorting the list is something that should be done in a separate patch.
Hence my "(partly?)" - the patch context alone tells that you could at least not make things worse.
Quoted 7 lines
Quoted 3 lines
Otherwise this all looks like pure code motion (except for the adjustments described), but it would be nice if you could clarify that's indeed (intended to be) the case.
I do say in the commit message this is mechanical code motion: "There are no code-changes introduced, the patch is mechanical code movement."
Oh, I'm sorry - I'm sure I've looked over the description a 2nd time before making the comment, but I still must have skipped that last sentence in the first paragraph.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 13 lines · Jan Beulich
Quoted 1 line
Quoted 1 line · On 09.12.16 at 19:38, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/arch/x86/mm/Makefile obj-y += guest_walk_3.o · line 12
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.12.16 at 23:57, <[email protected]> wrote:
xen/arch/x86/mm/Makefile +1
-0@@ -9,6 +9,7 @@ obj-y += guest_walk_3.o obj-y += guest_walk_4.o obj-y += mem_paging.o obj-y += mem_sharing.o +obj-y += mem_access.oPlease honor prior (mostly?) alphabetical ordering.
Quoted 3 lines
I don't think there is any alphabetical ordering here. The list begins with paging.o then goes to altp2m.o and then to guest_walk_2.o.. IMHO sorting the list is something that should be done in a separate patch.
Hence my "(partly?)" - the patch context alone tells that you could at least not make things worse.
I think this is one of those changes that I would rather not submit a new version for unless something else comes up as well.
Quoted 7 lines
Quoted 3 lines
Otherwise this all looks like pure code motion (except for the adjustments described), but it would be nice if you could clarify that's indeed (intended to be) the case.
I do say in the commit message this is mechanical code motion: "There are no code-changes introduced, the patch is mechanical code movement."
Oh, I'm sorry - I'm sure I've looked over the description a 2nd time before making the comment, but I still must have skipped that last sentence in the first paragraph.
No problem ;)
Thanks,
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Tamas,
Quoted 4 lines · Tamas K Lengyel
This patch relocates
mem_accesscomponents that are currently mixed with p2m code into separate files. This better aligns the code with similar subsystems, such asmem_sharingandmem_paging, which are already in separate files. There are no code-changes introduced, the patch is mechanical code movement.
Whilst I agree this is a good move in general, the ARM (both 32bits and 64bits) code deserves more attention to make it work in *all* the case. It would have been nice to show that by addressing my concerns when you first suggested this move (see [1]).
Quoted 5 lines
On ARM we also relocate the static inline
gfn_next_boundaryfunction top2m.has it is a function themem_accesscode needs access to.Signed-off-by Tamas K Lengyel <[email protected]>
[...]
Quoted 6 lines
xen/arch/arm/mem_access.c new file +6
-0+/* +* Lookup the MFN corresponding to a domain's GFN. +* Lookup mem access in the ratrix tree. +* The entries associated to the GFN is considered valid. +*/ +p2m_access_t p2m_mem_access_radix_get (struct p2m_domain *p2m,gfn_t gfn)
[...]
xen/arch/arm/mem_access.c line 113
Quoted 2 lines
xen/arch/arm/mem_access.c new file +2
-0+int p2m_mem_access_radix_set (struct p2m_domain *p2m,gfn_t gfn, +p2m_access_t a)
[...]
The radix tree functions should stay in p2m.c as they are tie to stage-2 page table handling.
xen/arch/arm/mem_access.c line 148
Quoted 9 lines
xen/arch/arm/mem_access.c new file +9
-0+ +/* +* If mem_access is in use it might have been the reason why get_page_from_gva +* failed to fetch the page, as it uses the MMU for the permission checking. +* Only in these cases we do a software-based type check and fetch the page if +* we indeed found a conflicting mem_access setting. +*/ +struct page_info * +p2m_mem_access_check_and_get_page (vaddr_t gva,unsigned long flag)
This interface should take a vCPU in parameter and not rely on current.
Also, p2m_mem_access_check_get_page is using the hardware to translate a VA to an IPA. This only works if the memory where the stage-1 page tables reside is not protected. The upcoming support of altp2m will make things trickier.
[1] https://lists.xenproject.org/archives/html/xen-devel/2016-08/msg00037.html
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines · Tamas K Lengyel
This patch relocates
mem_accesscomponents that are currently mixed with p2m code into separate files. This better aligns the code with similar subsystems, such asmem_sharingandmem_paging, which are already in separate files. There are no code-changes introduced, the patch is mechanical code movement.
Quoted 4 lines
On ARM we also relocate the static inline
gfn_next_boundaryfunction top2m.has it is a function themem_accesscode needs access to.Signed-off-by Tamas K Lengyel <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel