Re: [PATCH v2 bpf-next 0/7] bpf, printk: add BTF-based type printing

From: Alexei Starovoitov
Date: Wed May 13 2020 - 18:50:34 EST


On Wed, May 13, 2020 at 3:48 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> On Wed, 2020-05-13 at 15:24 -0700, Alexei Starovoitov wrote:
> > On Tue, May 12, 2020 at 06:56:38AM +0100, Alan Maguire wrote:
> > > The printk family of functions support printing specific pointer types
> > > using %p format specifiers (MAC addresses, IP addresses, etc). For
> > > full details see Documentation/core-api/printk-formats.rst.
> > >
> > > This patchset proposes introducing a "print typed pointer" format
> > > specifier "%pT"; the argument associated with the specifier is of
> > > form "struct btf_ptr *" which consists of a .ptr value and a .type
> > > value specifying a stringified type (e.g. "struct sk_buff") or
> > > an .id value specifying a BPF Type Format (BTF) id identifying
> > > the appropriate type it points to.
> > >
> > > pr_info("%pT", BTF_PTR_TYPE(skb, "struct sk_buff"));
> > >
> > > ...gives us:
> > >
> > > (struct sk_buff){
> > > .transport_header = (__u16)65535,
> > > .mac_header = (__u16)65535,
> > > .end = (sk_buff_data_t)192,
> > > .head = (unsigned char *)000000007524fd8b,
> > > .data = (unsigned char *)000000007524fd8b,
> >
> > could you add "0x" prefix here to make it even more C like
> > and unambiguous ?
>
> linux pointers are not emitted with an 0x prefix

So? This is not at all comparable to %p