From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mail.toke.dk (Postfix) with ESMTPS id 67861982BBF for ; Tue, 28 Jun 2022 21:49:07 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jBRAdB9C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445748; x=1687981748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sgjOMZvqwy3/sgeJmIw/5jGoi4GaZrbkmWa1wRm6tdY=; b=jBRAdB9C9Fvntg41sJc2BiatjoGBPcba0u4tLVtXp9nwUWsMoKYEti73 UYj6LRZYPnLLKZrgErRRBWNERwGFJowfg99syUTc3czypXDcRgYqaHdR7 TPrbbBIy0lm2jPMjfqqZr2OQrV5TTjDN58CJxyq3NFZyCtg6Zb1yPKqhB 0aztDNzPGJQNVOqaI+ig6jfL+tnlzaL6jIHpcR/wtE/GTGCVzy/1mwVOn bAJpTVnnab7OAXLp5ooYtkFDozvRcQVoTIK8/EbLXLjyi2HgO8qXa8J9A PzNwlugnTJosCGvkobAUxiMJFGKGTP0YDMytFotCAbZ9WwULhjXNRLMT8 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="368146796" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="368146796" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="836809320" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga006.fm.intel.com with ESMTP; 28 Jun 2022 12:49:00 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr94022013; Tue, 28 Jun 2022 20:48:59 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:24 +0200 Message-Id: <20220628194812.1453059-5-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: J2ZYSHUFO2VMBO6I424XOSQB2ITXNJBC X-Message-ID-Hash: J2ZYSHUFO2VMBO6I424XOSQB2ITXNJBC X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 04/52] libbpf: patch module BTF ID into BPF insns List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Larysa Zaremba Return both type id and BTF id from bpf_core_type_id_kernel(). Earlier only type id was returned despite the fact that llvm has enabled the 64 return type for this instruction [1]. This was done as a preparation to the patch [2], which also strongly served as a inspiration for this implementation. [1] https://reviews.llvm.org/D91489 [2] https://lore.kernel.org/all/20201205025140.443115-1-andrii@kernel.org Signed-off-by: Larysa Zaremba Signed-off-by: Alexander Lobakin --- tools/lib/bpf/bpf_core_read.h | 3 ++- tools/lib/bpf/relo_core.c | 8 +++++++- tools/lib/bpf/relo_core.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/bpf_core_read.h b/tools/lib/bpf/bpf_core_read.h index fd48b1ff59ca..2b7d675b2dd0 100644 --- a/tools/lib/bpf/bpf_core_read.h +++ b/tools/lib/bpf/bpf_core_read.h @@ -167,7 +167,8 @@ enum bpf_enum_value_kind { * Convenience macro to get BTF type ID of a target kernel's type that matches * specified local type. * Returns: - * - valid 32-bit unsigned type ID in kernel BTF; + * - valid 64-bit unsigned integer: the upper 32 bits is the BTF ID + * and the lower 32 bits is the type ID within the BTF. * - 0, if no matching type was found in a target kernel BTF. */ #define bpf_core_type_id_kernel(type) \ diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c index e070123332cd..020f0f81374c 100644 --- a/tools/lib/bpf/relo_core.c +++ b/tools/lib/bpf/relo_core.c @@ -884,6 +884,7 @@ static int bpf_core_calc_relo(const char *prog_name, res->fail_memsz_adjust = false; res->orig_sz = res->new_sz = 0; res->orig_type_id = res->new_type_id = 0; + res->btf_obj_id = 0; if (core_relo_is_field_based(relo->kind)) { err = bpf_core_calc_field_relo(prog_name, relo, local_spec, @@ -934,6 +935,8 @@ static int bpf_core_calc_relo(const char *prog_name, } else if (core_relo_is_type_based(relo->kind)) { err = bpf_core_calc_type_relo(relo, local_spec, &res->orig_val, &res->validate); err = err ?: bpf_core_calc_type_relo(relo, targ_spec, &res->new_val, NULL); + if (!err && relo->kind == BPF_CORE_TYPE_ID_TARGET) + res->btf_obj_id = btf_obj_id(targ_spec->btf); } else if (core_relo_is_enumval_based(relo->kind)) { err = bpf_core_calc_enumval_relo(relo, local_spec, &res->orig_val); err = err ?: bpf_core_calc_enumval_relo(relo, targ_spec, &res->new_val); @@ -1125,7 +1128,10 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn, } insn[0].imm = new_val; - insn[1].imm = new_val >> 32; + /* For type IDs, upper 32 bits are used for BTF ID */ + insn[1].imm = relo->kind == BPF_CORE_TYPE_ID_TARGET ? + res->btf_obj_id : + (new_val >> 32); pr_debug("prog '%s': relo #%d: patched insn #%d (LDIMM64) imm64 %llu -> %llu\n", prog_name, relo_idx, insn_idx, (unsigned long long)imm, (unsigned long long)new_val); diff --git a/tools/lib/bpf/relo_core.h b/tools/lib/bpf/relo_core.h index 3fd3842d4230..f026ea36140e 100644 --- a/tools/lib/bpf/relo_core.h +++ b/tools/lib/bpf/relo_core.h @@ -66,6 +66,7 @@ struct bpf_core_relo_res { __u32 orig_type_id; __u32 new_sz; __u32 new_type_id; + __u32 btf_obj_id; }; int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, -- 2.36.1