pvh/dom0/shadow/amd fixes
v6 cover pvh/dom0/shadow/amd fixes
The remaining set of patches contain changes to the p2m code that could affect HVM guests. Note that without those changes a PVH dom0 running on AMD hardware will be unable to create guests. Overall the patches are a nice cleanup to the handling of p2m_ioreq_server and p2m_map_foreign types IMO.
The series can also be found at:
git://xenbits.xen.org/people/royger/xen.git fixes-v6
Thanks, Roger.
Roger Pau Monne (5):
x86/p2m: pass the p2m to write_p2m_entry handlers x86/mm: split p2m ioreq server pages special handling into helper
p2m: change write_p2m_entry to return an error code x86/mm: handle foreign mappings in p2m_entry_modify npt/shadow: allow getting foreign page table entries
xen/arch/x86/mm/hap/hap.c | 17 ++++- xen/arch/x86/mm/hap/nested_hap.c | 4 +- xen/arch/x86/mm/p2m-ept.c | 106 ++++++----------------------- xen/arch/x86/mm/p2m-pt.c | 112 ++++++++++++++++++------------- xen/arch/x86/mm/paging.c | 12 ++-- xen/arch/x86/mm/shadow/common.c | 18 ++++- xen/arch/x86/mm/shadow/none.c | 7 +- xen/arch/x86/mm/shadow/private.h | 6 +- xen/include/asm-x86/p2m.h | 62 ++++++++++++++++- xen/include/asm-x86/paging.h | 9 +-- 10 files changed, 199 insertions(+), 154 deletions(-)
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v6 1/5 x86/p2m: pass the p2m to write_p2m_entry handlers
Current callers pass the p2m to paging_write_p2m_entry, but the implementation specific handlers of the write_p2m_entry hook instead of a p2m get a domain struct due to the handling done in paging_write_p2m_entry.
Change the code so that the implementations of write_p2m_entry take a p2m instead of a domain.
This is a non-functional change, but will be used by follow up patches.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v4:
- New in this version.
--- xen/arch/x86/mm/hap/hap.c | 3 ++- xen/arch/x86/mm/paging.c | 2 +- xen/arch/x86/mm/shadow/common.c | 4 +++- xen/arch/x86/mm/shadow/none.c | 2 +- xen/arch/x86/mm/shadow/private.h | 2 +- xen/include/asm-x86/paging.h | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-)
xen/arch/x86/mm/hap/hap.c +2 -1
@@ -709,9 +709,10 @@ static void hap_update_paging_modes(struct vcpu *v) }static void -hap_write_p2m_entry (struct domain *d,unsigned long gfn,l1_pgentry_t *p, +hap_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) { +struct domain *d = p2m->domain;uint32_t old_flags;bool_t flush_nestedp2m =0 ;
xen/arch/x86/mm/paging.c +1 -1
@@ -941,7 +941,7 @@ void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,if ( v->domain != d ) v = d->vcpu ? d->vcpu[0 ] :NULL ;if (likely (v &&paging_mode_enabled (d) &&paging_get_hostmode (v) !=NULL ) ) -paging_get_hostmode (v)->write_p2m_entry (d, gfn, p, new, level); +paging_get_hostmode (v)->write_p2m_entry (p2m, gfn, p, new, level);else safe_write_pte (p, new); }
xen/arch/x86/mm/shadow/common.c +3 -1
@@ -3177,10 +3177,12 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn, }void -shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) { +struct domain *d = p2m->domain; +paging_lock (d);/* If there are any shadows, update them. But if shadow_teardown()
xen/arch/x86/mm/shadow/none.c +1 -1
@@ -60,7 +60,7 @@ static void _update_paging_modes(struct vcpu *v)ASSERT_UNREACHABLE (); } -static void _write_p2m_entry (struct domain *d,unsigned long gfn, +static void _write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {
xen/arch/x86/mm/shadow/private.h +1 -1
@@ -372,7 +372,7 @@ extern int sh_remove_write_access(struct domain *d, mfn_t readonly_mfn, unsigned long fault_addr);/* Functions that atomically write PT/P2M entries and update state */ -void shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +void shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);
xen/include/asm-x86/paging.h +2 -1
@@ -124,7 +124,8 @@ struct paging_mode {void (*update_cr3 )(struct vcpu *v,int do_locking,bool noflush);void (*update_paging_modes )(struct vcpu *v); -void (*write_p2m_entry )(struct domain *d,unsigned long gfn, +void (*write_p2m_entry )(struct p2m_domain *p2m, +unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6 1/5] x86/p2m: pass the p2m to write_p2m_entry handlers
Gah -- sorry, Juergen, I pushed this series to staging erroneously; it wasn't targeted for 4.12 and doesn't have your release ack.
Should I revert it?
-George
Quoted 124 lines · Roger Pau Monne
Current callers pass the p2m to
paging_write_p2m_entry, but the implementation specific handlers of thewrite_p2m_entryhook instead of a p2m get a domain struct due to the handling done inpaging_write_p2m_entry.Change the code so that the implementations of
write_p2m_entrytake a p2m instead of a domain.This is a non-functional change, but will be used by follow up patches.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>Reviewed-by George Dunlap <[email protected]>---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v4:
- New in this version.--- xen/arch/x86/mm/hap/hap.c | 3 ++- xen/arch/x86/mm/paging.c | 2 +- xen/arch/x86/mm/shadow/common.c | 4 +++- xen/arch/x86/mm/shadow/none.c | 2 +- xen/arch/x86/mm/shadow/private.h | 2 +- xen/include/asm-x86/paging.h | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-)xen/arch/x86/mm/hap/hap.c +2
-1@@ -709,9 +709,10 @@ static void hap_update_paging_modes(struct vcpu *v) }static void -hap_write_p2m_entry (struct domain *d,unsigned long gfn,l1_pgentry_t *p, +hap_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) { +struct domain *d = p2m->domain;uint32_t old_flags;bool_t flush_nestedp2m =0 ;xen/arch/x86/mm/paging.c +1
-1@@ -941,7 +941,7 @@ void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,if ( v->domain != d ) v = d->vcpu ? d->vcpu[0 ] :NULL ;if (likely (v &&paging_mode_enabled (d) &&paging_get_hostmode (v) !=NULL ) ) -paging_get_hostmode (v)->write_p2m_entry (d, gfn, p, new, level); +paging_get_hostmode (v)->write_p2m_entry (p2m, gfn, p, new, level);else safe_write_pte (p, new); }xen/arch/x86/mm/shadow/common.c +3
-1@@ -3177,10 +3177,12 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn, }void -shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) { +struct domain *d = p2m->domain; +paging_lock (d);/* If there are any shadows, update them. But if shadow_teardown() xen/arch/x86/mm/shadow/none.c +1
-1@@ -60,7 +60,7 @@ static void _update_paging_modes(struct vcpu *v)ASSERT_UNREACHABLE (); } -static void _write_p2m_entry (struct domain *d,unsigned long gfn, +static void _write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {xen/arch/x86/mm/shadow/private.h +1
-1@@ -372,7 +372,7 @@ extern int sh_remove_write_access(struct domain *d, mfn_t readonly_mfn, unsigned long fault_addr);/* Functions that atomically write PT/P2M entries and update state */ -void shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +void shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);xen/include/asm-x86/paging.h +2
-2@@ -124,7 +124,8 @@ struct paging_mode {void (*update_cr3 )(struct vcpu *v,int do_locking,bool noflush);void (*update_paging_modes )(struct vcpu *v); -void (*write_p2m_entry )(struct domain *d,unsigned long gfn, +void (*write_p2m_entry )(struct p2m_domain *p2m, +unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level); --2.17.2 (Apple Git-113)
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6 1/5] x86/p2m: pass the p2m to write_p2m_entry handlers
Quoted 4 lines · George Dunlap
Gah -- sorry, Juergen, I pushed this series to staging erroneously; it wasn't targeted for 4.12 and doesn't have your release ack.
Should I revert it?
With an x86 hat on, if this code is in a good state, I'd vote for it to stay in. Accident aside, it puts PVH dom0 in a far better state than before.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v6 2/5 x86/mm: split p2m ioreq server pages special handling into helper
In reply to Roger Pau MonneSo that it can be shared by both ept, npt and shadow code, instead of duplicating it.
No change in functionality intended.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v4:
- Remove the p2m_get_hostp2m from callers of p2m_entry_modify.
Changes since v1:
- Remove unused p2mt_old from p2m_pt_set_entry.
--- xen/arch/x86/mm/hap/hap.c | 3 ++ xen/arch/x86/mm/p2m-ept.c | 55 +++++++++++---------------------- xen/arch/x86/mm/p2m-pt.c | 24 -------------- xen/arch/x86/mm/shadow/common.c | 3 ++ xen/include/asm-x86/p2m.h | 32 +++++++++++++++++++ 5 files changed, 56 insertions(+), 61 deletions(-)
xen/arch/x86/mm/hap/hap.c +3 -0
@@ -735,6 +735,9 @@ hap_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, l1_pgentry_t *p, && perms_strictly_increased(old_flags, l1e_get_flags(new)) ); } +p2m_entry_modify (p2m,p2m_flags_to_type (l1e_get_flags (new)), +p2m_flags_to_type (old_flags), level); +safe_write_pte (p, new);if ( old_flags & _PAGE_PRESENT )flush_tlb_mask (d->dirty_cpumask);
xen/arch/x86/mm/p2m-ept.c +18 -37
146 lines not on this page · raw message
xen/arch/x86/mm/p2m-pt.c +0 -24
@@ -436,13 +436,6 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) flags |= _PAGE_PSE; } -if ( ot == p2m_ioreq_server ) - { -ASSERT (p2m->ioreq.entry_count >0 ); -ASSERT (level ==0 ); - p2m->ioreq.entry_count--; - } - e =l1e_from_pfn (mfn, flags);p2m_add_iommu_flags (&e, level, (nt == p2m_ram_rw)
@@ -616,8 +609,6 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,if ( page_order ==PAGE_ORDER_4K ) { -p2m_type_t p2mt_old; - rc =p2m_next_level (p2m, &table, &gfn_remainder, gfn,L2_PAGETABLE_SHIFT -PAGE_SHIFT ,L2_PAGETABLE_ENTRIES ,1 ,1 );
@@ -641,21 +632,6 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,if ( entry_content.l1 !=0 )p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - p2mt_old =p2m_flags_to_type (l1e_get_flags (*p2m_entry)); - -/* -* p2m_ioreq_server is only used for 4K pages, so -* the count is only done for level 1 entries. -*/ -if ( p2mt == p2m_ioreq_server ) - p2m->ioreq.entry_count++; - -if ( p2mt_old == p2m_ioreq_server ) - { -ASSERT (p2m->ioreq.entry_count >0 ); - p2m->ioreq.entry_count--; - } -/* level 1 entry */ p2m->write_p2m_entry (p2m, gfn, p2m_entry, entry_content,1 );/* NB: paging_write_p2m_entry() handles tlb flushes properly */
xen/arch/x86/mm/shadow/common.c +3 -0
@@ -3190,6 +3190,9 @@ shadow_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,if (likely (d->arch.paging.shadow.total_pages !=0 ) )sh_unshadow_for_p2m_change (d, gfn, p, new, level); +p2m_entry_modify (p2m,p2m_flags_to_type (l1e_get_flags (new)), +p2m_flags_to_type (l1e_get_flags (*p)), level); +/* Update the entry with new content */ safe_write_pte (p, new);
xen/include/asm-x86/p2m.h +32 -0
@@ -932,6 +932,38 @@ int p2m_set_ioreq_server(struct domain *d, unsigned int flags,struct hvm_ioreq_server *p2m_get_ioreq_server (struct domain *d,unsigned int *flags); +static inline void p2m_entry_modify (struct p2m_domain *p2m,p2m_type_t nt, +p2m_type_t ot,unsigned int level) +{ +if ( level !=1 || nt == ot ) +return ; + +switch ( nt ) + { +case p2m_ioreq_server: +/* +* p2m_ioreq_server is only used for 4K pages, so +* the count is only done for level 1 entries. +*/ + p2m->ioreq.entry_count++; +break ; + +default : +break ; + } + +switch ( ot ) + { +case p2m_ioreq_server: +ASSERT (p2m->ioreq.entry_count >0 ); + p2m->ioreq.entry_count--; +break ; + +default : +break ; + } +} +#endif /* _XEN_ASM_X86_P2M_H */ /*
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v6 3/5 p2m: change write_p2m_entry to return an error code
In reply to Roger Pau MonneThis is in preparation for also changing p2m_entry_modify to return an error code.
No functional change intended.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v5:
- Return -EOPNOTSUPP from _write_p2m_entry.
- Use an error label in p2m_next_level.
Changes since v4:
- Handle errors in loops to avoid overwriting the variable containing the error code in non-debug builds.
- Change error handling in p2m_next_level so it's done in a single place.
Changes since v3:
- Use asserts instead of bugs to check return code from write_p2m_entry from callers that don't support or expect write_p2m_entry to fail.
Changes since v2:
- New in this version.
--- xen/arch/x86/mm/hap/hap.c | 4 +- xen/arch/x86/mm/hap/nested_hap.c | 4 +- xen/arch/x86/mm/p2m-pt.c | 77 +++++++++++++++++++++++++------- xen/arch/x86/mm/paging.c | 12 +++-- xen/arch/x86/mm/shadow/common.c | 4 +- xen/arch/x86/mm/shadow/none.c | 7 +-- xen/arch/x86/mm/shadow/private.h | 6 +-- xen/include/asm-x86/p2m.h | 4 +- xen/include/asm-x86/paging.h | 8 ++-- 9 files changed, 92 insertions(+), 34 deletions(-)
xen/arch/x86/mm/hap/hap.c +3 -1
@@ -708,7 +708,7 @@ static void hap_update_paging_modes(struct vcpu *v)put_gfn (d, cr3_gfn); } -static void +static int hap_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {
@@ -746,6 +746,8 @@ hap_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, l1_pgentry_t *p,if ( flush_nestedp2m )p2m_flush_nestedp2m (d); + +return 0 ; } static unsigned long hap_gva_to_gfn_real_mode(
xen/arch/x86/mm/hap/nested_hap.c +3 -1
@@ -71,7 +71,7 @@/* NESTED VIRT P2M FUNCTIONS */ /********************************************/ -void +int nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {
@@ -87,6 +87,8 @@ nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,flush_tlb_mask (p2m->dirty_cpumask);paging_unlock (d); + +return 0 ; }/********************************************/
xen/arch/x86/mm/p2m-pt.c +62 -15
168 lines not on this page · raw message
xen/arch/x86/mm/paging.c +8 -4
@@ -932,18 +932,22 @@ void paging_update_nestedmode(struct vcpu *v) }#endif -void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level) +int paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) {struct domain *d = p2m->domain;struct vcpu *v = current; +int rc =0 ; +if ( v->domain != d ) v = d->vcpu ? d->vcpu[0 ] :NULL ;if (likely (v &&paging_mode_enabled (d) &&paging_get_hostmode (v) !=NULL ) ) -paging_get_hostmode (v)->write_p2m_entry (p2m, gfn, p, new, level); + rc =paging_get_hostmode (v)->write_p2m_entry (p2m, gfn, p, new, level);else safe_write_pte (p, new); + +return rc; }int paging_set_allocation (struct domain *d,unsigned int pages,bool *preempted)
xen/arch/x86/mm/shadow/common.c +3 -1
@@ -3176,7 +3176,7 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn, } } -void +int shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level)
@@ -3211,6 +3211,8 @@ shadow_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,#endif paging_unlock (d); + +return 0 ; }/**************************************************************************/
xen/arch/x86/mm/shadow/none.c +4 -3
@@ -60,11 +60,12 @@ static void _update_paging_modes(struct vcpu *v)ASSERT_UNREACHABLE (); } -static void _write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level) +static int _write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) {ASSERT_UNREACHABLE (); +return -EOPNOTSUPP ; }static const struct paging_mode sh_paging_none = {
xen/arch/x86/mm/shadow/private.h +3 -3
@@ -372,9 +372,9 @@ extern int sh_remove_write_access(struct domain *d, mfn_t readonly_mfn, unsigned long fault_addr);/* Functions that atomically write PT/P2M entries and update state */ -void shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level); +int shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);/* Update all the things that are derived from the guest's CR0/CR3/CR4. * Called to initialize paging structures if the paging mode
xen/include/asm-x86/p2m.h +2 -2
@@ -265,7 +265,7 @@ struct p2m_domain { unsigned long last_gfn);void (*memory_type_changed)(struct p2m_domain *p2m); -void (*write_p2m_entry)(struct p2m_domain *p2m, +int (*write_p2m_entry)(struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);long (*audit_p2m)(struct p2m_domain *p2m);
@@ -837,7 +837,7 @@ void p2m_flush_nestedp2m(struct domain *d);/* Flushes the np2m specified by np2m_base (if it exists) */ void np2m_flush_base (struct vcpu *v,unsigned long np2m_base); -void nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +int nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);/*
xen/include/asm-x86/paging.h +4 -4
@@ -124,7 +124,7 @@ struct paging_mode {void (*update_cr3 )(struct vcpu *v,int do_locking,bool noflush);void (*update_paging_modes )(struct vcpu *v); -void (*write_p2m_entry )(struct p2m_domain *p2m, +int (*write_p2m_entry )(struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);
@@ -340,9 +340,9 @@ static inline void safe_write_pte(l1_pgentry_t *p, l1_pgentry_t new)* we are writing. */ struct p2m_domain ; -void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level); +int paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);/* * Called from the guest to indicate that the a process is being
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v6 3/5 p2m: change write_p2m_entry to return an error code
This is in preparation for also changing p2m_entry_modify to return an error code.
No functional change intended.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v6:
- Fix line wrapping in p2m_next_level.
Changes since v5:
- Return -EOPNOTSUPP from _write_p2m_entry.
- Use an error label in p2m_next_level.
Changes since v4:
- Handle errors in loops to avoid overwriting the variable containing the error code in non-debug builds.
- Change error handling in p2m_next_level so it's done in a single place.
Changes since v3:
- Use asserts instead of bugs to check return code from write_p2m_entry from callers that don't support or expect write_p2m_entry to fail.
Changes since v2:
- New in this version.
--- xen/arch/x86/mm/hap/hap.c | 4 +- xen/arch/x86/mm/hap/nested_hap.c | 4 +- xen/arch/x86/mm/p2m-pt.c | 73 ++++++++++++++++++++++++++------ xen/arch/x86/mm/paging.c | 12 ++++-- xen/arch/x86/mm/shadow/common.c | 4 +- xen/arch/x86/mm/shadow/none.c | 7 +-- xen/arch/x86/mm/shadow/private.h | 6 +-- xen/include/asm-x86/p2m.h | 4 +- xen/include/asm-x86/paging.h | 8 ++-- 9 files changed, 89 insertions(+), 33 deletions(-)
xen/arch/x86/mm/hap/hap.c +3 -1
@@ -708,7 +708,7 @@ static void hap_update_paging_modes(struct vcpu *v)put_gfn (d, cr3_gfn); } -static void +static int hap_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {
@@ -746,6 +746,8 @@ hap_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, l1_pgentry_t *p,if ( flush_nestedp2m )p2m_flush_nestedp2m (d); + +return 0 ; } static unsigned long hap_gva_to_gfn_real_mode(
xen/arch/x86/mm/hap/nested_hap.c +3 -1
@@ -71,7 +71,7 @@/* NESTED VIRT P2M FUNCTIONS */ /********************************************/ -void +int nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {
@@ -87,6 +87,8 @@ nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,flush_tlb_mask (p2m->dirty_cpumask);paging_unlock (d); + +return 0 ; }/********************************************/
xen/arch/x86/mm/p2m-pt.c +59 -14
165 lines not on this page · raw message
xen/arch/x86/mm/paging.c +8 -4
@@ -932,18 +932,22 @@ void paging_update_nestedmode(struct vcpu *v) }#endif -void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level) +int paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) {struct domain *d = p2m->domain;struct vcpu *v = current; +int rc =0 ; +if ( v->domain != d ) v = d->vcpu ? d->vcpu[0 ] :NULL ;if (likely (v &&paging_mode_enabled (d) &&paging_get_hostmode (v) !=NULL ) ) -paging_get_hostmode (v)->write_p2m_entry (p2m, gfn, p, new, level); + rc =paging_get_hostmode (v)->write_p2m_entry (p2m, gfn, p, new, level);else safe_write_pte (p, new); + +return rc; }int paging_set_allocation (struct domain *d,unsigned int pages,bool *preempted)
xen/arch/x86/mm/shadow/common.c +3 -1
@@ -3176,7 +3176,7 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn, } } -void +int shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level)
@@ -3211,6 +3211,8 @@ shadow_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,#endif paging_unlock (d); + +return 0 ; }/**************************************************************************/
xen/arch/x86/mm/shadow/none.c +4 -3
@@ -60,11 +60,12 @@ static void _update_paging_modes(struct vcpu *v)ASSERT_UNREACHABLE (); } -static void _write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level) +static int _write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) {ASSERT_UNREACHABLE (); +return -EOPNOTSUPP ; }static const struct paging_mode sh_paging_none = {
xen/arch/x86/mm/shadow/private.h +3 -3
@@ -372,9 +372,9 @@ extern int sh_remove_write_access(struct domain *d, mfn_t readonly_mfn, unsigned long fault_addr);/* Functions that atomically write PT/P2M entries and update state */ -void shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level); +int shadow_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);/* Update all the things that are derived from the guest's CR0/CR3/CR4. * Called to initialize paging structures if the paging mode
xen/include/asm-x86/p2m.h +2 -2
@@ -265,7 +265,7 @@ struct p2m_domain { unsigned long last_gfn);void (*memory_type_changed)(struct p2m_domain *p2m); -void (*write_p2m_entry)(struct p2m_domain *p2m, +int (*write_p2m_entry)(struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);long (*audit_p2m)(struct p2m_domain *p2m);
@@ -837,7 +837,7 @@ void p2m_flush_nestedp2m(struct domain *d);/* Flushes the np2m specified by np2m_base (if it exists) */ void np2m_flush_base (struct vcpu *v,unsigned long np2m_base); -void nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +int nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);/*
xen/include/asm-x86/paging.h +4 -4
@@ -124,7 +124,7 @@ struct paging_mode {void (*update_cr3 )(struct vcpu *v,int do_locking,bool noflush);void (*update_paging_modes )(struct vcpu *v); -void (*write_p2m_entry )(struct p2m_domain *p2m, +int (*write_p2m_entry )(struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);
@@ -340,9 +340,9 @@ static inline void safe_write_pte(l1_pgentry_t *p, l1_pgentry_t new)* we are writing. */ struct p2m_domain ; -void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,l1_pgentry_t new, -unsigned int level); +int paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);/* * Called from the guest to indicate that the a process is being
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6.1 3/5] p2m: change write_p2m_entry to return an error code
Quoted 6 lines · Roger Pau Monne
This is in preparation for also changing
p2m_entry_modifyto return an error code.No functional change intended.
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6.1 3/5] p2m: change write_p2m_entry to return an error code
In reply to Roger Pau MonneQuoted 6 lines · Roger Pau Monne
This is in preparation for also changing
p2m_entry_modifyto return an error code.No functional change intended.
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v6 4/5 x86/mm: handle foreign mappings in p2m_entry_modify
In reply to Roger Pau MonneSo that the specific handling can be removed from atomic_write_ept_entry and be shared with npt and shadow code.
This commit also removes the check that prevent non-ept PVH dom0 from mapping foreign pages.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v3:
- Replace the mfn_valid BUG_ONs with an assert & return.
Changes since v2:
- Return an error code from p2m_entry_modify and propagate it to the callers.
Changes since v1:
- Simply code since mfn_to_page cannot return NULL.
- Check if the mfn is valid before getting/dropping the page reference.
- Use BUG_ON instead of ASSERTs, since getting the reference counting wrong is more dangerous than a DoS.
--- xen/arch/x86/mm/hap/hap.c | 11 +++++-- xen/arch/x86/mm/p2m-ept.c | 55 +++------------------------------ xen/arch/x86/mm/p2m-pt.c | 7 ----- xen/arch/x86/mm/shadow/common.c | 11 +++++-- xen/include/asm-x86/p2m.h | 34 +++++++++++++++++--- 5 files changed, 53 insertions(+), 65 deletions(-)
xen/arch/x86/mm/hap/hap.c +9 -2
@@ -715,6 +715,7 @@ hap_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, l1_pgentry_t *p,struct domain *d = p2m->domain;uint32_t old_flags;bool_t flush_nestedp2m =0 ; +int rc;/* We know always use the host p2m here, regardless if the vcpu * is in host or guest mode. The vcpu can be in guest mode by
@@ -735,8 +736,14 @@ hap_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, l1_pgentry_t *p, && perms_strictly_increased(old_flags, l1e_get_flags(new)) ); } -p2m_entry_modify (p2m,p2m_flags_to_type (l1e_get_flags (new)), -p2m_flags_to_type (old_flags), level); + rc =p2m_entry_modify (p2m,p2m_flags_to_type (l1e_get_flags (new)), +p2m_flags_to_type (old_flags),l1e_get_mfn (new), +l1e_get_mfn (*p), level); +if ( rc ) + { +paging_unlock (d); +return rc; + }safe_write_pte (p, new);if ( old_flags & _PAGE_PRESENT )
xen/arch/x86/mm/p2m-ept.c +5 -50
65 lines not on this page · raw message
xen/arch/x86/mm/p2m-pt.c +0 -7
@@ -574,13 +574,6 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,__trace_var (TRC_MEM_SET_P2M_ENTRY ,0 ,sizeof (t), &t); } -if (unlikely (p2m_is_foreign (p2mt)) ) - { -/* hvm fixme: foreign types are only supported on ept at present */ -gdprintk (XENLOG_WARNING ,"Unimplemented foreign p2m type.\n" ); -return -EINVAL ; - } -/* Carry out any eventually pending earlier changes first. */ rc =do_recalc (p2m, gfn);if ( rc <0 )
xen/arch/x86/mm/shadow/common.c +9 -2
@@ -3182,6 +3182,7 @@ shadow_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, unsigned int level) {struct domain *d = p2m->domain; +int rc;paging_lock (d);
@@ -3190,8 +3191,14 @@ shadow_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,if (likely (d->arch.paging.shadow.total_pages !=0 ) )sh_unshadow_for_p2m_change (d, gfn, p, new, level); -p2m_entry_modify (p2m,p2m_flags_to_type (l1e_get_flags (new)), -p2m_flags_to_type (l1e_get_flags (*p)), level); + rc =p2m_entry_modify (p2m,p2m_flags_to_type (l1e_get_flags (new)), +p2m_flags_to_type (l1e_get_flags (*p)), +l1e_get_mfn (new),l1e_get_mfn (*p), level); +if ( rc ) + { +paging_unlock (d); +return rc; + }/* Update the entry with new content */ safe_write_pte (p, new);
xen/include/asm-x86/p2m.h +30 -4
@@ -932,11 +932,14 @@ int p2m_set_ioreq_server(struct domain *d, unsigned int flags,struct hvm_ioreq_server *p2m_get_ioreq_server (struct domain *d,unsigned int *flags); -static inline void p2m_entry_modify (struct p2m_domain *p2m,p2m_type_t nt, -p2m_type_t ot,unsigned int level) +static inline int p2m_entry_modify (struct p2m_domain *p2m,p2m_type_t nt, +p2m_type_t ot,mfn_t nfn,mfn_t ofn, +unsigned int level) { -if ( level !=1 || nt == ot ) -return ; +BUG_ON (level >1 && (nt == p2m_ioreq_server || nt == p2m_map_foreign)); + +if ( level !=1 || (nt == ot &&mfn_eq (nfn, ofn)) ) +return 0 ;switch ( nt ) {
@@ -948,6 +951,18 @@ static inline void p2m_entry_modify(struct p2m_domain *p2m, p2m_type_t nt, p2m->ioreq.entry_count++;break ; +case p2m_map_foreign: +if ( !mfn_valid (nfn) ) + { +ASSERT_UNREACHABLE (); +return -EINVAL ; + } + +if ( !page_get_owner_and_reference (mfn_to_page (nfn)) ) +return -EBUSY ; + +break ; +default :break ; }
@@ -959,9 +974,20 @@ static inline void p2m_entry_modify(struct p2m_domain *p2m, p2m_type_t nt, p2m->ioreq.entry_count--;break ; +case p2m_map_foreign: +if ( !mfn_valid (ofn) ) + { +ASSERT_UNREACHABLE (); +return -EINVAL ; + } +put_page (mfn_to_page (ofn)); +break ; +default : break; } + +return 0 ; }#endif /* _XEN_ASM_X86_P2M_H */
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6 4/5] x86/mm: handle foreign mappings in p2m_entry_modify
Quoted 8 lines · Roger Pau Monne
So that the specific handling can be removed from
atomic_write_ept_entryand be shared with npt and shadow code.This commit also removes the check that prevent non-ept PVH dom0 from mapping foreign pages.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Kevin Tian <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6 4/5] x86/mm: handle foreign mappings in p2m_entry_modify
In reply to Roger Pau MonneQuoted 8 lines · Roger Pau Monne
So that the specific handling can be removed from
atomic_write_ept_entryand be shared with npt and shadow code.This commit also removes the check that prevent non-ept PVH dom0 from mapping foreign pages.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Kevin Tian <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v6 5/5 npt/shadow: allow getting foreign page table entries
In reply to Roger Pau MonneCurrent npt and shadow code to get an entry will always return INVALID_MFN for foreign entries. Allow to return the entry mfn for foreign entries, like it's done for grant table entries.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v2:
- Use p2m_is_any_ram.
--- xen/arch/x86/mm/p2m-pt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m-pt.c +2 -2
@@ -903,8 +903,8 @@ pod_retry_l1: *t =p2m_recalc_type (recalc ||_needs_recalc (flags), l1t, p2m, gfn);unmap_domain_page (l1e); -ASSERT (mfn_valid (mfn) || !p2m_is_ram (*t) ||p2m_is_paging (*t)); -return (p2m_is_valid (*t) ||p2m_is_grant (*t)) ? mfn :INVALID_MFN ; +ASSERT (mfn_valid (mfn) || !p2m_is_any_ram (*t) ||p2m_is_paging (*t)); +return (p2m_is_valid (*t) ||p2m_is_any_ram (*t)) ? mfn :INVALID_MFN ; } static void p2m_pt_change_entry_type_global(struct p2m_domain *p2m,
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6 5/5] npt/shadow: allow getting foreign page table entries
Quoted 6 lines · Roger Pau Monne
Current npt and shadow code to get an entry will always return
INVALID_MFNfor foreign entries. Allow to return the entry mfn for foreign entries, like it's done for grant table entries.Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v6 5/5] npt/shadow: allow getting foreign page table entries
In reply to Roger Pau MonneQuoted 6 lines · Roger Pau Monne
Current npt and shadow code to get an entry will always return
INVALID_MFNfor foreign entries. Allow to return the entry mfn for foreign entries, like it's done for grant table entries.Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel