diff mbox series

[v2,10/12] x86/pv: Move x86/trace.c to x86/pv/trace.c

Message ID 20210920172529.24932-11-andrew.cooper3@citrix.com (mailing list archive)
State New, archived
Headers show
Series xen/trace: Fix leakage of uninitialised stack into the tracebuffer | expand

Commit Message

Andrew Cooper Sept. 20, 2021, 5:25 p.m. UTC
This entire file is pv-only, and not excluded from the build by
CONFIG_TRACEBUFFER.  Move it into the pv/ directory, build it conditionally,
and drop unused includes.

Also move the contents of asm/trace.h to asm/pv/trace.h to avoid the functions
being declared across the entire hypervisor.

One caller in fixup_page_fault() is effectively PV only, but is not subject to
dead code elimination.  Add an additional IS_ENABLED(CONFIG_PV) to keep the
build happy.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>

v2:
 * New
---
 xen/arch/x86/Makefile                |  1 -
 xen/arch/x86/pv/Makefile             |  1 +
 xen/arch/x86/pv/emul-inv-op.c        |  2 +-
 xen/arch/x86/pv/emul-priv-op.c       |  1 +
 xen/arch/x86/pv/ro-page-fault.c      |  2 +-
 xen/arch/x86/{ => pv}/trace.c        | 13 +++++------
 xen/arch/x86/pv/traps.c              |  2 +-
 xen/arch/x86/traps.c                 |  3 ++-
 xen/include/asm-x86/{ => pv}/trace.h |  8 ++++---
 xen/include/asm-x86/trace.h          | 42 ------------------------------------
 10 files changed, 17 insertions(+), 58 deletions(-)
 rename xen/arch/x86/{ => pv}/trace.c (95%)
 copy xen/include/asm-x86/{ => pv}/trace.h (92%)

Comments

Jan Beulich Sept. 21, 2021, 3:58 p.m. UTC | #1
On 20.09.2021 19:25, Andrew Cooper wrote:
> This entire file is pv-only, and not excluded from the build by
> CONFIG_TRACEBUFFER.  Move it into the pv/ directory, build it conditionally,
> and drop unused includes.
> 
> Also move the contents of asm/trace.h to asm/pv/trace.h to avoid the functions
> being declared across the entire hypervisor.
> 
> One caller in fixup_page_fault() is effectively PV only, but is not subject to
> dead code elimination.  Add an additional IS_ENABLED(CONFIG_PV) to keep the
> build happy.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
diff mbox series

Patch

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 202d4d27823d..82dd4e18bd36 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -61,7 +61,6 @@  obj-y += spec_ctrl.o
 obj-y += srat.o
 obj-y += string.o
 obj-y += time.o
-obj-y += trace.o
 obj-y += traps.o
 obj-y += tsx.o
 obj-y += usercopy.o
diff --git a/xen/arch/x86/pv/Makefile b/xen/arch/x86/pv/Makefile
index 75b01b0062d8..6cda354cc41f 100644
--- a/xen/arch/x86/pv/Makefile
+++ b/xen/arch/x86/pv/Makefile
@@ -12,6 +12,7 @@  obj-y += misc-hypercalls.o
 obj-y += mm.o
 obj-y += ro-page-fault.o
 obj-$(CONFIG_PV_SHIM) += shim.o
+obj-$(CONFIG_TRACEBUFFER) += trace.o
 obj-y += traps.o
 
 obj-bin-y += dom0_build.init.o
diff --git a/xen/arch/x86/pv/emul-inv-op.c b/xen/arch/x86/pv/emul-inv-op.c
index b15f302bcaad..2c07eed9a092 100644
--- a/xen/arch/x86/pv/emul-inv-op.c
+++ b/xen/arch/x86/pv/emul-inv-op.c
@@ -19,7 +19,7 @@ 
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <xen/trace.h>
+#include <asm/pv/trace.h>
 
 #include "emulate.h"
 
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 11467a1e3a90..d0df5bc616c0 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -30,6 +30,7 @@ 
 #include <asm/hypercall.h>
 #include <asm/mc146818rtc.h>
 #include <asm/pv/domain.h>
+#include <asm/pv/trace.h>
 #include <asm/shared.h>
 
 #include <xsm/xsm.h>
diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c
index 335aa8dc5dc0..ac5b66870c8c 100644
--- a/xen/arch/x86/pv/ro-page-fault.c
+++ b/xen/arch/x86/pv/ro-page-fault.c
@@ -20,7 +20,7 @@ 
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <xen/trace.h>
+#include <asm/pv/trace.h>
 #include <asm/shadow.h>
 
 #include "emulate.h"
diff --git a/xen/arch/x86/trace.c b/xen/arch/x86/pv/trace.c
similarity index 95%
rename from xen/arch/x86/trace.c
rename to xen/arch/x86/pv/trace.c
index 4a953c5b2f1e..550c22765bae 100644
--- a/xen/arch/x86/trace.c
+++ b/xen/arch/x86/pv/trace.c
@@ -1,9 +1,6 @@ 
-#include <xen/init.h>
-#include <xen/kernel.h>
-#include <xen/lib.h>
-#include <xen/domain.h>
 #include <xen/sched.h>
-#include <xen/trace.h>
+
+#include <asm/pv/trace.h>
 
 void __trace_pv_trap(int trapnr, unsigned long eip,
                      int use_error_code, unsigned error_code)
@@ -21,7 +18,7 @@  void __trace_pv_trap(int trapnr, unsigned long eip,
         d.trapnr = trapnr;
         d.error_code = error_code;
         d.use_error_code=!!use_error_code;
-                
+
         __trace_var(TRC_PV_TRAP, 1, sizeof(d), &d);
     }
     else
@@ -38,7 +35,7 @@  void __trace_pv_trap(int trapnr, unsigned long eip,
         d.trapnr = trapnr;
         d.error_code = error_code;
         d.use_error_code=!!use_error_code;
-                
+
         event = TRC_PV_TRAP;
         event |= TRC_64_FLAG;
         __trace_var(event, 1, sizeof(d), &d);
@@ -58,7 +55,7 @@  void __trace_pv_page_fault(unsigned long addr, unsigned error_code)
         d.eip = eip;
         d.addr = addr;
         d.error_code = error_code;
-                
+
         __trace_var(TRC_PV_PAGE_FAULT, 1, sizeof(d), &d);
     }
     else
diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c
index 7439b76df88d..764773c02104 100644
--- a/xen/arch/x86/pv/traps.c
+++ b/xen/arch/x86/pv/traps.c
@@ -22,10 +22,10 @@ 
 #include <xen/event.h>
 #include <xen/hypercall.h>
 #include <xen/lib.h>
-#include <xen/trace.h>
 #include <xen/softirq.h>
 
 #include <asm/apic.h>
+#include <asm/pv/trace.h>
 #include <asm/shared.h>
 #include <asm/traps.h>
 #include <irq_vectors.h>
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 4a0e498b4c21..0cc1ee95cb5b 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -82,6 +82,7 @@ 
 #include <xsm/xsm.h>
 #include <asm/mach-default/irq_vectors.h>
 #include <asm/pv/traps.h>
+#include <asm/pv/trace.h>
 #include <asm/pv/mm.h>
 
 /*
@@ -1480,7 +1481,7 @@  static int fixup_page_fault(unsigned long addr, struct cpu_user_regs *regs)
     {
         int ret = paging_fault(addr, regs);
 
-        if ( ret == EXCRET_fault_fixed )
+        if ( IS_ENABLED(CONFIG_PV) && ret == EXCRET_fault_fixed )
             trace_trap_two_addr(TRC_PV_PAGING_FIXUP, regs->rip, addr);
         return ret;
     }
diff --git a/xen/include/asm-x86/trace.h b/xen/include/asm-x86/pv/trace.h
similarity index 92%
copy from xen/include/asm-x86/trace.h
copy to xen/include/asm-x86/pv/trace.h
index e65b5de6eec4..c616206eeb15 100644
--- a/xen/include/asm-x86/trace.h
+++ b/xen/include/asm-x86/pv/trace.h
@@ -1,5 +1,7 @@ 
-#ifndef __ASM_TRACE_H__
-#define __ASM_TRACE_H__
+#ifndef XEN_X86_PV_TRACE_H
+#define XEN_X86_PV_TRACE_H
+
+#include <xen/trace.h>
 
 #include <asm/page.h>
 
@@ -43,4 +45,4 @@  static inline void trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte)
         __trace_ptwr_emulation(addr, npte);
 }
 
-#endif /* __ASM_TRACE_H__ */
+#endif /* XEN_X86_PV_TRACE_H */
diff --git a/xen/include/asm-x86/trace.h b/xen/include/asm-x86/trace.h
index e65b5de6eec4..edef1bb099d4 100644
--- a/xen/include/asm-x86/trace.h
+++ b/xen/include/asm-x86/trace.h
@@ -1,46 +1,4 @@ 
 #ifndef __ASM_TRACE_H__
 #define __ASM_TRACE_H__
 
-#include <asm/page.h>
-
-void __trace_pv_trap(int trapnr, unsigned long eip,
-                     int use_error_code, unsigned error_code);
-static inline void trace_pv_trap(int trapnr, unsigned long eip,
-                                 int use_error_code, unsigned error_code)
-{
-    if ( unlikely(tb_init_done) )
-        __trace_pv_trap(trapnr, eip, use_error_code, error_code);
-}
-
-void __trace_pv_page_fault(unsigned long addr, unsigned error_code);
-static inline void trace_pv_page_fault(unsigned long addr,
-                                       unsigned error_code)
-{
-    if ( unlikely(tb_init_done) )
-        __trace_pv_page_fault(addr, error_code);
-}
-
-void __trace_trap_one_addr(unsigned event, unsigned long va);
-static inline void trace_trap_one_addr(unsigned event, unsigned long va)
-{
-    if ( unlikely(tb_init_done) )
-        __trace_trap_one_addr(event, va);
-}
-
-void __trace_trap_two_addr(unsigned event, unsigned long va1,
-                           unsigned long va2);
-static inline void trace_trap_two_addr(unsigned event, unsigned long va1,
-                                       unsigned long va2)
-{
-    if ( unlikely(tb_init_done) )
-        __trace_trap_two_addr(event, va1, va2);
-}
-
-void __trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte);
-static inline void trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte)
-{
-    if ( unlikely(tb_init_done) )
-        __trace_ptwr_emulation(addr, npte);
-}
-
 #endif /* __ASM_TRACE_H__ */