All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zvi Effron <zeffron@riotgames.com>
To: Y Song <ys114321@gmail.com>
Cc: xdp-newbies@vger.kernel.org
Subject: Re: Issues with bpf_trace_printk
Date: Mon, 28 Aug 2017 15:12:40 -0700	[thread overview]
Message-ID: <CAC1LvL0Nc7dKdbmH+FbURycGpyrWar9emmbyReSOrVobdbGJhw@mail.gmail.com> (raw)
In-Reply-To: <CAH3MdRWk5R1DtUcPBbpNSv3kB-jJjP6RFUccRvqFS_7SZLnwzA@mail.gmail.com>

Full reproduction instructions:

1) Install Fedora 26 server. I chose all of the default options,
except I chose to install latest packages from the network. Otherwise,
just run a dnf update after install. I installed into a VM running on
HyperV
2) Install clang, llvm, and kernel-devel:
    dnf install -y clang llvm kernel-devel
3) Copy the program to xdp_test_kern.c
4) Compile the program into an elf object file:
    clang -S -O2 -Wall -Werror -nostdinc -isystem $(clang
-print-file-name=include) -I /lib/modules/$(uname
-r)/build/arch/x86/include  -I /lib/modules/$(uname
-r)/build/arch/x86/include/generated/uapi  -I /lib/modules/$(uname
-r)/build/arch/x86/include/generated  -I /lib/modules/$(uname
-r)/build/include  -I /lib/modules/$(uname
-r)/build/arch/x86/include/uapi  -I /lib/modules/$(uname
-r)/build/include/uapi  -I /lib/modules/$(uname
-r)/build/include/generated/uapi -include  /lib/modules/$(uname
-r)/build/include/linux/kconfig.h -D __KERNEL__ -c -emit-llvm -o
xdp_test_kern.ll xdp_test_kern.c
    llc -march bpf -filetype obj -o xdp_test_kern.o xdp_test_kern.ll
5) Attach the program to eth0:
    ip link set dev eth0 xdp object xdp_test_kern.o section .text verbose
6) Notice only 0s being printed for data in /sys/kernel/debug/tracing/trace_pipe

As near as I can tell, the driver being used for eth0 is hv_netvsc, in
case it's an issue with the driver.

Thanks!
--Zvi

On Mon, Aug 28, 2017 at 2:16 PM, Y Song <ys114321@gmail.com> wrote:
> bpf program itself is okay.
> I replaced linux:samples/bpf/xdp1_kern.c with this program and the
> bpf_trace_printk works fine.
> It could be some setup issue. But in any case, data start and data end
> are suspicious.
> It would be good you list all steps which can reproduce the issue.
>
> On Mon, Aug 28, 2017 at 10:20 AM, Zvi Effron <zeffron@riotgames.com> wrote:
>> Hello,
>>
>> I'm having an issue where bpf_trace_printk seems to always print 0 for
>> values. I'm running the following xdp program:
>>
>>
>> #include <uapi/linux/bpf.h>
>>
>> static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
>> (void *) BPF_FUNC_trace_printk;
>>
>> int xdp(struct xdp_md *ctx) {
>>     char format_string[] = "Data start: %x\tData end: %x\n";
>>     bpf_trace_printk(format_string, sizeof(format_string), ctx->data,
>> ctx->data_end);
>>
>>     {
>>         char format_string[] = "Constant: %x\n";
>>         bpf_trace_printk(format_string, sizeof(format_string), 1);
>>     }
>>
>>     if (ctx->data == 0) {
>>         char format_string[] = "Data starts at offset 0";
>>         bpf_trace_printk(format_string, sizeof(format_string));
>>     }
>>     if (ctx->data_end == 0) {
>>         char format_string[] = "Data ends at offset 0";
>>         bpf_trace_printk(format_string, sizeof(format_string));
>>     }
>>     return XDP_PASS;
>> }
>>
>> char __attribute__((section("license"), used)) license[] = "GPL";
>>
>>
>> and I get the following output in /sys/kernel/debug/tracing/trace_pipe
>>
>>
>>             sshd-4824  [000] ..s1 67372.673714: : Data start: 0 Data end: 0
>>             sshd-4824  [000] ..s1 67372.673720: : Constant: 0
>>           <idle>-0     [000] ..s. 67372.675062: : Data start: 0 Data end: 0
>>           <idle>-0     [000] .Ns. 67372.675090: : Constant: 0
>>           <idle>-0     [000] .Ns. 67372.675116: : Data start: 0 Data end: 0
>>           <idle>-0     [000] .Ns. 67372.675117: : Constant: 0
>>           <idle>-0     [000] .Ns. 67372.675129: : Data start: 0 Data end: 0
>>           <idle>-0     [000] .Ns. 67372.675130: : Constant: 0
>>           <idle>-0     [000] .Ns. 67372.675136: : Data start: 0 Data end: 0
>>           <idle>-0     [000] .Ns. 67372.675137: : Constant: 0
>>           <idle>-0     [000] .Ns. 67372.675142: : Data start: 0 Data end: 0
>>           <idle>-0     [000] .Ns. 67372.675143: : Constant: 0
>>               ip-6458  [000] ..s. 67372.676083: : Data start: 0 Data end: 0
>>               ip-6458  [000] ..s. 67372.676084: : Constant: 0
>>               ip-6458  [000] ..s. 67372.676093: : Data start: 0 Data end: 0
>>               ip-6458  [000] ..s. 67372.676094: : Constant: 0
>>
>>
>> It looks like ctx->data and ctx->data_end are not 0, because the calls
>> to bpf_trace_printk in those ifs aren't being called, and the constant
>> is definitely not 0.
>>
>> What might I be missing or doing incorrectly?
>>
>> Thank you!
>> --Zvi

  reply	other threads:[~2017-08-28 22:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 17:20 Issues with bpf_trace_printk Zvi Effron
2017-08-28 18:26 ` Daniel Borkmann
2017-08-28 19:54   ` Zvi Effron
2017-08-28 21:16 ` Y Song
2017-08-28 22:12   ` Zvi Effron [this message]
2017-08-29  5:39     ` Y Song
2017-08-29  5:53       ` Zvi Effron
2017-08-29 21:56         ` Y Song
2017-08-29 23:17           ` Daniel Borkmann
2017-08-30 17:53             ` Zvi Effron
     [not found]               ` <59A72D3E.1030909@iogearbox.net>
2017-08-30 21:50                 ` Zvi Effron
2017-08-30 21:57                   ` David Miller
2017-08-30 22:04                   ` Daniel Borkmann
2017-08-31 18:14                     ` Zvi Effron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAC1LvL0Nc7dKdbmH+FbURycGpyrWar9emmbyReSOrVobdbGJhw@mail.gmail.com \
    --to=zeffron@riotgames.com \
    --cc=xdp-newbies@vger.kernel.org \
    --cc=ys114321@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.