x86/altp2m: clean up p2m_{get/set}_suppress_ve()
PATCH 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()), and move the VMX-isms (cpu_has_vmx_virt_exceptions checks) to p2m_ept_{get/set}_entry().
--- xen/arch/x86/mm/mem_access.c | 102 ------------------------------------------- xen/arch/x86/mm/p2m-ept.c | 21 +++++++++ xen/arch/x86/mm/p2m-pt.c | 3 +- xen/arch/x86/mm/p2m.c | 93 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 103 deletions(-)
xen/arch/x86/mm/mem_access.c +0 -102
@@ -501,108 +501,6 @@ void arch_p2m_set_access_required(struct domain *d, bool access_required) } } -#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 +21 -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.
@@ -931,6 +942,16 @@ static mfn_t ept_get_entry(struct p2m_domain *p2m,mfn_t mfn =INVALID_MFN ;struct ept_data *ept = &p2m->ept; +if ( sve ) + { +if ( !cpu_has_vmx_virt_exceptions ) +return INVALID_MFN ; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return INVALID_MFN ; + } + *t = p2m_mmio_dm; *a = p2m_access_n;if ( sve )
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 +93 -0
99 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()), and move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry().Signed-off-by Razvan Cojocaru <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 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()), and move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry().Signed-off-by Razvan Cojocaru <[email protected]>
Thanks for the clean up. Two realtively minor comments...
xen/arch/x86/mm/p2m-ept.c static mfn_t ept_get_entry(struct p2m_domain *p2m, · line 953
Quoted 13 lines
xen/arch/x86/mm/p2m-ept.c +9
-0@@ -931,6 +942,16 @@ static mfn_t ept_get_entry(struct p2m_domain *p2m,mfn_t mfn =INVALID_MFN ;struct ept_data *ept = &p2m->ept; +if ( sve ) + { +if ( !cpu_has_vmx_virt_exceptions ) +return INVALID_MFN ; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return INVALID_MFN ; + }
Is there a good reason to return error her rather than just putting '1' in the sve location, like the p2m_pt.c version of this function does?
xen/arch/x86/mm/p2m.c out: · line 2810
Quoted 13 lines
xen/arch/x86/mm/p2m.c +13
-0+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; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return -ENXIO ;
What's the purpose of checking for this here, if we don't check for this in p2m_set_suppress_ve()?
Everything else looks good, thanks!
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · George Dunlap
Quoted 7 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()), and move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry().Signed-off-by Razvan Cojocaru <[email protected]>Thanks for the clean up. Two realtively minor comments...
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -931,6 +942,16 @@ static mfn_t ept_get_entry(struct p2m_domain *p2m,mfn_t mfn =INVALID_MFN ;struct ept_data *ept = &p2m->ept;
Quoted 12 lines
xen/arch/x86/mm/p2m-ept.c static mfn_t ept_get_entry(struct p2m_domain *p2m, · line 953
Quoted 9 lines
xen/arch/x86/mm/p2m-ept.c +9
-0+if ( sve ) + { +if ( !cpu_has_vmx_virt_exceptions ) +return INVALID_MFN ; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return INVALID_MFN ; + }Is there a good reason to return error her rather than just putting '1' in the sve location, like the
p2m_pt.cversion of this function does?
First, thanks for the review!
The p2m_pt.c version can only return 1 because that's the only value that bit can have on #VE-incapable hardware. For the cpu_has_vmx_virt_exceptions, that assumption does hold, however in a scenario where:
1. we enable #VE and set that bit to 0;
2. we disable #VE (so gfn_eq(vcpu_altp2m(current).veinfo_gfn, INVALID_GFN) == true);
3. we call ept_get_entry();
setting it to 1 would be misleading, since it's value is now really 0.
I do agree that returning INVALID_MFN is no necessarily more informative.
Alternatively, I could simply remove the checks here altogether. If !cpu_has_vmx_virt_exceptions then ept_get_entry() should fail anyway, so the bit will just remain 1 and thus the following code:
999 if ( is_epte_valid(ept_entry) )
1000 {
1001 *t = p2m_recalc_type(recalc || ept_entry->recalc,
1002 ept_entry->sa_p2mt, p2m, gfn);
1003 *a = ept_entry->access;
1004 if ( sve )
1005 *sve = ept_entry->suppress_ve;
should automatically do the right thing. And if, in the above scenario, the bit became 0, we return that value properly as well.
Would that be better?
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m.c +8
-0+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;
Quoted 8 lines
xen/arch/x86/mm/p2m.c out: · line 2810
Quoted 5 lines
xen/arch/x86/mm/p2m.c +5
-0+p2m_type_t t; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return -ENXIO ;What's the purpose of checking for this here, if we don't check for this in
p2m_set_suppress_ve()?
Sorry, I seem to have accidentally left that in p2m_get_suppress_ve() - I'll delete it from here and leave it only in ept_set_entry(). It's pointless to have it duplicated here.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 57 lines · Razvan Cojocaru
Quoted 15 lines · George Dunlap
Quoted 7 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()), and move the VMX-isms (cpu_has_vmx_virt_exceptionschecks) to p2m_ept_{get/set}_entry().Signed-off-by Razvan Cojocaru <[email protected]>Thanks for the clean up. Two realtively minor comments...
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -931,6 +942,16 @@ static mfn_t ept_get_entry(struct p2m_domain *p2m,mfn_t mfn =INVALID_MFN ;struct ept_data *ept = &p2m->ept;Quoted 12 lines
xen/arch/x86/mm/p2m-ept.c static mfn_t ept_get_entry(struct p2m_domain *p2m, · line 953
Quoted 9 lines
xen/arch/x86/mm/p2m-ept.c +9
-0+if ( sve ) + { +if ( !cpu_has_vmx_virt_exceptions ) +return INVALID_MFN ; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return INVALID_MFN ; + }Is there a good reason to return error her rather than just putting '1' in the sve location, like the
p2m_pt.cversion of this function does?First, thanks for the review!
The
p2m_pt.cversion can only return 1 because that's the only value that bit can have on #VE-incapable hardware. For thecpu_has_vmx_virt_exceptions, that assumption does hold, however in a scenario where:1. we enable #VE and set that bit to 0;
2. we disable #VE (sogfn_eq(vcpu_altp2m(current).veinfo_gfn, INVALID_GFN)== true);
3. we callept_get_entry();setting it to 1 would be misleading, since it's value is now really 0.
I do agree that returning
INVALID_MFNis no necessarily more informative.Alternatively, I could simply remove the checks here altogether. If !cpu_has_vmx_virt_exceptions then
ept_get_entry()should fail anyway, so the bit will just remain 1 and thus the following code:999 if (
is_epte_valid(ept_entry))
1000 {
1001 *t = p2m_recalc_type(recalc ||ept_entry->recalc,
1002ept_entry->sa_p2mt, p2m, gfn);
1003 *a =ept_entry->access;
1004 if ( sve )
1005 *sve =ept_entry->suppress_ve;
Quoted 4 lines
should automatically do the right thing. And if, in the above scenario, the bit became 0, we return that value properly as well.
Would that be better?
Sorry, yes, that's what I intended, although I certainly wasn't clear. What I meant was, the pt version of get_entry() would succeed and return something sensible even on non-#VE-capable hardware; why should the ept version not do the same thing?
So yes, I think just removing the checks and letting the actual value from the p2m entry be passed back is the right thing to do.
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
xen/arch/x86/mm/p2m.c +3
-0+int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, +unsigned int altp2m_idx) +{xen/arch/x86/mm/p2m.c out: · line 2810
Quoted 10 lines
xen/arch/x86/mm/p2m.c +10
-0+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; + +/* #VE should be enabled for this vcpu. */ +if (gfn_eq (vcpu_altp2m (current).veinfo_gfn,INVALID_GFN ) ) +return -ENXIO ;What's the purpose of checking for this here, if we don't check for this in
p2m_set_suppress_ve()?
Quoted 3 lines
Sorry, I seem to have accidentally left that in
p2m_get_suppress_ve()- I'll delete it from here and leave it only inept_set_entry(). It's pointless to have it duplicated here.
Great, thanks.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel