[DTrace-devel] [PATCH 42/47] Temporary fix to avoid excessive stack usage

Kris Van Hees kris.van.hees at oracle.com
Sun May 3 20:18:18 PDT 2020


For kernels that have CONFIG_BPF_JIT_ALWAYS_ON=y the BPF verifier checks
that the total stack use of a call chain (sequence of function calls)
is not greater than the maximum BPF stack size (currently set at 512
bytes in the kernel).

The trampoline code constructs the DTrace BPF context on the stack, and
then calls dt_predicate and dt_program.  The dt_program always starts
with a common prologue that stores some information on the stack.  We
also use stack locations for register spilling.  Finally, various helper
functions that are linked into our program may also make use of stack
slots.

The DTrace BPF context is the largest static structure on the stack and
it is architecture dependent due to the inclusion of pt_regs.  This
poses a problem on arm64 where the pt_regs structure is significantly
larger than on x86_64.

A new stack layout design is in the works which will make it possible to
rework this temporary fix.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_bpf_ctx.h      | 2 ++
 libdtrace/dt_prov_dtrace.c  | 2 ++
 libdtrace/dt_prov_fbt.c     | 2 ++
 libdtrace/dt_prov_sdt.c     | 2 ++
 libdtrace/dt_prov_syscall.c | 2 ++
 5 files changed, 10 insertions(+)

diff --git a/libdtrace/dt_bpf_ctx.h b/libdtrace/dt_bpf_ctx.h
index 3f24b318..906a8e95 100644
--- a/libdtrace/dt_bpf_ctx.h
+++ b/libdtrace/dt_bpf_ctx.h
@@ -17,7 +17,9 @@ struct dt_bpf_context {
 	uint32_t	epid;
 	uint32_t	pad;
 	uint64_t	fault;
+#if 0
 	dt_pt_regs	regs;
+#endif
 	uint64_t	argv[10];
 };
 
diff --git a/libdtrace/dt_prov_dtrace.c b/libdtrace/dt_prov_dtrace.c
index b1513108..ad4c7fac 100644
--- a/libdtrace/dt_prov_dtrace.c
+++ b/libdtrace/dt_prov_dtrace.c
@@ -93,6 +93,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 	instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_FAULT), 0);
 	dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 
+#if 0
 	/*
 	 *     dctx.regs = *regs;
 	 */
@@ -103,6 +104,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 				  BPF_REG_0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 	}
+#endif
 
 	/*
 	 *     dctx.argv[0] = PT_REGS_PARAM1(regs);
diff --git a/libdtrace/dt_prov_fbt.c b/libdtrace/dt_prov_fbt.c
index f42219d7..fa7e28bf 100644
--- a/libdtrace/dt_prov_fbt.c
+++ b/libdtrace/dt_prov_fbt.c
@@ -188,6 +188,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 	instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_FAULT), 0);
 	dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 
+#if 0
 	/*
 	 *     dctx.regs = *regs;
 	 */
@@ -198,6 +199,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 				  BPF_REG_0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 	}
+#endif
 
 	/*
 	 *     dctx.argv[0] = PT_REGS_PARAM1(regs);
diff --git a/libdtrace/dt_prov_sdt.c b/libdtrace/dt_prov_sdt.c
index ff3560a7..6ea905ad 100644
--- a/libdtrace/dt_prov_sdt.c
+++ b/libdtrace/dt_prov_sdt.c
@@ -322,6 +322,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 	instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_FAULT), 0);
 	dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 
+#if 0
 	/*
 	 *     (we clear the dctx.regs space because of the memset above)
 	 */
@@ -330,6 +331,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 				      DCTX_FP(DCTX_REGS) + i, 0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 	}
+#endif
 
 	/*
 	 *     (we clear dctx.argv[0] and on because of the memset above)
diff --git a/libdtrace/dt_prov_syscall.c b/libdtrace/dt_prov_syscall.c
index 9f3c75c9..5c1fb8ed 100644
--- a/libdtrace/dt_prov_syscall.c
+++ b/libdtrace/dt_prov_syscall.c
@@ -173,6 +173,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 	instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_FAULT), 0);
 	dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 
+#if 0
 	/*
 	 *     (we clear the dctx.regs space because of the memset above)
 	 */
@@ -181,6 +182,7 @@ static void trampoline(dt_pcb_t *pcb, int haspred)
 				      DCTX_FP(DCTX_REGS) + i, 0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 	}
+#endif
 
 	/*
 	 *     for (i = 0; i < argc; i++)
-- 
2.26.0




More information about the DTrace-devel mailing list