Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp355278pxu; Tue, 5 Jan 2021 12:56:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3+5i6gxi42nz5EjeBU22yTkCeTtMkKapTa5yjei8oE/EPo6ZN2068BfcpYpnccatzH7kc X-Received: by 2002:aa7:d608:: with SMTP id c8mr1611154edr.260.1609880191634; Tue, 05 Jan 2021 12:56:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609880191; cv=none; d=google.com; s=arc-20160816; b=Ew2yhjVIU1ZB0Dg7WSJ1HnUmBnklIDdlnolUZK7aMX6vjeWvsnREN3wB3vGnJWBb7d CO2Fk1x5j3DvjbWROovWHQw9WA+D4QX2krWa4HZEw61wz4cwAvOjpOLvtQpw24T4IGz7 N0n95XGMfqv+1lp6oNR3DcG4A4vq+PhLjYNTg1fXO3aRolRk/RdOY1PE8beCg3oafUWq WxNAiZ7CUBfzUVIqvVs1bGNUr88l9xPx/tas4j82OhHUW7BpKp1wrNXDS68kEPokeDyk WtS5G+kknhX6ObGEA3u4/Urb7sc9NKFvVpFXyQ+cnOpxvPvkRgkDweCgRa/gVN0d2HCy C37A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=2dUP4t+tg+XFgcxHkxTmAAVojig+Tu4Yn/X8zDkmUf0=; b=cdSWomqam3VszfF03x6ZqFNXp8UXdjwdtvXaycNUO/Jy/0/e3Lqq9ebXOpAvnSLJW1 huwlJll1lXJczGfBuDWrwO7nmhjlaGzM6aM3nAGF20pONgNhKFV7jnUkFcJvkmeP2o4u 2mYGvJulZXUbe6WeNBrVqe7O+jSOqg8CJ8cosNr4dk/LL6xynowe5nNG7vyyQb/qKbpu kqx5OOLSLA3bktNp/qwIx/a2+GGRgqWIhmkspzohohHZYOORhc8nbsyXiRAruyCMkMuK 6i61NxIiN2h6tW4Tz8a0jSHj9ew4D//etbMhHCJID3eCX+Xh1bxqykCAV/Lm6fa4N+Kd hACQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mess.org header.s=2020 header.b="XHOybA/r"; 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 zn8si156993ejb.32.2021.01.05.12.56.08; Tue, 05 Jan 2021 12:56:31 -0800 (PST) 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; dkim=fail header.i=@mess.org header.s=2020 header.b="XHOybA/r"; 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 S1728259AbhAEOqV (ORCPT + 99 others); Tue, 5 Jan 2021 09:46:21 -0500 Received: from gofer.mess.org ([88.97.38.141]:46111 "EHLO gofer.mess.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbhAEOqT (ORCPT ); Tue, 5 Jan 2021 09:46:19 -0500 Received: by gofer.mess.org (Postfix, from userid 1000) id 01ED6C63A5; Tue, 5 Jan 2021 14:45:34 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mess.org; s=2020; t=1609857935; bh=g86agJ+LPCw8ZkNJiHIjn0DJBtQq5JIr7Xq67deH28w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XHOybA/r4qqH1zaC2uKTFdjC2EijfmJkW3d1TIyxp0nrJ3ZBi+LQthgf5jiCUFEb5 zR+ZMU3J3k6BCc0FOnZuBWL5oVjbdlhIJpd7Hp7Mp5j1Sc4bF/vY84Kbfcc011OUpC LZLRppiXbiEV5ko1jHT4gPGaBJ2LbDbhTxkbHl0aouRai2FM98PG13HatJzHYbJX0C 6YRHdrobCpiPQwTp0K+OaV8gOwSNmuhhV97jW77PufdLz3CILYqcJduwwjsxKqtTl4 7gu5rHs/siDqlhWC+aa2QhOrIClNp8CagKEOoQiKJZcCTDh76JRPYUcJ0vryfv/N+P E4tn0ykEpX8gw== From: Sean Young To: Yonghong Song , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Nathan Chancellor , Nick Desaulniers , Quentin Monnet , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH v3 3/4] bpftool: add support for ints larger than 128 bits Date: Tue, 5 Jan 2021 14:45:33 +0000 Message-Id: <67ffe6998af5cf88bdda6eaa1e6b085db1e093ed.1609855479.git.sean@mess.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org clang supports arbitrary length ints using the _ExtInt extension. This can be useful to hold very large values, e.g. 256 bit or 512 bit types. This requires the _ExtInt extension enabled in clang, which is under review. Link: https://clang.llvm.org/docs/LanguageExtensions.html#extended-integer-types Link: https://reviews.llvm.org/D93103 Signed-off-by: Sean Young --- tools/bpf/bpftool/btf_dumper.c | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index 0e9310727281..8b5318ec5c26 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c @@ -271,6 +271,41 @@ static void btf_int128_print(json_writer_t *jw, const void *data, } } +static void btf_bigint_print(json_writer_t *jw, const void *data, int nr_bits, + bool is_plain_text) +{ + char buf[nr_bits / 4 + 1]; + int last_u64 = nr_bits / 64 - 1; + bool seen_nonzero = false; + int i; + + for (i = 0; i <= last_u64; i++) { +#ifdef __BIG_ENDIAN_BITFIELD + __u64 v = ((__u64 *)data)[i]; +#else + __u64 v = ((__u64 *)data)[last_u64 - i]; +#endif + + if (!seen_nonzero) { + if (!v && i != last_u64) + continue; + + snprintf(buf, sizeof(buf), "%llx", v); + + seen_nonzero = true; + } else { + size_t off = strlen(buf); + + snprintf(buf + off, sizeof(buf) - off, "%016llx", v); + } + } + + if (is_plain_text) + jsonw_printf(jw, "0x%s", buf); + else + jsonw_printf(jw, "\"0x%s\"", buf); +} + static void btf_int128_shift(__u64 *print_num, __u16 left_shift_bits, __u16 right_shift_bits) { @@ -373,6 +408,11 @@ static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset, return 0; } + if (nr_bits > 128) { + btf_bigint_print(jw, data, nr_bits, is_plain_text); + return 0; + } + if (nr_bits == 128) { btf_int128_print(jw, data, is_plain_text); return 0; -- 2.29.2