From patchwork Fri Sep 30 16:49:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 12995779 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9AD2C433FE for ; Fri, 30 Sep 2022 16:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbiI3QuV (ORCPT ); Fri, 30 Sep 2022 12:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiI3QuU (ORCPT ); Fri, 30 Sep 2022 12:50:20 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE9D3CA2A6 for ; Fri, 30 Sep 2022 09:50:18 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id sd10so10278313ejc.2 for ; Fri, 30 Sep 2022 09:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=TXmbbsssZ+72n59nGkn0OCOS8BwGPkuzgw55ockvPdM=; b=ZGQRUqgHUnMBzhjgQg0RLQAH/JUbIumq8idcWh0M1as0rtk5p5YN7Zmwbv8We/KmIQ FqBMptTV++eLqXWMFceAq2CbRd7q5rL1IhpJDVAYX+Yv66CSA5jveTRW/kh9hldMbb/6 t2bFi/cUvWBjTgmr2PPkFnDcUguP9ZNq5q2b2VgPpihPYVdTBZ0WLoks55q48W4UeeGj yzV+jiqU3FIgpQNv9Fi12jRWie3k60Xw619Ok5oPphWW5Npi3E3fcMMldxluTL6QsBl0 Xd3qR0on4c59nLTrEHmCpuVs4JGsyxhQpnzBwjpDR4CFMQ/6OHZftjdV5jIxla5L0/BW Uqig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=TXmbbsssZ+72n59nGkn0OCOS8BwGPkuzgw55ockvPdM=; b=cUsuLUJ317SHHqgXJ6JZpHpHNQFULGaw759m0+xvMv4H/takBdeg6XdwQv5a9BwCMF WGoqlfWwrSq1BTiQXSM2osfrgRpE9D6P3640tok5KXaWhJtTF9tGZbMpWSioLwmGN9Vn b3Elhz60M3WYVj3elyu0Z7j4TbOcE2EYix8EFVqDI3b1a7QvnWWFLdgf7pBs0yPGSJ5M adzeUid34F3IyevYeQ9tgHCtMAxxHJnVwKW4nVVhSK/5z0HXq+eEuW2Vpc2tVm8FQe/Y ishJYQLfjfHJWJmgkGjKboIHvvv9NOnAVk7HZmXlj3DNMLXMvAT+TPzPw0F0fvxzWqpB WEhw== X-Gm-Message-State: ACrzQf1Cid0waYMVGqTyzO2dZgFqD1Ze6SrtPQMiYO7LO2Us2GKgD3eV 5SJ1Aw+7Cc6NX5f/5EObCvcGPK6LhDtAfg== X-Google-Smtp-Source: AMsMyM5Q++9fwJr8sIMYTNVsTHxzsAEkMFGs2DcZ1PZ+RKhdmONDijwgIjHRmW2Ict7Z1H8QzsXfjA== X-Received: by 2002:a17:907:7d8d:b0:781:fd6b:4545 with SMTP id oz13-20020a1709077d8d00b00781fd6b4545mr7179237ejc.117.1664556617127; Fri, 30 Sep 2022 09:50:17 -0700 (PDT) Received: from badger.. (boundsly.muster.volia.net. [93.72.16.93]) by smtp.gmail.com with ESMTPSA id d7-20020a170906304700b0073d9630cbafsm1395021ejd.126.2022.09.30.09.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 09:50:16 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kernel-team@fb.com Cc: Eduard Zingerman Subject: [PATCH bpf-next 1/2] bpftool: fix newline for struct with padding only fields Date: Fri, 30 Sep 2022 19:49:17 +0300 Message-Id: <20220930164918.342310-2-eddyz87@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220930164918.342310-1-eddyz87@gmail.com> References: <20220930164918.342310-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net An update for `bpftool btf dump file ... format c`. Add a missing newline print for structures that consist of anonymous-only padding fields. E.g. here is struct bpf_timer from vmlinux.h before this patch: struct bpf_timer { long: 64; long: 64;}; And after this patch: struct bpf_dynptr { long: 64; long: 64; }; Signed-off-by: Eduard Zingerman --- tools/lib/bpf/btf_dump.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 4221f73a74d0..ebbba19ac122 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -852,7 +852,7 @@ static int chip_away_bits(int total, int at_most) return total % at_most ? : at_most; } -static void btf_dump_emit_bit_padding(const struct btf_dump *d, +static bool btf_dump_emit_bit_padding(const struct btf_dump *d, int cur_off, int m_off, int m_bit_sz, int align, int lvl) { @@ -861,10 +861,10 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d, if (off_diff <= 0) /* no gap */ - return; + return false; if (m_bit_sz == 0 && off_diff < align * 8) /* natural padding will take care of a gap */ - return; + return false; while (off_diff > 0) { const char *pad_type; @@ -886,6 +886,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d, btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits); off_diff -= pad_bits; } + + return true; } static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id, @@ -906,6 +908,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, bool is_struct = btf_is_struct(t); int align, i, packed, off = 0; __u16 vlen = btf_vlen(t); + bool padding_added = false; packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; @@ -940,11 +943,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, /* pad at the end, if necessary */ if (is_struct) { align = packed ? 1 : btf__align_of(d->btf, id); - btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align, - lvl + 1); + padding_added = btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align, + lvl + 1); } - if (vlen) + if (vlen || padding_added) btf_dump_printf(d, "\n"); btf_dump_printf(d, "%s}", pfx(lvl)); if (packed) From patchwork Fri Sep 30 16:49:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 12995781 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFD8EC4332F for ; Fri, 30 Sep 2022 16:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbiI3QuX (ORCPT ); Fri, 30 Sep 2022 12:50:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbiI3QuV (ORCPT ); Fri, 30 Sep 2022 12:50:21 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4259825298 for ; Fri, 30 Sep 2022 09:50:20 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id rk17so10245215ejb.1 for ; Fri, 30 Sep 2022 09:50:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=c6B1yIEwQpU4XABo1/44xbyjYSQ2Y4sphSXj6qcLO+A=; b=fHy10lxpcPTlnJF32y25DvbMHN4xnvMG/jDTaHEoaZ8I5uMpCAB9Bni/mvc+MJ8uuO ux975TY6frAdSOxBg5xc+OIoy8oJQFqcvUO7Oe5lJ/a7TIWbgOA/H5cbubQluJ0I3cFg Uej9UUJsEnd415gvSD5vHH2hA1/GRa079YXqaeyIZAfPLKf1yZI89WczwR6LPwcsg4EF Mp9zkhqyrcuu7977JjudEuVVSWNWNshit0D13xmyW7TmFNCk6fMPdvEXGGd/Z8lad0Ed pRYY2eNPKI8NPcHSgrNoMqMnHOBTfYJZ9dK2RPc0SUldjVS+LtM/gJJXF7+jlhTjtrYT z7qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=c6B1yIEwQpU4XABo1/44xbyjYSQ2Y4sphSXj6qcLO+A=; b=SJOD6YJfJnt8arVwcRFscuoXkBqrmL+hoZAloPPCyw2nHy49od5JALXeraxNST+tr8 eBt0Z3XYRmxEG6S+/S14YvUUHsmWfUt9pZtbR1uJXn11dAoYscsFBn287Ud4uc7NV+fO 4/qk/rwKdSjmSc1KRvgKGipZNwmatujQ4C2jvSaEKwtLJrZvMhHJaf8aBbCqKUAi9hXq pk2vyCcQNMnuA8VQJLkvjWVf9G5V8opvooffSOCjyCD2ViSX4+qKdcCuM20so8bM1gLV JRYNs4ihWlq5qivtAintCazuMzj2BQ/aaSZSXHVQX37HUJNvouf6RVeStyuiXx2Jg0jZ vO+w== X-Gm-Message-State: ACrzQf1+bLYkNSb3e6t/NVqTQNs4f4m7M7wB5TiKxzj2FjNv4ZbhBRhQ 9FkiyT0LqsbGMKt420NvuLJaWSLFp4TXbw== X-Google-Smtp-Source: AMsMyM7T9ZArljxNKsAfUBBQ0FzxBp2UavFWi6eYhdkt345iMhyoNpfrNp+aL2CV4SJLjNmqMJ5RVw== X-Received: by 2002:a17:907:2721:b0:77f:d471:47b3 with SMTP id d1-20020a170907272100b0077fd47147b3mr7091575ejl.591.1664556618465; Fri, 30 Sep 2022 09:50:18 -0700 (PDT) Received: from badger.. (boundsly.muster.volia.net. [93.72.16.93]) by smtp.gmail.com with ESMTPSA id d7-20020a170906304700b0073d9630cbafsm1395021ejd.126.2022.09.30.09.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 09:50:17 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kernel-team@fb.com Cc: Eduard Zingerman Subject: [PATCH bpf-next 2/2] selftests/bpf: verify newline for struct with padding only fields Date: Fri, 30 Sep 2022 19:49:18 +0300 Message-Id: <20220930164918.342310-3-eddyz87@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220930164918.342310-1-eddyz87@gmail.com> References: <20220930164918.342310-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Verify that `bpftool btf dump file ... format c` correctly prints newlines for structures that consist of anonymous-only padding fields. Signed-off-by: Eduard Zingerman --- .../bpf/progs/btf_dump_test_case_padding.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c index f2661c8d2d90..08e43ee38188 100644 --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c @@ -102,12 +102,28 @@ struct zone { struct zone_padding __pad__; }; +/* ----- START-EXPECTED-OUTPUT ----- */ +/* + *struct padding_wo_named_members { + * long: 64; + * long: 64; + *}; + * + */ +/* ------ END-EXPECTED-OUTPUT ------ */ + +struct padding_wo_named_members { + long: 64; + long: 64; +} __attribute__((aligned(8))); + int f(struct { struct padded_implicitly _1; struct padded_explicitly _2; struct padded_a_lot _3; struct padded_cache_line _4; struct zone _5; + struct padding_wo_named_members _6; } *_) { return 0;