On 7/10/20 4:49 PM, Andrii Nakryiko wrote:
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 025687120442..a9c634be8dd7 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -8973,6 +8973,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)
> kfree(xdp_link);
> }
>
> +static void bpf_xdp_link_show_fdinfo(const struct bpf_link *link,
> + struct seq_file *seq)
> +{
> + struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link,
> link);
> + u32 ifindex = 0;
> +
> + rtnl_lock();
> + if (xdp_link->dev)
> + ifindex = xdp_link->dev->ifindex;
> + rtnl_unlock();
Patch 2 you set dev but don't hold a refcnt on it which is why you need
the locking here. How do you know that the dev pointer is even valid here?
If xdp_link is going to have dev reference you need to take the refcnt
and you need to handle NETDEV notifications to cleanup the bpf_link when
the device goes away.