x86/altp2m: clean up p2m_{get/set}_suppress_ve()
PATCH v3 1/1 x86/altp2m: clean up p2m_{get/set}_suppress_ve()
Move p2m_{get/set}_suppress_ve() to p2m.c, replace incorrect ASSERT() in p2m-pt.c (since a guest can run in shadow mode even on a system with virt exceptions, which would trigger the ASSERT()), move the VMX-isms (cpu_has_vmx_virt_exceptions checks) to p2m_ept_{get/set}_entry(), and fix locking code in p2m_get_suppress_ve().
---
Changes since V2:
- Rebased on staging, double-checked the patch.
--- xen/arch/x86/mm/mem_access.c | 102 ------------------------------------------- xen/arch/x86/mm/p2m-ept.c | 11 +++++ xen/arch/x86/mm/p2m-pt.c | 3 +- xen/arch/x86/mm/p2m.c | 90 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 103 deletions(-)
xen/arch/x86/mm/mem_access.c +0 -102
@@ -514,108 +514,6 @@ void arch_p2m_set_access_required(struct domain *d, bool access_required)#endif } -#ifdef CONFIG_HVM -/* -* Set/clear the #VE suppress bit for a page. Only available on VMX. -*/ -int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve, -unsigned int altp2m_idx) -{ -struct p2m_domain *host_p2m =p2m_get_hostp2m (d); -struct p2m_domain *ap2m =NULL ; -struct p2m_domain *p2m; -mfn_t mfn; -p2m_access_t a; -p2m_type_t t; -int rc; - -if ( !cpu_has_vmx_virt_exceptions ) -return -EOPNOTSUPP ; - -/* #VE should be enabled for this vcpu. */ -if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) -return -ENXIO ; - -if ( altp2m_idx >0 ) - { -if ( altp2m_idx >=MAX_ALTP2M || - d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) -return -EINVAL ; - - p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; - } -else - p2m = host_p2m; - -gfn_lock (host_p2m, gfn,0 ); - -if ( ap2m ) -p2m_lock (ap2m); - - mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL ,NULL ); -if ( !mfn_valid (mfn) ) - { - rc = -ESRCH ; - goto out; - } - - rc = p2m->set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , t, a, suppress_ve); - -out: -if ( ap2m ) -p2m_unlock (ap2m); - -gfn_unlock (host_p2m, gfn,0 ); - -return rc; -} - -int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, -unsigned int altp2m_idx) -{ -struct p2m_domain *host_p2m =p2m_get_hostp2m (d); -struct p2m_domain *ap2m =NULL ; -struct p2m_domain *p2m; -mfn_t mfn; -p2m_access_t a; -p2m_type_t t; - -if ( !cpu_has_vmx_virt_exceptions ) -return -EOPNOTSUPP ; - -/* #VE should be enabled for this vcpu. */ -if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) -return -ENXIO ; - -if ( altp2m_idx >0 ) - { -if ( altp2m_idx >=MAX_ALTP2M || - d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) -return -EINVAL ; - - p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; - } -else - p2m = host_p2m; - -gfn_lock (host_p2m, gfn,0 ); - -if ( ap2m ) -p2m_lock (ap2m); - - mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL , suppress_ve); -if ( !mfn_valid (mfn) ) -return -ESRCH ; - -if ( ap2m ) -p2m_unlock (ap2m); - -gfn_unlock (host_p2m, gfn,0 ); - -return 0 ; -} -#endif -/* * Local variables: * mode: C
xen/arch/x86/mm/p2m-ept.c +11 -0
@@ -697,6 +697,17 @@ ept_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,struct domain *d = p2m->domain;ASSERT (ept); + +if ( !sve ) + { +if ( !cpu_has_vmx_virt_exceptions ) +return -EOPNOTSUPP ; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return -ENXIO ; + } +/* * the caller must make sure: * 1. passing valid gfn and mfn at order boundary.
xen/arch/x86/mm/p2m-pt.c +2 -1
@@ -501,7 +501,8 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,unsigned int flags, iommu_old_flags =0 ;unsigned long old_mfn =mfn_x (INVALID_MFN ); -ASSERT (sve !=0 ); +if ( !sve ) +return -EOPNOTSUPP ;if ( tb_init_done ) {
xen/arch/x86/mm/p2m.c +90 -0
96 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines · Razvan Cojocaru
Move p2m_{get/set}_suppress_ve() to
p2m.c, replace incorrectASSERT()inp2m-pt.c(since a guest can run in shadow mode even on a system with virt exceptions, which would trigger theASSERT()), move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry(), and fix locking code inp2m_get_suppress_ve().Signed-off-by Razvan Cojocaru <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines
From: Razvan Cojocaru [mailto:[email protected]]
Sent: Tuesday, September 25, 2018 7:03 PMMove p2m_{get/set}_suppress_ve() to
p2m.c, replace incorrectASSERT()inp2m-pt.c(since a guest can run in shadow mode even on a system with virt exceptions, which would trigger theASSERT()), move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry(), and fix locking code inp2m_get_suppress_ve().Signed-off-by Razvan Cojocaru <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 25.09.18 at 13:02, <[email protected]> wrote:
Move p2m_{get/set}_suppress_ve() to
p2m.c, replace incorrectASSERT()inp2m-pt.c(since a guest can run in shadow mode even on a system with virt exceptions, which would trigger theASSERT()), move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry(), and fix locking code inp2m_get_suppress_ve().Signed-off-by Razvan Cojocaru <[email protected]>---
Changes since V2:
- Rebased on staging, double-checked the patch.
Quoted 6 lines
--- xen/arch/x86/mm/mem_access.c | 102 ------------------------------------------- xen/arch/x86/mm/p2m-ept.c | 11 +++++ xen/arch/x86/mm/p2m-pt.c | 3 +- xen/arch/x86/mm/p2m.c | 90 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 103 deletions(-)
I still have this in my to-be-applied list, but I'm not sure whether it's now stale, and it's still missing an ack from Tamas.
Jan
Quoted 255 lines
xen/arch/x86/mm/mem_access.c +0
-102@@ -514,108 +514,6 @@ void arch_p2m_set_access_required(struct domain *d, bool access_required)#endif } -#ifdef CONFIG_HVM -/* -* Set/clear the #VE suppress bit for a page. Only available on VMX. -*/ -int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve, -unsigned int altp2m_idx) -{ -struct p2m_domain *host_p2m =p2m_get_hostp2m (d); -struct p2m_domain *ap2m =NULL ; -struct p2m_domain *p2m; -mfn_t mfn; -p2m_access_t a; -p2m_type_t t; -int rc; - -if ( !cpu_has_vmx_virt_exceptions ) -return -EOPNOTSUPP ; - -/* #VE should be enabled for this vcpu. */ -if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) -return -ENXIO ; - -if ( altp2m_idx >0 ) - { -if ( altp2m_idx >=MAX_ALTP2M || - d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) -return -EINVAL ; - - p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; - } -else - p2m = host_p2m; - -gfn_lock (host_p2m, gfn,0 ); - -if ( ap2m ) -p2m_lock (ap2m); - - mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL ,NULL ); -if ( !mfn_valid (mfn) ) - { - rc = -ESRCH ; - goto out; - } - - rc = p2m->set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , t, a, suppress_ve); - -out: -if ( ap2m ) -p2m_unlock (ap2m); - -gfn_unlock (host_p2m, gfn,0 ); - -return rc; -} - -int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, -unsigned int altp2m_idx) -{ -struct p2m_domain *host_p2m =p2m_get_hostp2m (d); -struct p2m_domain *ap2m =NULL ; -struct p2m_domain *p2m; -mfn_t mfn; -p2m_access_t a; -p2m_type_t t; - -if ( !cpu_has_vmx_virt_exceptions ) -return -EOPNOTSUPP ; - -/* #VE should be enabled for this vcpu. */ -if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) -return -ENXIO ; - -if ( altp2m_idx >0 ) - { -if ( altp2m_idx >=MAX_ALTP2M || - d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) -return -EINVAL ; - - p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; - } -else - p2m = host_p2m; - -gfn_lock (host_p2m, gfn,0 ); - -if ( ap2m ) -p2m_lock (ap2m); - - mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL , suppress_ve); -if ( !mfn_valid (mfn) ) -return -ESRCH ; - -if ( ap2m ) -p2m_unlock (ap2m); - -gfn_unlock (host_p2m, gfn,0 ); - -return 0 ; -} -#endif -/* * Local variables: * mode: C
xen/arch/x86/mm/p2m-ept.c +11
-0@@ -697,6 +697,17 @@ ept_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn, struct domain *d = p2m->domain;ASSERT (ept); + +if ( !sve ) + { +if ( !cpu_has_vmx_virt_exceptions ) +return -EOPNOTSUPP ; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return -ENXIO ; + } +/* * the caller must make sure: * 1. passing valid gfn and mfn at order boundary.
xen/arch/x86/mm/p2m-pt.c +2
-1@@ -501,7 +501,8 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_,mfn_t mfn, unsigned int flags, iommu_old_flags = 0;unsigned long old_mfn =mfn_x (INVALID_MFN ); -ASSERT (sve !=0 ); +if ( !sve ) +return -EOPNOTSUPP ;if ( tb_init_done ){xen/arch/x86/mm/p2m.c +90
-0@@ -2764,6 +2764,96 @@ out:rcu_unlock_domain (fdom);return rc; } + +#ifdef CONFIG_HVM +/* +* Set/clear the #VE suppress bit for a page. Only available on VMX. +*/ +int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve, +unsigned int altp2m_idx) +{ +struct p2m_domain *host_p2m =p2m_get_hostp2m (d); +struct p2m_domain *ap2m =NULL ; +struct p2m_domain *p2m; +mfn_t mfn; +p2m_access_t a; +p2m_type_t t; +int rc; + +if ( altp2m_idx >0 ) + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; + + p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; + } +else + p2m = host_p2m; + +gfn_lock (host_p2m, gfn,0 ); + +if ( ap2m ) +p2m_lock (ap2m); + + mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL ,NULL ); +if ( !mfn_valid (mfn) ) + { + rc = -ESRCH ; + goto out; + } + + rc = p2m->set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , t, a, suppress_ve); + +out: +if ( ap2m ) +p2m_unlock (ap2m); + +gfn_unlock (host_p2m, gfn,0 ); + +return rc; +} + +int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, +unsigned int altp2m_idx) +{ +struct p2m_domain *host_p2m =p2m_get_hostp2m (d); +struct p2m_domain *ap2m =NULL ; +struct p2m_domain *p2m; +mfn_t mfn; +p2m_access_t a; +p2m_type_t t; +int rc =0 ; + +if ( altp2m_idx >0 ) + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; + + p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; + } +else + p2m = host_p2m; + +gfn_lock (host_p2m, gfn,0 ); + +if ( ap2m ) +p2m_lock (ap2m); + + mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL , suppress_ve); +if ( !mfn_valid (mfn) ) + rc = -ESRCH ; + +if ( ap2m ) +p2m_unlock (ap2m); + +gfn_unlock (host_p2m, gfn,0 ); + +return rc; +} +#endif +/* * Local variables: * mode: C Signature · 1 line
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 25.09.18 at 13:02, <[email protected]> wrote:
Move p2m_{get/set}_suppress_ve() to
p2m.c, replace incorrectASSERT()inp2m-pt.c(since a guest can run in shadow mode even on a system with virt exceptions, which would trigger theASSERT()), move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry(), and fix locking code inp2m_get_suppress_ve().Signed-off-by Razvan Cojocaru <[email protected]>---
Changes since V2:
- Rebased on staging, double-checked the patch.Quoted 6 lines
--- xen/arch/x86/mm/mem_access.c | 102 ------------------------------------------- xen/arch/x86/mm/p2m-ept.c | 11 +++++ xen/arch/x86/mm/p2m-pt.c | 3 +- xen/arch/x86/mm/p2m.c | 90 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 103 deletions(-)
Quoted 2 lines
I still have this in my to-be-applied list, but I'm not sure whether it's now stale, and it's still missing an ack from Tamas.
It has already been applied by George:
https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=0348184dd2ee43d343623d3db647af3e635fd0c3
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel