netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Stanislav Fomichev <sdf@google.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com,
	jolsa@kernel.org, netdev@vger.kernel.org
Subject: Re: [RFC bpf-next 3/7] bpf: implement devtx hook points
Date: Thu, 15 Jun 2023 22:46:57 -0700	[thread overview]
Message-ID: <1fb38d17-619d-4cd9-30e4-624d2ee21a2b@gmail.com> (raw)
In-Reply-To: <20230612172307.3923165-4-sdf@google.com>



On 6/12/23 10:23, Stanislav Fomichev wrote:
..... cut .....
> +
> +__diag_push();
> +__diag_ignore_all("-Wmissing-prototypes",
> +		  "Global functions as their definitions will be in vmlinux BTF");
> +
> +/**
> + * bpf_devtx_sb_attach - Attach devtx 'packet submit' program
> + * @ifindex: netdev interface index.
> + * @prog_fd: BPF program file descriptor.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + */
> +__bpf_kfunc int bpf_devtx_sb_attach(int ifindex, int prog_fd)
> +{
> +	struct net_device *netdev;
> +	int ret;
> +
> +	netdev = dev_get_by_index(current->nsproxy->net_ns, ifindex);
> +	if (!netdev)
> +		return -EINVAL;
> +
> +	mutex_lock(&devtx_attach_lock);
> +	ret = __bpf_devtx_attach(netdev, prog_fd, "devtx_sb", &netdev->devtx_sb);
> +	mutex_unlock(&devtx_attach_lock);
> +
> +	dev_put(netdev);
> +
> +	return ret;
> +}

How about adding another detach kfunc instead of overloading
this one? It is easier to understand.

> +
> +/**
> + * bpf_devtx_cp_attach - Attach devtx 'packet complete' program
> + * @ifindex: netdev interface index.
> + * @prog_fd: BPF program file descriptor.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + */
> +__bpf_kfunc int bpf_devtx_cp_attach(int ifindex, int prog_fd)
> +{
> +	struct net_device *netdev;
> +	int ret;
> +
> +	netdev = dev_get_by_index(current->nsproxy->net_ns, ifindex);
> +	if (!netdev)
> +		return -EINVAL;
> +
> +	mutex_lock(&devtx_attach_lock);
> +	ret = __bpf_devtx_attach(netdev, prog_fd, "devtx_cp", &netdev->devtx_cp);
> +	mutex_unlock(&devtx_attach_lock);
> +
> +	dev_put(netdev);
> +
> +	return ret;
> +}
> +
> +__diag_pop();
> +
> +bool is_devtx_kfunc(u32 kfunc_id)
> +{
> +	return !!btf_id_set8_contains(&bpf_devtx_hook_ids, kfunc_id);
> +}
> +
> +void devtx_shutdown(struct net_device *netdev)
> +{
> +	mutex_lock(&devtx_attach_lock);
> +	__bpf_devtx_detach(netdev, &netdev->devtx_sb);
> +	__bpf_devtx_detach(netdev, &netdev->devtx_cp);
> +	mutex_unlock(&devtx_attach_lock);
> +}
> +
> +BTF_SET8_START(bpf_devtx_syscall_kfunc_ids)
> +BTF_ID_FLAGS(func, bpf_devtx_sb_attach)
> +BTF_ID_FLAGS(func, bpf_devtx_cp_attach)
> +BTF_SET8_END(bpf_devtx_syscall_kfunc_ids)
> +
> +static const struct btf_kfunc_id_set bpf_devtx_syscall_kfunc_set = {
> +	.owner = THIS_MODULE,
> +	.set   = &bpf_devtx_syscall_kfunc_ids,
> +};
> +
> +static int __init devtx_init(void)
> +{
> +	int ret;
> +
> +	ret = register_btf_fmodret_id_set(&bpf_devtx_hook_set);
> +	if (ret) {
> +		pr_warn("failed to register devtx hooks: %d", ret);
> +		return ret;
> +	}
> +
> +	ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &bpf_devtx_syscall_kfunc_set);
> +	if (ret) {
> +		pr_warn("failed to register syscall kfuncs: %d", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +late_initcall(devtx_init);

  parent reply	other threads:[~2023-06-16  5:47 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 17:23 [RFC bpf-next 0/7] bpf: netdev TX metadata Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 1/7] bpf: rename some xdp-metadata functions into dev-bound Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 2/7] bpf: resolve single typedef when walking structs Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 3/7] bpf: implement devtx hook points Stanislav Fomichev
2023-06-13 14:54   ` Willem de Bruijn
2023-06-13 19:00     ` Stanislav Fomichev
2023-06-13 19:29       ` Willem de Bruijn
2023-06-13 15:08   ` Simon Horman
2023-06-13 19:00     ` Stanislav Fomichev
2023-06-14  7:02       ` Simon Horman
2023-06-14 17:18         ` Stanislav Fomichev
2023-06-16  5:46   ` Kui-Feng Lee [this message]
2023-06-16 17:32     ` Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 4/7] bpf: implement devtx timestamp kfunc Stanislav Fomichev
2023-06-13 15:14   ` Simon Horman
2023-06-13 18:39     ` Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 5/7] net: veth: implement devtx timestamp kfuncs Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 6/7] selftests/bpf: extend xdp_metadata with devtx kfuncs Stanislav Fomichev
2023-06-13 14:47   ` Willem de Bruijn
2023-06-13 19:00     ` Stanislav Fomichev
2023-06-12 17:23 ` [RFC bpf-next 7/7] selftests/bpf: extend xdp_hw_metadata " Stanislav Fomichev
2023-06-13 15:03   ` Willem de Bruijn
2023-06-13 19:00     ` Stanislav Fomichev
2023-06-12 21:00 ` [RFC bpf-next 0/7] bpf: netdev TX metadata Toke Høiland-Jørgensen
2023-06-13 16:32   ` Stanislav Fomichev
2023-06-13 17:18     ` Toke Høiland-Jørgensen
2023-06-13 18:39       ` Stanislav Fomichev
2023-06-13 19:10         ` Toke Høiland-Jørgensen
2023-06-13 21:17           ` Stanislav Fomichev
2023-06-13 22:32             ` Alexei Starovoitov
2023-06-13 23:16               ` Stanislav Fomichev
2023-06-14  4:19                 ` Alexei Starovoitov
2023-06-14 11:59                   ` Toke Høiland-Jørgensen
2023-06-14 16:27                     ` Alexei Starovoitov
2023-06-15 12:36                       ` Toke Høiland-Jørgensen
2023-06-15 16:10                         ` Alexei Starovoitov
2023-06-15 16:31                           ` Stanislav Fomichev
2023-06-16  1:50                             ` Jakub Kicinski
2023-06-16  0:09   ` Stanislav Fomichev
2023-06-16  8:12     ` Magnus Karlsson
2023-06-16 17:32       ` Stanislav Fomichev
2023-06-16 23:10         ` Stanislav Fomichev
2023-06-19  7:15           ` Magnus Karlsson
2023-06-14  3:31 ` Jakub Kicinski
2023-06-14  3:54   ` David Ahern
2023-06-14  5:05     ` Jakub Kicinski
2023-06-14 17:17       ` Stanislav Fomichev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1fb38d17-619d-4cd9-30e4-624d2ee21a2b@gmail.com \
    --to=sinquersw@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).