Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8997410rwr; Thu, 11 May 2023 08:41:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68ol0neqj8UHNQO5h4CKjSeWMhUwt2jAaeZQeknKtkPdgdm5fi4Np9cZoESRVLjVGmrEAS X-Received: by 2002:a17:90a:ba98:b0:250:ac7f:a76e with SMTP id t24-20020a17090aba9800b00250ac7fa76emr9990667pjr.6.1683819699590; Thu, 11 May 2023 08:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683819699; cv=none; d=google.com; s=arc-20160816; b=I28GR0UozBVyK+9bXxwoSP28udH1YD0gba2NrdQ7vWZV9WYU9uCTgFkzV33mJAiORe 4KG7ud5tXMlrQycyIqE2ULGiRK1LsZQ1gXm/M0n3271tq9zmhqtGV4smh405omwQ+eyY cvoe5L5il0W0GDUZzV1ESvfY+5+aF0G7EGmSamFn7QKRBkrWhjSxg8Sr6FXmm2ii0kli BGLvqyIeAkxnf8MEWhMa7I3odOiXRKSjoCfFFF+EFhgKF5dCyd8MuyF9UPC+iFOp7f7D wJK+21fCf3WMJHsp+w/xYuMu4jJ49hfvN/WHlfG9bB/1hHZoFjjq1s2N9qjfEH7Bs37J oFZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9LEfa7BloCux0gpZPERBpZvr0PiKd8LtXXPn3LceYuM=; b=qbFQPY0SUjgM80wjAltIKUY+S8ircbUvkceOCSGozIXrrXPATHYD1KZuGqgcYkxC4N v/MkW7YqBfX+0El36AhfwuWXXyrtNjE8XmYh96VRH600RHhmlpAWaYHNUme1K7aFvBn3 XIo5QavjllA9yPF63UOIFr2DR7+jSAPxQo9uu1M0QUKwWRBT/X/1VedoyIch4lNiESd6 08qNT7QGWRHeL9vN5vYfULmnERMK2oKeca03N3fuxOykegH7JHl5agaXaCcylkbU++hI HUZdLaHRiR/6/5WYJa3aFffjiG2198d65Ue6CChnary0Bc9qSpDJtap3iwbaVrZ2lw+m AmMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jlXojrXq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a63340f000000b005303b3da2d1si7337109pga.173.2023.05.11.08.41.21; Thu, 11 May 2023 08:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jlXojrXq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238644AbjEKPWA (ORCPT + 99 others); Thu, 11 May 2023 11:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238612AbjEKPV4 (ORCPT ); Thu, 11 May 2023 11:21:56 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59A0138; Thu, 11 May 2023 08:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683818512; x=1715354512; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=XR/zMIbG4Jcm24Yt1GRfoMUGo5dYfwoSu6slMdxjNv0=; b=jlXojrXqon1WWvbp+EcLZkFcoys1+84ZnRSwfMh/R3uCSRNCo2u/Kths 6FQzaD7kromafBDXORasEL+sclbnkMRuBJJYPzrgKn4RGmrdK0BJHIeF5 z+BmkW3oHyaztnJ+6g8eN6XhvJuZwvE01tcjqESo5cuKWo6rmKljKPZpp WKcmA7k0tpbWPwwgXhbulutpfH77AFa7ZB+ZZyVdxiIixMIW+n4aLJswT OdWVfYk6++m7+sOUxzILk7KpuIHkdHgyTNV33woEOvCJKqrMYJycSFxUA 8c7aE7RoWoVwo9j6n9ot6CGrPeZpyRWyyNbuPJwf5sFof755W8gplIkQi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="352760702" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="352760702" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 08:20:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="702782185" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="702782185" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmsmga007.fm.intel.com with ESMTP; 11 May 2023 08:20:06 -0700 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id 6D7EE36C0E; Thu, 11 May 2023 16:20:05 +0100 (IST) From: Larysa Zaremba To: Quentin Monnet Cc: Larysa Zaremba , Stanislav Fomichev , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next] bpftool: specify XDP Hints ifname when loading program Date: Thu, 11 May 2023 17:13:46 +0200 Message-Id: <20230511151345.7529-1-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add ability to specify a network interface used to resolve XDP Hints kfuncs when loading program through bpftool. Usage: bpftool prog load dev xdpmeta Signed-off-by: Larysa Zaremba --- tools/bpf/bpftool/prog.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 91b6075b2db3..a9cb96d99277 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -1517,12 +1517,13 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) struct bpf_program *prog = NULL, *pos; unsigned int old_map_fds = 0; const char *pinmaps = NULL; + __u32 offload_ifindex = 0; bool auto_attach = false; + __u32 meta_ifindex = 0; struct bpf_object *obj; struct bpf_map *map; const char *pinfile; unsigned int i, j; - __u32 ifindex = 0; const char *file; int idx, err; @@ -1614,17 +1615,25 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) map_replace[old_map_fds].fd = fd; old_map_fds++; } else if (is_prefix(*argv, "dev")) { + __u32 *cur_ifindex; + NEXT_ARG(); - if (ifindex) { - p_err("offload device already specified"); + if (offload_ifindex || meta_ifindex) { + p_err("device already specified"); goto err_free_reuse_maps; } + if (is_prefix(*argv, "xdpmeta")) { + cur_ifindex = &meta_ifindex; + NEXT_ARG(); + } else { + cur_ifindex = &offload_ifindex; + } if (!REQ_ARGS(1)) goto err_free_reuse_maps; - ifindex = if_nametoindex(*argv); - if (!ifindex) { + *cur_ifindex = if_nametoindex(*argv); + if (!(*cur_ifindex)) { p_err("unrecognized netdevice '%s': %s", *argv, strerror(errno)); goto err_free_reuse_maps; @@ -1671,7 +1680,12 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) goto err_close_obj; } - bpf_program__set_ifindex(pos, ifindex); + if (prog_type == BPF_PROG_TYPE_XDP && meta_ifindex) { + bpf_program__set_flags(pos, BPF_F_XDP_DEV_BOUND_ONLY); + bpf_program__set_ifindex(pos, meta_ifindex); + } else { + bpf_program__set_ifindex(pos, offload_ifindex); + } if (bpf_program__type(pos) != prog_type) bpf_program__set_type(pos, prog_type); bpf_program__set_expected_attach_type(pos, expected_attach_type); @@ -1709,7 +1723,7 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) idx = 0; bpf_object__for_each_map(map, obj) { if (bpf_map__type(map) != BPF_MAP_TYPE_PERF_EVENT_ARRAY) - bpf_map__set_ifindex(map, ifindex); + bpf_map__set_ifindex(map, offload_ifindex); if (j < old_map_fds && idx == map_replace[j].idx) { err = bpf_map__reuse_fd(map, map_replace[j++].fd); -- 2.35.3