[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6d0e13eb-63e0-a777-2a27-7f2e02867a13@linux.dev>
Date: Fri, 2 Dec 2022 11:08:29 -0800
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Eyal Birger <eyal.birger@...il.com>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
steffen.klassert@...unet.com, herbert@...dor.apana.org.au,
andrii@...nel.org, daniel@...earbox.net, nicolas.dichtel@...nd.com,
razor@...ckwall.org, mykolal@...com, ast@...nel.org,
song@...nel.org, yhs@...com, john.fastabend@...il.com,
kpsingh@...nel.org, sdf@...gle.com, haoluo@...gle.com,
jolsa@...nel.org, shuah@...nel.org, liuhangbin@...il.com,
lixiaoyan@...gle.com
Subject: Re: [PATCH bpf-next,v4 2/4] xfrm: interface: Add unstable helpers for
setting/getting XFRM metadata from TC-BPF
On 12/2/22 1:59 AM, Eyal Birger wrote:
> +__used noinline
> +int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx,
> + const struct bpf_xfrm_info *from)
> +{
> + struct sk_buff *skb = (struct sk_buff *)skb_ctx;
> + struct metadata_dst *md_dst;
> + struct xfrm_md_info *info;
> +
> + if (unlikely(skb_metadata_dst(skb)))
> + return -EINVAL;
> +
> + md_dst = this_cpu_ptr(xfrm_md_dst);
> +
> + info = &md_dst->u.xfrm_info;
> +
> + info->if_id = from->if_id;
> + info->link = from->link;
> + skb_dst_force(skb);
> + info->dst_orig = skb_dst(skb);
> +
> + dst_hold((struct dst_entry *)md_dst);
> + skb_dst_set(skb, (struct dst_entry *)md_dst);
I may be missed something obvious and this just came to my mind,
What stops cleanup_xfrm_interface_bpf() being run while skb is still holding the
md_dst?
[ ... ]
> +static const struct btf_kfunc_id_set xfrm_interface_kfunc_set = {
> + .owner = THIS_MODULE,
> + .set = &xfrm_ifc_kfunc_set,
> +};
> +
> +int __init register_xfrm_interface_bpf(void)
> +{
> + int err;
> +
> + xfrm_md_dst = metadata_dst_alloc_percpu(0, METADATA_XFRM,
> + GFP_KERNEL);
> + if (!xfrm_md_dst)
> + return -ENOMEM;
> + err = register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS,
> + &xfrm_interface_kfunc_set);
> + if (err < 0) {
> + metadata_dst_free_percpu(xfrm_md_dst);
> + return err;
> + }
> + return 0;
> +}
> +
> +void cleanup_xfrm_interface_bpf(void)
> +{
> + metadata_dst_free_percpu(xfrm_md_dst);
> +}
Powered by blists - more mailing lists