[DTrace-devel] [PATCH v2] Handle unlabeled BPF_NOP instructions

Kris Van Hees kris.van.hees at oracle.com
Mon Jan 4 22:31:35 PST 2021


On Tue, Jan 05, 2021 at 01:09:12AM -0500, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> In BPF code generation, we emit branches with a label id stored in
> the offset field, to be resolved during assembly.  Since "jmp 0" is
> used to encode a NOP in BPF, we need to exclude jumps with offset 0
> from jump-target relocation.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

> ---
>  libdtrace/dt_as.c  | 8 ++++++--
>  libdtrace/dt_dis.c | 2 +-
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/libdtrace/dt_as.c b/libdtrace/dt_as.c
> index 437a2d86..5b6f5cf3 100644
> --- a/libdtrace/dt_as.c
> +++ b/libdtrace/dt_as.c
> @@ -330,8 +330,8 @@ fail:
>  
>  	/*
>  	 * Make a second pass through the instructions, relocating each branch
> -	 * label to the index of the final instruction in the buffer and noting
> -	 * any other instruction-specific DIFO flags such as dtdo_destructive.
> +	 * target (a label ID) to the relative location of the label and noting
> +	 * any instruction-specific DIFO flags such as dtdo_destructive.
>  	 */
>  	for (i = 0; i < dp->dtdo_len; i++) {
>  		struct bpf_insn instr = dp->dtdo_buf[i];
> @@ -341,6 +341,10 @@ fail:
>  		if (BPF_CLASS(instr.code) != BPF_JMP)
>  			continue;
>  
> +		/* We ignore NOP (jmp 0). */
> +		if (BPF_IS_NOP(instr))
> +			continue;
> +
>  		/* We ignore function calls and function exits. */
>  		if (op == BPF_CALL || op == BPF_EXIT)
>  			continue;
> diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
> index d047bde3..27e98c30 100644
> --- a/libdtrace/dt_dis.c
> +++ b/libdtrace/dt_dis.c
> @@ -346,7 +346,7 @@ dt_dis_jump(const dtrace_difo_t *dp, const char *name, uint_t addr,
>  	    const struct bpf_insn *in, const char *rname, FILE *fp)
>  {
>  	if (in->off == 0)
> -		fprintf(fp, "nop");
> +		fprintf(fp, "nop\n");
>  	else {
>  		int	n;
>  
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list