From patchwork Fri Aug 30 07:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 824267 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C081E15F40D; Fri, 30 Aug 2024 07:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003002; cv=none; b=CzUhi9VjDVoGJfsrDYcH1BO2jCDAP/CWxxMc9HYy2AjL/fPxTlPf+mgOq68111hO0BYFwUFreLXcum5/U6A8sVCZ9IEgtv3eW+tdI38AOTarBE5VAFRuqIPj+sPn48KlfSbPd9pkjUGAcl2W5DM2lY+A1qu3i0173nfU/Xwp0zY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003002; c=relaxed/simple; bh=UJoIZbAwd0dcyPldGPlUH3SNsQcKTlS8LGIL6P+fhDs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BuCnwy6VIYbeRsdH6oF5uvCHrilbs7HK03uZ4y+tMY/C7OWHlNmMZDIISkTIF+DBw1Kb12syg6ev2sEaenZjMdH5uM+idqf9cFJAfm2n1NM7TIwnL0eMM3ONcwVDR60LqcYssDYXSWw750xiXAjSxFU86dlJ0hlWIRAeSLkGeeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=a7vYhx/n; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a7vYhx/n" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2053525bd90so872585ad.0; Fri, 30 Aug 2024 00:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725003000; x=1725607800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p7S9DLK/xi9tXkFIx+X5J9oUvgA+SnKs7nCanjbxcE8=; b=a7vYhx/ngRj5sExYjE1DHzE3ADfr5r8Gm/A27CxTM+XeAY4O7eJXH7hWJOoqJaf/2o EwqxybeChTAkCtqJVOa7jPBish6nbrouulgnOdrSFIn+tLvS9LSZQ/sI7e2CJiPV7u/K rMWWPQb99EhaYQwhyXQC+KhN8Dx4KZRPSjgYmOM5YYudOFf70eUquBreg5WixIk9kHAo I5vtmYzee2neMTVQnut6rPrVa+hu/iQD9wHl4179mkLjVNnB1ZdCwKQE+03UwNDs/iP+ HwiPC+VSOGLipZHixjSN4sKIgGbjwO/CED0Xxb0RMQ86fjDtd4Bdqxl/Eah2+eHrMnwr u8oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725003000; x=1725607800; 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:message-id:reply-to; bh=p7S9DLK/xi9tXkFIx+X5J9oUvgA+SnKs7nCanjbxcE8=; b=lBxql31IK7P84/YlMryvMeosGxLeSvrUl6KPTvihswwmxGPgPOAMNtyst2li4TOmah FwW7yUGlh9mWeOTsXpzxSiZ4xZ/5iFU52PaH0fzS93vkcrTj/2nQbc6+ErCpGz5WEG/V 9v4jeaXuSwcKrWEv0IhJYsAqS19SGWk13bAN8AnJb7Oujp/qBvSTsLezYAvw/i2U5skY iXXXJzU2z6mNW6GH4ybmix52d+4TUTOWsyHnRLAeWfZmMN0gSCBnvHsxKpSsLVY+MNoV 7/w3Ux8LP7X2XHQMcsjTO7GcqvA4JnNqKqVjtClLqB6vTtue5SCxRbRF5fNZp2yrVLDj sbbQ== X-Forwarded-Encrypted: i=1; AJvYcCX+qd4qgAxNUOhJoUt9To0lTTn6I5HU+GXIcWVnPFdyTJh2vdOk0TXCl6ZddAypZ+j7Iectq/NBjumMvSm5zfw=@vger.kernel.org X-Gm-Message-State: AOJu0YyQnxyvYpoX2aCvtHT4LoLTlDHgNKLb06rviVmeD34QPau5kDPi yNAtTiH6NMRunXUiAJvYRXqinoIJgMlL+HY6Zl+V2gFdT+07iiyjgSmxJtgj X-Google-Smtp-Source: AGHT+IFaw8cTmwpVNWzGzOfOyWf2b9H+orw8klmZc0zkB3oxfED/PsP49GM5HDFZbwThURgqnixSDA== X-Received: by 2002:a17:903:41d0:b0:202:4317:79c1 with SMTP id d9443c01a7336-2050c44cc9bmr50547695ad.37.1725002999873; Fri, 30 Aug 2024 00:29:59 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b4dd0sm21698085ad.15.2024.08.30.00.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:29:59 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Ilya Leoshkevich , Quentin Monnet Subject: [PATCH bpf-next v4 2/8] libbpf: Fix header comment typos for BTF.ext Date: Fri, 30 Aug 2024 00:29:24 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mention struct btf_ext_info_sec rather than non-existent btf_sec_func_info in BTF.ext struct documentation. Signed-off-by: Tony Ambardar --- tools/lib/bpf/libbpf_internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index 408df59e0771..8cda511a1982 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -448,11 +448,11 @@ struct btf_ext_info { * * The func_info subsection layout: * record size for struct bpf_func_info in the func_info subsection - * struct btf_sec_func_info for section #1 + * struct btf_ext_info_sec for section #1 * a list of bpf_func_info records for section #1 * where struct bpf_func_info mimics one in include/uapi/linux/bpf.h * but may not be identical - * struct btf_sec_func_info for section #2 + * struct btf_ext_info_sec for section #2 * a list of bpf_func_info records for section #2 * ...... * From patchwork Fri Aug 30 07:29:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 824266 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAAF61531D8; Fri, 30 Aug 2024 07:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003008; cv=none; b=nT4qtJCOSFh7uBk6JkOCXZpHjZNPTjKVZax5iN1Cb5xGBudti84FL+8tOa94sEqMmQNJuk1KBER8EqfRZoVf7YQJ1qfH9e5xwymdNB/bmi1LEvIsGlKGIP6DfUk8zoPOJdvubJpdJFZIlpsfTRSOLujPWXovJxxmO8lzhKC9kXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003008; c=relaxed/simple; bh=LkrBafs0NAlbpfTuD47AlJgJMZSzJnYvog6iNcs9XIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hknea0gGHJxrlXz3UJMbhHwTz77Hr9Q2fC6l5/XA7gYUKatekuNyJzVTiQCz3a/IRgJfZ1aN70Jo8GzFznW0Wuo1sb4pgF3XSeemFsDF7Mzkt2Fyrws9H/QHNGaxOKUU0oDtAL8OjthI74yZT70wfw2cqIk2ecLEjdQp4hhJslw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QMK52TJn; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QMK52TJn" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-204d391f53bso11966595ad.2; Fri, 30 Aug 2024 00:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725003006; x=1725607806; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vDhNeLRGMCGXFgaiAMyGz0HhiL4NmL5mHyzaYQ5Npec=; b=QMK52TJn9PeZSIwG8+m+hrasMIJt26J1xsgZ0jXia9fv/Guq0nMs2tznPGFygq+mJY e7LflrilYyv50Ee7PLB6e5VFArcJbJvBzJQdGcyG/5YJUCHX1VkP3w5eRHy9Vlll4rn3 cyA8o2md/zc8t8fkWf2pB++Xicg2zQb0ylXdUsZZ3Q+bIRyrVA2Mnx/ZXQhoja3iT3Tg 985rAPXa3QlHtb/Zm4xodl13h3jppmNx0Lsw33fckJR0JFk+s+v4/CifM+119JIEJsnP j+VIJlL0cZF5RB3DxrtDduoS3y5+/pkcnWu90GKSo3u6iWNFVnYxDF1iV6dAKUyW4bJ7 98CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725003006; x=1725607806; 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:message-id:reply-to; bh=vDhNeLRGMCGXFgaiAMyGz0HhiL4NmL5mHyzaYQ5Npec=; b=abiI6sPC84Q7zu5SKVPRsNa15nAXkSGFz0pf5jQ3wDz5faEy4U/yuYVgyk+6X4Y+hS +VvXLf3wyRECU/elGEurGjF0XcDL/MA0Otxu6gDTE6Sy7txaPvuqFOlbMOivBOzzfGKT U715bfELy64SX08UroM2M3MMyCt+kMqSpI33EJxMazfyZJQ6wnSwVhs2juhPtBMDF1V5 OQpglOFKx6kbKac6IF0p1wH/MiIDR0aIEE403QV6NiUv5cEaMRTsJAVCVIFMttn983wR SGU/oCz+VSx1IRwGzrdMLkYETvwY5Lw8gzbHzMSdF+g1DquimOEJ53gK+TM3SzDclsL9 U2qw== X-Forwarded-Encrypted: i=1; AJvYcCUdOnUNwNe2qDKbgdHscDqU1rItHxlGxCrVdQD4AoMeg+whXjVnlmYFd6bpN3YEQhVGDxrNwra7bBrfBRfwQLY=@vger.kernel.org X-Gm-Message-State: AOJu0YwzSTq+cauus8080GBp8ythaIz+vm0zw3fy278ohn90uVOI+yqd uzje5l39mFhRWlfjhSJHuGvzcgiwSOzm8BgqYo5AOTRWPClZ5g435b9AoPfc X-Google-Smtp-Source: AGHT+IE8AXEwfirYXZhteZv/yl1lGSPAi+7whaciuszhDey8BHMBLPY5VAWsh/R9c1PbAuXkAtVZMA== X-Received: by 2002:a17:902:d2cc:b0:1fd:6677:69b4 with SMTP id d9443c01a7336-2050c4a666bmr60117675ad.49.1725003005742; Fri, 30 Aug 2024 00:30:05 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b4dd0sm21698085ad.15.2024.08.30.00.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:30:05 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Ilya Leoshkevich , Quentin Monnet Subject: [PATCH bpf-next v4 4/8] libbpf: Support BTF.ext loading and output in either endianness Date: Fri, 30 Aug 2024 00:29:26 -0700 Message-Id: <8eaba4b675cba9035121121bba6618c9f8f65610.1724976539.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support for handling BTF data of either endianness was added in [1], but did not include BTF.ext data for lack of use cases. Later, support for static linking [2] provided a use case, but this feature and later ones were restricted to native-endian usage. Add support for BTF.ext handling in either endianness. Convert BTF.ext data to native endianness when read into memory for further processing, and support raw data access that restores the original byte-order for output. Add internal header functions for byte-swapping func, line, and core info records. Add new API functions btf_ext__endianness() and btf_ext__set_endianness() for query and setting byte-order, as already exist for BTF data. [1] 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness") [2] 8fd27bf69b86 ("libbpf: Add BPF static linker BTF and BTF.ext support") Signed-off-by: Tony Ambardar --- tools/lib/bpf/btf.c | 192 +++++++++++++++++++++++++++++--- tools/lib/bpf/btf.h | 3 + tools/lib/bpf/libbpf.map | 2 + tools/lib/bpf/libbpf_internal.h | 33 ++++++ 4 files changed, 214 insertions(+), 16 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index f5081de86ee0..064cfe126c09 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -3022,25 +3022,102 @@ static int btf_ext_setup_core_relos(struct btf_ext *btf_ext) return btf_ext_setup_info(btf_ext, ¶m); } -static int btf_ext_parse_hdr(__u8 *data, __u32 data_size) +/* Swap byte-order of BTF.ext header with any endianness */ +static void btf_ext_bswap_hdr(struct btf_ext *btf_ext, __u32 hdr_len) { - const struct btf_ext_header *hdr = (struct btf_ext_header *)data; + struct btf_ext_header *h = btf_ext->hdr; - if (data_size < offsetofend(struct btf_ext_header, hdr_len) || - data_size < hdr->hdr_len) { - pr_debug("BTF.ext header not found\n"); + h->magic = bswap_16(h->magic); + h->hdr_len = bswap_32(h->hdr_len); + h->func_info_off = bswap_32(h->func_info_off); + h->func_info_len = bswap_32(h->func_info_len); + h->line_info_off = bswap_32(h->line_info_off); + h->line_info_len = bswap_32(h->line_info_len); + + if (hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) + return; + + h->core_relo_off = bswap_32(h->core_relo_off); + h->core_relo_len = bswap_32(h->core_relo_len); +} + +/* Swap byte-order of a generic info subsection */ +static void info_subsec_bswap(const struct btf_ext_header *hdr, bool native, + __u32 off, __u32 len, anon_info_bswap_fn_t bswap) +{ + __u32 left, i, *rs, rec_size, num_info; + struct btf_ext_info_sec *si; + void *p; + + if (len == 0) + return; + + rs = (void *)hdr + hdr->hdr_len + off; /* record size */ + si = (void *)rs + sizeof(__u32); /* sec info #1 */ + rec_size = native ? *rs : bswap_32(*rs); + *rs = bswap_32(*rs); + left = len - sizeof(__u32); + while (left > 0) { + num_info = native ? si->num_info : bswap_32(si->num_info); + si->sec_name_off = bswap_32(si->sec_name_off); + si->num_info = bswap_32(si->num_info); + left -= offsetof(struct btf_ext_info_sec, data); + p = si->data; + for (i = 0; i < num_info; i++) /* list of records */ + p += bswap(p); + si = p; + left -= rec_size * num_info; + } +} + +/* + * Swap endianness of the whole info segment in a BTF.ext data section: + * - requires BTF.ext header data in native byte order + * - only support info structs from BTF version 1 + * - native: current info data is native endianness + */ +static void btf_ext_bswap_info(struct btf_ext *btf_ext, bool native) +{ + const struct btf_ext_header *hdr = btf_ext->hdr; + + /* Swap func_info subsection byte-order */ + info_subsec_bswap(hdr, native, hdr->func_info_off, hdr->func_info_len, + (anon_info_bswap_fn_t)bpf_func_info_bswap); + + /* Swap line_info subsection byte-order */ + info_subsec_bswap(hdr, native, hdr->line_info_off, hdr->line_info_len, + (anon_info_bswap_fn_t)bpf_line_info_bswap); + + /* Swap core_relo subsection byte-order (if present) */ + if (hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) + return; + + info_subsec_bswap(hdr, native, hdr->core_relo_off, hdr->core_relo_len, + (anon_info_bswap_fn_t)bpf_core_relo_bswap); +} + +/* Validate hdr data & info sections, convert to native endianness */ +static int btf_ext_parse(struct btf_ext *btf_ext) +{ + struct btf_ext_header *hdr = btf_ext->hdr; + __u32 hdr_len, info_size, data_size = btf_ext->data_size; + + if (data_size < offsetofend(struct btf_ext_header, hdr_len)) { + pr_debug("BTF.ext header too short\n"); return -EINVAL; } + hdr_len = hdr->hdr_len; if (hdr->magic == bswap_16(BTF_MAGIC)) { - pr_warn("BTF.ext in non-native endianness is not supported\n"); - return -ENOTSUP; + btf_ext->swapped_endian = true; + hdr_len = bswap_32(hdr_len); } else if (hdr->magic != BTF_MAGIC) { pr_debug("Invalid BTF.ext magic:%x\n", hdr->magic); return -EINVAL; } - if (hdr->version != BTF_VERSION) { + /* Ensure known version of structs, current BTF_VERSION == 1 */ + if (hdr->version != 1) { pr_debug("Unsupported BTF.ext version:%u\n", hdr->version); return -ENOTSUP; } @@ -3050,11 +3127,42 @@ static int btf_ext_parse_hdr(__u8 *data, __u32 data_size) return -ENOTSUP; } - if (data_size == hdr->hdr_len) { + if (data_size < hdr_len) { + pr_debug("BTF.ext header not found\n"); + return -EINVAL; + } else if (data_size == hdr_len) { pr_debug("BTF.ext has no data\n"); return -EINVAL; } + /* Verify mandatory hdr info details present */ + if (hdr_len < offsetofend(struct btf_ext_header, line_info_len)) { + pr_warn("BTF.ext header missing func_info, line_info\n"); + return -EINVAL; + } + + /* Keep hdr native byte-order in memory for introspection */ + if (btf_ext->swapped_endian) + btf_ext_bswap_hdr(btf_ext, hdr_len); + + /* Basic info section consistency checks*/ + info_size = btf_ext->data_size - hdr_len; + if (info_size & 0x03) { + pr_warn("BTF.ext info size not 4-byte multiple\n"); + return -EINVAL; + } + info_size -= hdr->func_info_len + hdr->line_info_len; + if (hdr_len >= offsetofend(struct btf_ext_header, core_relo_len)) + info_size -= hdr->core_relo_len; + if (info_size) { + pr_warn("BTF.ext info size mismatch with header data\n"); + return -EINVAL; + } + + /* Keep infos native byte-order in memory for introspection */ + if (btf_ext->swapped_endian) + btf_ext_bswap_info(btf_ext, !btf_ext->swapped_endian); + return 0; } @@ -3066,6 +3174,7 @@ void btf_ext__free(struct btf_ext *btf_ext) free(btf_ext->line_info.sec_idxs); free(btf_ext->core_relo_info.sec_idxs); free(btf_ext->data); + free(btf_ext->data_swapped); free(btf_ext); } @@ -3086,15 +3195,10 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size) } memcpy(btf_ext->data, data, size); - err = btf_ext_parse_hdr(btf_ext->data, size); + err = btf_ext_parse(btf_ext); if (err) goto done; - if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, line_info_len)) { - err = -EINVAL; - goto done; - } - err = btf_ext_setup_func_info(btf_ext); if (err) goto done; @@ -3119,15 +3223,71 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size) return btf_ext; } +static void *btf_ext_raw_data(const struct btf_ext *btf_ext_ro, __u32 *size, + bool swap_endian) +{ + struct btf_ext *btf_ext = (struct btf_ext *)btf_ext_ro; + const __u32 data_sz = btf_ext->data_size; + void *data; + + data = swap_endian ? btf_ext->data_swapped : btf_ext->data; + if (data) { + *size = data_sz; + return data; + } + + data = calloc(1, data_sz); + if (!data) + return NULL; + memcpy(data, btf_ext->data, data_sz); + + if (swap_endian) { + btf_ext_bswap_info(btf_ext, true); + btf_ext_bswap_hdr(btf_ext, btf_ext->hdr->hdr_len); + btf_ext->data_swapped = data; + } + + *size = data_sz; + return data; +} + const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size) { + __u32 data_sz; + void *data; + + data = btf_ext_raw_data(btf_ext, &data_sz, btf_ext->swapped_endian); + if (!data) + return errno = ENOMEM, NULL; + *size = btf_ext->data_size; - return btf_ext->data; + return data; } __attribute__((alias("btf_ext__raw_data"))) const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext, __u32 *size); +enum btf_endianness btf_ext__endianness(const struct btf_ext *btf_ext) +{ + if (is_host_big_endian()) + return btf_ext->swapped_endian ? BTF_LITTLE_ENDIAN : BTF_BIG_ENDIAN; + else + return btf_ext->swapped_endian ? BTF_BIG_ENDIAN : BTF_LITTLE_ENDIAN; +} + +int btf_ext__set_endianness(struct btf_ext *btf_ext, enum btf_endianness endian) +{ + if (endian != BTF_LITTLE_ENDIAN && endian != BTF_BIG_ENDIAN) + return libbpf_err(-EINVAL); + + btf_ext->swapped_endian = is_host_big_endian() != (endian == BTF_BIG_ENDIAN); + + if (!btf_ext->swapped_endian) { + free(btf_ext->data_swapped); + btf_ext->data_swapped = NULL; + } + return 0; +} struct btf_dedup; diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index b68d216837a9..e3cf91687c78 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -167,6 +167,9 @@ LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size); LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext); LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size); +LIBBPF_API enum btf_endianness btf_ext__endianness(const struct btf_ext *btf_ext); +LIBBPF_API int btf_ext__set_endianness(struct btf_ext *btf_ext, + enum btf_endianness endian); LIBBPF_API int btf__find_str(struct btf *btf, const char *s); LIBBPF_API int btf__add_str(struct btf *btf, const char *s); diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 8f0d9ea3b1b4..5c17632807b6 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -421,6 +421,8 @@ LIBBPF_1.5.0 { global: btf__distill_base; btf__relocate; + btf_ext__endianness; + btf_ext__set_endianness; bpf_map__autoattach; bpf_map__set_autoattach; bpf_program__attach_sockmap; diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index 8cda511a1982..81d375015c2b 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -484,6 +484,8 @@ struct btf_ext { struct btf_ext_header *hdr; void *data; }; + void *data_swapped; + bool swapped_endian; struct btf_ext_info func_info; struct btf_ext_info line_info; struct btf_ext_info core_relo_info; @@ -511,6 +513,37 @@ struct bpf_line_info_min { __u32 line_col; }; +/* Functions/typedef to help byte-swap info records, returning their size */ + +typedef int (*anon_info_bswap_fn_t)(void *); + +static inline int bpf_func_info_bswap(struct bpf_func_info *i) +{ + i->insn_off = bswap_32(i->insn_off); + i->type_id = bswap_32(i->type_id); + return sizeof(*i); +} + +static inline int bpf_line_info_bswap(struct bpf_line_info *i) +{ + i->insn_off = bswap_32(i->insn_off); + i->file_name_off = bswap_32(i->file_name_off); + i->line_off = bswap_32(i->line_off); + i->line_col = bswap_32(i->line_col); + return sizeof(*i); +} + +static inline int bpf_core_relo_bswap(struct bpf_core_relo *i) +{ + _Static_assert(sizeof(i->kind) == sizeof(__u32), + "enum bpf_core_relo_kind is not 32-bit\n"); + i->insn_off = bswap_32(i->insn_off); + i->type_id = bswap_32(i->type_id); + i->access_str_off = bswap_32(i->access_str_off); + i->kind = bswap_32(i->kind); + return sizeof(*i); +} + enum btf_field_iter_kind { BTF_FIELD_ITER_IDS, BTF_FIELD_ITER_STRS, From patchwork Fri Aug 30 07:29:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 824265 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 247651607BB; Fri, 30 Aug 2024 07:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003014; cv=none; b=QzHDk0QX6kvPcdbYd8zsEyygnCcGFekiiD0TJzFlWCzqnMp7423e8tK30EdTQAnWIpvfPHhqmnM7qen9VdLrLhkMni7Y1PNdVripfqm2Jwxgknl3bAN9QLTPNQ4KCUy4f/yeK34nvHHuRH81MpZW99pKvf5LFO4f5uiV1dH+uF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003014; c=relaxed/simple; bh=bZFiVLxsPqJFp+7OFMaqX0ZvCLgCDYIYtrLGMsK2oz0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Qkm9QM13tyNacxL0nBshtGxOfJAdh9fXl/7cS0HSquXffu2tTxGCIm1ZIVZO3aBJARiZmmzpNd8ozNPFM1kyecaTiYjtdxYpKuseLc5/1eRVnt0FUtrPYCeinMHHfrUp4MTQx2cp/uJO2l3c9A4b7LnVJ2QMlBIK38ulgqJQJNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IwlWw4Ve; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IwlWw4Ve" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20231aa8908so11557615ad.0; Fri, 30 Aug 2024 00:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725003012; x=1725607812; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lCLEqvYFcYfbFDmBpnULkP78s+23ipk0h/fW+02tbBM=; b=IwlWw4Ve6JZmBni/iiuimdFP+P/QCLGMTI5BbpcDp1KjznoN8uGuZjVw8BpIqTALIT VjuNYXwQPNqJOmz0MJSEarzQqd+wQqB4ZLGD9rs4fXBdSBGbENmB3RHV+ro/AAMossRU DLrOY4HITuDz+nnL68dKM+325sgrK9rKljxkdh2m2+YkrGQOEgZHuxoO0/f1GOqnHq4m l+KGnvp0sJzn9HzdE0f4xmPXAq02m9yxuHgQVCXV2+ZZT4UgrmzNv7pypiC/LGnqfA8l mpIfny7WVFxpETKu30ulrlvBBEhVnsmhKKe3opHyAJPfmZJf+feowCK1UWgCw/2N9hIU ULXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725003012; x=1725607812; 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:message-id:reply-to; bh=lCLEqvYFcYfbFDmBpnULkP78s+23ipk0h/fW+02tbBM=; b=NjF4EYM/ADhcxWc5pO8caOMFypcyatsgJ21goZwAvYW6idQKbd0EIiLHUr9dn4UDcH b+YqAwAw9POP1oN5rOIKMT1cAitaEGq08ZosAP/AwRucLrWSF2YUFy7pAJ7aIhGaJ0QY iiM3+2pn5lV0+qjPmgFVWfNNEwaHaRKjWu+VdNveh/razKtVlSSXv6OiL3CLgDwnToUT oGZ8pBijK98AuJXmVul9slY+HGkLSVuP9gwULoLReDvJ/yqiR5ttlTixmn3r293h3Iy9 5JMTmSGhV2fZUX6BbUPDvfbwnTm96//PBbnYlRWb3u1vrxrl0ekFvoHzfBEFLtR/B9za 7GRQ== X-Forwarded-Encrypted: i=1; AJvYcCVnFPJLi3dhQuITYU7XW/Et8dDH5X4XZrLM0IpPyaCi/eIQr7q+/EkYiIirPvo+CjvosvKlp4BK40HMJQBAnIg=@vger.kernel.org X-Gm-Message-State: AOJu0YzMxlmsSMBTjkJzr4I9lfYOb6YEQn0k62hAU0yV8lO1+24aM8Fv RK/iGuzd5RAsf5NfSwxTfYz1nv+Qi0gEXApcfDJIVQbKVtQyVaNvocQ5eZsE X-Google-Smtp-Source: AGHT+IEs9SU9D0i7I40ChktQADK5+wH4dZhhKyxvKfHl0U8D/im4JnxT8BFD2i78X9laiER7tuLdYg== X-Received: by 2002:a17:903:22c6:b0:1fd:d3db:bd06 with SMTP id d9443c01a7336-2050c34f1fcmr61723295ad.2.1725003012258; Fri, 30 Aug 2024 00:30:12 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b4dd0sm21698085ad.15.2024.08.30.00.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:30:12 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Ilya Leoshkevich , Quentin Monnet Subject: [PATCH bpf-next v4 6/8] libbpf: Support linking bpf objects of either endianness Date: Fri, 30 Aug 2024 00:29:28 -0700 Message-Id: <895753fe6de5a06dee8ac110f0c05571db73e70c.1724976539.git.tony.ambardar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allow static linking object files of either endianness, checking that input files have consistent byte-order, and setting output endianness from input. Linking requires in-memory processing of programs, relocations, sections, etc. in native endianness, and output conversion to target byte-order. This is enabled by built-in ELF translation and recent BTF/BTF.ext endianness functions. Further add local functions for swapping byte-order of sections containing BPF insns. Signed-off-by: Tony Ambardar --- tools/lib/bpf/linker.c | 90 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 7489306cd6f7..bd97da68eed6 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -135,6 +135,7 @@ struct bpf_linker { int fd; Elf *elf; Elf64_Ehdr *elf_hdr; + bool swapped_endian; /* Output sections metadata */ struct dst_sec *secs; @@ -324,13 +325,8 @@ static int init_output_elf(struct bpf_linker *linker, const char *file) linker->elf_hdr->e_machine = EM_BPF; linker->elf_hdr->e_type = ET_REL; -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2LSB; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB; -#else -#error "Unknown __BYTE_ORDER__" -#endif + /* Set unknown ELF endianness, assign later from input files */ + linker->elf_hdr->e_ident[EI_DATA] = ELFDATANONE; /* STRTAB */ /* initialize strset with an empty string to conform to ELF */ @@ -541,19 +537,21 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, const struct bpf_linker_file_opts *opts, struct src_obj *obj) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - const int host_endianness = ELFDATA2LSB; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - const int host_endianness = ELFDATA2MSB; -#else -#error "Unknown __BYTE_ORDER__" -#endif int err = 0; Elf_Scn *scn; Elf_Data *data; Elf64_Ehdr *ehdr; Elf64_Shdr *shdr; struct src_sec *sec; + unsigned char obj_byteorder; + unsigned char link_byteorder = linker->elf_hdr->e_ident[EI_DATA]; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + const unsigned char host_byteorder = ELFDATA2LSB; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + const unsigned char host_byteorder = ELFDATA2MSB; +#else +#error "Unknown __BYTE_ORDER__" +#endif pr_debug("linker: adding object file '%s'...\n", filename); @@ -579,11 +577,25 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, pr_warn_elf("failed to get ELF header for %s", filename); return err; } - if (ehdr->e_ident[EI_DATA] != host_endianness) { + + /* Linker output endianness set by first input object */ + obj_byteorder = ehdr->e_ident[EI_DATA]; + if (obj_byteorder != ELFDATA2LSB && obj_byteorder != ELFDATA2MSB) { + err = -EOPNOTSUPP; + pr_warn("unknown byte order of ELF file %s\n", filename); + return err; + } + if (link_byteorder == ELFDATANONE) { + linker->elf_hdr->e_ident[EI_DATA] = obj_byteorder; + linker->swapped_endian = obj_byteorder != host_byteorder; + pr_debug("linker: set %s-endian output byte order\n", + obj_byteorder == ELFDATA2MSB ? "big" : "little"); + } else if (link_byteorder != obj_byteorder) { err = -EOPNOTSUPP; - pr_warn_elf("unsupported byte order of ELF file %s", filename); + pr_warn("byte order mismatch with ELF file %s\n", filename); return err; } + if (ehdr->e_type != ET_REL || ehdr->e_machine != EM_BPF || ehdr->e_ident[EI_CLASS] != ELFCLASS64) { @@ -1111,6 +1123,27 @@ static bool sec_content_is_same(struct dst_sec *dst_sec, struct src_sec *src_sec return true; } +static bool is_exec_sec(struct dst_sec *sec) +{ + if (!sec || sec->ephemeral) + return false; + return (sec->shdr->sh_type == SHT_PROGBITS) && + (sec->shdr->sh_flags & SHF_EXECINSTR); +} + +static int exec_sec_bswap(void *raw_data, int size) +{ + const int insn_cnt = size / sizeof(struct bpf_insn); + struct bpf_insn *insn = raw_data; + int i; + + if (size % sizeof(struct bpf_insn)) + return -EINVAL; + for (i = 0; i < insn_cnt; i++, insn++) + bpf_insn_bswap(insn); + return 0; +} + static int extend_sec(struct bpf_linker *linker, struct dst_sec *dst, struct src_sec *src) { void *tmp; @@ -1170,6 +1203,10 @@ static int extend_sec(struct bpf_linker *linker, struct dst_sec *dst, struct src memset(dst->raw_data + dst->sec_sz, 0, dst_align_sz - dst->sec_sz); /* now copy src data at a properly aligned offset */ memcpy(dst->raw_data + dst_align_sz, src->data->d_buf, src->shdr->sh_size); + + /* convert added bpf insns to native byte-order */ + if (linker->swapped_endian && is_exec_sec(dst)) + exec_sec_bswap(dst->raw_data + dst_align_sz, src->shdr->sh_size); } dst->sec_sz = dst_final_sz; @@ -2630,6 +2667,10 @@ int bpf_linker__finalize(struct bpf_linker *linker) if (!sec->scn) continue; + /* restore sections with bpf insns to target byte-order */ + if (linker->swapped_endian && is_exec_sec(sec)) + exec_sec_bswap(sec->raw_data, sec->sec_sz); + sec->data->d_buf = sec->raw_data; } @@ -2698,6 +2739,7 @@ static int emit_elf_data_sec(struct bpf_linker *linker, const char *sec_name, static int finalize_btf(struct bpf_linker *linker) { + enum btf_endianness link_endianness; LIBBPF_OPTS(btf_dedup_opts, opts); struct btf *btf = linker->btf; const void *raw_data; @@ -2742,6 +2784,22 @@ static int finalize_btf(struct bpf_linker *linker) return err; } + /* Set .BTF and .BTF.ext output byte order */ + link_endianness = linker->elf_hdr->e_ident[EI_DATA] == ELFDATA2MSB ? + BTF_BIG_ENDIAN : BTF_LITTLE_ENDIAN; + err = btf__set_endianness(linker->btf, link_endianness); + if (err) { + pr_warn("failed to set .BTF output endianness: %d\n", err); + return err; + } + if (linker->btf_ext) { + err = btf_ext__set_endianness(linker->btf_ext, link_endianness); + if (err) { + pr_warn("failed to set .BTF.ext output endianness: %d\n", err); + return err; + } + } + /* Emit .BTF section */ raw_data = btf__raw_data(linker->btf, &raw_sz); if (!raw_data) From patchwork Fri Aug 30 07:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Ambardar X-Patchwork-Id: 824264 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CC0616BE0C; Fri, 30 Aug 2024 07:30:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003024; cv=none; b=q3l/MZcAzG2bow9vAH6LX04U83fquSUaaTEVHdde1eBLJ2gdoNZaNtaq995r8o8Ag4P74zkjxR4pBxroADqlUVuxZnEcQW/Z+WRmtGtJ+rgsh/cmXc//LRzrDul0I8zQi4nIunvn5b2QXCLHXEmFUWWDd4vlV61qfP1KC6VGrkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725003024; c=relaxed/simple; bh=Sf7g9q6kzZ2QDVZ42l9TEK1MrgR/netlPt93lP7g9x4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qvu5kMo2Owsez961UyXU8cjowkfWFoajArp6mx2HKmtAwHkuitIQUZkwfgw7F840umaCYZVz6/nl9dgtT5sm7eRuI3c37QTduGxtFjT/iOK2PnvusVDKHC74cc2hK7cV0hAqkZMa1PoERMj4oGUDcbPoqX1VVwgh4hR7IpmVT5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D/+8cHw/; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D/+8cHw/" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-201f2b7fe0dso12818905ad.1; Fri, 30 Aug 2024 00:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725003022; x=1725607822; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DRgUXWe8dZjfzs16xzJQ+DDVhbgl0JeJ2Y/m+gXLXrs=; b=D/+8cHw/6SMPg0vXP2K+PVjCQpvUBYFwPaA8ioQSgBd+MCK/eYjpdbdrudd1nazRKt S77ipLRYWnEPgDZtNLGzU5k9AbHDc59sg+ieml6ohJ8Q9MkfuD9a3CpJ3XJA+bRbU3Qo FPGrcCYBKQiHJkgZ96a54plk2gfnyWKPcTluuBzwV1YTTZisKfyshvaTA6EmVj1GHIA+ uQALOhcnhRfpnXbTc1/0bjaE6sE9otd/4nXqPpJP9kpHwwndxvWiNbVKFV0buN7oRBfy tC1KMPnyj4KnEO5OcOp9F+jFOgaOfD9pkubMa9V/kRVbMiUV3VxbalOiXQaI1MN+Vt1X GvEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725003022; x=1725607822; 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:message-id:reply-to; bh=DRgUXWe8dZjfzs16xzJQ+DDVhbgl0JeJ2Y/m+gXLXrs=; b=Mbra98jErVwR7ippTWo7HOcg8rG6WsbR1LHFbs7NFsADg2+h9UpqqZT2HUyaNhaBPE 6x80uv9ALziWsr+ZO93JuOibVIergd7kIDzyADjEl8Z+Sctdg5DR7Na5vjnX4rAqpH6D LxxXOph2u9TGKOzJoYvHoS0Aje68syOSvbqRHl6TgWhKuVqdjdq4vSnX+OpHP5sqU87w 0lB7QsmwEMhrhZTdWYY5TiRPq8lxIqh6RvoccJH7gdUaKeRvpIcZnpSthAp4rQfxHkAf IkINAxQWRu+W3oW7oQ5khUrgjDb1NQxl4WRoS65GZ+0OCrsXQj9J8vIVpuCtXTDSHocy 5KGg== X-Forwarded-Encrypted: i=1; AJvYcCWzJSLLLPlRvzO/QyrH3O16Nb0Pjv02tGyKoLtnvtOgKxajS9qIrxR3atAOSMP/m98wER3+WUJFVYHV1Zpzbsw=@vger.kernel.org X-Gm-Message-State: AOJu0YzYQzeYAEnMTh4YsMENvy1ug1xVV8BkGGT67Uiw1okEHSuGcfLe U3XDkKhTL6KM4Vryiye4isWwF1DcktZwD/N5gabDDDrH/C3UgETRoQ9VKRFW X-Google-Smtp-Source: AGHT+IF8A+tzbxB2dPzmuiLZQVlvRGJkJrjG6ut3uVXWa1gSLUlWERkW2TZfKNDo8kF7/P8Ei5N+yw== X-Received: by 2002:a17:903:2444:b0:202:562c:f3cd with SMTP id d9443c01a7336-2050c4f4331mr54598785ad.56.1725003022188; Fri, 30 Aug 2024 00:30:22 -0700 (PDT) Received: from localhost.localdomain (69-172-146-21.cable.teksavvy.com. [69.172.146.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b4dd0sm21698085ad.15.2024.08.30.00.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:30:22 -0700 (PDT) From: Tony Ambardar To: bpf@vger.kernel.org Cc: Tony Ambardar , linux-kselftest@vger.kernel.org, Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Ilya Leoshkevich , Quentin Monnet Subject: [PATCH bpf-next v4 8/8] selftests/bpf: Support cross-endian building Date: Fri, 30 Aug 2024 00:29:30 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update Makefile build rules to compile BPF programs with target endianness rather than host byte-order. With recent changes, this allows building the full selftests/bpf suite hosted on x86_64 and targeting s390x or mips64eb for example. Signed-off-by: Tony Ambardar --- tools/testing/selftests/bpf/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index c120617b64ad..27afbfa9e831 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -438,6 +438,7 @@ endef IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E -