remove one more shared xenheap page: shared_info
v4 cover remove one more shared xenheap page: shared_info
From: Paul Durrant <[email protected]>
Paul Durrant (6):
domain: introduce alloc/free_shared_info() helpers... x86 / p2m: remove page_list check in p2m_alloc_table... x86 / pv: do not treat PGC_extra pages as RAM
x86 / ioreq: use a MEMF_no_refcount allocation for server pages...
mm: add 'is_special_page' inline function...
domain: use PGC_extra domheap page for shared_info
xen/arch/arm/domain.c | 10 +++---- xen/arch/arm/mm.c | 2 +- xen/arch/x86/domain.c | 18 +++++++------ xen/arch/x86/domctl.c | 2 +- xen/arch/x86/hvm/ioreq.c | 2 +- xen/arch/x86/mm.c | 11 ++++---- xen/arch/x86/mm/altp2m.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 3 +-- xen/arch/x86/mm/p2m.c | 6 +++-- xen/arch/x86/mm/shadow/common.c | 13 ++++++---- xen/arch/x86/mm/shadow/multi.c | 2 +- xen/arch/x86/numa.c | 3 +++ xen/arch/x86/pv/dom0_build.c | 6 ++++- xen/arch/x86/pv/shim.c | 2 +- xen/arch/x86/tboot.c | 11 +++++--- xen/common/domain.c | 46 +++++++++++++++++++++++++++++++++ xen/common/domctl.c | 2 +- xen/common/event_channel.c | 3 +++ xen/common/time.c | 19 ++++++++++++-- xen/include/asm-x86/shared.h | 15 ++++++----- xen/include/xen/domain.h | 3 +++ xen/include/xen/mm.h | 5 ++++ xen/include/xen/sched.h | 5 +++- xen/include/xen/shared.h | 2 +- 24 files changed, 142 insertions(+), 51 deletions(-)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/6 domain: introduce alloc/free_shared_info() helpers...
From: Paul Durrant <[email protected]>
... and save the MFN.
This patch modifies the 'shared_info' field of struct domain to be a structure comprising an MFN and a virtual address. Allocations are still done from xenheap, so the virtual address still equates to virt_to_mfn() called on the MFN but subsequent patch will change this. Hence the need to save the MFN.
NOTE: Whist defining the new helpers, virt_to_mfn() in common/domain.c
is made type safe.
The definition of nmi_reason() in asm-x86/shared.h is also re- flowed to avoid overly long lines.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Volodymyr Babchuk <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
--- xen/arch/arm/domain.c | 8 ++------ xen/arch/arm/mm.c | 2 +- xen/arch/x86/domain.c | 11 ++++------- xen/arch/x86/mm.c | 2 +- xen/arch/x86/pv/dom0_build.c | 2 +- xen/arch/x86/pv/shim.c | 2 +- xen/common/domain.c | 26 ++++++++++++++++++++++++++ xen/common/domctl.c | 2 +- xen/common/time.c | 4 ++-- xen/include/asm-x86/shared.h | 15 ++++++++------- xen/include/xen/domain.h | 3 +++ xen/include/xen/sched.h | 5 ++++- xen/include/xen/shared.h | 2 +- 13 files changed, 55 insertions(+), 29 deletions(-)
xen/arch/arm/domain.c +2 -6
@@ -689,13 +689,9 @@ int arch_domain_create(struct domain *d,if ( (rc =p2m_init (d)) !=0 ) goto fail; - rc = -ENOMEM ; -if ( (d->shared_info =alloc_xenheap_pages (0 ,0 )) ==NULL ) +if ( (rc =alloc_shared_info (d,0 )) !=0 ) goto fail; -clear_page (d->shared_info); -share_xen_page_with_guest (virt_to_page (d->shared_info), d, SHARE_rw); -switch ( config->arch.gic_version ) {case XEN_DOMCTL_CONFIG_GIC_V2 :
@@ -766,7 +762,7 @@ void arch_domain_destroy(struct domain *d)p2m_teardown (d);domain_vgic_free (d);domain_vuart_free (d); -free_xenheap_page (d->shared_info); +free_shared_info (d);#ifdef CONFIG_ACPI free_xenheap_pages (d->arch.efi_acpi_table,get_order_from_bytes (d->arch.efi_acpi_len));
xen/arch/arm/mm.c +1 -1
@@ -1424,7 +1424,7 @@ int xenmem_add_to_physmap_one(if ( idx !=0 )return -EINVAL ; - mfn =virt_to_mfn (d->shared_info); + mfn = d->shared_info.mfn; t = p2m_ram_rw;break ;
xen/arch/x86/domain.c +4 -7
@@ -611,12 +611,9 @@ int arch_domain_create(struct domain *d,* The shared_info machine address must fit in a 32-bit field within a * 32-bit guest's start_info structure. Hence we specify MEMF_bits(32). */ -if ( (d->shared_info =alloc_xenheap_pages (0 ,MEMF_bits (32 ))) ==NULL ) +if ( (rc =alloc_shared_info (d,MEMF_bits (32 ))) !=0 ) goto fail; -clear_page (d->shared_info); -share_xen_page_with_guest (virt_to_page (d->shared_info), d, SHARE_rw); -if ( (rc =init_domain_irq_mapping (d)) !=0 ) goto fail;
@@ -664,7 +661,7 @@ int arch_domain_create(struct domain *d,psr_domain_free (d);iommu_domain_destroy (d);cleanup_domain_irq_mapping (d); -free_xenheap_page (d->shared_info); +free_shared_info (d);xfree (d->arch.cpuid);xfree (d->arch.msr);if ( paging_initialised )
@@ -693,7 +690,7 @@ void arch_domain_destroy(struct domain *d)pv_domain_destroy (d);free_perdomain_mappings (d); -free_xenheap_page (d->shared_info); +free_shared_info (d);cleanup_domain_irq_mapping (d);psr_domain_free (d);
@@ -719,7 +716,7 @@ void arch_domain_unpause(struct domain *d)int arch_domain_soft_reset (struct domain *d) { -struct page_info *page =virt_to_page (d->shared_info), *new_page; +struct page_info *page =mfn_to_page (d->shared_info.mfn), *new_page;int ret =0 ;struct domain *owner;mfn_t mfn;
xen/arch/x86/mm.c +1 -1
@@ -4540,7 +4540,7 @@ int xenmem_add_to_physmap_one( {case XENMAPSPACE_shared_info:if ( idx ==0 ) - mfn =virt_to_mfn (d->shared_info); + mfn = d->shared_info.mfn;break ;case XENMAPSPACE_grant_table: rc =gnttab_map_frame (d, idx, gpfn, &mfn);
xen/arch/x86/pv/dom0_build.c +1 -1
@@ -743,7 +743,7 @@ int __init dom0_construct_pv(struct domain *d,clear_page (si); si->nr_pages = nr_pages; - si->shared_info =virt_to_maddr (d->shared_info); + si->shared_info =mfn_to_maddr (d->shared_info.mfn);if ( !pv_shim ) si->flags =SIF_PRIVILEGED |SIF_INITDOMAIN ;
xen/arch/x86/pv/shim.c +1 -1
@@ -282,7 +282,7 @@ static void write_start_info(struct domain *d)snprintf (si->magic,sizeof (si->magic),"xen-3.0-x86_%s" ,is_pv_32bit_domain (d) ?"32p" :"64" ); si->nr_pages =domain_tot_pages (d); - si->shared_info =virt_to_maddr (d->shared_info); + si->shared_info =mfn_to_maddr (d->shared_info.mfn); si->flags =0 ;BUG_ON (xen_hypercall_hvm_get_param (HVM_PARAM_STORE_PFN , &si->store_mfn));BUG_ON (xen_hypercall_hvm_get_param (HVM_PARAM_STORE_EVTCHN , ¶m));
xen/common/domain.c +26 -0
@@ -47,6 +47,10 @@#include <asm/guest.h> #endif +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (v) _mfn(__virt_to_mfn(v)) +/* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */ unsigned int xen_processor_pmbits =XEN_PROCESSOR_PM_PX ;
@@ -1644,6 +1648,28 @@ int continue_hypercall_on_cpu(return 0 ; } +int alloc_shared_info (struct domain *d,unsigned int memflags) +{ +if ( (d->shared_info.virt =alloc_xenheap_pages (0 , memflags)) ==NULL ) +return -ENOMEM ; + + d->shared_info.mfn =virt_to_mfn (d->shared_info.virt); + +clear_page (d->shared_info.virt); +share_xen_page_with_guest (mfn_to_page (d->shared_info.mfn), d, SHARE_rw); + +return 0 ; +} + +void free_shared_info (struct domain *d) +{ +if ( !d->shared_info.virt ) +return ; + +free_xenheap_page (d->shared_info.virt); + d->shared_info.virt =NULL ; +} +/* * Local variables: * mode: C
xen/common/domctl.c +1 -1
@@ -196,7 +196,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info) info->outstanding_pages = d->outstanding_pages; info->shr_pages =atomic_read (&d->shr_pages); info->paged_pages =atomic_read (&d->paged_pages); - info->shared_info_frame =mfn_to_gmfn (d,virt_to_mfn (d->shared_info)); + info->shared_info_frame =mfn_to_gmfn (d,mfn_x (d->shared_info.mfn));BUG_ON (SHARED_M2P (info->shared_info_frame)); info->cpupool =cpupool_get_id (d);
xen/common/time.c +2 -2
@@ -110,9 +110,9 @@ void update_domain_wallclock_time(struct domain *d)shared_info (d, wc_nsec) = wc_nsec;#ifdef CONFIG_X86 if (likely (!has_32bit_shinfo (d)) ) - d->shared_info->native.wc_sec_hi = sec >>32 ; + d->shared_info.virt->native.wc_sec_hi = sec >>32 ;else - d->shared_info->compat.arch.wc_sec_hi = sec >>32 ; + d->shared_info.virt->compat.arch.wc_sec_hi = sec >>32 ;#else shared_info (d, wc_sec_hi) = sec >>32 ;#endif
xen/include/asm-x86/shared.h +8 -7
@@ -1,24 +1,25 @@#ifndef __XEN_X86_SHARED_H__#define __XEN_X86_SHARED_H__ -#define nmi_reason (d) (!has_32bit_shinfo(d) ? \ - (u32 *)&(d)->shared_info->native.arch.nmi_reason : \ - (u32 *)&(d)->shared_info->compat.arch.nmi_reason) +#define nmi_reason (d) \ + (!has_32bit_shinfo(d) ? \ + (u32 *)&(d)->shared_info.virt->native.arch.nmi_reason : \ + (u32 *)&(d)->shared_info.virt->compat.arch.nmi_reason)#define GET_SET_SHARED (type, field) \ static inline type arch_get_##field(const struct domain *d) \ { \ return !has_32bit_shinfo(d) ? \ - d->shared_info->native.arch.field : \ - d->shared_info->compat.arch.field; \ + d->shared_info.virt->native.arch.field : \ + d->shared_info.virt->compat.arch.field; \ } \ static inline void arch_set_##field(struct domain *d, \ type val) \ { \ if ( !has_32bit_shinfo(d) ) \ - d->shared_info->native.arch.field = val; \ + d->shared_info.virt->native.arch.field = val; \ else \ - d->shared_info->compat.arch.field = val; \ + d->shared_info.virt->compat.arch.field = val; \ }#define GET_SET_VCPU (type, field) \
xen/include/xen/domain.h +3 -0
@@ -130,4 +130,7 @@ struct vnuma_info {void vnuma_destroy (struct vnuma_info *vnuma); +int alloc_shared_info (struct domain *d,unsigned int memflags); +void free_shared_info (struct domain *d); +#endif /* __XEN_DOMAIN_H__ */
xen/include/xen/sched.h +4 -1
@@ -346,7 +346,10 @@ struct domainunsigned int max_vcpus;struct vcpu **vcpu; -shared_info_t *shared_info;/* shared data area */ +struct { +mfn_t mfn; +shared_info_t *virt; + } shared_info;/* shared data area */ spinlock_t domain_lock;
xen/include/xen/shared.h +1 -1
@@ -43,7 +43,7 @@ typedef struct vcpu_info vcpu_info_t;extern vcpu_info_t dummy_vcpu_info; -#define shared_info (d, field) __shared_info(d, (d)->shared_info, field) +#define shared_info (d, field) __shared_info(d, (d)->shared_info.virt, field)#define vcpu_info (v, field) __vcpu_info(v, (v)->vcpu_info, field)#endif /* __XEN_SHARED_H__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 2/6 x86 / p2m: remove page_list check in p2m_alloc_table...
In reply to [email protected]From: Paul Durrant <[email protected]>
... and replace with a check of domain_tot_pages().
The check of page_list prevents the prior allocation of PGC_extra pages, whereas what the code is trying to verify is that the toolstack has not already RAM for the domain.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
v4:
- Re-worked so as not to completely remove the check
v2:
- New in v2
--- xen/arch/x86/mm/p2m.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +1 -2
@@ -695,8 +695,7 @@ int p2m_alloc_table(struct p2m_domain *p2m)p2m_lock (p2m); -if (p2m_is_hostp2m (p2m) - && !page_list_empty (&d->page_list) ) +if (p2m_is_hostp2m (p2m) &&domain_tot_pages (d) ) {P2M_ERROR ("dom %d already has memory allocated\n" , d->domain_id);p2m_unlock (p2m);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 2/6] x86 / p2m: remove page_list check in p2m_alloc_table...
Quoted 9 lines · On 09.03.2020 10:35, [email protected] wrote:
From: Paul Durrant <[email protected]>
... and replace with a check of
domain_tot_pages().The check of
page_listprevents the prior allocation ofPGC_extrapages, whereas what the code is trying to verify is that the toolstack has not already RAM for the domain.Signed-off-by Paul Durrant <[email protected]>
preferably with "remove" in the subject replaced by the "replace" currently at the beginning of the description. (It also looks as if there was "allocated" or some such missing near the end of the description.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 2/6] x86 / p2m: remove page_list check in p2m_alloc_table...
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 09 March 2020 09:59
To: [email protected]
Cc: [email protected]; Paul Durrant <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: Re: [PATCH v4 2/6] x86 / p2m: removepage_listcheck inp2m_alloc_table...Quoted 4 lines · On 09.03.2020 10:35, [email protected] wrote:
From: Paul Durrant <[email protected]>
... and replace with a check of
domain_tot_pages().
Quoted 7 lines
Quoted 5 lines
The check of
page_listprevents the prior allocation ofPGC_extrapages, whereas what the code is trying to verify is that the toolstack has not already RAM for the domain.Signed-off-by Paul Durrant <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thnaks.
Quoted 5 lines
preferably with "remove" in the subject replaced by the "replace" currently at the beginning of the description. (It also looks as if there was "allocated" or some such missing near the end of the description.)
Ok, I'll fix in v5.
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 3/6 x86 / pv: do not treat PGC_extra pages as RAM
In reply to [email protected]From: Paul Durrant <[email protected]>
This patch modifies several places walking the domain's page_list to make them ignore PGC_extra pages:
- dump_pageframe_info() should ignore PGC_extra pages in its dump as it determines whether to dump using domain_tot_pages() which also ignores PGC_extra pages.
- arch_set_info_guest() is looking for an L4 page table which will definitely not be in a PGC_extra page.
- audit_p2m() should ignore PGC_extra pages as it is perfectly legitimate for them not to be present in the P2M.
- dump_nama() should ignore PGC_extra pages as they are essentially uninteresting in that context.
- dom0_construct_pv() should ignore PGC_extra pages when setting up the physmap as they are only created for special purposes and, if they need to be mapped, will be mapped explicitly for whatever purpose is relevant.
- tboot_gen_domain_integrity() should ignore PGC_extra pages as they should not form part of the measurement.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
v4:
- Expand to cover more than just dom0_construct_pv()
v2:
- New in v2
--- xen/arch/x86/domain.c | 6 +++++- xen/arch/x86/mm/p2m.c | 3 +++ xen/arch/x86/numa.c | 3 +++ xen/arch/x86/pv/dom0_build.c | 4 ++++ xen/arch/x86/tboot.c | 7 ++++++- 5 files changed, 21 insertions(+), 2 deletions(-)
xen/arch/x86/domain.c +5 -1
@@ -231,6 +231,9 @@ void dump_pageframe_info(struct domain *d)unsigned int index =MASK_EXTR (page->u.inuse.type_info, PGT_type_mask); +if ( page->count_info & PGC_extra ) +continue ; +if ( ++total[index] >16 ) { switch ( page->u.inuse.type_info & PGT_type_mask )
@@ -1044,7 +1047,8 @@ int arch_set_info_guest( {struct page_info *page =page_list_remove_head (&d->page_list); -if (page_lock (page) ) +if ( !(page->count_info & PGC_extra) && +page_lock (page) ) {if ( (page->u.inuse.type_info & PGT_type_mask) == PGT_l4_page_table )
xen/arch/x86/mm/p2m.c +3 -0
@@ -2843,6 +2843,9 @@ void audit_p2m(struct domain *d,spin_lock (&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { +if ( page->count_info & PGC_extra ) +continue ; + mfn =mfn_x (page_to_mfn (page));P2M_PRINTK ("auditing guest page, mfn=%#lx\n" , mfn);
xen/arch/x86/numa.c +3 -0
@@ -428,6 +428,9 @@ static void dump_numa(unsigned char key)spin_lock (&d->page_alloc_lock);page_list_for_each (page, &d->page_list) { +if ( page->count_info & PGC_extra ) +break ; + i =phys_to_nid (page_to_maddr (page)); page_num_node[i]++; }
xen/arch/x86/pv/dom0_build.c +4 -0
@@ -792,6 +792,10 @@ int __init dom0_construct_pv(struct domain *d, { mfn =mfn_x (page_to_mfn (page));BUG_ON (SHARED_M2P (get_gpfn_from_mfn (mfn))); + +if ( page->count_info & PGC_extra ) +continue ; +if (get_gpfn_from_mfn (mfn) >= count ) {BUG_ON (is_pv_32bit_domain (d));
xen/arch/x86/tboot.c +6 -1
@@ -220,7 +220,12 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE],spin_lock (&d->page_alloc_lock);page_list_for_each (page, &d->page_list) { -void *pg =__map_domain_page (page); +void *pg; + +if ( page->count_info & PGC_extra ) +continue ; + + pg =__map_domain_page (page);vmac_update (pg,PAGE_SIZE , &ctx);unmap_domain_page (pg); }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 4/6 x86 / ioreq: use a MEMF_no_refcount allocation for server pages...
In reply to [email protected]From: Paul Durrant <[email protected]>
... now that it is safe to assign them.
This avoids relying on libxl (or whatever toolstack is in use) setting max_pages up with sufficient 'slop' to allow all necessary ioreq server pages to be allocated.
---
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
v2:
- New in v2
--- xen/arch/x86/hvm/ioreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/ioreq.c +1 -1
@@ -375,7 +375,7 @@ static int hvm_alloc_ioreq_mfn(struct hvm_ioreq_server *s, bool buf)return 0 ; } - page =alloc_domheap_page (s->target,0 ); + page =alloc_domheap_page (s->target, MEMF_no_refcount);if ( !page )return -ENOMEM ;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 5/6 mm: add 'is_special_page' inline function...
In reply to [email protected]From: Paul Durrant <[email protected]>
... to cover xenheap and PGC_extra pages.
PGC_extra pages are intended to hold data structures that are associated with a domain and may be mapped by that domain. They should not be treated as 'normal' guest pages (i.e. RAM or page tables). Hence, in many cases where code currently tests is_xen_heap_page() it should also check for the PGC_extra bit in 'count_info'.
This patch therefore defines is_special_page() to cover both cases and converts tests if is_xen_heap_page() to is_special_page() where appropriate.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
v4:
- Use inline function instead of macro
- Add missing conversions from is_xen_heap_page()
v3:
- Delete obsolete comment.
v2:
- New in v2
--- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/mm.c | 9 ++++----- xen/arch/x86/mm/altp2m.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 3 +-- xen/arch/x86/mm/shadow/common.c | 13 ++++++++----- xen/arch/x86/mm/shadow/multi.c | 2 +- xen/arch/x86/tboot.c | 4 ++-- xen/include/xen/mm.h | 5 +++++ 8 files changed, 23 insertions(+), 17 deletions(-)
xen/arch/x86/domctl.c +1 -1
@@ -394,7 +394,7 @@ long arch_do_domctl( page =get_page_from_gfn (d, gfn, &t,P2M_ALLOC );if (unlikely (!page) || -unlikely (is_xen_heap_page (page)) ) +unlikely (is_special_page (page)) ) {if (unlikely (p2m_is_broken (t)) ) type =XEN_DOMCTL_PFINFO_BROKEN ;
xen/arch/x86/mm.c +4 -5
@@ -1014,7 +1014,7 @@ get_page_from_l1e(unsigned long cacheattr =pte_flags_to_cacheattr (l1f);int err; -if (is_xen_heap_page (page) ) +if (is_special_page (page) ) {if ( write )put_page_type (page);
@@ -2447,7 +2447,7 @@ static int cleanup_page_mappings(struct page_info *page) { page->count_info &= ~PGC_cacheattr_mask; -BUG_ON (is_xen_heap_page (page)); +BUG_ON (is_special_page (page)); rc =update_xen_mappings (mfn,0 ); }
@@ -2477,7 +2477,7 @@ static int cleanup_page_mappings(struct page_info *page) rc = rc2; } -if (likely (!is_xen_heap_page (page)) ) +if (likely (!is_special_page (page)) ) {ASSERT ((page->u.inuse.type_info & (PGT_type_mask | PGT_count_mask)) == PGT_writable_page);
@@ -4216,8 +4216,7 @@ int steal_page(if ( !(owner =page_get_owner_and_reference (page)) ) goto fail; -if ( owner != d ||is_xen_heap_page (page) || - (page->count_info & PGC_extra) ) +if ( owner != d ||is_special_page (page) ) goto fail_put;/*
xen/arch/x86/mm/altp2m.c +1 -1
@@ -77,7 +77,7 @@ int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn)* pageable() predicate for this, due to it having the same properties * that we want. */ -if ( !p2m_is_pageable (p2mt) ||is_xen_heap_page (pg) ) +if ( !p2m_is_pageable (p2mt) ||is_special_page (pg) ) { rc = -EINVAL ; goto err;
xen/arch/x86/mm/mem_sharing.c +1 -2
@@ -840,9 +840,8 @@ static int nominate_page(struct domain *d, gfn_t gfn,if ( !p2m_is_sharable (p2mt) ) goto out; -/* Skip xen heap pages */ page =mfn_to_page (mfn); -if ( !page ||is_xen_heap_page (page) ) +if ( !page ||is_special_page (page) ) goto out;/* Check if there are mem_access/remapped altp2m entries for this page */
xen/arch/x86/mm/shadow/common.c +8 -5
@@ -2087,19 +2087,22 @@ static int sh_remove_all_mappings(struct domain *d, mfn_t gmfn, gfn_t gfn)* The qemu helper process has an untyped mapping of this dom's RAM * and the HVM restore program takes another. * Also allow one typed refcount for -* - Xen heap pages, to match share_xen_page_with_guest(), -* - ioreq server pages, to match prepare_ring_for_helper(). +* - special pages, which are explicitly referenced and mapped by +* Xen. +* - ioreq server pages, which may be special pages or normal +* guest pages with an extra reference taken by +* prepare_ring_for_helper(). */ if ( !(shadow_mode_external (d) && (page->count_info & PGC_count_mask) <=3 && ((page->u.inuse.type_info & PGT_count_mask) - == (is_xen_heap_page (page) || + == (is_special_page (page) || (is_hvm_domain (d) &&is_ioreq_server_page (d, page))))) )printk (XENLOG_G_ERR "can't find all mappings of mfn %" PRI_mfn -" (gfn %" PRI_gfn"): c=%lx t=%lx x=%d i=%d\n" , +" (gfn %" PRI_gfn"): c=%lx t=%lx s=%d i=%d\n" ,mfn_x (gmfn),gfn_x (gfn), page->count_info, page->u.inuse.type_info, - !!is_xen_heap_page (page), + !!is_special_page (page), (is_hvm_domain (d) &&is_ioreq_server_page (d, page))); }
xen/arch/x86/mm/shadow/multi.c +1 -1
@@ -559,7 +559,7 @@ _sh_propagate(struct vcpu *v,* caching attributes in the shadows to match what was asked for. */ if ( (level ==1 ) &&is_hvm_domain (d) && - !is_xen_heap_mfn (target_mfn) ) + !is_special_page (mfn_to_page (target_mfn)) ) {int type;
xen/arch/x86/tboot.c +2 -2
@@ -189,7 +189,7 @@ static void update_pagetable_mac(vmac_ctx_t *ctx)if ( !mfn_valid (_mfn (mfn)) )continue ; -if (is_page_in_use (page) && !is_xen_heap_page (page) ) +if (is_page_in_use (page) && !is_special_page (page) ) {if ( page->count_info & PGC_page_table ) {
@@ -294,7 +294,7 @@ static void tboot_gen_xenheap_integrity(const uint8_t key[TB_KEY_SIZE], + 3 * PAGE_SIZE)) )continue ;/* skip tboot and its page tables */ -if (is_page_in_use (page) &&is_xen_heap_page (page) ) +if (is_page_in_use (page) &&is_special_page (page) ) {void *pg;
xen/include/xen/mm.h +5 -0
@@ -285,6 +285,11 @@ extern struct domain *dom_cow;#include <asm/mm.h> +static inline bool is_special_page (struct page_info *page) +{ +return is_xen_heap_page (page) || (page->count_info & PGC_extra); +} +#ifndef page_list_entrystruct page_list_head {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 6/6 domain: use PGC_extra domheap page for shared_info
In reply to [email protected]From: Paul Durrant <[email protected]>
Currently shared_info is a shared xenheap page but shared xenheap pages complicate future plans for live-update of Xen so it is desirable to, where possible, not use them [1]. This patch therefore converts shared_info into a PGC_extra domheap page. This does entail freeing shared_info during domain_relinquish_resources() rather than domain_destroy() so care is needed to avoid de-referencing a NULL shared_info pointer hence some extra checks of 'is_dying' are needed.
NOTE: For Arm, the call to free_shared_info() in arch_domain_destroy() is
left in place since it is idempotent and called in the error path for arch_domain_create().
[1] See https://lists.xenproject.org/archives/html/xen-devel/2020-02/msg02018.html
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Volodymyr Babchuk <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Wei Liu <[email protected]>
v2:
- Addressed comments from Julien
- Expanded the commit comment to explain why this patch is wanted
--- xen/arch/arm/domain.c | 2 ++ xen/arch/x86/domain.c | 3 ++- xen/common/domain.c | 28 ++++++++++++++++++++++++---- xen/common/event_channel.c | 3 +++ xen/common/time.c | 15 +++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-)
xen/arch/arm/domain.c +2 -0
@@ -1005,6 +1005,8 @@ int domain_relinquish_resources(struct domain *d)BUG (); } +free_shared_info (d); +return 0 ; }
xen/arch/x86/domain.c +2 -1
@@ -693,7 +693,6 @@ void arch_domain_destroy(struct domain *d)pv_domain_destroy (d);free_perdomain_mappings (d); -free_shared_info (d);cleanup_domain_irq_mapping (d);psr_domain_free (d);
@@ -2249,6 +2248,8 @@ int domain_relinquish_resources(struct domain *d)if (is_hvm_domain (d) )hvm_domain_relinquish_resources (d); +free_shared_info (d); +return 0 ; }
xen/common/domain.c +24 -4
@@ -1650,24 +1650,44 @@ int continue_hypercall_on_cpu(int alloc_shared_info (struct domain *d,unsigned int memflags) { -if ( (d->shared_info.virt =alloc_xenheap_pages (0 , memflags)) ==NULL ) +struct page_info *pg; + + pg =alloc_domheap_page (d, MEMF_no_refcount | memflags); +if ( !pg )return -ENOMEM ; - d->shared_info.mfn =virt_to_mfn (d->shared_info.virt); +if ( !get_page_and_type (pg, d, PGT_writable_page) ) + { +/* +* The domain should not be running at this point so there is +* no way we should reach this error path. +*/ +ASSERT_UNREACHABLE (); +return -ENODATA ; + } + + d->shared_info.mfn =page_to_mfn (pg); + d->shared_info.virt =__map_domain_page_global (pg);clear_page (d->shared_info.virt); -share_xen_page_with_guest (mfn_to_page (d->shared_info.mfn), d, SHARE_rw);return 0 ; }void free_shared_info (struct domain *d) { +struct page_info *pg; +if ( !d->shared_info.virt )return ; -free_xenheap_page (d->shared_info.virt); +unmap_domain_page_global (d->shared_info.virt); d->shared_info.virt =NULL ; + + pg =mfn_to_page (d->shared_info.mfn); + +put_page_alloc_ref (pg); +put_page_and_type (pg); }/*
xen/common/event_channel.c +3 -0
@@ -1325,6 +1325,9 @@ void evtchn_destroy(struct domain *d) {unsigned int i; +/* This must be done before shared_info is freed */ +BUG_ON (!d->shared_info.virt); +/* After this barrier no new event-channel allocations can occur. */ BUG_ON (!d->is_dying);spin_barrier (&d->event_lock);
xen/common/time.c +15 -0
@@ -99,6 +99,18 @@ void update_domain_wallclock_time(struct domain *d)uint32_t *wc_version;uint64_t sec; +if ( d != current->domain ) + { +/* +* We need to check is_dying here as, if it is set, the +* shared_info may have been freed. To do this safely we need +* hold the domain lock. +*/ +domain_lock (d); +if ( d->is_dying ) + goto unlock; + } +spin_lock (&wc_lock); wc_version = &shared_info (d, wc_version);
@@ -121,6 +133,9 @@ void update_domain_wallclock_time(struct domain *d) *wc_version =version_update_end (*wc_version);spin_unlock (&wc_lock); + unlock: +if ( d != current->domain ) +domain_unlock (d); }/* Set clock to <secs,usecs> after 00:00:00 UTC, 1 January, 1970. */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 6/6] domain: use PGC_extra domheap page for shared_info
Quoted 21 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: 09 March 2020 09:35
To: [email protected]
Cc: Durrant, Paul <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Wei Liu <[email protected]>
Subject: [PATCH v4 6/6] domain: usePGC_extradomheap page forshared_infoFrom: Paul Durrant <[email protected]>
Currently
shared_infois a shared xenheap page but shared xenheap pages complicate future plans for live-update of Xen so it is desirable to, where possible, not use them [1]. This patch therefore convertsshared_infointo aPGC_extradomheap page. This does entail freeingshared_infoduringdomain_relinquish_resources()rather thandomain_destroy()so care is needed to avoid de-referencing a NULLshared_infopointer hence some extra checks of 'is_dying' are needed.
Quoted 7 lines
NOTE: For Arm, the call to
free_shared_info()inarch_domain_destroy()is
left in place since it is idempotent and called in the error path forarch_domain_create().[1] See https://lists.xenproject.org/archives/html/xen-devel/2020-02/msg02018.html
Signed-off-by Paul Durrant <[email protected]>
I realise I forgot to fold in the new dump function for shared_info (needed since it will no longer feature in the dump of xen pages) so I will send a v5 of this series shortly.
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel