Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10070142rwr; Fri, 12 May 2023 03:26:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bhYiPNniN16qbZjSjN6yfkUg9hM4ItXLGoZp8iyTcyUi4kW8NItCBxyn2ISWTFiM1/qp8 X-Received: by 2002:a05:6a00:15c6:b0:635:d9e1:8e1e with SMTP id o6-20020a056a0015c600b00635d9e18e1emr36842717pfu.11.1683887209425; Fri, 12 May 2023 03:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683887209; cv=none; d=google.com; s=arc-20160816; b=K9jUyfDdFAjwiXI8LjK1cg8F7LQPjxEf+x9MIVEJHEj0ubDu2at+WeJFRcPOO0sjza 0/BFXMFolzfION959YRG3Jyk4PQj1BW9/ecAtSBlx1XdT2Tv1wkZFzo64a6y05R8gnSb 1ntbMljNB3r2iJV+UGxUU8gj9eADZGTxHRAYRW2wWoL9/QewQbcwGghnSrucrGJb0VjA OyA1zaVtPMSp2vQJq8E0frfypBc4TfABAi/keQ0DujBC1+gUuTEFsV4k0Ntlf47Ivio9 v0h+Wt3gRW0qIvZQlkrAm2lr5CXWdNIVrXpeg+orzPu116Hfs60UhenZr69NXa2VgmCU MG9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=2+Wf8mVZDbx31shCs97RQqyKh5s1MqwXoRc+dmnhzU4=; b=qGTdx5aOCWAPT7tM6ZtdPyo3EgAqM2Y6zt4eR5KUskRnAyzDi6aLpV7yMOEXrtUf79 BA5vRp5KxmXLr1BqmnAMoFMi490H/gFs60rpD8S5Y5HdVLUxJyP03M5QvX4Sn/Lp6UAc lmxDvWsGWE7xFPFNCxABehw8b4CHkWYluqIO24a+NDqybQuk69ohLZ5HqtjpG3MxVn6F RS2UxDZNs9j1L2vGBOfCWXyWZ8WsziXDdACalIxX1wsoCH6YpXXzWl5BNoIPofI1iQWr Yl7dUPLkTCKJNi91i56hLW0sVGLWpvTf2CIfwS5owtqjmZCc9efO8SUDf1o9GDuvb+1H 47qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent.com header.s=google header.b=Ij9QKWpI; 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=isovalent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i70-20020a638749000000b0051b930ef847si8784536pge.134.2023.05.12.03.26.35; Fri, 12 May 2023 03:26:49 -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=@isovalent.com header.s=google header.b=Ij9QKWpI; 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=isovalent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240460AbjELKXL (ORCPT + 99 others); Fri, 12 May 2023 06:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240652AbjELKXI (ORCPT ); Fri, 12 May 2023 06:23:08 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 320BB83DC for ; Fri, 12 May 2023 03:23:03 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3063433fa66so6355281f8f.3 for ; Fri, 12 May 2023 03:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1683886981; x=1686478981; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2+Wf8mVZDbx31shCs97RQqyKh5s1MqwXoRc+dmnhzU4=; b=Ij9QKWpIoMZsXOQZ5zF+5uXiCfMBJ1ntLurb/gL5AOk3hPXrAjZOLK/aOnzYMkhpN0 mkHUUoUPwadC8WJE+yBPzRFO1HynAAwLHK6+RkXi/KlsDXq8STd54YL89WXRUSOafSa0 LbXzOe6Kj2bCrZRYNuj+gfFOsDl27rNLmIDAUTCIIL32qNe8aBu/CSVP0FffwVRXUk/n gXyXiq91G6P11C73oEp2Wz9X5vYuc+/zv0FFq23ah1VS928QgBnityP3Cl7gBEsEEFyN js7o3eNeAGRZOMMSyBGdiE5Y6PKoKKI9HTcZxgU7zz/KGa1pmzgJFWE9tZ4pXo/R2s2d 9c2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683886981; x=1686478981; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2+Wf8mVZDbx31shCs97RQqyKh5s1MqwXoRc+dmnhzU4=; b=XD2vseuwtUn5nS7hNdS7T6wEpTH3L1Q0HOM0aHjFgRWqmAZ1vp3cBWV/eoYYOxoFGJ ln9N7iEZ/UFkLLyl7EMyZdom9s51XzZebTHtwIMteofRk0hM8bbQ2KieCyfXTKvjGuKx p8H1xxuAeF0f83REtqvgBm866AlePHiSAuBROkLW7jqcFJhUvdSMf945RS1cobEMCRoZ 85O7NtMcDrjBZE1nhkIb6ZG2GkViRQ20a14QLH3xe+QW5oeVq8jJjOlsgrDji8HsYL/b +58QDFsVaKvVtihFOCywuWe4KTEn8MpXV47rQEef2fqETSbNOqts335xmxUsylEk2XK9 P8cQ== X-Gm-Message-State: AC+VfDzAMAGFlzWmspppKj/2Ar4B/kAb2b69dQozQ7kj36eyoDgKGrTk Yc1izNJslVTUD6bo0eB+cn5E4w== X-Received: by 2002:adf:dbc8:0:b0:307:8b3e:2858 with SMTP id e8-20020adfdbc8000000b003078b3e2858mr13745375wrj.45.1683886981570; Fri, 12 May 2023 03:23:01 -0700 (PDT) Received: from ?IPV6:2a02:8011:e80c:0:a162:20e4:626a:dd? ([2a02:8011:e80c:0:a162:20e4:626a:dd]) by smtp.gmail.com with ESMTPSA id k9-20020a05600c1c8900b003f4283f5c1bsm16930478wms.2.2023.05.12.03.23.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 May 2023 03:23:01 -0700 (PDT) Message-ID: Date: Fri, 12 May 2023 11:23:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH bpf-next] bpftool: specify XDP Hints ifname when loading program Content-Language: en-GB To: Larysa Zaremba Cc: 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, =?UTF-8?Q?Niklas_S=c3=b6derlund?= References: <20230511151345.7529-1-larysa.zaremba@intel.com> From: Quentin Monnet In-Reply-To: <20230511151345.7529-1-larysa.zaremba@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 2023-05-11 17:13 UTC+0200 ~ Larysa Zaremba > Add ability to specify a network interface used to resolve > XDP Hints kfuncs when loading program through bpftool. > > Usage: > bpftool prog load dev xdpmeta Thanks for this patch! Regarding the command-line syntax, I'm not a big fan of the optional sub-keyword for the device for XDP hints. I must admit I had not anticipated other another use for the "dev" keyword. Instead, have you considered one of the following: 1) Adding a different keyword ("xdpmeta_dev"?) and making it incompatible with "dev" 2) Another alternative would be adding a sub-keyword for offload too: bpftool p l [...] dev <[offload | xdpmeta ]> If the ifname is provided with no sub-keyword, we would consider it for offload for legacy support, possibly warn that the syntax is deprecated. What do you think? > > 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"); I'd add a note to tell somehow that offload and XDP hints are mutually exclusive. I suspect not all users understand these well. > 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); Could you please also update the following items: - The usage message for "bpftool prog load" near the end of prog.c - The related doc in Documentation/bpftool-prog.rst (command summary near the top, and detailed description later in the doc) - Bash completion (for keyword "dev", look for "_sysfs_get_netdevs" in bash-completion/bpftool). I'm happy to help with this one if necessary. Thanks, Quentin