Netdev List
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: ast@fb.com, daniel@iogearbox.net, netdev@vger.kernel.org,
	kafai@fb.com, kernel-team@fb.com
Subject: Re: [PATCH bpf] tools: bpftool: fix a bitfield pretty print issue
Date: Wed, 28 Nov 2018 16:42:11 -0800	[thread overview]
Message-ID: <20181129004210.e2l54yt3s6silvlu@ast-mbp> (raw)
In-Reply-To: <20181128173823.547847-1-yhs@fb.com>

On Wed, Nov 28, 2018 at 09:38:23AM -0800, Yonghong Song wrote:
> Commit b12d6ec09730 ("bpf: btf: add btf print functionality")
> added btf pretty print functionality to bpftool.
> There is a problem though in printing a bitfield whose type
> has modifiers.
> 
> For example, for a type like
>   typedef int ___int;
>   struct tmp_t {
>           int a:3;
>           ___int b:3;
>   };
> Suppose we have a map
>   struct bpf_map_def SEC("maps") tmpmap = {
>           .type = BPF_MAP_TYPE_HASH,
>           .key_size = sizeof(__u32),
>           .value_size = sizeof(struct tmp_t),
>           .max_entries = 1,
>   };
> and the hash table is populated with one element with
> key 0 and value (.a = 1 and .b = 2).
> 
> In BTF, the struct member "b" will have a type "typedef" which
> points to an int type. The current implementation does not
> pass the bit offset during transition from typedef to int type,
> hence incorrectly print the value as
>   $ bpftool m d id 79
>   [{
>           "key": 0,
>           "value": {
>               "a": 0x1,
>               "b": 0x1
>           }
>       }
>   ]
> 
> This patch fixed the issue by carrying bit_offset along the type
> chain during bit_field print. The correct result can be printed as
>   $ bpftool m d id 76
>   [{
>           "key": 0,
>           "value": {
>               "a": 0x1,
>               "b": 0x2
>           }
>       }
>   ]
> 
> The kernel pretty print is implemented correctly and does not
> have this issue.
> 
> Fixes: b12d6ec09730 ("bpf: btf: add btf print functionality")
> Signed-off-by: Yonghong Song <yhs@fb.com>

Applied to bpf tree. Thanks

      parent reply	other threads:[~2018-11-29 11:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 17:38 [PATCH bpf] tools: bpftool: fix a bitfield pretty print issue Yonghong Song
2018-11-28 23:28 ` Song Liu
2018-11-29  0:42 ` Alexei Starovoitov [this message]

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=20181129004210.e2l54yt3s6silvlu@ast-mbp \
    --to=alexei.starovoitov@gmail.com \
    --cc=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox