Skip to content

Commit 8c31ab6

Browse files
eulohkvanhees
authored andcommitted
Preface usym/umod/uaddr with pid
Translation of user space addresses requires that we know which process to use for the translation. We have been prefacing the address to translate like this: /* Preface the value with the user process tgid. */ emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_current_pid_tgid)); emit(dlp, BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffffffff)); One problem is that the IMM "and" operation is a no-op. The 0xffffffff is promoted to a 64-bit -1, leading to no %r0 bits changing. Another problem is that we are pulling out the tgid. This means that the translation will fail. Further, even if the consumer knew which part of the pid_tgid combination to use for address translation, keys for aggregations could fail spuriously due to different tgids for the same process. Convert to /* Preface the value with the user process pid. */ emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_current_pid_tgid)); emit(dlp, BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, 32)); Also, in the umod test (which uncovered this problem), add ld-*.so to the list of shared objects we're going to skip. Signed-off-by: Eugene Loh <[email protected]> Reviewed-by: Kris Van Hees <[email protected]>
1 parent 504b546 commit 8c31ab6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libdtrace/dt_cg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,13 +1645,13 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
16451645
kind == DTRACEACT_UADDR) {
16461646
off = dt_rec_add(dtp, dt_cg_fill_gap, kind, 16, 8, NULL, arg);
16471647

1648-
/* preface the value with the user process tgid */
1648+
/* preface the value with the user process pid */
16491649
if (dt_regset_xalloc_args(drp) == -1)
16501650
longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
16511651
dt_regset_xalloc(drp, BPF_REG_0);
16521652
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_current_pid_tgid));
16531653
dt_regset_free_args(drp);
1654-
emit(dlp, BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffffffff));
1654+
emit(dlp, BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, 32));
16551655
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_9, off, BPF_REG_0));
16561656
dt_regset_free(drp, BPF_REG_0);
16571657

@@ -3821,13 +3821,13 @@ dt_cg_arglist(dt_ident_t *idp, dt_node_t *args, dt_irlist_t *dlp,
38213821
if (tuplesize < nextoff)
38223822
emit(dlp, BPF_ALU64_IMM(BPF_ADD, treg, nextoff - tuplesize));
38233823

3824-
/* Preface the value with the user process tgid. */
3824+
/* Preface the value with the user process pid. */
38253825
if (dt_regset_xalloc_args(drp) == -1)
38263826
longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
38273827
dt_regset_xalloc(drp, BPF_REG_0);
38283828
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_current_pid_tgid));
38293829
dt_regset_free_args(drp);
3830-
emit(dlp, BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffffffff));
3830+
emit(dlp, BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, 32));
38313831
emit(dlp, BPF_STORE(BPF_DW, treg, 0, BPF_REG_0));
38323832
dt_regset_free(drp, BPF_REG_0);
38333833

test/unittest/profile-n/tst.umod.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if ! grep -wq 'bash' $tmpfile; then
5353
fi
5454

5555
# Check that modules are unique. (Exclude shared libraries and unresolved addresses.)
56-
if gawk '!/^ *lib/ && !/^ *0x/ {print $1}' $tmpfile | sort | uniq -c | grep -qv " 1 "; then
56+
if gawk '!/^ *lib/ && !/^ *ld-.*\.so / && !/^ *0x/ {print $1}' $tmpfile | sort | uniq -c | grep -qv " 1 "; then
5757
echo ERROR: duplicate umod
5858
status=1
5959
fi

0 commit comments

Comments
 (0)