Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp887008ybk; Wed, 13 May 2020 16:07:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4645G9N5MdzSkZaYNBKSmgC4uQe3kilc29JLDqU9odL4IF3+gdbTg1FDVW0BSA99n9jdt X-Received: by 2002:a05:6402:1757:: with SMTP id v23mr1742814edx.335.1589411252009; Wed, 13 May 2020 16:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589411252; cv=none; d=google.com; s=arc-20160816; b=nFP/O04Gad1vNSa57WSo4ihfF2Fo/KwRNJj5WW6TIoIcw0ACMqvkYeoXFX1HBW8GsV Fx9eiZcCfr8m1ljdttTfiQs42iSxsHUcwYBR83FKTpbSe9XQ9CI/OBi/ZJnlHLSYCHHR HTiMHD4cM3xNL0AIqvKB9o0GXz4l34nv6ljWGk3a45+9ymmJF0Hr7ZnmkzqbQ01CT5E1 OGW5V1FS5dPVIv/5GqWWw/glVlLx67QmfzNeGUb9754+QjTFWTPhwGshCBzTCXlwzMPv iQ9MGh21dN8DmzbBrn+STXsW1MApAqnks+RBphBr8lV60yidtY94dLqbCStpLDfDaS/T 4JSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=8In434j28/kPxknFvVXiv8+Gsf0/FCmhFyHvgWRH9+k=; b=fZtg+kmHQ71CpdyrDHl2EMRJEsjoDpoxFD71su95wHCnCRA4olxK7mqo4OfJ4JEOtF sW7KIB6eryBjCEEIbhc+nRxA/vgl3e2ptBnXEluTzjQFKn0klHRT3WhEGFWWibT84yPk Zb7gmj+i7bPb/+wpcnqqv18Z0VnGjQ7doFn6FSiGNlIme3QmO6C+IyJ8BR7fuO+s/iP+ VMXVP0q/3wYuQs+wWLonN46DB3I2WUlJdDqLoqiTh2KUsOQgYIMiu1Uyn8IlmkRsmNEW AcxhCQa0rsd5ih1oMNNMzDWHJ7g9lq58SpsgM/iTIWkPi08IctoY96gB0E15wu/DHaLY +4jQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si636527edn.344.2020.05.13.16.07.09; Wed, 13 May 2020 16:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732408AbgEMXFq (ORCPT + 99 others); Wed, 13 May 2020 19:05:46 -0400 Received: from smtprelay0224.hostedemail.com ([216.40.44.224]:57856 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731815AbgEMXFq (ORCPT ); Wed, 13 May 2020 19:05:46 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 2442C181D3026; Wed, 13 May 2020 23:05:45 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:2892:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:4250:4321:5007:6119:7903:9036:10004:10400:10848:11026:11232:11473:11658:11914:12048:12109:12296:12297:12555:12740:12760:12895:12986:13255:13439:14096:14097:14659:14721:21063:21080:21451:21627:21972:21990:30030:30054:30075:30080:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: seed96_14d1be0aeb62e X-Filterd-Recvd-Size: 3196 Received: from XPS-9350.home (unknown [47.151.136.130]) (Authenticated sender: joe@perches.com) by omf14.hostedemail.com (Postfix) with ESMTPA; Wed, 13 May 2020 23:05:42 +0000 (UTC) Message-ID: <1b63a6b193073674b6e0f9f95c62ce2af1b977cc.camel@perches.com> Subject: Re: [PATCH v2 bpf-next 4/7] printk: add type-printing %pT format specifier which uses BTF From: Joe Perches To: Alan Maguire , ast@kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org Cc: linux@rasmusvillemoes.dk, arnaldo.melo@gmail.com, yhs@fb.com, kafai@fb.com, songliubraving@fb.com, andriin@fb.com, john.fastabend@gmail.com, kpsingh@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Date: Wed, 13 May 2020 16:05:41 -0700 In-Reply-To: <1589263005-7887-5-git-send-email-alan.maguire@oracle.com> References: <1589263005-7887-1-git-send-email-alan.maguire@oracle.com> <1589263005-7887-5-git-send-email-alan.maguire@oracle.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.1-2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2020-05-12 at 06:56 +0100, Alan Maguire wrote: > printk supports multiple pointer object type specifiers (printing > netdev features etc). Extend this support using BTF to cover > arbitrary types. "%pT" specifies the typed format, and the pointer > argument is a "struct btf_ptr *" where struct btf_ptr is as follows: > > struct btf_ptr { > void *ptr; > const char *type; > u32 id; > }; > > Either the "type" string ("struct sk_buff") or the BTF "id" can be > used to identify the type to use in displaying the associated "ptr" > value. A convenience function to create and point at the struct > is provided: > > printk(KERN_INFO "%pT", BTF_PTR_TYPE(skb, struct sk_buff)); > > When invoked, BTF information is used to traverse the sk_buff * > and display it. Support is present for structs, unions, enums, > typedefs and core types (though in the latter case there's not > much value in using this feature of course). > > Default output is indented, but compact output can be specified > via the 'c' option. Type names/member values can be suppressed > using the 'N' option. Zero values are not displayed by default > but can be using the '0' option. Pointer values are obfuscated > unless the 'x' option is specified. As an example: > > struct sk_buff *skb = alloc_skb(64, GFP_KERNEL); > 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 *)000000006b71155a, > .data = (unsigned char *)000000006b71155a, > .truesize = (unsigned int)768, > .users = (refcount_t){ > .refs = (atomic_t){ > .counter = (int)1, Given #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) Maybe #define BTF_INT_SIGNED (1 << 0) #define BTF_INT_CHAR (1 << 1) #define BTF_INT_BOOL (1 << 2) could be extended to include #define BTF_INT_HEX (1 << 3) So hex values can be appropriately pretty-printed.