[PATCH] x86: replace a few more is_hvm_*() by is_pv_*()

Jan Beulich posted 1 patch 1 week ago
[PATCH] x86: replace a few more is_hvm_*() by is_pv_*()
Posted by Jan Beulich 1 week ago
Along the lines of [1]. Both (respectively negated) can be used
interchangeably when no system domains are (potentially) involved.

For gtime_to_gtsc():
- with !is_hvm_domain() and HVM=n the conditional but not its body would
  disappear,
- with is_pv_domain() and PV=n, the conditional and its body will
  disappear.
Then mirror the change to gtsc_to_gtime() for consistency.

For mem_sharing_control() vm_event_toggle_singlestep(), as VM_EVENT /
MEM_SHARING depend on HVM anyway, the !is_hvm() form can't ever become
compile-time constant, while the is_pv() form can. Same for PoD code,
HVM-specific pieces of shadow/{common,multi}.c, and everything in
shadow/hvm.c.

[1] https://lists.xen.org/archives/html/xen-devel/2026-08/msg01156.html

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
Pretty likely there are more instances of this pattern that could do with
using the opposite predicate. However, e.g. further is_{hvm,pv}() uses in
time.c look to be asking for a little more trickery to benefit both PV=n
and HVM=n (not at the same time, of course).

As to system domains, and as previously pointed out: is_pv_domain() is odd
there for the PV=n case. With PV=y it returns true there, while with PV=n
it yields false.

--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -1509,7 +1509,7 @@ static inline int mem_sharing_control(st
 {
     if ( enable )
     {
-        if ( unlikely(!is_hvm_domain(d) || !cpu_has_vmx) )
+        if ( unlikely(is_pv_domain(d) || !cpu_has_vmx) )
             return -EOPNOTSUPP;
 
         if ( unlikely(!hap_enabled(d)) )
--- a/xen/arch/x86/mm/p2m-pod.c
+++ b/xen/arch/x86/mm/p2m-pod.c
@@ -353,7 +353,7 @@ void p2m_pod_get_mem_target(const struct
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
-    ASSERT(is_hvm_domain(d));
+    ASSERT(!is_pv_domain(d));
 
     pod_lock(p2m);
     lock_page_alloc(p2m);
@@ -1432,7 +1432,7 @@ bool p2m_pod_active(const struct domain
     struct p2m_domain *p2m;
     bool res;
 
-    if ( !is_hvm_domain(d) )
+    if ( is_pv_domain(d) )
         return false;
 
     p2m = p2m_get_hostp2m(d);
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -171,7 +171,7 @@ void shadow_promote(struct domain *d, mf
     {
         page->shadow_flags = 0;
 #ifdef CONFIG_HVM
-        if ( is_hvm_domain(d) )
+        if ( !is_pv_domain(d) )
             page->pagetable_dying = false;
 #endif
     }
@@ -1520,7 +1520,7 @@ int sh_remove_all_mappings(struct domain
                    mfn_x(gmfn), gfn_x(gfn),
                    page->count_info, page->u.inuse.type_info,
                    is_special_page(page),
-                   (is_hvm_domain(d) && is_ioreq_server_page(d, page)));
+                   (!is_pv_domain(d) && is_ioreq_server_page(d, page)));
     }
 
     paging_unlock(d);
@@ -2318,7 +2318,7 @@ void shadow_teardown(struct domain *d, b
     d->arch.paging.mode &= ~PG_log_dirty;
 
 #ifdef CONFIG_HVM
-    if ( is_hvm_domain(d) && d->arch.hvm.dirty_vram.sh )
+    if ( !is_pv_domain(d) && d->arch.hvm.dirty_vram.sh )
     {
         xfree(d->arch.hvm.dirty_vram.sh->sl1ma);
         xfree(d->arch.hvm.dirty_vram.sh->dirty_bitmap);
--- a/xen/arch/x86/mm/shadow/hvm.c
+++ b/xen/arch/x86/mm/shadow/hvm.c
@@ -315,7 +315,7 @@ const struct x86_emulate_ops *shadow_ini
     const struct vcpu *curr = current;
     unsigned long addr;
 
-    ASSERT(is_hvm_vcpu(curr));
+    ASSERT(!is_pv_vcpu(curr));
 
     memset(sh_ctxt, 0, sizeof(*sh_ctxt));
 
@@ -361,7 +361,7 @@ void shadow_continue_emulation(struct sh
 {
     unsigned long addr, diff;
 
-    ASSERT(is_hvm_vcpu(current));
+    ASSERT(!is_pv_vcpu(current));
 
     /*
      * We don't refetch the segment bases, because we don't emulate
@@ -1217,7 +1217,7 @@ void shadow_vram_get_mfn(mfn_t mfn, unsi
     unsigned long gfn;
     struct sh_dirty_vram *dirty_vram = d->arch.hvm.dirty_vram.sh;
 
-    ASSERT(is_hvm_domain(d));
+    ASSERT(!is_pv_domain(d));
 
     if ( !dirty_vram /* tracking disabled? */ ||
          !(l1f & _PAGE_RW) /* read-only mapping? */ ||
@@ -1247,7 +1247,7 @@ void shadow_vram_put_mfn(mfn_t mfn, unsi
     unsigned long gfn;
     struct sh_dirty_vram *dirty_vram = d->arch.hvm.dirty_vram.sh;
 
-    ASSERT(is_hvm_domain(d));
+    ASSERT(!is_pv_domain(d));
 
     if ( !dirty_vram /* tracking disabled? */ ||
          !(l1f & _PAGE_RW) /* read-only mapping? */ ||
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -601,7 +601,7 @@ _sh_propagate(struct vcpu *v,
         sflags &= ~_PAGE_RW;
 
 #ifdef CONFIG_HVM
-    if ( unlikely(level == 1) && is_hvm_domain(d) )
+    if ( unlikely(level == 1) && !is_pv_domain(d) )
     {
         struct sh_dirty_vram *dirty_vram = d->arch.hvm.dirty_vram.sh;
 
@@ -2240,7 +2240,7 @@ static int cf_check sh_page_fault(
 #ifdef CONFIG_HVM
             /* Magic MMIO marker: extract gfn for MMIO address */
             ASSERT(sh_l1e_is_mmio(sl1e));
-            ASSERT(is_hvm_vcpu(v));
+            ASSERT(!is_pv_vcpu(v));
             gpa = gfn_to_gaddr(sh_l1e_mmio_get_gfn(sl1e)) | (va & ~PAGE_MASK);
             perfc_incr(shadow_fault_fast_mmio);
             SHADOW_PRINTK("fast path mmio %#"PRIpaddr"\n", gpa);
@@ -2562,7 +2562,7 @@ static int cf_check sh_page_fault(
     /* Need to hand off device-model MMIO to the device model */
     if ( p2mt == p2m_mmio_dm )
     {
-        ASSERT(is_hvm_vcpu(v));
+        ASSERT(!is_pv_vcpu(v));
 
         sh_audit_gw(v, &gw);
         gpa = guest_walk_to_gpa(&gw);
@@ -2589,7 +2589,7 @@ static int cf_check sh_page_fault(
      * CR0.WP is clear, we must emulate faulting supervisor writes to
      * allow the guest to write through read-only PTEs.  Emulate if the
      * fault was a non-user write to a present page.  */
-    if ( is_hvm_domain(d)
+    if ( !is_pv_domain(d)
          && unlikely(!hvm_wp_enabled(v))
          && regs->error_code == (PFEC_write_access|PFEC_page_present)
          && mfn_valid(gmfn) )
@@ -3718,7 +3718,7 @@ static void cf_check sh_pagetable_dying(
     unsigned long l3gfn;
     mfn_t l3mfn;
 
-    ASSERT(is_hvm_domain(d));
+    ASSERT(!is_pv_domain(d));
 
     gcr3 = v->arch.hvm.guest_cr[3];
     /* fast path: the pagetable belongs to the current context */
@@ -3794,7 +3794,7 @@ static void cf_check sh_pagetable_dying(
     mfn_t smfn, gmfn;
     p2m_type_t p2mt;
 
-    ASSERT(is_hvm_domain(d));
+    ASSERT(!is_pv_domain(d));
 
     gmfn = get_gfn_query(d, _gfn(gpa >> PAGE_SHIFT), &p2mt);
     paging_lock(d);
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2867,7 +2867,7 @@ custom_param("tsc", tsc_parse);
 
 uint64_t gtime_to_gtsc(const struct domain *d, uint64_t time)
 {
-    if ( !is_hvm_domain(d) )
+    if ( is_pv_domain(d) )
     {
         if ( time < d->arch.vtsc_offset )
             return -scale_delta(d->arch.vtsc_offset - time,
@@ -2880,7 +2880,7 @@ uint64_t gtime_to_gtsc(const struct doma
 #ifdef CONFIG_HVM
 uint64_t gtsc_to_gtime(const struct domain *d, uint64_t tsc)
 {
-    ASSERT(is_hvm_domain(d));
+    ASSERT(!is_pv_domain(d));
     return scale_delta(tsc, &d->arch.vtsc_to_ns);
 }
 #endif /* CONFIG_HVM */
--- a/xen/arch/x86/vm_event.c
+++ b/xen/arch/x86/vm_event.c
@@ -65,7 +65,7 @@ void vm_event_toggle_singlestep(struct d
                          VM_EVENT_FLAG_FAST_SINGLESTEP)) )
         return;
 
-    if ( !is_hvm_domain(d) )
+    if ( is_pv_domain(d) )
         return;
 
     ASSERT(atomic_read(&v->vm_event_pause_count));