From: "Daniel Xu" <dxu@dxuuu.xyz>
To: "Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
"Alexander Shalimov" <alex-shalimov@yandex-team.ru>
Cc: "Andrew Lunn" <andrew@lunn.ch>,
"David Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jacob Keller" <jacob.e.keller@intel.com>,
jasowang@redhat.com, "Jakub Kicinski" <kuba@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
"Paolo Abeni" <pabeni@redhat.com>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH] net/tun: expose queue utilization stats via ethtool
Date: Fri, 16 May 2025 13:21:30 -0700 [thread overview]
Message-ID: <81d6fb01-e914-4c04-875a-58e61b433a80@app.fastmail.com> (raw)
In-Reply-To: <68277463d4c43_2ba041294cf@willemb.c.googlers.com.notmuch>
On Fri, May 16, 2025, at 10:22 AM, Willem de Bruijn wrote:
> Daniel Xu wrote:
>> On Thu, May 15, 2025, at 7:12 AM, Willem de Bruijn wrote:
>> > Alexander Shalimov wrote:
>> >> 06.05.2025, 22:32, "Willem de Bruijn" <willemdebruijn.kernel@gmail.com>:
>> >> > Perhaps bpftrace with a kfunc at a suitable function entry point to
>> >> > get access to these ring structures.
>> >>
>> >> Thank you for your responses!
>> >>
>> >> Initially, we implemented such monitoring using bpftrace but we were
>> >> not satisfied with the need to double-check the structure definitions
>> >> in tun.c for each new kernel version.
>> >>
>> >> We attached kprobe to the "tun_net_xmit()" function. This function
>> >> gets a "struct net_device" as an argument, which is then explicitly
>> >> cast to a tun_struct - "struct tun_struct *tun = netdev_priv(dev)".
>> >> However, performing such a cast within bpftrace is difficult because
>> >> tun_struct is defined in tun.c - meaning the structure definition
>> >> cannot be included directly (not a header file). As a result, we were
>> >> forced to add fake "struct tun_struct" and "struct tun_file"
>> >> definitions, whose maintenance across kernel versions became
>> >> cumbersome (see below). The same problems exists even with kfunc and
>> >> btf - we are not able to cast properly netdev to tun_struct.
>> >>
>> >> That’s why we decided to add this functionality directly to the kernel.
>> >
>> > Let's solve this in bpftrace instead. That's no reason to rever to
>> > hardcoded kernel APIs.
>> >
>> > It quite possibly already is. I'm no bpftrace expert. Cc:ing bpf@
>>
>> Yeah, should be possible. You haven't needed to include header
>> files to access type information available in BTF for a while now.
>> This seems to work for me - mind giving this a try?
>>
>> ```
>> fentry:tun:tun_net_xmit {
>> $tun = (struct tun_struct *)args->dev->priv;
>> print($tun->numqueues); // or whatever else you want
>> }
>> ```
>>
>> fentry probes are better in general than kprobes if all you're doing
>> is attaching to the entry of a function.
>>
>> You could do the same with kprobes like this if you really want, though:
>>
>> ```
>> kprobe:tun:tun_net_xmit {
>> $dev = (struct net_device *)arg1;
>> $tun = (struct tun_struct *)$dev->priv;
>> print($tun->numqueues); // or whatever else you want
>> }
>> ```
>>
>> Although it looks like there's a bug when you omit the module name
>> where bpftrace doesn't find the struct definition. I'll look into that.
>
> Minor: unless tun is built-in.
Ah, right.
>
> Thanks a lot for your response, Daniel. Good to know that we can get
> this information without kernel changes. And I learned something new
> :) Replicated your examples.
Nice! Feel free to CC me if you have other stuff in the future.
Bug fix for parsing implicit module BTF up here:
https://github.com/bpftrace/bpftrace/pull/4137
next prev parent reply other threads:[~2025-05-16 20:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 15:41 Alexander Shalimov
2025-05-06 16:07 ` Andrew Lunn
2025-05-06 19:00 ` Jacob Keller
2025-05-06 19:32 ` Willem de Bruijn
2025-05-14 23:39 ` Alexander Shalimov
2025-05-15 14:12 ` Willem de Bruijn
2025-05-16 1:56 ` Daniel Xu
2025-05-16 17:22 ` Willem de Bruijn
2025-05-16 20:21 ` Daniel Xu [this message]
2025-05-22 14:26 ` Alexander Shalimov
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=81d6fb01-e914-4c04-875a-58e61b433a80@app.fastmail.com \
--to=dxu@dxuuu.xyz \
--cc=alex-shalimov@yandex-team.ru \
--cc=andrew@lunn.ch \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemdebruijn.kernel@gmail.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
all inboxes | Powered by JetHome®