[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 03/25] xen/x86: complement PG_log_dirty wrapping


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Sun, 3 Aug 2025 17:47:16 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zKfaBv21hy3PX6mTeeZ/7uP64ANF3Yth3995UwDHufA=; b=IasKbFx7FM7HgS5gS0BF1sSYl9r7vcZVe/Na7/p99c5Wz99bnb9UCN/o1UZb18z5BwU/dOyb/qJDMjBXGZp/1NoQH0pWQDa7p6/D4c7ovT1ioPPuIrN+WTpthKRbbrzQ5AQNiUIzEwOMU7ff67QceC/BBXzGdZHRumAAgkQa9uddk7qUHVhSfR0SftL4WL8XFqakdPFrXH0ZMvloOR0FjkZq9Q9UnjfSNoGCyhzIKkb/YxgWzP/UlM0UZ6Q+u5VQXIHzm6VS64vzMJGo6bmgaM99qmntv8mu1hrH92uunZbBfZHNiWNeR+/4dQdm/ghRuXMQt2Bo3t5m/RHmiCNsPg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IC0NaRaDI2pu/xzL5DuhIccR8iIPDArRIDuf0laeJyyLigOMcdc78IhEollBIMyCvhAHxvz3LVPvlxxhdMjUt739gwseXU/t47IBUH3waIz9WmD/aJWPb2WexZYvKF/78TA1D/QtO2vDKISRaFOTorbbFJWjs8sfAJc59eHLtjzE1Qmk8/ZvIlYWmtos9Rj8AyvLBGHzsilKSLBk6omaIjjv3vpS8BKVZxTVXi98Fr0lRcuxwFf2CRp0cZYSZiNtLCVXQPktOPggwKTCaph+et+xU2eo507FEJ1z+b1M62/iNyW6pQa4t3impYb/T04+MOVkvXRG3vHA2TlkYYpb+w==
  • Cc: <ray.huang@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Tim Deegan" <tim@xxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Sun, 03 Aug 2025 09:48:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

We have PG_log_dirty flag to wrap codes about paging log-dirty support.
The main entry is paging_domctl(), and tracking its call chain, the
following functions needs wrapping too:
- xsm_shadow_control
- hvm_mapped_guest_frames_mark_dirty
- hap_domctl
- shadow_domctl
  - shadow_test_disable
    - shadow_one_bit_disable
  - shadow_test_enable
  - shadow_get_allocation
- log_dirty_ops.enable
  - hap_enable_log_dirty
  - sh_enable_log_dirty
  - _toggle_log_dirty
- log_dirty_ops.disable
  - hap_disable_log_dirty
  - sh_disable_log_dirty
- log_dirty_ops.clean
  - hap_clean_dirty_bitmap
  - sh_clean_dirty_bitmap
  - _clean_dirty_bitmap
Wrap paging_domctl hypercall-defs with PG_log_dirty and release PG_log_dirty
from PV_SHIM_EXCLUSIVE, as PV_SHIM_EXCLUSIVE will be cleaned up in the future.

Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
---
 xen/arch/x86/domctl.c                | 4 ++++
 xen/arch/x86/hvm/hvm.c               | 2 ++
 xen/arch/x86/include/asm/hypercall.h | 2 ++
 xen/arch/x86/include/asm/paging.h    | 2 +-
 xen/arch/x86/mm/hap/hap.c            | 6 ++++++
 xen/arch/x86/mm/shadow/common.c      | 8 ++++++++
 xen/arch/x86/mm/shadow/none.c        | 4 ++++
 xen/include/hypercall-defs.c         | 4 ++++
 xen/include/xsm/xsm.h                | 4 ++++
 xen/xsm/dummy.c                      | 2 ++
 xen/xsm/flask/hooks.c                | 4 ++++
 11 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 3044f706de..156c74e07a 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -213,10 +213,14 @@ long arch_do_domctl(
     {
 
     case XEN_DOMCTL_shadow_op:
+#if PG_log_dirty
         ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
         if ( ret == -ERESTART )
             return hypercall_create_continuation(
                        __HYPERVISOR_paging_domctl_cont, "h", u_domctl);
+#else
+        ret = -EOPNOTSUPP;
+#endif /* PG_log_dirty */
         copyback = true;
         break;
 
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index cb8ecd050d..ea97815deb 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2831,6 +2831,7 @@ void hvm_unmap_guest_frame(void *p, bool permanent)
     put_page(page);
 }
 
+#if PG_log_dirty
 void hvm_mapped_guest_frames_mark_dirty(struct domain *d)
 {
     struct hvm_write_map *track;
@@ -2840,6 +2841,7 @@ void hvm_mapped_guest_frames_mark_dirty(struct domain *d)
         paging_mark_dirty(d, page_to_mfn(track->page));
     spin_unlock(&d->arch.hvm.write_map.lock);
 }
+#endif /* PG_log_dirty */
 
 static void *hvm_map_entry(unsigned long va, bool *writable)
 {
diff --git a/xen/arch/x86/include/asm/hypercall.h 
b/xen/arch/x86/include/asm/hypercall.h
index f6e9e2313b..fac93527ce 100644
--- a/xen/arch/x86/include/asm/hypercall.h
+++ b/xen/arch/x86/include/asm/hypercall.h
@@ -16,7 +16,9 @@
 #include <public/arch-x86/xen-mca.h> /* for do_mca */
 #include <asm/paging.h>
 
+#if PG_log_dirty
 #define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
+#endif
 
 #ifdef CONFIG_PV
 void pv_hypercall(struct cpu_user_regs *regs);
diff --git a/xen/arch/x86/include/asm/paging.h 
b/xen/arch/x86/include/asm/paging.h
index 173a569610..956b83215c 100644
--- a/xen/arch/x86/include/asm/paging.h
+++ b/xen/arch/x86/include/asm/paging.h
@@ -55,7 +55,7 @@
 #define PG_translate   0
 #define PG_external    0
 #endif
-#if defined(CONFIG_HVM) || !defined(CONFIG_PV_SHIM_EXCLUSIVE)
+#if defined(CONFIG_HVM)
 /* Enable log dirty mode */
 #define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
 #else
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index 668a233923..ccbc9128dd 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -189,6 +189,7 @@ out:
     return rc;
 }
 
+#if PG_log_dirty
 /************************************************/
 /*            HAP LOG DIRTY SUPPORT             */
 /************************************************/
@@ -254,6 +255,7 @@ static void cf_check hap_clean_dirty_bitmap(struct domain 
*d)
     p2m_change_entry_type_global(d, p2m_ram_rw, p2m_ram_logdirty);
     guest_flush_tlb_mask(d, d->dirty_cpumask);
 }
+#endif /* PG_log_dirty */
 
 /************************************************/
 /*             HAP SUPPORT FUNCTIONS            */
@@ -468,9 +470,11 @@ static bool cf_check flush_tlb(const unsigned long 
*vcpu_bitmap);
 void hap_domain_init(struct domain *d)
 {
     static const struct log_dirty_ops hap_ops = {
+#if PG_log_dirty
         .enable  = hap_enable_log_dirty,
         .disable = hap_disable_log_dirty,
         .clean   = hap_clean_dirty_bitmap,
+#endif
     };
 
     /* Use HAP logdirty mechanism. */
@@ -662,6 +666,7 @@ out:
     paging_unlock(d);
 }
 
+#if PG_log_dirty
 int hap_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
@@ -692,6 +697,7 @@ int hap_domctl(struct domain *d, struct 
xen_domctl_shadow_op *sc,
         return -EINVAL;
     }
 }
+#endif /* PG_log_dirty */
 
 static const struct paging_mode hap_paging_real_mode;
 static const struct paging_mode hap_paging_protected_mode;
diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c
index 0176e33bc9..f678e7b149 100644
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -69,9 +69,11 @@ const uint8_t sh_type_to_size[] = {
 
 DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags);
 
+#if PG_log_dirty
 static int cf_check sh_enable_log_dirty(struct domain *);
 static int cf_check sh_disable_log_dirty(struct domain *);
 static void cf_check sh_clean_dirty_bitmap(struct domain *);
+#endif
 
 static void cf_check shadow_update_paging_modes(struct vcpu *);
 
@@ -80,9 +82,11 @@ static void cf_check shadow_update_paging_modes(struct vcpu 
*);
 int shadow_domain_init(struct domain *d)
 {
     static const struct log_dirty_ops sh_ops = {
+#if PG_log_dirty
         .enable  = sh_enable_log_dirty,
         .disable = sh_disable_log_dirty,
         .clean   = sh_clean_dirty_bitmap,
+#endif
     };
 
     INIT_PAGE_LIST_HEAD(&d->arch.paging.shadow.pinned_shadows);
@@ -1414,6 +1418,7 @@ int shadow_set_allocation(struct domain *d, unsigned int 
pages, bool *preempted)
     return 0;
 }
 
+#if PG_log_dirty
 /* Return the size of the shadow pool, rounded up to the nearest MB */
 static unsigned int shadow_get_allocation(struct domain *d)
 {
@@ -1422,6 +1427,7 @@ static unsigned int shadow_get_allocation(struct domain 
*d)
     return ((pg >> (20 - PAGE_SHIFT))
             + ((pg & ((1 << (20 - PAGE_SHIFT)) - 1)) ? 1 : 0));
 }
+#endif /* PG_log_dirty */
 
 /**************************************************************************/
 /* Hash table for storing the guest->shadow mappings.
@@ -2958,6 +2964,7 @@ static int shadow_one_bit_enable(struct domain *d, u32 
mode)
     return 0;
 }
 
+#if PG_log_dirty
 static int shadow_one_bit_disable(struct domain *d, u32 mode)
 /* Turn off a single shadow mode feature */
 {
@@ -3158,6 +3165,7 @@ int shadow_domctl(struct domain *d,
     }
 }
 
+#endif /* PG_log_dirty */
 
 /**************************************************************************/
 /* Auditing shadow tables */
diff --git a/xen/arch/x86/mm/shadow/none.c b/xen/arch/x86/mm/shadow/none.c
index 2a4005a795..6c6971b458 100644
--- a/xen/arch/x86/mm/shadow/none.c
+++ b/xen/arch/x86/mm/shadow/none.c
@@ -1,6 +1,7 @@
 #include <xen/mm.h>
 #include <asm/shadow.h>
 
+#if PG_log_dirty
 static int cf_check _toggle_log_dirty(struct domain *d)
 {
     ASSERT(is_pv_domain(d));
@@ -11,6 +12,7 @@ static void cf_check _clean_dirty_bitmap(struct domain *d)
 {
     ASSERT(is_pv_domain(d));
 }
+#endif /* PG_log_dirty */
 
 static void cf_check _update_paging_modes(struct vcpu *v)
 {
@@ -21,9 +23,11 @@ int shadow_domain_init(struct domain *d)
 {
     /* For HVM set up pointers for safety, then fail. */
     static const struct log_dirty_ops sh_none_ops = {
+#if PG_log_dirty
         .enable  = _toggle_log_dirty,
         .disable = _toggle_log_dirty,
         .clean   = _clean_dirty_bitmap,
+#endif
     };
 
     paging_log_dirty_init(d, &sh_none_ops);
diff --git a/xen/include/hypercall-defs.c b/xen/include/hypercall-defs.c
index a2f2a7fa75..c70f745ac2 100644
--- a/xen/include/hypercall-defs.c
+++ b/xen/include/hypercall-defs.c
@@ -198,7 +198,9 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t 
*bufs)
 sysctl(xen_sysctl_t *u_sysctl)
 #endif
 domctl(xen_domctl_t *u_domctl)
+#if PG_log_dirty
 paging_domctl_cont(xen_domctl_t *u_domctl)
+#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif
@@ -294,6 +296,8 @@ dm_op                              compat   do       compat 
  do       do
 hypfs_op                           do       do       do       do       do
 #endif
 mca                                do       do       -        -        -
+#if PG_log_dirty
 paging_domctl_cont                 do       do       do       do       -
+#endif
 
 #endif /* !CPPCHECK */
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index 9a23d2827c..dad69905c9 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -173,7 +173,9 @@ struct xsm_ops {
 
 #ifdef CONFIG_X86
     int (*do_mca)(void);
+#if PG_log_dirty
     int (*shadow_control)(struct domain *d, uint32_t op);
+#endif
     int (*mem_sharing_op)(struct domain *d, struct domain *cd, int op);
     int (*apic)(struct domain *d, int cmd);
     int (*machine_memory_map)(void);
@@ -687,11 +689,13 @@ static inline int xsm_do_mca(xsm_default_t def)
     return alternative_call(xsm_ops.do_mca);
 }
 
+#if PG_log_dirty
 static inline int xsm_shadow_control(
     xsm_default_t def, struct domain *d, uint32_t op)
 {
     return alternative_call(xsm_ops.shadow_control, d, op);
 }
+#endif
 
 static inline int xsm_mem_sharing_op(
     xsm_default_t def, struct domain *d, struct domain *cd, int op)
diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c
index 8b7e01b506..8a893c6eee 100644
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -132,7 +132,9 @@ static const struct xsm_ops __initconst_cf_clobber 
dummy_ops = {
     .platform_op                   = xsm_platform_op,
 #ifdef CONFIG_X86
     .do_mca                        = xsm_do_mca,
+#if PG_log_dirty
     .shadow_control                = xsm_shadow_control,
+#endif
     .mem_sharing_op                = xsm_mem_sharing_op,
     .apic                          = xsm_apic,
     .machine_memory_map            = xsm_machine_memory_map,
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index b0308e1b26..0382182f94 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -1605,6 +1605,7 @@ static int cf_check flask_do_mca(void)
     return domain_has_xen(current->domain, XEN__MCA_OP);
 }
 
+#if PG_log_dirty
 static int cf_check flask_shadow_control(struct domain *d, uint32_t op)
 {
     uint32_t perm;
@@ -1631,6 +1632,7 @@ static int cf_check flask_shadow_control(struct domain 
*d, uint32_t op)
 
     return current_has_perm(d, SECCLASS_SHADOW, perm);
 }
+#endif /* PG_log_dirty */
 
 struct ioport_has_perm_data {
     uint32_t ssid;
@@ -2003,7 +2005,9 @@ static const struct xsm_ops __initconst_cf_clobber 
flask_ops = {
     .platform_op = flask_platform_op,
 #ifdef CONFIG_X86
     .do_mca = flask_do_mca,
+#if PG_log_dirty
     .shadow_control = flask_shadow_control,
+#endif
     .mem_sharing_op = flask_mem_sharing_op,
     .apic = flask_apic,
     .machine_memory_map = flask_machine_memory_map,
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.