Skip to contentSkip to conversation

x86/shadow: Reposition sh_remove_write_access_from_sl1p()

PATCH In review Andrew Cooper 4 participants 7 messages May 21, 2020 – May 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/shadow: Reposition sh_remove_write_access_from_sl1p()

When compiling with SHOPT_OUT_OF_SYNC disabled, the build fails with:

common.c:41:12: error: ‘sh_remove_write_access_from_sl1p’ declared ‘static’ but never defined [-Werror=unused-function]
static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,

              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

due to an unguarded forward declaration.

It turns out there is no need to forward declare sh_remove_write_access_from_sl1p() to begin with, so move it to just ahead of its first users, which is within a larger #ifdef'd SHOPT_OUT_OF_SYNC block.

Fix up for style while moving it. No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Tim Deegan <[email protected]>

---
 xen/arch/x86/mm/shadow/common.c | 56 ++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 31 deletions(-)
xen/arch/x86/mm/shadow/common.c +25 -31
index 0ac3f880e1..6dff240e97 100644
@@ -38,9 +38,6 @@
 #include <xen/numa.h>
 #include "private.h"
 
-static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
-                                            mfn_t smfn, unsigned long offset);
-
 DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags);
 
 static int sh_enable_log_dirty(struct domain *, bool log_global);
@@ -252,6 +249,31 @@ static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn)
         SHADOW_INTERNAL_NAME(sh_resync_l1, 4)(v, gmfn, snpmfn);
 }
 
+static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
+                                            mfn_t smfn, unsigned long off)
+{
+    struct page_info *sp = mfn_to_page(smfn);
+
+    ASSERT(mfn_valid(smfn));
+    ASSERT(mfn_valid(gmfn));
+
+    if ( sp->u.sh.type == SH_type_l1_32_shadow ||
+         sp->u.sh.type == SH_type_fl1_32_shadow )
+        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p, 2)
+            (d, gmfn, smfn, off);
+
+    if ( sp->u.sh.type == SH_type_l1_pae_shadow ||
+         sp->u.sh.type == SH_type_fl1_pae_shadow )
+        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p, 3)
+            (d, gmfn, smfn, off);
+
+    if ( sp->u.sh.type == SH_type_l1_64_shadow ||
+         sp->u.sh.type == SH_type_fl1_64_shadow )
+        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p, 4)
+            (d, gmfn, smfn, off);
+
+    return 0;
+}
 
 /*
  * Fixup arrays: We limit the maximum number of writable mappings to
@@ -2001,34 +2023,6 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
 }
 #endif /* CONFIG_HVM */
 
-#if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)
-static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
-                                            mfn_t smfn, unsigned long off)
-{
-    struct page_info *sp = mfn_to_page(smfn);
-
-    ASSERT(mfn_valid(smfn));
-    ASSERT(mfn_valid(gmfn));
-
-    if ( sp->u.sh.type == SH_type_l1_32_shadow
-         || sp->u.sh.type == SH_type_fl1_32_shadow )
-    {
-        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p,2)
-            (d, gmfn, smfn, off);
-    }
-    else if ( sp->u.sh.type == SH_type_l1_pae_shadow
-              || sp->u.sh.type == SH_type_fl1_pae_shadow )
-        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p,3)
-            (d, gmfn, smfn, off);
-    else if ( sp->u.sh.type == SH_type_l1_64_shadow
-              || sp->u.sh.type == SH_type_fl1_64_shadow )
-        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p,4)
-            (d, gmfn, smfn, off);
-
-    return 0;
-}
-#endif
-
 /**************************************************************************/
 /* Remove all mappings of a guest frame from the shadow tables.
  * Returns non-zero if we need to flush TLBs. */
Signature · 1 line
2.11.0
#1 lore raw
Quoted 8 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Andrew Cooper
Sent: 21 May 2020 10:04
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Tim Deegan <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH] x86/shadow: Reposition sh_remove_write_access_from_sl1p()

Quoted 8 lines

When compiling with SHOPT_OUT_OF_SYNC disabled, the build fails with:

common.c:41:12: error: ‘sh_remove_write_access_from_sl1p’ declared ‘static’ but never defined [-
Werror=unused-function]
static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,

              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

due to an unguarded forward declaration.

Is this, perhaps, an argument for making SHADOW_OPTIMIZATIONS tunable via Kconfig so that randconfig could catch things like this?

Paul

Quoted 101 lines

It turns out there is no need to forward declare sh_remove_write_access_from_sl1p() to begin with, so move it to just ahead of its first users, which is within a larger #ifdef'd SHOPT_OUT_OF_SYNC block.

Fix up for style while moving it. No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Tim Deegan <[email protected]>

---
 xen/arch/x86/mm/shadow/common.c | 56 ++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 31 deletions(-)
xen/arch/x86/mm/shadow/common.c +25 -32
index 0ac3f880e1..6dff240e97 100644
@@ -38,9 +38,6 @@
 #include <xen/numa.h>
 #include "private.h"
 
-static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
-                                            mfn_t smfn, unsigned long offset);
-
 DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags);
 
 static int sh_enable_log_dirty(struct domain *, bool log_global);
@@ -252,6 +249,31 @@ static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn)
         SHADOW_INTERNAL_NAME(sh_resync_l1, 4)(v, gmfn, snpmfn);
 }
 
+static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
+                                            mfn_t smfn, unsigned long off)
+{
+    struct page_info *sp = mfn_to_page(smfn);
+
+    ASSERT(mfn_valid(smfn));
+    ASSERT(mfn_valid(gmfn));
+
+    if ( sp->u.sh.type == SH_type_l1_32_shadow ||
+         sp->u.sh.type == SH_type_fl1_32_shadow )
+        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p, 2)
+            (d, gmfn, smfn, off);
+
+    if ( sp->u.sh.type == SH_type_l1_pae_shadow ||
+         sp->u.sh.type == SH_type_fl1_pae_shadow )
+        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p, 3)
+            (d, gmfn, smfn, off);
+
+    if ( sp->u.sh.type == SH_type_l1_64_shadow ||
+         sp->u.sh.type == SH_type_fl1_64_shadow )
+        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p, 4)
+            (d, gmfn, smfn, off);
+
+    return 0;
+}
 
 /*
  * Fixup arrays: We limit the maximum number of writable mappings to
@@ -2001,34 +2023,6 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
 }
 #endif /* CONFIG_HVM */
 
-#if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)
-static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
-                                            mfn_t smfn, unsigned long off)
-{
-    struct page_info *sp = mfn_to_page(smfn);
-
-    ASSERT(mfn_valid(smfn));
-    ASSERT(mfn_valid(gmfn));
-
-    if ( sp->u.sh.type == SH_type_l1_32_shadow
-         || sp->u.sh.type == SH_type_fl1_32_shadow )
-    {
-        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p,2)
-            (d, gmfn, smfn, off);
-    }
-    else if ( sp->u.sh.type == SH_type_l1_pae_shadow
-              || sp->u.sh.type == SH_type_fl1_pae_shadow )
-        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p,3)
-            (d, gmfn, smfn, off);
-    else if ( sp->u.sh.type == SH_type_l1_64_shadow
-              || sp->u.sh.type == SH_type_fl1_64_shadow )
-        return SHADOW_INTERNAL_NAME(sh_rm_write_access_from_sl1p,4)
-            (d, gmfn, smfn, off);
-
-    return 0;
-}
-#endif
-
 /**************************************************************************/
 /* Remove all mappings of a guest frame from the shadow tables.
  * Returns non-zero if we need to flush TLBs. */
--

2.11.0

#2 lore raw
Quoted 10 lines · Paul Durrant
Quoted 10 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Andrew Cooper
Sent: 21 May 2020 10:04
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Tim Deegan <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH] x86/shadow: Reposition sh_remove_write_access_from_sl1p()

When compiling with SHOPT_OUT_OF_SYNC disabled, the build fails with:

Quoted 7 lines
Quoted 6 lines

common.c:41:12: error: ‘sh_remove_write_access_from_sl1p’ declared ‘static’ but never defined [-
Werror=unused-function]
static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,

              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

due to an unguarded forward declaration.

Is this, perhaps, an argument for making SHADOW_OPTIMIZATIONS tunable via Kconfig so that randconfig could catch things like this?

Given enough TUITS, yes.

~Andrew

Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

When compiling with SHOPT_OUT_OF_SYNC disabled, the build fails with:

common.c:41:12: error: ‘sh_remove_write_access_from_sl1p’ declared ‘static’ but never defined [-Werror=unused-function]
static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,

              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

due to an unguarded forward declaration.

Quoted 7 lines

It turns out there is no need to forward declare sh_remove_write_access_from_sl1p() to begin with, so move it to just ahead of its first users, which is within a larger #ifdef'd SHOPT_OUT_OF_SYNC block.

Fix up for style while moving it. No functional change.

Quoted 27 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Tim Deegan <[email protected]>

---
 xen/arch/x86/mm/shadow/common.c | 56 ++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 31 deletions(-)
xen/arch/x86/mm/shadow/common.c +0 -3
index 0ac3f880e1..6dff240e97 100644
@@ -38,9 +38,6 @@
 #include <xen/numa.h>
 #include "private.h"
 
-static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
-                                            mfn_t smfn, unsigned long offset);
-
 DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags);
 
 static int sh_enable_log_dirty(struct domain *, bool log_global);
@@ -252,6 +249,31 @@ static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn)
         SHADOW_INTERNAL_NAME(sh_resync_l1, 4)(v, gmfn, snpmfn);
 }
 

xen/arch/x86/mm/shadow/common.c static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn) · line 261

Quoted 10 lines
xen/arch/x86/mm/shadow/common.c +10 -0
+static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
+                                            mfn_t smfn, unsigned long off)
+{
+    struct page_info *sp = mfn_to_page(smfn);
+
+    ASSERT(mfn_valid(smfn));
+    ASSERT(mfn_valid(gmfn));
+
+    if ( sp->u.sh.type == SH_type_l1_32_shadow ||
+         sp->u.sh.type == SH_type_fl1_32_shadow )

Using a switch would also be nice IMO and would avoid some of the code churn.

Thanks, Roger.

#4 lore raw
Quoted 45 lines · Roger Pau Monné
Quoted 8 lines · Andrew Cooper

When compiling with SHOPT_OUT_OF_SYNC disabled, the build fails with:

common.c:41:12: error: ‘sh_remove_write_access_from_sl1p’ declared ‘static’ but never defined [-Werror=unused-function]
static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,

              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

due to an unguarded forward declaration.

Quoted 7 lines

It turns out there is no need to forward declare sh_remove_write_access_from_sl1p() to begin with, so move it to just ahead of its first users, which is within a larger #ifdef'd SHOPT_OUT_OF_SYNC block.

Fix up for style while moving it. No functional change.

Quoted 27 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Tim Deegan <[email protected]>

---
 xen/arch/x86/mm/shadow/common.c | 56 ++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 31 deletions(-)
xen/arch/x86/mm/shadow/common.c +0 -3
index 0ac3f880e1..6dff240e97 100644
@@ -38,9 +38,6 @@
 #include <xen/numa.h>
 #include "private.h"
 
-static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
-                                            mfn_t smfn, unsigned long offset);
-
 DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags);
 
 static int sh_enable_log_dirty(struct domain *, bool log_global);
@@ -252,6 +249,31 @@ static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn)
         SHADOW_INTERNAL_NAME(sh_resync_l1, 4)(v, gmfn, snpmfn);
 }
 
Quoted 12 lines

xen/arch/x86/mm/shadow/common.c static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn) · line 261

Quoted 10 lines
xen/arch/x86/mm/shadow/common.c +10 -0
+static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
+                                            mfn_t smfn, unsigned long off)
+{
+    struct page_info *sp = mfn_to_page(smfn);
+
+    ASSERT(mfn_valid(smfn));
+    ASSERT(mfn_valid(gmfn));
+
+    if ( sp->u.sh.type == SH_type_l1_32_shadow ||
+         sp->u.sh.type == SH_type_fl1_32_shadow )

Using a switch would also be nice IMO and would avoid some of the code churn.

Good point.  Happy to do that if Tim agrees (but I won't bother sending a v2 just now).

~Andrew

#5 lore raw
Quoted 15 lines · Andrew Cooper
Quoted 13 lines · Roger Pau Monné

xen/arch/x86/mm/shadow/common.c static inline void _sh_resync_l1(struct vcpu *v, mfn_t gmfn, mfn_t snpmfn) · line 261

Quoted 10 lines · Andrew Cooper
xen/arch/x86/mm/shadow/common.c +10 -0
+static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,
+                                            mfn_t smfn, unsigned long off)
+{
+    struct page_info *sp = mfn_to_page(smfn);
+
+    ASSERT(mfn_valid(smfn));
+    ASSERT(mfn_valid(gmfn));
+
+    if ( sp->u.sh.type == SH_type_l1_32_shadow ||
+         sp->u.sh.type == SH_type_fl1_32_shadow )

Using a switch would also be nice IMO and would avoid some of the code churn.

Quoted 2 lines

Good point.  Happy to do that if Tim agrees (but I won't bother sending a v2 just now).

Sure, feel free to keep my RB after that.

Roger.

Reviewed-by on v1 1/1
#6 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

When compiling with SHOPT_OUT_OF_SYNC disabled, the build fails with:

common.c:41:12: error: ‘sh_remove_write_access_from_sl1p’ declared ‘static’ but never defined [-Werror=unused-function]
static int sh_remove_write_access_from_sl1p(struct domain *d, mfn_t gmfn,

              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

due to an unguarded forward declaration.

Quoted 7 lines

It turns out there is no need to forward declare sh_remove_write_access_from_sl1p() to begin with, so move it to just ahead of its first users, which is within a larger #ifdef'd SHOPT_OUT_OF_SYNC block.

Fix up for style while moving it. No functional change.

Thank you! This is fine, either as-is or with the suggested change to a switch.