Skip to contentSkip to conversation

x86/shadow: Drop SHADOW_AUDIT_ENABLE indirection

PATCH In review Andrew Cooper 2 participants 2 messages Dec 12, 2025 – Dec 15, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/shadow: Drop SHADOW_AUDIT_ENABLE indirection

Simply define shadow_audit_enable to be false for the !SHADOW_AUDIT case.

Change the variable to be a bool, and __read_mostly as it's only enabled by debugkey.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/mm/shadow/common.c  | 8 ++++----
 xen/arch/x86/mm/shadow/multi.c   | 2 +-
 xen/arch/x86/mm/shadow/private.h | 5 ++---
 3 files changed, 7 insertions(+), 8 deletions(-)
xen/arch/x86/mm/shadow/common.c +4 -4
index f2aee5be46a7..e78aac415077 100644
@@ -126,7 +126,7 @@ void shadow_vcpu_init(struct vcpu *v)
 }
 
 #if SHADOW_AUDIT
-int shadow_audit_enable = 0;
+bool __read_mostly shadow_audit_enable;
 
 static void cf_check shadow_audit_key(unsigned char key)
 {
@@ -1453,7 +1453,7 @@ static void sh_hash_audit_bucket(struct domain *d, int bucket)
     struct page_info *sp, *x;
 
     if ( !(SHADOW_AUDIT & (SHADOW_AUDIT_HASH|SHADOW_AUDIT_HASH_FULL)) ||
-         !SHADOW_AUDIT_ENABLE )
+         !shadow_audit_enable )
         return;
 
     sp = d->arch.paging.shadow.hash_table[bucket];
@@ -1522,7 +1522,7 @@ static void sh_hash_audit(struct domain *d)
 {
     int i;
 
-    if ( !(SHADOW_AUDIT & SHADOW_AUDIT_HASH_FULL) || !SHADOW_AUDIT_ENABLE )
+    if ( !(SHADOW_AUDIT & SHADOW_AUDIT_HASH_FULL) || !shadow_audit_enable )
         return;
 
     for ( i = 0; i < SHADOW_HASH_BUCKETS; i++ )
@@ -3188,7 +3188,7 @@ void shadow_audit_tables(struct vcpu *v)
     unsigned int mask;
 
     if ( !(SHADOW_AUDIT & (SHADOW_AUDIT_ENTRIES | SHADOW_AUDIT_ENTRIES_FULL)) ||
-         !SHADOW_AUDIT_ENABLE )
+         !shadow_audit_enable )
         return;
 
     if ( SHADOW_AUDIT & SHADOW_AUDIT_ENTRIES_FULL )
xen/arch/x86/mm/shadow/multi.c +1 -1
index 03be61e225c0..2106643651d9 100644
@@ -314,7 +314,7 @@ static void sh_audit_gw(struct vcpu *v, const walk_t *gw)
     struct domain *d = v->domain;
     mfn_t smfn;
 
-    if ( !(SHADOW_AUDIT_ENABLE) )
+    if ( !shadow_audit_enable )
         return;
 
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */
xen/arch/x86/mm/shadow/private.h +2 -3
index 1ef908a380de..0e63ebea4e17 100644
@@ -33,11 +33,10 @@
 
 #ifdef NDEBUG
 #define SHADOW_AUDIT                   0
-#define SHADOW_AUDIT_ENABLE            0
+#define shadow_audit_enable        false
 #else
 #define SHADOW_AUDIT                0x15  /* Basic audit of all */
-#define SHADOW_AUDIT_ENABLE         shadow_audit_enable
-extern int shadow_audit_enable;
+extern bool shadow_audit_enable;
 #endif
 
 /******************************************************************************
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrew Cooper

Simply define shadow_audit_enable to be false for the !SHADOW_AUDIT case.

Change the variable to be a bool, and __read_mostly as it's only enabled by debugkey.

No functional change.

However, any tidying of shadow code reminds me that I still have a series pending [1]. Iirc you did look at v1 and/or v2, but v3 has been sitting largely unresponded to for two and a half years (one patch went in with Roger's ack, and one other patch was ack-ed by him but apparently wants other stuff to go in first). Can we please see about having that make some progress as well?

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2023-05/msg01140.html