From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexei Starovoitov Subject: Re: [PATCH bpf] tools: bpftool: fix a bitfield pretty print issue Date: Wed, 28 Nov 2018 16:42:11 -0800 Message-ID: <20181129004210.e2l54yt3s6silvlu@ast-mbp> References: <20181128173823.547847-1-yhs@fb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: ast@fb.com, daniel@iogearbox.net, netdev@vger.kernel.org, kafai@fb.com, kernel-team@fb.com To: Yonghong Song Return-path: Received: from mail-it1-f194.google.com ([209.85.166.194]:54254 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbeK2Lpo (ORCPT ); Thu, 29 Nov 2018 06:45:44 -0500 Received: by mail-it1-f194.google.com with SMTP id g85so957782ita.3 for ; Wed, 28 Nov 2018 16:42:15 -0800 (PST) Content-Disposition: inline In-Reply-To: <20181128173823.547847-1-yhs@fb.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 Applied to bpf tree. Thanks