xen/arm: Handle correctly foreign mapping
v2 cover xen/arm: Handle correctly foreign mapping
Hello,
This patch series aims to fix "Failed to unmap" message in dom0 when a guest is creating. Without this patch series, dom0 will leak memory each time a domain is created. It should be considered as a blocker for Xen 4.4 release.
The series is based on pvh dom0 v6 patch series from Mukesh with patch #7
(http://lists.xenproject.org/archives/html/xen-devel/2013-12/msg01026.html)
replaced by the version V6.1
(http://lists.xenproject.org/archives/html/xen-devel/2013-12/msg01168.html)
- Patch #1-2: prepare work for the others patches
- Patch #3-6: add support for p2m type
- Patch #7-9: handle correctly foreign mapping
- Patch #10: it's not really part of this series. It adds support for read-only grant-mapping
All the patches can be found on this git:
git clone -b map-foreign-v2 git://xenbits.xen.org/people/julieng/xen-unstable.git
For all the changes, see in each patch.
Sincerely yours,
Julien Grall (10):
xen/arm: Introduce steps in domain_relinquish_resource xen/arm: move mfn_to_p2m_entry in arch/arm/p2m.c xen/arm: Implement p2m_type_t as an enum
xen/arm: Store p2m type in each page of the guest xen/arm: p2m: Extend p2m_lookup parameters to retrieve the p2m type xen/arm: Retrieve p2m type in get_page_from_gfn
xen/arm: Introduce relinquish_p2m_mapping to remove refcount every
mapped page
xen/arm: Implement xen_rem_foreign_from_p2m
xen/arm: Set foreign page type to p2m_map_foreign xen/arm: grant-table: Support read-only mapping
xen/arch/arm/domain.c | 42 ++++++++++--- xen/arch/arm/mm.c | 52 +++++++++++----- xen/arch/arm/p2m.c | 136 +++++++++++++++++++++++++++++++++++++----- xen/arch/arm/traps.c | 6 +- xen/include/asm-arm/domain.h | 9 +++ xen/include/asm-arm/p2m.h | 65 ++++++++++++++++---- xen/include/asm-arm/page.h | 24 +------- 7 files changed, 258 insertions(+), 76 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v2 1/10 xen/arm: Introduce steps in domain_relinquish_resource
In a later patch, a new step will be added. It will avoid to check every step when the function was preempted.
---
Changes in v2:
- Introduce the patch
--- xen/arch/arm/domain.c | 37 ++++++++++++++++++++++++++++++------- xen/include/asm-arm/domain.h | 8 ++++++++ 2 files changed, 38 insertions(+), 7 deletions(-)
xen/arch/arm/domain.c +30 -7
@@ -497,6 +497,8 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags) {int rc; + d->arch.relmem = RELMEM_not_started; +/* Idle domains do not need this setup */ if (is_idle_domain (d) )return 0 ;
@@ -696,15 +698,36 @@ int domain_relinquish_resources(struct domain *d) {int ret =0 ; - ret =relinquish_memory (d, &d->xenpage_list); -if ( ret ) -return ret; +switch ( d->arch.relmem ) + { +case RELMEM_not_started: + d->arch.relmem = RELMEM_xen; +/* Falltrough */ - ret =relinquish_memory (d, &d->page_list); -if ( ret ) -return ret; +case RELMEM_xen: + ret =relinquish_memory (d, &d->xenpage_list); +if ( ret ) +return ret; -return ret; + d->arch.relmem = RELMEM_page; +/* Fallthrough */ + +case RELMEM_page: + ret =relinquish_memory (d, &d->page_list); +if ( ret ) +return ret; + + d->arch.relmem = RELMEM_done; +/* Fallthrough */ + +case RELMEM_done: +break ; + +default : +BUG (); + } + +return 0 ; }void arch_dump_domain_info (struct domain *d)
xen/include/asm-arm/domain.h +8 -0
@@ -70,6 +70,14 @@ struct arch_domainstruct hvm_domain hvm_domain;xen_pfn_t *grant_table_gpfn; +/* Continuable domain_relinquish_resources(). */ +enum { + RELMEM_not_started, + RELMEM_xen, + RELMEM_page, + RELMEM_done, + } relmem; +/* Virtual CPUID */ uint32_t vpidr;
Signature · 1 line
1.7.10.4
Re: [PATCH v2 01/10] xen/arm: Introduce steps in domain_relinquish_resource
Quoted 4 lines · Julien Grall
In a later patch, a new step will be added. It will avoid to check every step when the function was preempted.
Signed-off-by Julien Grall <[email protected]>
PATCH v2 2/10 xen/arm: move mfn_to_p2m_entry in arch/arm/p2m.c
In reply to Julien GrallThe function mfn_to_p2m_entry will be extended in a following patch to handle p2m_type_t. It will break compilation because p2m_type_t is not defined (interdependence between includes).
It's easier to move the function in arch/arm/p2m.c and it's not harmful as the function is only used in this file.
--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++++ xen/include/asm-arm/page.h | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-)
xen/arch/arm/p2m.c +22 -0
@@ -124,6 +124,28 @@ int p2m_pod_decrease_reservation(struct domain *d,return -ENOSYS ; } +static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr) +{ +paddr_t pa = ((paddr_t ) mfn) <<PAGE_SHIFT ; +lpae_t e = (lpae_t ) { + .p2m.xn =0 , + .p2m.af =1 , + .p2m.sh =LPAE_SH_OUTER , + .p2m.read =1 , + .p2m.write =1 , + .p2m.mattr = mattr, + .p2m.table =1 , + .p2m.valid =1 , + }; + +ASSERT (!(pa & ~PAGE_MASK )); +ASSERT (!(pa & ~PADDR_MASK )); + + e.bits |= pa; + +return e; +} +/* Allocate a new page table page and hook it in via the given entry */ static int p2m_create_table (struct domain *d,lpae_t *entry)
xen/include/asm-arm/page.h +0 -22
@@ -213,28 +213,6 @@ static inline lpae_t mfn_to_xen_entry(unsigned long mfn)return e; } -static inline lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr) -{ -paddr_t pa = ((paddr_t ) mfn) <<PAGE_SHIFT ; -lpae_t e = (lpae_t ) { - .p2m.xn =0 , - .p2m.af =1 , - .p2m.sh =LPAE_SH_OUTER , - .p2m.write =1 , - .p2m.read =1 , - .p2m.mattr = mattr, - .p2m.table =1 , - .p2m.valid =1 , - }; - -ASSERT (!(pa & ~PAGE_MASK )); -ASSERT (!(pa & ~PADDR_MASK )); - - e.bits |= pa; - -return e; -} -#if defined(CONFIG_ARM_32 )# include <asm/arm32/page.h> #elif defined(CONFIG_ARM_64 )
Signature · 1 line
1.7.10.4
PATCH v2 3/10 xen/arm: Implement p2m_type_t as an enum
In reply to Julien GrallUntil now, Xen doesn't know the type of the page (ram, foreign page, mmio,...). Introduce p2m_type_t with basic types:
- p2m_invalid: Nothing is mapped here
- p2m_ram_rw: Normal read/write guest RAM
- p2m_ram_ro: Read-only guest RAM
- p2m_mmio_direct: Read/write mapping of device memory
- p2m_map_foreign: RAM page from foreign guest
- p2m_grant_map_rw: Read/write grant mapping
- p2m_grant_map_ro: Read-only grant mapping
---
Changes in v2:
- Add comment for future improvement
- Add p2m_max_real_type. Will be use later to check the size of the enum
- Let the compiler choose the value for each name of the enum
- Add grant mapping type
--- xen/include/asm-arm/p2m.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
xen/include/asm-arm/p2m.h +19 -2
@@ -20,6 +20,25 @@ struct p2m_domain {uint8_t vmid; }; +/* List of possible type for each page in the p2m +* The number of available bit per page in the p2m for this purpose is 4 bits. +* So it's possible to only have 16 fields. If we run out of value in the +* future, it's possible to use higher value for pseudo-type and don't store +* them in the p2m. +*/ +typedef enum { + p2m_invalid =0 ,/* Nothing mapped here */ + p2m_ram_rw,/* Normal read/write guest RAM */ + p2m_ram_ro,/* Read-only; writes are silently dropped */ + p2m_mmio_direct,/* Read/write mapping of genuine MMIO area */ + p2m_map_foreign,/* Ram pages from foreign domain */ + p2m_grant_map_rw,/* Read/write grant mapping */ + p2m_grant_map_ro,/* Read-only grant mapping */ + p2m_max_real_type,/* Types after this won't be store in the p2m */ +}p2m_type_t ; + +#define p2m_is_foreign (_t) ((_t) == p2m_map_foreign) +/* Initialise vmid allocator */ void p2m_vmid_allocator_init (void );
@@ -72,7 +91,6 @@ p2m_pod_decrease_reservation(struct domain *d, unsigned int order);/* Look up a GFN and take a reference count on the backing page. */ -typedef int p2m_type_t ;typedef unsigned int p2m_query_t ;#define P2M_ALLOC (1u<<0)/* Populate PoD and paged-out entries */ #define P2M_UNSHARE (1u<<1)/* Break CoW sharing */
@@ -108,7 +126,6 @@ static inline int get_page_and_type(struct page_info *page,return rc; } -#define p2m_is_foreign (_t) (0 && (_t))static inline int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn) {
Signature · 1 line
1.7.10.4
Re: [PATCH v2 03/10] xen/arm: Implement p2m_type_t as an enum
Quoted 28 lines · Julien Grall
Until now, Xen doesn't know the type of the page (ram, foreign page, mmio,...). Introduce
p2m_type_twith basic types:
-p2m_invalid: Nothing is mapped here
-p2m_ram_rw: Normal read/write guest RAM
-p2m_ram_ro: Read-only guest RAM
-p2m_mmio_direct: Read/write mapping of device memory
-p2m_map_foreign: RAM page from foreign guest
-p2m_grant_map_rw: Read/write grant mapping
-p2m_grant_map_ro: Read-only grant mappingSigned-off-by Julien Grall <[email protected]>---
Changes in v2:
- Add comment for future improvement
- Addp2m_max_real_type. Will be use later to check the size of the enum
- Let the compiler choose the value for each name of the enum
- Add grant mapping type--- xen/include/asm-arm/p2m.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)xen/include/asm-arm/p2m.h +0
-0
xen/include/asm-arm/p2m.h struct p2m_domain { · line 24
Quoted 5 lines
xen/include/asm-arm/p2m.h +2
-0@@ -20,6 +20,25 @@ struct p2m_domain {uint8_t vmid; }; +/* List of possible type for each page in the p2m +* The number of available bit per page in the p2m for this purpose is 4 bits.
s/ / /.
I think you might also have meant s/p2m/pte/ or "p2m entry"?
xen/include/asm-arm/p2m.h struct p2m_domain { · line 37
Quoted 13 lines
xen/include/asm-arm/p2m.h +13
-0+* So it's possible to only have 16 fields. If we run out of value in the +* future, it's possible to use higher value for pseudo-type and don't store +* them in the p2m. +*/ +typedef enum { + p2m_invalid = 0, /* Nothing mapped here */ + p2m_ram_rw, /* Normal read/write guest RAM */ + p2m_ram_ro, /* Read-only; writes are silently dropped */ + p2m_mmio_direct, /* Read/write mapping of genuine MMIO area */ + p2m_map_foreign, /* Ram pages from foreign domain */ + p2m_grant_map_rw, /* Read/write grant mapping */ + p2m_grant_map_ro, /* Read-only grant mapping */ + p2m_max_real_type, /* Types after this won't be store in the p2m */
Did you intend to add a BUILD_BUG_ON referencing this last one?
In any case:
Quoted 23 lines
xen/include/asm-arm/p2m.h +4
-2+} p2m_type_t; + +#define p2m_is_foreign (_t) ((_t) == p2m_map_foreign) +/* Initialise vmid allocator */ void p2m_vmid_allocator_init (void );@@ -72,7 +91,6 @@ p2m_pod_decrease_reservation(struct domain *d, unsigned int order);/* Look up a GFN and take a reference count on the backing page. */ -typedef int p2m_type_t ;typedef unsigned int p2m_query_t ;#define P2M_ALLOC (1u<<0)/* Populate PoD and paged-out entries */ #define P2M_UNSHARE (1u<<1)/* Break CoW sharing */ @@ -108,7 +126,6 @@ static inline int get_page_and_type(struct page_info *page,return rc; } -#define p2m_is_foreign (_t) (0 && (_t))static inline int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn) {
Re: [PATCH v2 03/10] xen/arm: Implement p2m_type_t as an enum
Quoted 32 lines · Ian Campbell
Quoted 31 lines · Julien Grall
Until now, Xen doesn't know the type of the page (ram, foreign page, mmio,...). Introduce
p2m_type_twith basic types:
-p2m_invalid: Nothing is mapped here
-p2m_ram_rw: Normal read/write guest RAM
-p2m_ram_ro: Read-only guest RAM
-p2m_mmio_direct: Read/write mapping of device memory
-p2m_map_foreign: RAM page from foreign guest
-p2m_grant_map_rw: Read/write grant mapping
-p2m_grant_map_ro: Read-only grant mappingSigned-off-by Julien Grall <[email protected]>---
Changes in v2:
- Add comment for future improvement
- Addp2m_max_real_type. Will be use later to check the size of the enum
- Let the compiler choose the value for each name of the enum
- Add grant mapping type--- xen/include/asm-arm/p2m.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)xen/include/asm-arm/p2m.h +0
-0@@ -20,6 +20,25 @@ struct p2m_domain {uint8_t vmid; };
Quoted 6 lines
xen/include/asm-arm/p2m.h struct p2m_domain { · line 24
Quoted 2 lines
xen/include/asm-arm/p2m.h +2
-0+/* List of possible type for each page in the p2m +* The number of available bit per page in the p2m for this purpose is 4 bits. s/ / /.
I think you might also have meant s/p2m/pte/ or "p2m entry"?
Right, I will fix it.
Quoted 15 lines
Quoted 4 lines
xen/include/asm-arm/p2m.h +3
-0+* So it's possible to only have 16 fields. If we run out of value in the +* future, it's possible to use higher value for pseudo-type and don't store +* them in the p2m. xen/include/asm-arm/p2m.h struct p2m_domain { · line 37
Quoted 10 lines
xen/include/asm-arm/p2m.h +10
-0+*/ +typedef enum { + p2m_invalid = 0, /* Nothing mapped here */ + p2m_ram_rw, /* Normal read/write guest RAM */ + p2m_ram_ro, /* Read-only; writes are silently dropped */ + p2m_mmio_direct, /* Read/write mapping of genuine MMIO area */ + p2m_map_foreign, /* Ram pages from foreign domain */ + p2m_grant_map_rw, /* Read/write grant mapping */ + p2m_grant_map_ro, /* Read-only grant mapping */ + p2m_max_real_type, /* Types after this won't be store in the p2m */
Quoted 1 line
Did you intend to add a
BUILD_BUG_ONreferencing this last one?
The BUILD_BUG_ON is added by patch #4.
Quoted 2 lines
In any case:
Acked-by Ian Campbell <[email protected]>
Thanks.
Signature · 1 line
Julien Grall
Re: [PATCH v2 03/10] xen/arm: Implement p2m_type_t as an enum
Quoted 7 lines · Julien Grall
Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall
+
p2m_max_real_type, /* Types after this won't be store in the p2m */Did you intend to add a
BUILD_BUG_ONreferencing this last one?The
BUILD_BUG_ONis added by patch #4.
So it is. Perhaps it should either be in this patch or you should add max_real_type in that patch.
Ian.
Re: [PATCH v2 03/10] xen/arm: Implement p2m_type_t as an enum
Quoted 11 lines · Ian Campbell
Quoted 7 lines · Julien Grall
Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall
+
p2m_max_real_type, /* Types after this won't be store in the p2m */Did you intend to add a
BUILD_BUG_ONreferencing this last one?The
BUILD_BUG_ONis added by patch #4.So it is. Perhaps it should either be in this patch or you should add
max_real_typein that patch.
I have moved the BUILD_BUG_ON in this patch.
Signature · 1 line
Julien Grall
PATCH v2 4/10 xen/arm: Store p2m type in each page of the guest
In reply to Julien GrallUse the field 'avail' to store the type of the page. Rename it to 'p2mt' for convenience.
The information stored in this field will be retrieved in a future patch to hange the behaviour when the page is removed.
Also introduce guest_physmap_add_entry to map and set a specific p2m type for a page.
---
Changes in v2:
- Rename 'avail' field to 'p2mt' in the p2m structure
- Add BUILD_BUG_ON to check if the enum value will fit in the field
- Implement grant mapping type
--- xen/arch/arm/p2m.c | 58 ++++++++++++++++++++++++++++++++------------ xen/include/asm-arm/p2m.h | 18 +++++++++++--- xen/include/asm-arm/page.h | 2 +- 3 files changed, 58 insertions(+), 20 deletions(-)
xen/arch/arm/p2m.c +43 -15
@@ -124,7 +124,8 @@ int p2m_pod_decrease_reservation(struct domain *d,return -ENOSYS ; } -static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr) +static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr, +p2m_type_t t) {paddr_t pa = ((paddr_t ) mfn) <<PAGE_SHIFT ;lpae_t e = (lpae_t ) {
@@ -132,12 +133,34 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) .p2m.af = 1, .p2m.sh = LPAE_SH_OUTER, .p2m.read = 1, - .p2m.write = 1, .p2m.mattr = mattr, .p2m.table = 1, .p2m.valid = 1, + .p2m.p2mt = t, }; +BUILD_BUG_ON (p2m_max_real_type > (2 <<4 )); + +switch (t) + { +case p2m_grant_map_rw: + e.p2m.xn =1 ; +/* Fallthrough */ +case p2m_ram_rw: +case p2m_mmio_direct: +case p2m_map_foreign: + e.p2m.write =1 ; +break ; + +case p2m_grant_map_ro: + e.p2m.xn =1 ; +/* Fallthrough */ +case p2m_invalid: +case p2m_ram_ro: +default : + e.p2m.write =0 ; + } +ASSERT (!(pa & ~PAGE_MASK ));ASSERT (!(pa & ~PADDR_MASK ));
@@ -167,7 +190,7 @@ static int p2m_create_table(struct domain *d,clear_page (p);unmap_domain_page (p); - pte =mfn_to_p2m_entry (page_to_mfn (page),MATTR_MEM ); + pte =mfn_to_p2m_entry (page_to_mfn (page),MATTR_MEM , p2m_invalid);write_pte (entry, pte);
@@ -185,7 +208,8 @@ static int create_p2m_entries(struct domain *d,paddr_t start_gpaddr, paddr_t end_gpaddr, paddr_t maddr, - int mattr) + int mattr, + p2m_type_t t) { int rc, flush;struct p2m_domain *p2m = &d->arch.p2m;
@@ -260,14 +284,15 @@ static int create_p2m_entries(struct domain *d, goto out; } - pte =mfn_to_p2m_entry (page_to_mfn (page), mattr); + pte =mfn_to_p2m_entry (page_to_mfn (page), mattr, t);write_pte (&third[third_table_offset (addr)], pte); }break ;case INSERT : { -lpae_t pte =mfn_to_p2m_entry (maddr >>PAGE_SHIFT , mattr); +lpae_t pte =mfn_to_p2m_entry (maddr >>PAGE_SHIFT , + mattr, t);write_pte (&third[third_table_offset (addr)], pte); maddr +=PAGE_SIZE ; }
@@ -302,7 +327,8 @@ int p2m_populate_ram(struct domain *d,paddr_t start, paddr_t end) { - return create_p2m_entries(d, ALLOCATE, start, end, 0, MATTR_MEM); + return create_p2m_entries(d, ALLOCATE, start, end, + 0, MATTR_MEM, p2m_ram_rw); } int map_mmio_regions(struct domain *d,
@@ -310,18 +336,20 @@ int map_mmio_regions(struct domain *d,paddr_t end_gaddr, paddr_t maddr) { - return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr, maddr, MATTR_DEV); + return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr, +maddr ,MATTR_DEV ,p2m_mmio_direct ); } -int guest_physmap_add_page (struct domain *d, -unsigned long gpfn, -unsigned long mfn, -unsigned int page_order) +int guest_physmap_add_entry (struct domain *d, +unsigned long gpfn, +unsigned long mfn, +unsigned long page_order, +p2m_type_t t) {return create_p2m_entries (d,INSERT ,pfn_to_paddr (gpfn), -pfn_to_paddr (gpfn + (1 <<page_order)), -pfn_to_paddr (mfn),MATTR_MEM ); +pfn_to_paddr (gpfn + (1 << page_order)), +pfn_to_paddr (mfn),MATTR_MEM , t); } void guest_physmap_remove_page(struct domain *d,
@@ -331,7 +359,7 @@ void guest_physmap_remove_page(struct domain *d,create_p2m_entries (d,REMOVE ,pfn_to_paddr (gpfn),pfn_to_paddr (gpfn + (1 <<page_order)), -pfn_to_paddr (mfn),MATTR_MEM ); +pfn_to_paddr (mfn),MATTR_MEM , p2m_invalid); }int p2m_alloc_table (struct domain *d)
xen/include/asm-arm/p2m.h +14 -4
@@ -68,11 +68,21 @@ int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);int map_mmio_regions (struct domain *d,paddr_t start_gaddr,paddr_t end_gaddr,paddr_t maddr); +int guest_physmap_add_entry (struct domain *d, +unsigned long gfn, +unsigned long mfn, +unsigned long page_order, +p2m_type_t t); +/* Untyped version for RAM only, for compatibility */ -int guest_physmap_add_page (struct domain *d, -unsigned long gfn, -unsigned long mfn, -unsigned int page_order); +static inline int guest_physmap_add_page (struct domain *d, +unsigned long gfn, +unsigned long mfn, +unsigned int page_order) +{ +return guest_physmap_add_entry (d, gfn, mfn, page_order, p2m_ram_rw); +} +void guest_physmap_remove_page (struct domain *d,unsigned long gpfn,unsigned long mfn,unsigned int page_order);
xen/include/asm-arm/page.h +1 -1
@@ -153,7 +153,7 @@ typedef struct { unsigned long contig:1; /* In a block of 16 contiguous entries */ unsigned long sbz2:1; unsigned long xn:1; /* eXecute-Never */ - unsigned long avail:4; /* Ignored by hardware */ + unsigned long p2mt:4; /* Ignore by hardware. Used to store p2m types */ unsigned long sbz1:5; } __attribute__((__packed__)) lpae_p2m_t;
Signature · 1 line
1.7.10.4
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
Quoted 2 lines · Julien Grall
Use the field 'avail' to store the type of the page. Rename it to 'p2mt' for convenience.
The p2m is redundant in most uses, and the t isn't very descriptive. I think "type" would be fine.
Quoted 2 lines
The information stored in this field will be retrieved in a future patch to hange the behaviour when the page is removed.
"change"
Quoted 50 lines
Also introduce
guest_physmap_add_entryto map and set a specific p2m type for a page.Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Rename 'avail' field to 'p2mt' in the p2m structure
- AddBUILD_BUG_ONto check if the enum value will fit in the field
- Implement grant mapping type--- xen/arch/arm/p2m.c | 58 ++++++++++++++++++++++++++++++++------------ xen/include/asm-arm/p2m.h | 18 +++++++++++--- xen/include/asm-arm/page.h | 2 +- 3 files changed, 58 insertions(+), 20 deletions(-)xen/arch/arm/p2m.c +12
-2@@ -124,7 +124,8 @@ int p2m_pod_decrease_reservation(struct domain *d,return -ENOSYS ; } -static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr) +static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr, +p2m_type_t t) {paddr_t pa = ((paddr_t ) mfn) <<PAGE_SHIFT ;lpae_t e = (lpae_t ) {@@ -132,12 +133,34 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) .p2m.af = 1, .p2m.sh = LPAE_SH_OUTER, .p2m.read = 1, - .p2m.write = 1, .p2m.mattr = mattr, .p2m.table = 1, .p2m.valid = 1, + .p2m.p2mt = t, }; +BUILD_BUG_ON (p2m_max_real_type > (2 <<4 )); + +switch (t) + { +case p2m_grant_map_rw: + e.p2m.xn =1 ; +/* Fallthrough */ +case p2m_ram_rw: +case p2m_mmio_direct:
xen/arch/arm/p2m.c static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) · line 160
Quoted 10 lines
xen/arch/arm/p2m.c +10
-0+case p2m_map_foreign: + e.p2m.write =1 ; +break ; + +case p2m_grant_map_ro: + e.p2m.xn =1 ; +/* Fallthrough */ +case p2m_invalid: +case p2m_ram_ro: +default :
I think you've enumerated all the options, so it is better to leave out the default -- then at least some compilers will complain if we add a new type and forget to add it here.
The bulk of the patch looks good though, thanks.
Ian.
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
Quoted 68 lines · Ian Campbell
Quoted 2 lines · Julien Grall
Use the field 'avail' to store the type of the page. Rename it to 'p2mt' for convenience.
The p2m is redundant in most uses, and the t isn't very descriptive. I think "type" would be fine.
Quoted 2 lines
The information stored in this field will be retrieved in a future patch to hange the behaviour when the page is removed.
"change"
Quoted 56 lines
Also introduce
guest_physmap_add_entryto map and set a specific p2m type for a page.Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Rename 'avail' field to 'p2mt' in the p2m structure
- AddBUILD_BUG_ONto check if the enum value will fit in the field
- Implement grant mapping type--- xen/arch/arm/p2m.c | 58 ++++++++++++++++++++++++++++++++------------ xen/include/asm-arm/p2m.h | 18 +++++++++++--- xen/include/asm-arm/page.h | 2 +- 3 files changed, 58 insertions(+), 20 deletions(-)xen/arch/arm/p2m.c +18
-2@@ -124,7 +124,8 @@ int p2m_pod_decrease_reservation(struct domain *d,return -ENOSYS ; } -static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr) +static lpae_t mfn_to_p2m_entry (unsigned long mfn,unsigned int mattr, +p2m_type_t t) {paddr_t pa = ((paddr_t ) mfn) <<PAGE_SHIFT ;lpae_t e = (lpae_t ) {@@ -132,12 +133,34 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) .p2m.af = 1, .p2m.sh = LPAE_SH_OUTER, .p2m.read = 1, - .p2m.write = 1, .p2m.mattr = mattr, .p2m.table = 1, .p2m.valid = 1, + .p2m.p2mt = t, }; +BUILD_BUG_ON (p2m_max_real_type > (2 <<4 )); + +switch (t) + { +case p2m_grant_map_rw: + e.p2m.xn =1 ; +/* Fallthrough */ +case p2m_ram_rw: +case p2m_mmio_direct: +case p2m_map_foreign: + e.p2m.write =1 ; +break ; + +case p2m_grant_map_ro: + e.p2m.xn =1 ;
Quoted 9 lines
xen/arch/arm/p2m.c static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) · line 160
Quoted 4 lines
xen/arch/arm/p2m.c +4
-0+/* Fallthrough */ +case p2m_invalid: +case p2m_ram_ro: +default :I think you've enumerated all the options, so it is better to leave out the default -- then at least some compilers will complain if we add a new type and forget to add it here.
Ok. I will remove it.
Signature · 1 line
Julien Grall
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
In reply to Julien GrallQuoted 1 line · Julien Grall
+
BUILD_BUG_ON(p2m_max_real_type > (2 << 4));
2<<4 is 32.
I think you want either 1<<4, 2^4 or just 16 (my preference is 16). And I think it should be >= since the valid values are 0..15 inclusive.
Ian.
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
Quoted 6 lines · Ian Campbell
Quoted 1 line · Julien Grall
+
BUILD_BUG_ON(p2m_max_real_type > (2 << 4));2<<4 is 32.
I think you want either 1<<4, 2^4 or just 16 (my preference is 16). And
Right.
Quoted 1 line
I think it should be >= since the valid values are 0..15 inclusive.
No, because p2m_max_real_type won't be store in the p2m, so we can have 16 values [0..15] and p2m_max_real_type will be the 17th (ie 16).
Signature · 1 line
Julien Grall
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
Quoted 6 lines · Julien Grall
Quoted 5 lines · Ian Campbell
Quoted 1 line · Julien Grall
+
BUILD_BUG_ON(p2m_max_real_type > (2 << 4));2<<4 is 32.
Quoted 8 lines
Quoted 1 line
I think you want either 1<<4, 2^4 or just 16 (my preference is 16). And
Right.
Quoted 1 line
I think it should be >= since the valid values are 0..15 inclusive.
No, because
p2m_max_real_typewon't be store in the p2m, so we can have 16 values [0..15] andp2m_max_real_typewill be the 17th (ie 16).
If p2m_max_real_type will be the 17th (ie 16) then the check needs to be p2m_max_real_type >= 16.
Ian.
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
Quoted 11 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Quoted 6 lines · Ian Campbell
Quoted 1 line · Julien Grall
+
BUILD_BUG_ON(p2m_max_real_type > (2 << 4));2<<4 is 32.
I think you want either 1<<4, 2^4 or just 16 (my preference is 16). And
Right.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I think it should be >= since the valid values are 0..15 inclusive.
No, because
p2m_max_real_typewon't be store in the p2m, so we can have 16 values [0..15] andp2m_max_real_typewill be the 17th (ie 16).If
p2m_max_real_typewill be the 17th (ie 16) then the check needs to bep2m_max_real_type>= 16.
No because p2m_max_real_type = 16 is valid. Which is invalid is foo = 16 and p2m_max_real_type = 17.
Signature · 1 line
Julien Grall
Re: [PATCH v2 04/10] xen/arm: Store p2m type in each page of the guest
Quoted 15 lines · Julien Grall
Quoted 13 lines · Ian Campbell
Quoted 12 lines · Julien Grall
Quoted 6 lines · Ian Campbell
Quoted 1 line · Julien Grall
+
BUILD_BUG_ON(p2m_max_real_type > (2 << 4));2<<4 is 32.
I think you want either 1<<4, 2^4 or just 16 (my preference is 16). And
Right.
Quoted 1 line
I think it should be >= since the valid values are 0..15 inclusive.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
No, because
p2m_max_real_typewon't be store in the p2m, so we can have 16 values [0..15] andp2m_max_real_typewill be the 17th (ie 16).If
p2m_max_real_typewill be the 17th (ie 16) then the check needs to bep2m_max_real_type>= 16.No because
p2m_max_real_type= 16 is valid. Which is invalid is foo = 16 andp2m_max_real_type= 17.
Oh right, because it's actually the one after the last valid one.
OK.
Ian.
PATCH v2 5/10 xen/arm: p2m: Extend p2m_lookup parameters to retrieve the p2m type
In reply to Julien Grall---
Changes in v2:
- This patch was "Add p2m_get_entry" on the previous version
- Don't add a new function but only extend p2m_lookup
--- xen/arch/arm/p2m.c | 13 +++++++++++-- xen/arch/arm/traps.c | 6 +++--- xen/include/asm-arm/p2m.h | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-)
xen/arch/arm/p2m.c +11 -2
@@ -71,11 +71,17 @@ static lpae_t *p2m_map_first(struct p2m_domain *p2m, paddr_t addr)* There are no processor functions to do a stage 2 only lookup therefore we * do a a software walk. */ -paddr_t p2m_lookup (struct domain *d,paddr_t paddr) +paddr_t p2m_lookup (struct domain *d,paddr_t paddr,p2m_type_t *t) {struct p2m_domain *p2m = &d->arch.p2m;lpae_t pte, *first =NULL , *second =NULL , *third =NULL ;paddr_t maddr =INVALID_PADDR ; +p2m_type_t _t; + +/* Allow t to be NULL */ + t = t ?: &_t; + + *t = p2m_invalid;spin_lock (&p2m->lock);
@@ -99,7 +105,10 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr) done:if ( pte.p2m.valid ) + { maddr = (pte.bits &PADDR_MASK &PAGE_MASK ) | (paddr & ~PAGE_MASK ); + *t = pte.p2m.p2mt; + }if (third)unmap_domain_page (third);if (second)unmap_domain_page (second);
@@ -502,7 +511,7 @@ err:unsigned long gmfn_to_mfn (struct domain *d,unsigned long gpfn) { -paddr_t p =p2m_lookup (d,pfn_to_paddr (gpfn)); +paddr_t p =p2m_lookup (d,pfn_to_paddr (gpfn),NULL );return p >>PAGE_SHIFT ; }
xen/arch/arm/traps.c +3 -3
@@ -1267,7 +1267,7 @@ void dump_guest_s1_walk(struct domain *d, vaddr_t addr)printk ("dom%d VA 0x%08" PRIvaddr"\n" , d->domain_id, addr);printk (" TTBCR: 0x%08" PRIregister"\n" , ttbcr);printk (" TTBR0: 0x%016" PRIx64" = 0x%" PRIpaddr"\n" , - ttbr0,p2m_lookup (d, ttbr0 &PAGE_MASK )); + ttbr0,p2m_lookup (d, ttbr0 &PAGE_MASK ,NULL ));if ( ttbcr &TTBCR_EAE ) {
@@ -1280,7 +1280,7 @@ void dump_guest_s1_walk(struct domain *d, vaddr_t addr)return ; } - paddr =p2m_lookup (d, ttbr0 &PAGE_MASK ); + paddr =p2m_lookup (d, ttbr0 &PAGE_MASK ,NULL );if ( paddr ==INVALID_PADDR ) {printk ("Failed TTBR0 maddr lookup\n" );
@@ -1295,7 +1295,7 @@ void dump_guest_s1_walk(struct domain *d, vaddr_t addr) !(first[offset] & 0x2) ) goto done; - paddr =p2m_lookup (d, first[offset] &PAGE_MASK ); + paddr =p2m_lookup (d, first[offset] &PAGE_MASK ,NULL );if ( paddr ==INVALID_PADDR ) {
xen/include/asm-arm/p2m.h +1 -1
@@ -58,7 +58,7 @@ int p2m_alloc_table(struct domain *d);void p2m_load_VTTBR (struct domain *d);/* Look up the MFN corresponding to a domain's PFN. */ -paddr_t p2m_lookup (struct domain *d,paddr_t gpfn); +paddr_t p2m_lookup (struct domain *d,paddr_t gpfn,p2m_type_t *t);/* Setup p2m RAM mapping for domain d from start-end. */ int p2m_populate_ram (struct domain *d,paddr_t start,paddr_t end);
Signature · 1 line
1.7.10.4
Re: [PATCH v2 05/10] xen/arm: p2m: Extend p2m_lookup parameters to retrieve the p2m type
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
PATCH v2 6/10 xen/arm: Retrieve p2m type in get_page_from_gfn
In reply to Julien Grall---
Changes in v2:
- Use p2m_lookup as p2m_get_entry was removed
--- xen/include/asm-arm/p2m.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/include/asm-arm/p2m.h +2 -1
@@ -109,7 +109,8 @@ static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; -unsigned long mfn =gmfn_to_mfn (d, gfn); +paddr_t maddr =p2m_lookup (d,pfn_to_paddr (gfn), t); +unsigned long mfn = maddr >>PAGE_SHIFT ;if (!mfn_valid (mfn))return NULL ;
Signature · 1 line
1.7.10.4
Re: [PATCH v2 06/10] xen/arm: Retrieve p2m type in get_page_from_gfn
Quoted 14 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Usep2m_lookupasp2m_get_entrywas removed--- xen/include/asm-arm/p2m.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)xen/include/asm-arm/p2m.h +0
-0
xen/include/asm-arm/p2m.h static inline struct page_info *get_page_from_gfn( · line 113
Quoted 6 lines
xen/include/asm-arm/p2m.h +2
-1@@ -109,7 +109,8 @@ static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; -unsigned long mfn =gmfn_to_mfn (d, gfn); +paddr_t maddr =p2m_lookup (d,pfn_to_paddr (gfn), t); +unsigned long mfn = maddr >>PAGE_SHIFT ;
I think this resend happened before I replied to the original a second time, (in <[email protected]>) so you hadn't seen it.
TL;DR: INVALID_MADDR >> PAGE_SHIFT != INVALID_MFN on arm64.
Ian.
Re: [PATCH v2 06/10] xen/arm: Retrieve p2m type in get_page_from_gfn
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Usep2m_lookupasp2m_get_entrywas removed--- xen/include/asm-arm/p2m.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
xen/include/asm-arm/p2m.h static inline struct page_info *get_page_from_gfn( · line 113
Quoted 11 lines
xen/include/asm-arm/p2m.h +2
-1@@ -109,7 +109,8 @@ static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; -unsigned long mfn =gmfn_to_mfn (d, gfn); +paddr_t maddr =p2m_lookup (d,pfn_to_paddr (gfn), t); +unsigned long mfn = maddr >>PAGE_SHIFT ;I think this resend happened before I replied to the original a second time, (in <[email protected]>) so you hadn't seen it.
Indeed, I will fix it.
Quoted 1 line
TL;DR:
INVALID_MADDR>>PAGE_SHIFT!=INVALID_MFNon arm64.
Does it mean that INVALID_MFN can be a valid mfn on arm64? If so, we have some place in common code where this constant is used (see common/domain.c for instance).
Signature · 1 line
Julien Grall
Re: [PATCH v2 06/10] xen/arm: Retrieve p2m type in get_page_from_gfn
Quoted 27 lines · Julien Grall
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Usep2m_lookupasp2m_get_entrywas removed--- xen/include/asm-arm/p2m.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 15 lines
xen/include/asm-arm/p2m.h static inline struct page_info *get_page_from_gfn( · line 113
Quoted 11 lines
xen/include/asm-arm/p2m.h +2
-1@@ -109,7 +109,8 @@ static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; -unsigned long mfn =gmfn_to_mfn (d, gfn); +paddr_t maddr =p2m_lookup (d,pfn_to_paddr (gfn), t); +unsigned long mfn = maddr >>PAGE_SHIFT ;I think this resend happened before I replied to the original a second time, (in <[email protected]>) so you hadn't seen it.
Quoted 7 lines
Indeed, I will fix it.
Quoted 1 line
TL;DR:
INVALID_MADDR>>PAGE_SHIFT!=INVALID_MFNon arm64.Does it mean that
INVALID_MFNcan be a valid mfn on arm64? If so, we have some place in common code where this constant is used (seecommon/domain.cfor instance).
No, INVALID_MFN is 0xffffffffffffffff which is fine[0].
But given INVALID_MADDR of 0xffffffffffffffff, (INVALID_MADDR>>PAGE_SHIFT) is 0x000fffffffffffff.
Ian.
[0] actually, the page at -1 could in theory be valid on any platform, either arm32 or x86, bit a) it's unlikely and b) there isn't really any better value to use as this sentinal. Lets not worry about it right now.
Re: [PATCH v2 06/10] xen/arm: Retrieve p2m type in get_page_from_gfn
Quoted 32 lines · Ian Campbell
Quoted 31 lines · Julien Grall
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Usep2m_lookupasp2m_get_entrywas removed--- xen/include/asm-arm/p2m.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 15 lines
xen/include/asm-arm/p2m.h static inline struct page_info *get_page_from_gfn( · line 113
Quoted 11 lines
xen/include/asm-arm/p2m.h +2
-1@@ -109,7 +109,8 @@ static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; -unsigned long mfn =gmfn_to_mfn (d, gfn); +paddr_t maddr =p2m_lookup (d,pfn_to_paddr (gfn), t); +unsigned long mfn = maddr >>PAGE_SHIFT ;I think this resend happened before I replied to the original a second time, (in <[email protected]>) so you hadn't seen it.
Indeed, I will fix it.
Quoted 1 line
TL;DR:
INVALID_MADDR>>PAGE_SHIFT!=INVALID_MFNon arm64.
Quoted 8 lines
Quoted 3 lines
Does it mean that
INVALID_MFNcan be a valid mfn on arm64? If so, we have some place in common code where this constant is used (seecommon/domain.cfor instance).No,
INVALID_MFNis0xffffffffffffffffwhich is fine[0].But given
INVALID_MADDRof0xffffffffffffffff, (INVALID_MADDR>>PAGE_SHIFT) is0x000fffffffffffff.
oh right, I didn't pay attention for that. The patch is now fixed.
Signature · 1 line
Julien Grall
PATCH v2 7/10 xen/arm: Introduce relinquish_p2m_mapping to remove refcount every mapped page
In reply to Julien GrallThis function will be called when the domain relinquishes its memory. It removes refcount on every mapped page to a valid MFN.
Currently, Xen doesn't take refcount on every new mapping but only for foreign mapping. Restrict the function only on foreign mapping.
---
Changes in v2:
- Introduce the patch
--- xen/arch/arm/domain.c | 5 +++++ xen/arch/arm/p2m.c | 47 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 1 + xen/include/asm-arm/p2m.h | 15 ++++++++++++++ 4 files changed, 68 insertions(+)
xen/arch/arm/domain.c +5 -0
@@ -717,6 +717,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret; +case RELMEM_mapping: + ret =relinquish_p2m_mapping (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_done;/* Fallthrough */
xen/arch/arm/p2m.c +47 -0
71 lines not on this page · raw message
xen/include/asm-arm/domain.h +1 -0
@@ -75,6 +75,7 @@ struct arch_domain RELMEM_not_started, RELMEM_xen, RELMEM_page, + RELMEM_mapping, RELMEM_done, } relmem;
xen/include/asm-arm/p2m.h +15 -0
@@ -18,6 +18,15 @@ struct p2m_domain {/* Current VMID in use */ uint8_t vmid; + +/* Highest guest frame that's ever been mapped in the p2m +* Take only into account ram and foreign mapping +*/ +unsigned long max_mapped_gfn; + +/* When releasing mapped gfn's in a preemptible manner, recall where +* to resume the search */ +unsigned long next_gfn_to_relinquish; };/* List of possible type for each page in the p2m
@@ -48,6 +57,12 @@ int p2m_init(struct domain *d);/* Return all the p2m resources to Xen. */ void p2m_teardown (struct domain *d); +/* Remove mapping refcount on each mapping page in the p2m +* +* TODO: For the moment only foreign mapping is handled +*/ +int relinquish_p2m_mapping (struct domain *d); +/* Allocate a new p2m table for a domain. * * Returns 0 for success or -errno.
Signature · 1 line
1.7.10.4
Re: [PATCH v2 07/10] xen/arm: Introduce relinquish_p2m_mapping to remove refcount every mapped page
Quoted 5 lines · Julien Grall
This function will be called when the domain relinquishes its memory. It removes refcount on every mapped page to a valid MFN.
Currently, Xen doesn't take refcount on every new mapping but only for foreign mapping. Restrict the function only on foreign mapping.
Skimming the remainder of the patch's titles and recalling a previous conversation the intention is not to extend this for 4.4, correct?
Quoted 18 lines
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/domain.c | 5 +++++ xen/arch/arm/p2m.c | 47 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 1 + xen/include/asm-arm/p2m.h | 15 ++++++++++++++ 4 files changed, 68 insertions(+)xen/arch/arm/domain.c +0
-0
xen/arch/arm/domain.c int domain_relinquish_resources(struct domain *d) · line 720
Quoted 4 lines
xen/arch/arm/domain.c +1
-0@@ -717,6 +717,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret; +case RELMEM_mapping:
Something somewhere should be setting d->arch.relmem = RELMEM_mapping at the appropriate time. (immediately above I think?)
You also want a "Fallthrough" comment just above.
Quoted 47 lines
xen/arch/arm/domain.c +4
-0+ ret =relinquish_p2m_mapping (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_done;/* Fallthrough */ xen/arch/arm/p2m.c +14
-0@@ -6,6 +6,7 @@#include <xen/bitops.h> #include <asm/flushtlb.h> #include <asm/gic.h> +#include <asm/event.h> /* First level P2M is 2 consecutive pages */ #define P2M_FIRST_ORDER 1@@ -320,6 +321,16 @@ static int create_p2m_entries(struct domain *d,flush_tlb_all_local (); } +if ( (t == p2m_ram_rw) || (t == p2m_ram_ro) || (t == p2m_map_foreign)) + { +unsigned long sgfn =paddr_to_pfn (start_gpaddr); +unsigned long egfn =paddr_to_pfn (end_gpaddr); + + p2m->max_mapped_gfn =MAX (p2m->max_mapped_gfn, egfn); +/* Use next_gfn_to_relinquish to store the lowest gfn mapped */ + p2m->next_gfn_to_relinquish =MIN (p2m->next_gfn_to_relinquish, sgfn); + } + rc =0 ; out:@@ -503,12 +514,48 @@ int p2m_init(struct domain *d) p2m->first_level =NULL ; + p2m->max_mapped_gfn =0 ; + p2m->next_gfn_to_relinquish =ULONG_MAX ; + err:spin_unlock (&p2m->lock);return rc;
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 533
Quoted 10 lines
xen/arch/arm/p2m.c +8
-0} +int relinquish_p2m_mapping (struct domain *d) +{ +struct p2m_domain *p2m = &d->arch.p2m; +unsigned long gfn, count =0 ; +int rc =0 ; + +for ( gfn = p2m->next_gfn_to_relinquish; + gfn < p2m->max_mapped_gfn; gfn++ )
I know that Tim has been keen to get rid of these sorts of loops on x86, and with good reason I think.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 536
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +p2m_type_t t; +paddr_t p =p2m_lookup (d, gfn, &t);
This does the full walk for each address, even though 2/3 of the levels are more than likely identical to the previous gfn.
It would be better to do a full walk, which sadly will look a lot like p2m_lookup, no avoiding that I think.
You can still resume the walk based on next_gfn_to_relinquish and bound it on max_mapped_gfn, although I don't think it is strictly necessary.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 539
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+unsigned long mfn = p >>PAGE_SHIFT ; + +if (mfn_valid (mfn) &&p2m_is_foreign (t) )
I think it would be worth reiterating in a comment that we only take a ref for foreign mappings right now.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 542
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +put_page (mfn_to_page (mfn)); +guest_physmap_remove_page (d, gfn, mfn,0 );
You should unmap it and then put it I think.
Is this going to do yet another lookup/walk?
The REMOVE case of create_p2m_entries is so trivial you could open code it here, or if you wanted to you could refactor it into a helper.
I am wondering if the conditional put page ought to be at the point of removal (i.e. in the helper) rather than here. (I think Tim made a similar comment on the x86 version of the remove_from_physmap pvh patches, you probably need to match the generic change which that implies)
BTW, if you do the clear (but not the put_page) for every entry then the present bit (or pte.bits == 0) might be a useful proxy for next_lN_entry? I suppose even walking, say, 4GB of mostly empty P2M is not going to be super cheap.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 551
Quoted 9 lines
xen/arch/arm/p2m.c +9
-0+ } + + count++; + +/* Preempt every 2MiB. Arbitrary */ +if ( (count ==512 ) &&hypercall_preempt_check () ) + { + p2m->next_gfn_to_relinquish = gfn +1 ; + rc = -EAGAIN ;
I think I'm just failing to find it, but where is the call to hypercall_create_continuation? I suppose it is somewhere way up the stack?
I'm not sure the count == 512 is needed -- hypercall_preempt_check should be sufficient?
Quoted 55 lines
xen/arch/arm/p2m.c +7
-0+break ; + } + } + +return rc; +} +unsigned long gmfn_to_mfn (struct domain *d,unsigned long gpfn) {paddr_t p =p2m_lookup (d,pfn_to_paddr (gpfn),NULL );xen/include/asm-arm/domain.h +1
-0@@ -75,6 +75,7 @@ struct arch_domain RELMEM_not_started, RELMEM_xen, RELMEM_page, + RELMEM_mapping, RELMEM_done, } relmem;xen/include/asm-arm/p2m.h +15
-0@@ -18,6 +18,15 @@ struct p2m_domain {/* Current VMID in use */ uint8_t vmid; + +/* Highest guest frame that's ever been mapped in the p2m +* Take only into account ram and foreign mapping +*/ +unsigned long max_mapped_gfn; + +/* When releasing mapped gfn's in a preemptible manner, recall where +* to resume the search */ +unsigned long next_gfn_to_relinquish; };/* List of possible type for each page in the p2m @@ -48,6 +57,12 @@ int p2m_init(struct domain *d);/* Return all the p2m resources to Xen. */ void p2m_teardown (struct domain *d); +/* Remove mapping refcount on each mapping page in the p2m +* +* TODO: For the moment only foreign mapping is handled +*/ +int relinquish_p2m_mapping (struct domain *d); +/* Allocate a new p2m table for a domain. * * Returns 0 for success or -errno.
Re: [PATCH v2 07/10] xen/arm: Introduce relinquish_p2m_mapping to remove refcount every mapped page
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Julien Grall
This function will be called when the domain relinquishes its memory. It removes refcount on every mapped page to a valid MFN.
Currently, Xen doesn't take refcount on every new mapping but only for foreign mapping. Restrict the function only on foreign mapping.
Skimming the remainder of the patch's titles and recalling a previous conversation the intention is not to extend this for 4.4, correct?
Right, it's too big for Xen 4.4.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/domain.c | 5 +++++ xen/arch/arm/p2m.c | 47 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 1 + xen/include/asm-arm/p2m.h | 15 ++++++++++++++ 4 files changed, 68 insertions(+)xen/arch/arm/domain.c +0
-0@@ -717,6 +717,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret;
Quoted 6 lines
xen/arch/arm/domain.c int domain_relinquish_resources(struct domain *d) · line 720
Quoted 1 line
xen/arch/arm/domain.c +1
-0+case RELMEM_mapping:Something somewhere should be setting
d->arch.relmem=RELMEM_mappingat the appropriate time. (immediately above I think?)You also want a "Fallthrough" comment just above.
Oops, I will update the patch for the next version.
Quoted 71 lines
Quoted 47 lines
xen/arch/arm/domain.c +4
-0+ ret =relinquish_p2m_mapping (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_done;/* Fallthrough */ xen/arch/arm/p2m.c +14
-0@@ -6,6 +6,7 @@#include <xen/bitops.h> #include <asm/flushtlb.h> #include <asm/gic.h> +#include <asm/event.h> /* First level P2M is 2 consecutive pages */ #define P2M_FIRST_ORDER 1@@ -320,6 +321,16 @@ static int create_p2m_entries(struct domain *d,flush_tlb_all_local (); } +if ( (t == p2m_ram_rw) || (t == p2m_ram_ro) || (t == p2m_map_foreign)) + { +unsigned long sgfn =paddr_to_pfn (start_gpaddr); +unsigned long egfn =paddr_to_pfn (end_gpaddr); + + p2m->max_mapped_gfn =MAX (p2m->max_mapped_gfn, egfn); +/* Use next_gfn_to_relinquish to store the lowest gfn mapped */ + p2m->next_gfn_to_relinquish =MIN (p2m->next_gfn_to_relinquish, sgfn); + } + rc =0 ; out:@@ -503,12 +514,48 @@ int p2m_init(struct domain *d) p2m->first_level =NULL ; + p2m->max_mapped_gfn =0 ; + p2m->next_gfn_to_relinquish =ULONG_MAX ; + err:spin_unlock (&p2m->lock);return rc;xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 533
Quoted 10 lines
xen/arch/arm/p2m.c +8
-0} +int relinquish_p2m_mapping (struct domain *d) +{ +struct p2m_domain *p2m = &d->arch.p2m; +unsigned long gfn, count =0 ; +int rc =0 ; + +for ( gfn = p2m->next_gfn_to_relinquish; + gfn < p2m->max_mapped_gfn; gfn++ )I know that Tim has been keen to get rid of these sorts of loops on x86, and with good reason I think.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 536
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +p2m_type_t t; +paddr_t p =p2m_lookup (d, gfn, &t);This does the full walk for each address, even though 2/3 of the levels are more than likely identical to the previous gfn.
It would be better to do a full walk, which sadly will look a lot like
p2m_lookup, no avoiding that I think.
Quoted 8 lines
You can still resume the walk based on
next_gfn_to_relinquishand bound it onmax_mapped_gfn, although I don't think it is strictly necessary.xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 539
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+unsigned long mfn = p >>PAGE_SHIFT ; + +if (mfn_valid (mfn) &&p2m_is_foreign (t) )I think it would be worth reiterating in a comment that we only take a ref for foreign mappings right now.
Will do.
Quoted 17 lines
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 542
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +put_page (mfn_to_page (mfn)); +guest_physmap_remove_page (d, gfn, mfn,0 );You should unmap it and then put it I think.
Is this going to do yet another lookup/walk?
The REMOVE case of
create_p2m_entriesis so trivial you could open code it here, or if you wanted to you could refactor it into a helper.I am wondering if the conditional put page ought to be at the point of removal (i.e. in the helper) rather than here. (I think Tim made a similar comment on the x86 version of the
remove_from_physmappvh patches, you probably need to match the generic change which that implies)
Quoted 4 lines
BTW, if you do the clear (but not the
put_page) for every entry then the present bit (or pte.bits == 0) might be a useful proxy fornext_lN_entry? I suppose even walking, say, 4GB of mostly empty P2M is not going to be super cheap.
Following the discution we had IRL, I will try to extend create_p2m_entries by adding RELINQUISH option.
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+ } + + count++; + +/* Preempt every 2MiB. Arbitrary */
Quoted 8 lines
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 551
Quoted 4 lines
xen/arch/arm/p2m.c +4
-0+if ( (count ==512 ) &&hypercall_preempt_check () ) + { + p2m->next_gfn_to_relinquish = gfn +1 ; + rc = -EAGAIN ;I think I'm just failing to find it, but where is the call to
hypercall_create_continuation? I suppose it is somewhere way up the stack?
Actually rc = -EAGAIN will be catched by xc_domain_destroy in libxc. The function will call again the hypercall if needed.
I'm not sure why... do you have any idea why x86 also uses this trick?
Quoted 2 lines
I'm not sure the count == 512 is needed --
hypercall_preempt_checkshould be sufficient?
On ARM hypercall_preempt_check is a bit complex. Checking every loop seems a bit overkill.
Signature · 1 line
Julien Grall
Re: [PATCH v2 07/10] xen/arm: Introduce relinquish_p2m_mapping to remove refcount every mapped page
Quoted 173 lines · Julien Grall
Quoted 10 lines · Ian Campbell
Quoted 6 lines · Julien Grall
This function will be called when the domain relinquishes its memory. It removes refcount on every mapped page to a valid MFN.
Currently, Xen doesn't take refcount on every new mapping but only for foreign
mapping. Restrict the function only on foreign mapping.Skimming the remainder of the patch's titles and recalling a previous conversation the intention is not to extend this for 4.4, correct?
Right, it's too big for Xen 4.4.
Quoted 22 lines
Quoted 22 lines
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/domain.c | 5 +++++ xen/arch/arm/p2m.c | 47 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 1 + xen/include/asm-arm/p2m.h | 15 ++++++++++++++ 4 files changed, 68 insertions(+)xen/arch/arm/domain.c +0
-0@@ -717,6 +717,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret;Quoted 6 lines
xen/arch/arm/domain.c int domain_relinquish_resources(struct domain *d) · line 720
Quoted 1 line
xen/arch/arm/domain.c +1
-0+case RELMEM_mapping:Something somewhere should be setting
d->arch.relmem=RELMEM_mappingat the appropriate time. (immediately above I think?)You also want a "Fallthrough" comment just above.
Oops, I will update the patch for the next version.
Quoted 73 lines
Quoted 49 lines
xen/arch/arm/domain.c +4
-0+ ret =relinquish_p2m_mapping (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_done;/* Fallthrough */ xen/arch/arm/p2m.c +11
-0@@ -6,6 +6,7 @@#include <xen/bitops.h> #include <asm/flushtlb.h> #include <asm/gic.h> +#include <asm/event.h> /* First level P2M is 2 consecutive pages */ #define P2M_FIRST_ORDER 1@@ -320,6 +321,16 @@ static int create_p2m_entries(struct domain *d,flush_tlb_all_local (); } +if ( (t == p2m_ram_rw) || (t == p2m_ram_ro) || (t == p2m_map_foreign)) + { +unsigned long sgfn =paddr_to_pfn (start_gpaddr); +unsigned long egfn =paddr_to_pfn (end_gpaddr); + + p2m->max_mapped_gfn =MAX (p2m->max_mapped_gfn, egfn); +/* Use next_gfn_to_relinquish to store the lowest gfn mapped */ + p2m->next_gfn_to_relinquish =MIN (p2m->next_gfn_to_relinquish, sgfn); + } + rc =0 ;out:
xen/arch/arm/p2m.c +3
-0@@ -503,12 +514,48 @@ int p2m_init(struct domain *d) p2m->first_level =NULL ; + p2m->max_mapped_gfn =0 ; + p2m->next_gfn_to_relinquish =ULONG_MAX ; + err:spin_unlock (&p2m->lock);return rc;xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 533
Quoted 10 lines
xen/arch/arm/p2m.c +8
-0} +int relinquish_p2m_mapping (struct domain *d) +{ +struct p2m_domain *p2m = &d->arch.p2m; +unsigned long gfn, count =0 ; +int rc =0 ; + +for ( gfn = p2m->next_gfn_to_relinquish; + gfn < p2m->max_mapped_gfn; gfn++ )I know that Tim has been keen to get rid of these sorts of loops on x86, and with good reason I think.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 536
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +p2m_type_t t; +paddr_t p =p2m_lookup (d, gfn, &t);This does the full walk for each address, even though 2/3 of the levels are more than likely identical to the previous gfn.
It would be better to do a full walk, which sadly will look a lot like
p2m_lookup, no avoiding that I think.Quoted 8 lines
You can still resume the walk based on
next_gfn_to_relinquishand bound it onmax_mapped_gfn, although I don't think it is strictly necessary.xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 539
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+unsigned long mfn = p >>PAGE_SHIFT ; + +if (mfn_valid (mfn) &&p2m_is_foreign (t) )I think it would be worth reiterating in a comment that we only take a ref for foreign mappings right now.
Will do.
Quoted 17 lines
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 542
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +put_page (mfn_to_page (mfn)); +guest_physmap_remove_page (d, gfn, mfn,0 );You should unmap it and then put it I think.
Is this going to do yet another lookup/walk?
The REMOVE case of
create_p2m_entriesis so trivial you could open code it here, or if you wanted to you could refactor it into a helper.I am wondering if the conditional put page ought to be at the point of removal (i.e. in the helper) rather than here. (I think Tim made a similar comment on the x86 version of the
remove_from_physmappvh patches, you probably need to match the generic change which that implies)Quoted 4 lines
BTW, if you do the clear (but not the
put_page) for every entry then the present bit (or pte.bits == 0) might be a useful proxy fornext_lN_entry? I suppose even walking, say, 4GB of mostly empty P2M is not going to be super cheap.Following the discution we had IRL, I will try to extend
create_p2m_entriesby adding RELINQUISH option.Quoted 5 lines
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+ } + + count++; + +/* Preempt every 2MiB. Arbitrary */ Quoted 8 lines
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 551
Quoted 4 lines
xen/arch/arm/p2m.c +4
-0+if ( (count ==512 ) &&hypercall_preempt_check () ) + { + p2m->next_gfn_to_relinquish = gfn +1 ; + rc = -EAGAIN ;I think I'm just failing to find it, but where is the call to
hypercall_create_continuation? I suppose it is somewhere way up the stack?Actually rc =
-EAGAINwill be catched byxc_domain_destroyin libxc. The function will call again the hypercall if needed.
Quoted 8 lines
I'm not sure why... do you have any idea why x86 also uses this trick?
Quoted 2 lines
I'm not sure the count == 512 is needed --
hypercall_preempt_checkshould be sufficient?On ARM
hypercall_preempt_checkis a bit complex. Checking every loop seems a bit overkill.
So I gave a try to remove the (count == 512) and it's very very slow (more than 10 times slower). So I will keep it.
Signature · 1 line
Julien Grall
Re: [PATCH v2 07/10] xen/arm: Introduce relinquish_p2m_mapping to remove refcount every mapped page
In reply to Julien GrallQuoted 143 lines · Julien Grall
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Julien Grall
This function will be called when the domain relinquishes its memory. It removes refcount on every mapped page to a valid MFN.
Currently, Xen doesn't take refcount on every new mapping but only for foreign mapping. Restrict the function only on foreign mapping.
Skimming the remainder of the patch's titles and recalling a previous conversation the intention is not to extend this for 4.4, correct?
Right, it's too big for Xen 4.4.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/domain.c | 5 +++++ xen/arch/arm/p2m.c | 47 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 1 + xen/include/asm-arm/p2m.h | 15 ++++++++++++++ 4 files changed, 68 insertions(+)xen/arch/arm/domain.c +0
-0@@ -717,6 +717,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret;Quoted 6 lines
xen/arch/arm/domain.c int domain_relinquish_resources(struct domain *d) · line 720
Quoted 1 line
xen/arch/arm/domain.c +1
-0+case RELMEM_mapping:Something somewhere should be setting
d->arch.relmem=RELMEM_mappingat the appropriate time. (immediately above I think?)You also want a "Fallthrough" comment just above.
Oops, I will update the patch for the next version.
Quoted 71 lines
Quoted 47 lines
xen/arch/arm/domain.c +4
-0+ ret =relinquish_p2m_mapping (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_done;/* Fallthrough */ xen/arch/arm/p2m.c +14
-0@@ -6,6 +6,7 @@#include <xen/bitops.h> #include <asm/flushtlb.h> #include <asm/gic.h> +#include <asm/event.h> /* First level P2M is 2 consecutive pages */ #define P2M_FIRST_ORDER 1@@ -320,6 +321,16 @@ static int create_p2m_entries(struct domain *d,flush_tlb_all_local (); } +if ( (t == p2m_ram_rw) || (t == p2m_ram_ro) || (t == p2m_map_foreign)) + { +unsigned long sgfn =paddr_to_pfn (start_gpaddr); +unsigned long egfn =paddr_to_pfn (end_gpaddr); + + p2m->max_mapped_gfn =MAX (p2m->max_mapped_gfn, egfn); +/* Use next_gfn_to_relinquish to store the lowest gfn mapped */ + p2m->next_gfn_to_relinquish =MIN (p2m->next_gfn_to_relinquish, sgfn); + } + rc =0 ; out:@@ -503,12 +514,48 @@ int p2m_init(struct domain *d) p2m->first_level =NULL ; + p2m->max_mapped_gfn =0 ; + p2m->next_gfn_to_relinquish =ULONG_MAX ; + err:spin_unlock (&p2m->lock);return rc;xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 533
Quoted 10 lines
xen/arch/arm/p2m.c +8
-0} +int relinquish_p2m_mapping (struct domain *d) +{ +struct p2m_domain *p2m = &d->arch.p2m; +unsigned long gfn, count =0 ; +int rc =0 ; + +for ( gfn = p2m->next_gfn_to_relinquish; + gfn < p2m->max_mapped_gfn; gfn++ )I know that Tim has been keen to get rid of these sorts of loops on x86, and with good reason I think.
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 536
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +p2m_type_t t; +paddr_t p =p2m_lookup (d, gfn, &t);This does the full walk for each address, even though 2/3 of the levels are more than likely identical to the previous gfn.
It would be better to do a full walk, which sadly will look a lot like
p2m_lookup, no avoiding that I think.Quoted 8 lines
You can still resume the walk based on
next_gfn_to_relinquishand bound it onmax_mapped_gfn, although I don't think it is strictly necessary.xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 539
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+unsigned long mfn = p >>PAGE_SHIFT ; + +if (mfn_valid (mfn) &&p2m_is_foreign (t) )I think it would be worth reiterating in a comment that we only take a ref for foreign mappings right now.
Will do.
Quoted 17 lines
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 542
Quoted 3 lines
xen/arch/arm/p2m.c +3
-0+ { +put_page (mfn_to_page (mfn)); +guest_physmap_remove_page (d, gfn, mfn,0 );You should unmap it and then put it I think.
Is this going to do yet another lookup/walk?
The REMOVE case of
create_p2m_entriesis so trivial you could open code it here, or if you wanted to you could refactor it into a helper.I am wondering if the conditional put page ought to be at the point of removal (i.e. in the helper) rather than here. (I think Tim made a similar comment on the x86 version of the
remove_from_physmappvh patches, you probably need to match the generic change which that implies)
Quoted 7 lines
Quoted 4 lines
BTW, if you do the clear (but not the
put_page) for every entry then the present bit (or pte.bits == 0) might be a useful proxy fornext_lN_entry? I suppose even walking, say, 4GB of mostly empty P2M is not going to be super cheap.Following the discution we had IRL, I will try to extend
create_p2m_entriesby adding RELINQUISH option.
Looking at it again this morning the main change in behaviour will be to continue on non-present entries instead of either filling them in or aborting. It'll be interesting to see how this new mode of operation fits into the function...
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+ } + + count++; + +/* Preempt every 2MiB. Arbitrary */ Quoted 8 lines
xen/arch/arm/p2m.c int p2m_init(struct domain *d) · line 551
Quoted 4 lines
xen/arch/arm/p2m.c +4
-0+if ( (count ==512 ) &&hypercall_preempt_check () ) + { + p2m->next_gfn_to_relinquish = gfn +1 ; + rc = -EAGAIN ;I think I'm just failing to find it, but where is the call to
hypercall_create_continuation? I suppose it is somewhere way up the stack?
Quoted 2 lines
Actually rc =
-EAGAINwill be catched byxc_domain_destroyin libxc. The function will call again the hypercall if needed.
Ah, I only followed the call chain on the hypervisor side.
Quoted 1 line
I'm not sure why... do you have any idea why x86 also uses this trick?
I suspect that this operation is so long running that it is beneficial to return all the way to userspace context in order to allow other processes to be scheduled. Avoiding the kernel's softlockup timer etc.
A hypercall continuation only give the opportunity for the guest kernel to process interrupts IIRC.
Quoted 5 lines
Quoted 2 lines
I'm not sure the count == 512 is needed --
hypercall_preempt_checkshould be sufficient?On ARM
hypercall_preempt_checkis a bit complex. Checking every loop seems a bit overkill.
OK. I see now that existing code has a mixture, every 512 is fine. Perhaps using LPAE_ENTRIES is a little bit less arbitrary (although it remains almost completely so...)
Ian.
PATCH v2 8/10 xen/arm: Implement xen_rem_foreign_from_p2m
In reply to Julien Grall---
Changes in v2:
- Introduce the patch
--- xen/arch/arm/mm.c | 16 ++++++++++++++++ xen/include/asm-arm/p2m.h | 6 +----- 2 files changed, 17 insertions(+), 5 deletions(-)
xen/arch/arm/mm.c +16 -0
@@ -968,6 +968,22 @@ void share_xen_page_with_privileged_guests(share_xen_page_with_guest (page, dom_xen, readonly); } +int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn) +{ +unsigned long mfn =gmfn_to_mfn (d, gpfn); +if ( !mfn_valid (mfn) ) + { +gdprintk (XENLOG_WARNING ,"Invalid mfn for gpfn:%lx domid:%d\n" , + gpfn, d->domain_id); +return -EINVAL ; + } + +guest_physmap_remove_page (d, gpfn, mfn,0 ); +put_page (mfn_to_page (mfn)); + +return 0 ; +} + static int xenmem_add_to_physmap_one( struct domain *d, uint16_t space,
xen/include/asm-arm/p2m.h +1 -5
@@ -152,11 +152,7 @@ static inline int get_page_and_type(struct page_info *page, return rc; } -static inline int xenmem_rem_foreign_from_p2m (struct domain *d, -unsigned long gpfn) -{ -return -ENOSYS ; -} +int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn);#endif /* _XEN_P2M_H */
Signature · 1 line
1.7.10.4
Re: [PATCH v2 08/10] xen/arm: Implement xen_rem_foreign_from_p2m
Quoted 15 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/mm.c | 16 ++++++++++++++++ xen/include/asm-arm/p2m.h | 6 +----- 2 files changed, 17 insertions(+), 5 deletions(-)xen/arch/arm/mm.c +0
-0
xen/arch/arm/mm.c void share_xen_page_with_privileged_guests( · line 977
Quoted 10 lines
xen/arch/arm/mm.c +7
-0@@ -968,6 +968,22 @@ void share_xen_page_with_privileged_guests(share_xen_page_with_guest (page, dom_xen, readonly); } +int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn) +{ +unsigned long mfn =gmfn_to_mfn (d, gpfn); +if ( !mfn_valid (mfn) ) + { +gdprintk (XENLOG_WARNING ,"Invalid mfn for gpfn:%lx domid:%d\n" , + gpfn, d->domain_id);
Is this guest triggerable? Or does it indicate a mistake when we made the mapping?
xen/arch/arm/mm.c void share_xen_page_with_privileged_guests( · line 982
Quoted 5 lines
xen/arch/arm/mm.c +5
-0+return -EINVAL ; + } + +guest_physmap_remove_page (d, gpfn, mfn,0 ); +put_page (mfn_to_page (mfn));
Some of this could become a common helper with create_p2m_entries and the relinquish stuff in the previous patch.
Quoted 24 lines
xen/arch/arm/mm.c +4
-0+ +return 0 ; +} + static int xenmem_add_to_physmap_one( struct domain *d, uint16_t space,xen/include/asm-arm/p2m.h +1
-5@@ -152,11 +152,7 @@ static inline int get_page_and_type(struct page_info *page, return rc; } -static inline int xenmem_rem_foreign_from_p2m (struct domain *d, -unsigned long gpfn) -{ -return -ENOSYS ; -} +int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn);#endif /* _XEN_P2M_H */
Re: [PATCH v2 08/10] xen/arm: Implement xen_rem_foreign_from_p2m
Quoted 19 lines · Ian Campbell
Quoted 18 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/mm.c | 16 ++++++++++++++++ xen/include/asm-arm/p2m.h | 6 +----- 2 files changed, 17 insertions(+), 5 deletions(-)xen/arch/arm/mm.c +0
-0@@ -968,6 +968,22 @@ void share_xen_page_with_privileged_guests(share_xen_page_with_guest (page, dom_xen, readonly); }
Quoted 10 lines
xen/arch/arm/mm.c void share_xen_page_with_privileged_guests( · line 977
Quoted 7 lines
xen/arch/arm/mm.c +7
-0+int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn) +{ +unsigned long mfn =gmfn_to_mfn (d, gpfn); +if ( !mfn_valid (mfn) ) + { +gdprintk (XENLOG_WARNING ,"Invalid mfn for gpfn:%lx domid:%d\n" , + gpfn, d->domain_id);Is this guest triggerable? Or does it indicate a mistake when we made the mapping?
It indicates a mistake when we made the mapping. Perhaps an ASSERT is better here.
Quoted 9 lines
xen/arch/arm/mm.c void share_xen_page_with_privileged_guests( · line 982
Quoted 6 lines
xen/arch/arm/mm.c +5
-0+return -EINVAL ; + } + +guest_physmap_remove_page (d, gpfn, mfn,0 ); +put_page (mfn_to_page (mfn));Some of this could become a common helper with
create_p2m_entriesand the relinquish stuff in the previous patch.
The best solution is to move put_page in guest_physmap_remove_page. But as we didn't plan to handle refcount for each mapping in Xen 4.4, perhaps we can delay it?
Signature · 1 line
Julien Grall
Re: [PATCH v2 08/10] xen/arm: Implement xen_rem_foreign_from_p2m
Quoted 31 lines · Julien Grall
Quoted 19 lines · Ian Campbell
Quoted 18 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Introduce the patch--- xen/arch/arm/mm.c | 16 ++++++++++++++++ xen/include/asm-arm/p2m.h | 6 +----- 2 files changed, 17 insertions(+), 5 deletions(-)xen/arch/arm/mm.c +0
-0@@ -968,6 +968,22 @@ void share_xen_page_with_privileged_guests(share_xen_page_with_guest (page, dom_xen, readonly); }Quoted 10 lines
xen/arch/arm/mm.c void share_xen_page_with_privileged_guests( · line 977
Quoted 7 lines
xen/arch/arm/mm.c +7
-0+int xenmem_rem_foreign_from_p2m (struct domain *d,unsigned long gpfn) +{ +unsigned long mfn =gmfn_to_mfn (d, gpfn); +if ( !mfn_valid (mfn) ) + { +gdprintk (XENLOG_WARNING ,"Invalid mfn for gpfn:%lx domid:%d\n" , + gpfn, d->domain_id);Is this guest triggerable? Or does it indicate a mistake when we made the mapping?
Quoted 2 lines
It indicates a mistake when we made the mapping. Perhaps an ASSERT is better here.
In that case either works for me.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
xen/arch/arm/mm.c +5
-0+return -EINVAL ; + } + +guest_physmap_remove_page (d, gpfn, mfn,0 ); +put_page (mfn_to_page (mfn));
Quoted 6 lines
Quoted 2 lines
Some of this could become a common helper with
create_p2m_entriesand the relinquish stuff in the previous patch.The best solution is to move
put_pageinguest_physmap_remove_page. But as we didn't plan to handle refcount for each mapping in Xen 4.4, perhaps we can delay it?
You can move it and still have it be conditional I think, since g_p_r_p can see the type in the pte, can't it?
Ian.
Re: [PATCH v2 08/10] xen/arm: Implement xen_rem_foreign_from_p2m
Quoted 3 lines · Ian Campbell
Quoted 2 lines · Julien Grall
Quoted 1 line · Ian Campbell
On Mon, 2013-12-09 at 03:34 +0000, Julien Grall wrote:
[..]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
xen/arch/arm/mm.c void share_xen_page_with_privileged_guests( · line 982
Quoted 7 lines
xen/arch/arm/mm.c +5
-0+return -EINVAL ; + } + +guest_physmap_remove_page (d, gpfn, mfn,0 ); +put_page (mfn_to_page (mfn));Some of this could become a common helper with
create_p2m_entriesand the relinquish stuff in the previous patch.
Quoted 6 lines
Quoted 3 lines
The best solution is to move
put_pageinguest_physmap_remove_page. But as we didn't plan to handle refcount for each mapping in Xen 4.4, perhaps we can delay it?You can move it and still have it be conditional I think, since
g_p_r_pcan see the type in the pte, can't it?
I plan to move the put_page in create_p2m_entries and check pte type.
Signature · 1 line
Julien Grall
PATCH v2 9/10 xen/arm: Set foreign page type to p2m_map_foreign
In reply to Julien GrallXen needs to know that the current page belongs to another domain. Also take the refcount to this page.
---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.
--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
xen/arch/arm/mm.c +16 -8
@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {
@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;
@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page. +* Refcount will be release in XENMEM_remove_from_physmap */ + page =get_page_from_gfn (od, idx,NULL ,P2M_ALLOC ); +if ( !page ) {dump_p2m_lookup (od,pfn_to_paddr (idx));rcu_unlock_domain (od);return -EINVAL ; } - mfn = maddr >>PAGE_SHIFT ; + mfn =page_to_mfn (page); + t = p2m_map_foreign;rcu_unlock_domain (od);break ;
@@ -1067,7 +1075,7 @@ static int xenmem_add_to_physmap_one( }/* Map at new location. */ - rc =guest_physmap_add_page (d, gpfn, mfn,0 ); + rc =guest_physmap_add_entry (d, gpfn, mfn,0 , t);return rc; }
Signature · 1 line
1.7.10.4
Re: [PATCH v2 09/10] xen/arm: Set foreign page type to p2m_map_foreign
Quoted 54 lines · Julien Grall
Xen needs to know that the current page belongs to another domain. Also take the refcount to this page.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)xen/arch/arm/mm.c +9
-4@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1056
Quoted 6 lines
xen/arch/arm/mm.c +1
-2@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page.
"refcount on...". Or "Take a reference to..."
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1057
Quoted 1 line
xen/arch/arm/mm.c +1
-0+* Refcount will be release in XENMEM_remove_from_physmap */
and a few other places...
Like with the unmap it might be best to push this reference manipulation down into the eventual function which makes the mapping. That would keep this stuff much more localised.
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1058
Quoted 1 line
xen/arch/arm/mm.c +1
-0+ page =get_page_from_gfn (od, idx,NULL ,P2M_ALLOC );
This made me wonder what happens if the guest drops its mapping while the foreign one is around. At least the page won't be freed until the foreign mapping goes away, but it won't be what the tools think it is.
I think this is probably OK, or at least I'm not sure right now what we could do about it.
Quoted 22 lines
xen/arch/arm/mm.c +4
-2+if ( !page ) {dump_p2m_lookup (od,pfn_to_paddr (idx));rcu_unlock_domain (od);return -EINVAL ; } - mfn = maddr >>PAGE_SHIFT ; + mfn =page_to_mfn (page); + t = p2m_map_foreign;rcu_unlock_domain (od);break ;@@ -1067,7 +1075,7 @@ static int xenmem_add_to_physmap_one( }/* Map at new location. */ - rc =guest_physmap_add_page (d, gpfn, mfn,0 ); + rc =guest_physmap_add_entry (d, gpfn, mfn,0 , t);return rc; }
Re: [PATCH v2 09/10] xen/arm: Set foreign page type to p2m_map_foreign
Quoted 72 lines · Ian Campbell
Quoted 54 lines · Julien Grall
Xen needs to know that the current page belongs to another domain. Also take the refcount to this page.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)xen/arch/arm/mm.c +9
-4@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1056
Quoted 6 lines
xen/arch/arm/mm.c +1
-2@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page. "refcount on...". Or "Take a reference to..."
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1057
Quoted 1 line
xen/arch/arm/mm.c +1
-0+* Refcount will be release in XENMEM_remove_from_physmap */ and a few other places...
Like with the unmap it might be best to push this reference manipulation down into the eventual function which makes the mapping. That would keep this stuff much more localised.
Quoted 5 lines
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1058
Quoted 1 line
xen/arch/arm/mm.c +1
-0+ page =get_page_from_gfn (od, idx,NULL ,P2M_ALLOC );This made me wonder what happens if the guest drops its mapping while the foreign one is around. At least the page won't be freed until the foreign mapping goes away, but it won't be what the tools think it is.
In this case, the domain will get wrong data and can crash. It won't corrupted the domain who mapped the foreign mapping.
Signature · 1 line
Julien Grall
Re: [PATCH v2 09/10] xen/arm: Set foreign page type to p2m_map_foreign
In reply to Ian CampbellQuoted 64 lines · Ian Campbell
Quoted 54 lines · Julien Grall
Xen needs to know that the current page belongs to another domain. Also take the refcount to this page.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)xen/arch/arm/mm.c +9
-4@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1056
Quoted 6 lines
xen/arch/arm/mm.c +1
-2@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page. "refcount on...". Or "Take a reference to..."
Quoted 7 lines
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1057
Quoted 1 line
xen/arch/arm/mm.c +1
-0+* Refcount will be release in XENMEM_remove_from_physmap */ and a few other places...
Like with the unmap it might be best to push this reference manipulation down into the eventual function which makes the mapping. That would keep this stuff much more localised.
Forget to answer to this part:
We need to take the reference with foreign domain in parameter, otherwise we don't really know if the foreign domain has unlikely removed the mapping between the hypercall was called and now.
Signature · 1 line
Julien Grall
Re: [PATCH v2 09/10] xen/arm: Set foreign page type to p2m_map_foreign
Quoted 74 lines · Julien Grall
Quoted 64 lines · Ian Campbell
Quoted 54 lines · Julien Grall
Xen needs to know that the current page belongs to another domain. Also take the refcount to this page.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)xen/arch/arm/mm.c +9
-4@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1056
Quoted 6 lines
xen/arch/arm/mm.c +1
-2@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page. "refcount on...". Or "Take a reference to..."
Quoted 7 lines
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1057
Quoted 1 line
xen/arch/arm/mm.c +1
-0+* Refcount will be release in XENMEM_remove_from_physmap */ and a few other places...
Like with the unmap it might be best to push this reference manipulation down into the eventual function which makes the mapping. That would keep this stuff much more localised.
Quoted 5 lines
Forget to answer to this part:
We need to take the reference with foreign domain in parameter, otherwise we don't really know if the foreign domain has unlikely removed the mapping between the hypercall was called and now.
Are we not holding the p2m lock at this point?
We probably do need to do the final check and unmap with the lock held. Either by moving the unmap within the same lock as the lookup or perhaps with some sort of cmpxchg mechanism where we pass in the pte value we think we are tearing down. Just checking the type may not be sufficient if the guest tears down one foreign mapping and replaces it with another.
Ian.
Re: [PATCH v2 09/10] xen/arm: Set foreign page type to p2m_map_foreign
Quoted 75 lines · Ian Campbell
Quoted 74 lines · Julien Grall
Quoted 71 lines · Ian Campbell
Quoted 54 lines · Julien Grall
Xen needs to know that the current page belongs to another domain. Also take the refcount to this page.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)xen/arch/arm/mm.c +9
-4@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1056
Quoted 6 lines
xen/arch/arm/mm.c +1
-2@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page. "refcount on...". Or "Take a reference to..."
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1057
Quoted 1 line
xen/arch/arm/mm.c +1
-0+* Refcount will be release in XENMEM_remove_from_physmap */ and a few other places...
Like with the unmap it might be best to push this reference manipulation down into the eventual function which makes the mapping. That would keep this stuff much more localised.
Quoted 7 lines
Quoted 5 lines
Forget to answer to this part:
We need to take the reference with foreign domain in parameter, otherwise we don't really know if the foreign domain has unlikely removed the mapping between the hypercall was called and now.
Are we not holding the p2m lock at this point?
p2m lock of which domain? For now, neither of foreign and current domain lock are taken in this function.
Quoted 6 lines
We probably do need to do the final check and unmap with the lock held. Either by moving the unmap within the same lock as the lookup or perhaps with some sort of cmpxchg mechanism where we pass in the pte value we think we are tearing down. Just checking the type may not be sufficient if the guest tears down one foreign mapping and replaces it with another.
I'm not sure to follow you, are you talking about remove the foreign mapping? If so, I have reworking all the removing code to include the put_page (see V3).
Signature · 1 line
Julien Grall
Re: [PATCH v2 09/10] xen/arm: Set foreign page type to p2m_map_foreign
Quoted 79 lines · Julien Grall
Quoted 77 lines · Ian Campbell
Quoted 76 lines · Julien Grall
Quoted 64 lines · Ian Campbell
Quoted 54 lines · Julien Grall
Xen needs to know that the current page belongs to another domain. Also take the refcount to this page.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized values.--- xen/arch/arm/mm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)xen/arch/arm/mm.c +9
-4@@ -993,6 +993,7 @@ static int xenmem_add_to_physmap_one( {unsigned long mfn =0 ;int rc; +p2m_type_t t;switch ( space ) {@@ -1025,18 +1026,22 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; +spin_unlock (&d->grant_table->lock);break ;case XENMAPSPACE_shared_info: -if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); -else +if ( idx !=0 )return -EINVAL ; + + mfn =virt_to_mfn (d->shared_info); + t = p2m_ram_rw; +break ;case XENMAPSPACE_gmfn_foreign: { -paddr_t maddr;struct domain *od; +struct page_info *page; od =rcu_lock_domain_by_any_id (foreign_domid);if ( od ==NULL )return -ESRCH ;xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1056
Quoted 6 lines
xen/arch/arm/mm.c +1
-2@@ -1048,15 +1053,18 @@ static int xenmem_add_to_physmap_one(return rc; } - maddr =p2m_lookup (od,pfn_to_paddr (idx)); -if ( maddr ==INVALID_PADDR ) +/* Take refcount to the foreign domain page. "refcount on...". Or "Take a reference to..."
Quoted 7 lines
xen/arch/arm/mm.c static int xenmem_add_to_physmap_one( · line 1057
Quoted 1 line
xen/arch/arm/mm.c +1
-0+* Refcount will be release in XENMEM_remove_from_physmap */ and a few other places...
Like with the unmap it might be best to push this reference manipulation down into the eventual function which makes the mapping. That would keep this stuff much more localised.
Forget to answer to this part:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
We need to take the reference with foreign domain in parameter, otherwise we don't really know if the foreign domain has unlikely removed the mapping between the hypercall was called and now.
Are we not holding the p2m lock at this point?
p2m lock of which domain? For now, neither of foreign and current domain lock are taken in this function.
Possibly both? We need to make sure that the foreign entry we are referencing doesn't get pulled out from under us, and also protect against simultaneous modification of the one we are adding two.
Quoted 10 lines
Quoted 6 lines
We probably do need to do the final check and unmap with the lock held. Either by moving the unmap within the same lock as the lookup or perhaps with some sort of cmpxchg mechanism where we pass in the pte value we think we are tearing down. Just checking the type may not be sufficient if the guest tears down one foreign mapping and replaces it with another.
I'm not sure to follow you, are you talking about remove the foreign mapping? If so, I have reworking all the removing code to include the
put_page(see V3).
This will probably help, by moving it within the locked region. On teardown we only need to care about the p2m of the entry we are removing, not the foreign one.
Ian.
PATCH v2 10/10 xen/arm: grant-table: Support read-only mapping
In reply to Julien Grall---
Changes in v2:
- Use p2m grant type to map grant-table mapping
--- xen/arch/arm/mm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
xen/arch/arm/mm.c +5 -7
@@ -1297,19 +1297,17 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, unsigned int flags, unsigned int cache_flags) { int rc; +p2m_type_t t = p2m_grant_map_rw;if ( cache_flags || (flags & ~GNTMAP_readonly) != GNTMAP_host_map )return GNTST_general_error; -/* XXX: read only mappings */ if ( flags & GNTMAP_readonly ) - { -gdprintk (XENLOG_WARNING ,"read only mappings not implemented yet\n" ); -return GNTST_general_error; - } + t = p2m_grant_map_ro; + + rc =guest_physmap_add_entry (current->domain, addr >>PAGE_SHIFT , + frame,0 , t); - rc =guest_physmap_add_page (current->domain, - addr >>PAGE_SHIFT , frame,0 );if ( rc )return GNTST_general_error;else
Signature · 1 line
1.7.10.4
Re: [PATCH v2 10/10] xen/arm: grant-table: Support read-only mapping
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
Ian.
Quoted 5 lines · Julien Grall
Hello,
This patch series aims to fix "Failed to unmap" message in dom0 when a guest is creating. Without this patch series, dom0 will leak memory each time a domain is created. It should be considered as a blocker for Xen 4.4 release.
Leaking physical address space (which is I think what happens here) certainly sounds like a bug to me.
It's a bit unfortunate that all of this work (both PVH dom0 and this fix for ARM) is still being sorted out at this stage in the game, but I agree that both are blockers.
-George