[XEN PATCH v5 02/13] x86/monitor: guard altp2m usage

Sergiy Kibrik posted 13 patches 3 months, 3 weeks ago
There is a newer version of this series
[XEN PATCH v5 02/13] x86/monitor: guard altp2m usage
Posted by Sergiy Kibrik 3 months, 3 weeks ago
Explicitly check whether altp2m is on for domain when getting altp2m index.
If explicit call to altp2m_active() always returns false, DCE will remove
call to altp2m_vcpu_idx().

p2m_get_mem_access() expects 0 as altp2m_idx parameter when altp2m not active
or not supported, so 0 is a fallback value then.

The puspose of that is later to be able to disable altp2m support and
exclude its code from the build completely, when not supported by target
platform (as of now it's supported for VT-d only).

Also all other calls to altp2m_vcpu_idx() are guarded by altp2m_active(), so
this change puts usage of this routine in line with the rest of code.

Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com>
CC: Tamas K Lengyel <tamas@tklengyel.com>
CC: Jan Beulich <jbeulich@suse.com>
---
changes in v5:
 - changed patch description
changes in v2:
 - patch description changed, removed VMX mentioning
 - guard by altp2m_active() instead of hvm_altp2m_supported()
---
 xen/arch/x86/hvm/monitor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c
index 2a8ff07ec9..74621000b2 100644
--- a/xen/arch/x86/hvm/monitor.c
+++ b/xen/arch/x86/hvm/monitor.c
@@ -262,6 +262,8 @@ bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn, uint32_t pfec,
     struct vcpu *curr = current;
     vm_event_request_t req = {};
     paddr_t gpa = (gfn_to_gaddr(gfn) | (gla & ~PAGE_MASK));
+    unsigned int altp2m_idx = altp2m_active(curr->domain) ?
+                              altp2m_vcpu_idx(curr) : 0;
     int rc;
 
     ASSERT(curr->arch.vm_event->send_event);
@@ -270,7 +272,7 @@ bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn, uint32_t pfec,
      * p2m_get_mem_access() can fail from a invalid MFN and return -ESRCH
      * in which case access must be restricted.
      */
-    rc = p2m_get_mem_access(curr->domain, gfn, &access, altp2m_vcpu_idx(curr));
+    rc = p2m_get_mem_access(curr->domain, gfn, &access, altp2m_idx);
 
     if ( rc == -ESRCH )
         access = XENMEM_access_n;
-- 
2.25.1
Re: [XEN PATCH v5 02/13] x86/monitor: guard altp2m usage
Posted by Tamas K Lengyel 3 months, 3 weeks ago
On Tue, Jul 30, 2024 at 6:18 AM Sergiy Kibrik <Sergiy_Kibrik@epam.com> wrote:
>
> Explicitly check whether altp2m is on for domain when getting altp2m index.
> If explicit call to altp2m_active() always returns false, DCE will remove
> call to altp2m_vcpu_idx().
>
> p2m_get_mem_access() expects 0 as altp2m_idx parameter when altp2m not active
> or not supported, so 0 is a fallback value then.
>
> The puspose of that is later to be able to disable altp2m support and

"purpose" misspelled here

> exclude its code from the build completely, when not supported by target
> platform (as of now it's supported for VT-d only).

Probably wanted to say "VT-x only" here

>
> Also all other calls to altp2m_vcpu_idx() are guarded by altp2m_active(), so
> this change puts usage of this routine in line with the rest of code.
>
> Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com>

With the commit message fixed (probably could be done when applied):
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>