From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5172FC4828F for ; Fri, 2 Feb 2024 23:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aOqjSLFygCVPj8WTKrb38ML3JPoVQxV1T1s3ZaTTvLE=; b=pZkwcIDAwQQcAs ChZdsFgSDEY2B12Cx9Wh0bPA3n7Oe2aT71zdl+b1YFGNG2s0AZ9kMibMefVnYPXhtYpACnXDK30iL DpM/jjKxoR5svwGzuDqH72SgHkLwleYyl+eZdfx+zuv14Of9ga0NCOGJUHDWD18XFrFzZBi0LauPx jB+4ECim7EiJsxzkHKQ68U4byCqVDgK0mip8wmn6lN3vUDmmFwrJcqwWi1HyZzs+3j4eDmVySftCH 6qtE+o0/ni5FW3sZBjvl6B9K0o5c2yN/DTHzKcqq74HRPMgBEhBgSGqZ6z1XQoz96/9gK9uhcgEtC JHKv7PVxtEa8VAWuPyjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rW2em-0000000DkW1-1aR4; Fri, 02 Feb 2024 23:09:12 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rW2ej-0000000DkVY-3wlW for linux-arm-kernel@lists.infradead.org; Fri, 02 Feb 2024 23:09:11 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1d76671e5a4so20633755ad.0 for ; Fri, 02 Feb 2024 15:09:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706915349; x=1707520149; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ns/bvPkKWqK4cT5hwWAJS7KQis8SRbW6Visd6BLTiUI=; b=c0ng5oQA/85tAfHmGGcQUxjt93oY8T8BS/sA7X06iNL6YJLSUnsTlmMpPdk61QczRv i5gy/yGsScpYUHLr3aFWmIZlYLNTtPkQ8uiKhbQTZM6vkq7ijUlY5jYFMTUUkVu52DUS zE5EuDm6f43rSYuB/tcmySK86ay/gb2jG5rJuflZWnoaDt6Ec54K7unV43IfzK0z5Arm vybFNUEVvEkgsWG+YYtzhU/hvhDStgXZIFJwHk8IkkeHk4Kt7TZeMqhMXcw2rU8uBOlW px4OOd1OIBsfehshVJ6iyXbePW4LznivNTXNuROVBTWFvcFrZG4E9xcTk4gxqpcMfXLj +fAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706915349; x=1707520149; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ns/bvPkKWqK4cT5hwWAJS7KQis8SRbW6Visd6BLTiUI=; b=ZAtHM/hmfX2UXkEHQI9UcfUX8ZpO23qKzTYI4MdSCO8d0VYflIl+Lwi2ui/ph3ugvu P+tPfoPOL17m04y2vh7ubc2Jkt/M7WQe4tS4jobpehOMLBCvepgH4PFQApgFMRvVMons QUcjWjLxkiIY7FyVuQOWgy3JP77HdPWiiPjteZhOjKRI8j1DonI+xN/6p1QdYDxAHV2i ZivCpLaduWQAPdWr02+K2FhKciuZzrNUyYSd5CWNS9ZtjFTDy4T2g9z/0vgW3EJSJzlG wQFUOdfibSS4ZtyKYurV/916qSDJOd5R4wOOL4PN6QQRoyeh29ddM3mUMFfJch55xJux as4w== X-Gm-Message-State: AOJu0YwGYJm9H+6Cr1rjjEpSi5/o2Iv21l5WKlx8yfGU6t2WsAQohGZU fauqzCV9sL+pclBdmc3jj6/Un1qS0p8T05kYt755mqQqo+kSzF1Z X-Google-Smtp-Source: AGHT+IFxxTOrsdYhKRWr9e6jHbv8TCklGcEQIE8BSnW/BV4FuD23/hWYjE901pv5pKGyJLGFlLZjBQ== X-Received: by 2002:a17:902:b194:b0:1d5:c08e:52eb with SMTP id s20-20020a170902b19400b001d5c08e52ebmr8168069plr.65.1706915348583; Fri, 02 Feb 2024 15:09:08 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXh8AopKfi/YqWmfKiAwlQ/PCijITod0oFhPh7EZgbe4IqqVCTYplEzVZLk725jsEN7/jjrF3+q6jwqjZIAWgtFJwhn9qmdKmzSh1WTQWyzKIR3Vu1RR9VOQ/mVdMEOrdQtYnhjryw1mdCQexA9JgKi6G6x/jm8n0qLhDny1Uyh9vw8IV8OyRb46UVpGGduitQ9ram54QIx/Q4+QDflTEF+IDMbGP6LDutZoBqdGyGeIDaHWDuGJjeQGgpi3kWxY6Mxokz3ztlOAqOGqeQDd+PFxUQapdW8eUtWM9krlaYdDID3UIGv6Ao+xrLQWDCxkdxkdWrDdbxlfq5IiqlrLk7HA0UnJpJ4jkFfgWd75iHDEi8ZdxAD0XE06DRBlvejpEon3X1Owg03SqEYrAL6rJdyOqiuNnhveN6rok4raRhfJSFqktdoCqF5aru6yMErGbiCNxd0+0aDnqt1T1XYbEGqcirlu5DKCtQ6o6ulW7Vylya1gXBRqZMMo8UuNV9ealWnc8Uf9Vfw1XOhHZ4j41gYSibJO6X/qQ9m3wUuH/DVujlBkGxKAkVqWMc+Wc4KsIxm/EtloqOHI0LTPMMffFTsW5xMa5t9igm/5IU1NvJ0UaL1KXIbvnzxQdLod4WO3cP7eM+SLAzmpsRCYZ37BA3OS0HH2DSw/vYCAqccICCfyklhIqIq0wBZrEXbqubqWvBOtecAaQ== Received: from surya ([70.134.61.176]) by smtp.gmail.com with ESMTPSA id c9-20020a170902d48900b001d9557f6c04sm2086428plg.267.2024.02.02.15.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:09:08 -0800 (PST) Date: Fri, 2 Feb 2024 15:09:05 -0800 From: Manu Bretelle To: Daniel Xu Cc: linux-trace-kernel@vger.kernel.org, coreteam@netfilter.org, bpf@vger.kernel.org, linux-input@vger.kernel.org, cgroups@vger.kernel.org, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, fsverity@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netfilter-devel@vger.kernel.org, alexei.starovoitov@gmail.com, olsajiri@gmail.com, quentin@isovalent.com, alan.maguire@oracle.com, memxor@gmail.com, vmalik@redhat.com Subject: Re: [PATCH bpf-next v4 0/3] Annotate kfuncs in .BTF_ids section Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240202_150910_018225_460C8BDF X-CRM114-Status: GOOD ( 27.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, Jan 28, 2024 at 06:24:05PM -0700, Daniel Xu wrote: > === Description === > > This is a bpf-treewide change that annotates all kfuncs as such inside > .BTF_ids. This annotation eventually allows us to automatically generate > kfunc prototypes from bpftool. > > We store this metadata inside a yet-unused flags field inside struct > btf_id_set8 (thanks Kumar!). pahole will be taught where to look. > > More details about the full chain of events are available in commit 3's > description. > > The accompanying pahole and bpftool changes can be viewed > here on these "frozen" branches [0][1]. > > [0]: https://github.com/danobi/pahole/tree/kfunc_btf-v3-mailed > [1]: https://github.com/danobi/linux/tree/kfunc_bpftool-mailed I hit a similar issue to [0] on master 943b043aeecc ("selftests/bpf: Fix bench runner SIGSEGV") when cross-compiling on x86_64 (LE) to s390x (BE). I do have CONFIG_DEBUG_INFO_BTF enable and the issue would not trigger if I disabled CONFIG_DEBUG_INFO_BTF (and with the fix mentioned in [0]). What seems to happen is that `tools/resolve_btfids` is ran in the context of the host endianess and if I printk before the WARN_ON: diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index ef380e546952..a9ed7a1a4936 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -8128,6 +8128,7 @@ int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, * WARN() for initcall registrations that do not check errors. */ if (!(kset->set->flags & BTF_SET8_KFUNCS)) { + printk("Flag 0x%08X, expected 0x%08X\n", kset->set->flags, BTF_SET8_KFUNCS); WARN_ON(!kset->owner); return -EINVAL; } the boot logs would show: Flag 0x01000000, expected 0x00000001 The issue did not happen prior to 6f3189f38a3e ("bpf: treewide: Annotate BPF kfuncs in BTF") has only 0 was written before. It seems [1] will be addressing cross-compilation, but it did not fix it as is by just applying on top of master, so probably some of the changes will also need to be ported to `tools/include/linux/btf_ids.h`? A hacky workaround to cross-compilation I have is to apply: diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile index 4b8079f294f6..b706e7ab066f 100644 --- a/tools/bpf/resolve_btfids/Makefile +++ b/tools/bpf/resolve_btfids/Makefile @@ -22,10 +22,10 @@ HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH) CROSS_COMPILE="" EXTRA_CFLAGS="$(HOSTCFLAGS)" RM ?= rm -HOSTCC ?= gcc -HOSTLD ?= ld -HOSTAR ?= ar -CROSS_COMPILE = +HOSTCC = $(CC) +HOSTLD = $(LD) +HOSTAR = $(AR) +#CROSS_COMPILE = OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ @@ -56,16 +56,16 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \ - DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ + DESTDIR=$(SUBCMD_DESTDIR) prefix= subdir= \ $(abspath $@) install_headers $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT) $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \ - DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \ + DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \ $(abspath $@) install_headers -LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) -LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) +LIBELF_FLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null) +LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) HOSTCFLAGS_resolve_btfids += -g \ -I$(srctree)/tools/include \ @@ -84,7 +84,7 @@ $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT) $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) $(call msg,LINK,$@) - $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) + $(Q)$(CC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) clean_objects := $(wildcard $(OUTPUT)/*.o \ $(OUTPUT)/.*.o.cmd \ diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index a38a3001527c..5cd193c04448 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -171,7 +171,7 @@ INCLUDE_DIR := $(SCRATCH_DIR)/include BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a ifneq ($(CROSS_COMPILE),) HOST_BUILD_DIR := $(BUILD_DIR)/host -HOST_SCRATCH_DIR := $(OUTPUT)/host-tools +HOST_SCRATCH_DIR := $(SCRATCH_DIR) HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR)/include else HOST_BUILD_DIR := $(BUILD_DIR) This causes `resolve_btfids` to be compiled in the target endianess and gets magically run provided that the hosts has `qemu-s390x-static` and a functional binfmt_misc [2] on the host, but having this using host architecture per [1] is likely better. Here are steps to reproduce the issue on Ubuntu 23.10 and assuming danobi/vmtest [3] is installed: XPLATFORM="s390x" XARCH="s390" # Set up repo for s390x cat <> /etc/apt/sources.list.d/s390x.list deb [arch=s390x] http://ports.ubuntu.com/ubuntu-ports mantic main restricted deb [arch=s390x] http://ports.ubuntu.com/ubuntu-ports mantic-updates main restricted EOF sudo dpkg --add-architecture s390x apt install qemu-system-s390x qemu-user-static g{cc,++}-"${XARCH}-linux-gnu" {libelf-dev,libssl-dev,pkgconf}:s390x KBUILD_OUTPUT_DIR="/tmp/kbuild-${XPLATFORM}" mkdir "${KBUILD_OUTPUT_DIR}" cat tools/testing/selftests/bpf/config{,.vm,.${XPLATFORM}} > ${KBUILD_OUTPUT_DIR}/.config make ARCH="${XARCH}" CROSS_COMPILE="${XPLATFORM}-linux-gnu-" O="${KBUILD_OUTPUT_DIR}" -j$((4 * $(nproc))) olddefconfig make ARCH="${XARCH}" CROSS_COMPILE="${XPLATFORM}-linux-gnu-" O="${KBUILD_OUTPUT_DIR}" -j$((4 * $(nproc))) all # No need for a s390x ubuntu 23.10 rootfs, we only care about booting the kernel vmtest -k "${KBUILD_OUTPUT_DIR}/arch/s390/boot/bzImage" -a s390x "uname -m" | cat For the chroot route, see [4]. [0] https://lore.kernel.org/linux-kernel/20240201155339.2b5936be@canb.auug.org.au/T/ [1] https://lore.kernel.org/bpf/cover.1706717857.git.vmalik@redhat.com/ [2] https://en.wikipedia.org/wiki/Binfmt_misc [3] https://github.com/danobi/vmtest [4] https://chantra.github.io/bpfcitools/bpf-cross-compile.html Manu > > === Changelog === > > Changes from v3: > * Rebase to bpf-next and add missing annotation on new kfunc > > Changes from v2: > * Only WARN() for vmlinux kfuncs > > Changes from v1: > * Move WARN_ON() up a call level > * Also return error when kfunc set is not properly tagged > * Use BTF_KFUNCS_START/END instead of flags > * Rename BTF_SET8_KFUNC to BTF_SET8_KFUNCS > > Daniel Xu (3): > bpf: btf: Support flags for BTF_SET8 sets > bpf: btf: Add BTF_KFUNCS_START/END macro pair > bpf: treewide: Annotate BPF kfuncs in BTF > > Documentation/bpf/kfuncs.rst | 8 +++---- > drivers/hid/bpf/hid_bpf_dispatch.c | 8 +++---- > fs/verity/measure.c | 4 ++-- > include/linux/btf_ids.h | 21 +++++++++++++++---- > kernel/bpf/btf.c | 8 +++++++ > kernel/bpf/cpumask.c | 4 ++-- > kernel/bpf/helpers.c | 8 +++---- > kernel/bpf/map_iter.c | 4 ++-- > kernel/cgroup/rstat.c | 4 ++-- > kernel/trace/bpf_trace.c | 8 +++---- > net/bpf/test_run.c | 8 +++---- > net/core/filter.c | 20 +++++++++--------- > net/core/xdp.c | 4 ++-- > net/ipv4/bpf_tcp_ca.c | 4 ++-- > net/ipv4/fou_bpf.c | 4 ++-- > net/ipv4/tcp_bbr.c | 4 ++-- > net/ipv4/tcp_cubic.c | 4 ++-- > net/ipv4/tcp_dctcp.c | 4 ++-- > net/netfilter/nf_conntrack_bpf.c | 4 ++-- > net/netfilter/nf_nat_bpf.c | 4 ++-- > net/xfrm/xfrm_interface_bpf.c | 4 ++-- > net/xfrm/xfrm_state_bpf.c | 4 ++-- > .../selftests/bpf/bpf_testmod/bpf_testmod.c | 8 +++---- > 23 files changed, 87 insertions(+), 66 deletions(-) > > -- > 2.42.1 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel