From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by mail.toke.dk (Postfix) with ESMTPS id A85709CFC9B for ; Wed, 14 Dec 2022 19:44:04 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=Odil4Kik Received: by mail-pl1-x636.google.com with SMTP id l10so4268423plb.8 for ; Wed, 14 Dec 2022 10:44:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JnOlNEVM5JqV3wE3k9/PzZ4i3lcEcVI0S6phNBabVFY=; b=Odil4KikOc9OuEumEX767aMYDlGJ1NLTUtYpo4AirTQU2qNwPiBvvnNy+s3Uw9xNwb cihb3h8FCw3jpQPWbwvDqQrYpb/QtL4dWRSIZVFfRtexbE9omby/qUHQEvQTIKNd1KyW F5oxZ2ijNhTOjEjBkVCKhQtXS/Gp2+s/iGzaKJhby3xgln9x1kG6b1zaaVeNgT0HI9Qn vANrJgbaPu5uLw+GOhFGlwoWNbegcRDuXhrQWnF0dnsT5Zuth9cUg4k3knWPNVZtxts3 kvoD/6dbi6ljAgm/L3OmZ8p4aGb8/dWRXktkC6b798A27p9CRrFtRRa3o8Btjzl+ZKW4 Bg2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JnOlNEVM5JqV3wE3k9/PzZ4i3lcEcVI0S6phNBabVFY=; b=63r4knPTgYF8tqc1cJ4oxClMMfTR9D3pKJtqtHvChqztdeL4+r3BzuvbisM9O8qYL3 MyUoucGDDPCbnKLu1UW+w0SNyKb5PFhCa2dBm0ezxriwjLc/ehhup4o5GoG5IHHEdCk4 SHSRfE+QAaiXS7KH8bgEqzYFFlbvnht14dDVNT3QfUeGekNyZ/G+/q76h9/2OwdZV0V/ 3hFGQ7U6bNwH14BKv4sqDL+/1Dj6/eSniJndl2ShQW2hC4WjdgkuQoDKdqWpquHdblzv PzKtlihkuOCFUi70gOLsQ2iPiORw14CXK2t1S4iND4p359Ohj7yoFYadNSvotD2G5qNb llSA== X-Gm-Message-State: ANoB5pnvoyrn7yvk9E6ZFejajiJ5yGUq8hY6kUJR/Vsus7sG3Wky3FIG xzN67VXzy5wCN/yNVphCYk0NjpQcOrfp824a7CpJ+A== X-Google-Smtp-Source: AA0mqf63Mmzf5TI9e0MWyXM4Xi/jEwuRunkR35qO/ou1KM7Exy0P82kXP4HHtSiZ8H+zASf+FJ8ZTm88t81z7hHVt84= X-Received: by 2002:a17:902:d711:b0:188:c7b2:2dd with SMTP id w17-20020a170902d71100b00188c7b202ddmr80295252ply.88.1671043442639; Wed, 14 Dec 2022 10:44:02 -0800 (PST) MIME-Version: 1.0 References: <20221213023605.737383-1-sdf@google.com> <20221213023605.737383-6-sdf@google.com> <74e48fc9-8f5d-4183-9f39-c4587c74a74e@linux.dev> In-Reply-To: <74e48fc9-8f5d-4183-9f39-c4587c74a74e@linux.dev> From: Stanislav Fomichev Date: Wed, 14 Dec 2022 10:43:51 -0800 Message-ID: To: Martin KaFai Lau Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: K6OPSYO4M4F2BJ3FACG3X4YOCINDV3CL X-Message-ID-Hash: K6OPSYO4M4F2BJ3FACG3X4YOCINDV3CL X-MailFrom: sdf@google.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: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org, bpf@vger.kernel.org X-Mailman-Version: 3.3.7 Precedence: list Subject: [xdp-hints] Re: [PATCH bpf-next v4 05/15] bpf: XDP metadata RX kfuncs List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, Dec 13, 2022 at 5:54 PM Martin KaFai Lau wrote: > > On 12/12/22 6:35 PM, Stanislav Fomichev wrote: > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index ca22e8b8bd82..de6279725f41 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -2477,6 +2477,8 @@ void bpf_offload_dev_netdev_unregister(struct bpf_offload_dev *offdev, > > struct net_device *netdev); > > bool bpf_offload_dev_match(struct bpf_prog *prog, struct net_device *netdev); > > > > +void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog, u32 func_id); > > + > > This probably requires an inline version for !CONFIG_NET. Yeah, not sure why my confings didn't catch this :-( > > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > > index d434a994ee04..c3e501e3e39c 100644 > > --- a/kernel/bpf/core.c > > +++ b/kernel/bpf/core.c > > @@ -2097,6 +2097,13 @@ bool bpf_prog_map_compatible(struct bpf_map *map, > > if (fp->kprobe_override) > > return false; > > > > + /* When tail-calling from a non-dev-bound program to a dev-bound one, > > + * XDP metadata helpers should be disabled. Until it's implemented, > > + * prohibit adding dev-bound programs to tail-call maps. > > + */ > > + if (bpf_prog_is_dev_bound(fp->aux)) > > + return false; > > + > > spin_lock(&map->owner.lock); > > if (!map->owner.type) { > > /* There's no owner yet where we could check for > > diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c > > index f714c941f8ea..3b6c9023f24d 100644 > > --- a/kernel/bpf/offload.c > > +++ b/kernel/bpf/offload.c > > @@ -757,6 +757,29 @@ void bpf_dev_bound_netdev_unregister(struct net_device *dev) > > up_write(&bpf_devs_lock); > > } > > > > +void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog, u32 func_id) > > +{ > > + const struct xdp_metadata_ops *ops; > > + void *p = NULL; > > + > > + down_read(&bpf_devs_lock); > > + if (!prog->aux->offload || !prog->aux->offload->netdev) > > This happens when netdev is unregistered in the middle of bpf_prog_load and the > bpf_offload_dev_match() will eventually fail during dev_xdp_attach()? A comment > will be useful. Right, that's the expectation - we load/verify the prog but it's essentially un-attach-able. Will try to clarify here. > > + goto out; > > + > > + ops = prog->aux->offload->netdev->xdp_metadata_ops; > > + if (!ops) > > + goto out; > > + > > + if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP)) > > + p = ops->xmo_rx_timestamp; > > + else if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_HASH)) > > + p = ops->xmo_rx_hash; > > +out: > > + up_read(&bpf_devs_lock); > > + > > + return p; > > +} > > + > > static int __init bpf_offload_init(void) > > { > > int err; > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 203d8cfeda70..e61fe0472b9b 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -15479,12 +15479,35 @@ static int fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, > > struct bpf_insn *insn_buf, int insn_idx, int *cnt) > > { > > const struct bpf_kfunc_desc *desc; > > + void *xdp_kfunc; > > > > if (!insn->imm) { > > verbose(env, "invalid kernel function call not eliminated in verifier pass\n"); > > return -EINVAL; > > } > > > > + *cnt = 0; > > + > > + if (xdp_is_metadata_kfunc_id(insn->imm)) { > > + if (!bpf_prog_is_dev_bound(env->prog->aux)) { > > The "xdp_is_metadata_kfunc_id() && (!bpf_prog_is_dev_bound() || > bpf_prog_is_offloaded())" test should have been done much earlier in > add_kfunc_call(). Then the later stage of the verifier does not have to keep > worrying about it like here. > > nit. may be rename xdp_is_metadata_kfunc_id() to bpf_dev_bound_kfunc_id() and > hide the "!bpf_prog_is_dev_bound() || bpf_prog_is_offloaded()" test into > bpf_dev_bound_kfunc_check(&env->log, env->prog). > > The change in fixup_kfunc_call could then become: > > if (bpf_dev_bound_kfunc_id(insn->imm)) { > xdp_kfunc = bpf_dev_bound_resolve_kfunc(env->prog, insn->imm); > /* ... */ > } Makes sense, ty! > > + verbose(env, "metadata kfuncs require device-bound program\n"); > > + return -EINVAL; > > + } > > + > > + if (bpf_prog_is_offloaded(env->prog->aux)) { > > + verbose(env, "metadata kfuncs can't be offloaded\n"); > > + return -EINVAL; > > + } > > + > > + xdp_kfunc = bpf_dev_bound_resolve_kfunc(env->prog, insn->imm); > > + if (xdp_kfunc) { > > + insn->imm = BPF_CALL_IMM(xdp_kfunc); > > + return 0; > > + } > > + > > + /* fallback to default kfunc when not supported by netdev */ > > + } > > + > >