Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13473913ybl; Sun, 29 Dec 2019 12:46:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwzF+w0u64uiyaS6bsf/wrQEBsLJTyYxyNsI/9r4k85hjnw5sDmEUMMsi4MYPid+LTi1OLf X-Received: by 2002:a9d:750b:: with SMTP id r11mr66218006otk.209.1577652379237; Sun, 29 Dec 2019 12:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652379; cv=none; d=google.com; s=arc-20160816; b=ycp1JRRDP3USGeGP1nl/O+FD48ittdkQEtTXAkURfeJExTHRLzyylOz1xfH/QzVsyg DM3DofukH+8zlHGvVL6spOxCaRD10eScc3H4lUFWbTIvOruKmnqlPP9oWyulQyKZ/FbP oKiKvdLOGC+58lAUIzjHFfD2/IOtGPO1iYQby94s8PXmbjgUSrwoZjlCtU/NSlGIo0Mp 5JFacppj6aLkRwxilSR2cHjiOLnsR0Uso7wRJO602mdpKP3nXJnlTMJbKAPy1eoRtdNN E+VB/A6APOZlz2+3RH3S1G6rud3U3rakDyFM+BMfTJiKL9EpJheXD+oFa0pacb5/Uxbh 61bw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=/z6AZeLQCW21OpAD203R4J1C3sF0oDFJpHSgLAe8L78=; b=w9DOUSF8keZ1LLxdw2m8RDyNhTfI5zscQryabOFA3ory7asUH0nNJsN1gc8Ntw2nrJ KrNWYiiKeyRWYSAbbxlvLmX4PIBgPQjWu4P9Luzt3DPiy1BkMyp7vyHsS4w7Mny1JqOf E1Sv5yOms7X3tmDsapukLIYnXsG6qcXZw00Mx63ldX2/51VQj0vwYo17uEcpBg1NHGPG FANtwN7z2WvwT8+k7EpPaTwhMts4MixJT52bt+QOBCNdPwHm1BHWVSsNpSH0LwnbxR3k AzOjgYNp8bP8u0ucAb/L+eXJRjvINEf8naOJAH6f6rvPB/bIDv7MNCcca8eKYzT6QRO7 byjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sGk25XE8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si21829198ota.19.2019.12.29.12.46.09; Sun, 29 Dec 2019 12:46:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sGk25XE8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731008AbfL2RqF (ORCPT + 99 others); Sun, 29 Dec 2019 12:46:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:55498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730997AbfL2RqC (ORCPT ); Sun, 29 Dec 2019 12:46:02 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A222D207FF; Sun, 29 Dec 2019 17:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641562; bh=u9H7d1EB6Cl7G4ftfrANC02XwN66e+Nwp3ptfHOWEq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sGk25XE8GYj9MC+W252gaGH0Mb/hnuG1uscf4vnjV3XDuongjI+RbjlvKGtJAA4Vc ltW9if7leeNSCjbpCt+1luP904mTV8HxfWaVsPUC2Cg8VHQ78NwlAb2lTXo685MySB vxGtKzMmyA74RgPIo8eggHhVCLifyNAT0ogH5Msg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Fastabend , Andrii Nakryiko , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.4 118/434] libbpf: Fix struct end padding in btf_dump Date: Sun, 29 Dec 2019 18:22:51 +0100 Message-Id: <20191229172709.523831060@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko [ Upstream commit b4099769f3321a8d258a47a8b4b9d278dad28a73 ] Fix a case where explicit padding at the end of a struct is necessary due to non-standart alignment requirements of fields (which BTF doesn't capture explicitly). Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion") Reported-by: John Fastabend Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Tested-by: John Fastabend Link: https://lore.kernel.org/bpf/20191008231009.2991130-2-andriin@fb.com Signed-off-by: Sasha Levin --- tools/lib/bpf/btf_dump.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index ede55fec3618..87f27e2664c5 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -876,7 +876,6 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, __u16 vlen = btf_vlen(t); packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; - align = packed ? 1 : btf_align_of(d->btf, id); btf_dump_printf(d, "%s%s%s {", is_struct ? "struct" : "union", @@ -906,6 +905,13 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, btf_dump_printf(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); + } + if (vlen) btf_dump_printf(d, "\n"); btf_dump_printf(d, "%s}", pfx(lvl)); -- 2.20.1