From: Greg KH <gregkh@linuxfoundation.org>
To: Alice Ryhl <alice@ryhl.io>
Cc: Andrew Lunn <andrew@lunn.ch>, Jakub Kicinski <kuba@kernel.org>,
FUJITA Tomonori <fujita.tomonori@gmail.com>,
netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
aliceryhl@google.com, miguel.ojeda.sandonis@gmail.com
Subject: Re: [PATCH 0/5] Rust abstractions for network device drivers
Date: Sat, 17 Jun 2023 12:15:14 +0200 [thread overview]
Message-ID: <2023061743-reverb-movie-969e@gregkh> (raw)
In-Reply-To: <c1b23f21-d161-6241-26fb-7a2cbc4c059c@ryhl.io>
On Sat, Jun 17, 2023 at 12:08:26PM +0200, Alice Ryhl wrote:
> On 6/16/23 22:04, Andrew Lunn wrote:
> > > Yes, you can certainly put a WARN_ON in the destructor.
> > >
> > > Another possibility is to use a scope to clean up. I don't know anything
> > > about these skb objects are used, but you could have the user define a
> > > "process this socket" function that you pass a pointer to the skb, then make
> > > the return value be something that explains what should be done with the
> > > packet. Since you must return a value of the right type, this forces you to
> > > choose.
> > >
> > > Of course, this requires that the processing of packets can be expressed as
> > > a function call, where it only inspects the packet for the duration of that
> > > function call. (Lifetimes can ensure that the skb pointer does not escape
> > > the function.)
> > >
> > > Would something like that work?
> >
> > I don't think so, at least not in the contest of an Rust Ethernet
> > driver.
> >
> > There are two main flows.
> >
> > A packet is received. An skb is allocated and the received packet is
> > placed into the skb. The Ethernet driver then hands the packet over to
> > the network stack. The network stack is free to do whatever it wants
> > with the packet. Things can go wrong within the driver, so at times it
> > needs to free the skb rather than pass it to the network stack, which
> > would be a drop.
> >
> > The second flow is that the network stack has a packet it wants sent
> > out an Ethernet port, in the form of an skb. The skb gets passed to
> > the Ethernet driver. The driver will do whatever it needs to do to
> > pass the contents of the skb to the hardware. Once the hardware has
> > it, the driver frees the skb. Again, things can go wrong and it needs
> > to free the skb without sending it, which is a drop.
> >
> > So the lifetime is not a simple function call.
> >
> > The drop reason indicates why the packet was dropped. It should give
> > some indication of what problem occurred which caused the drop. So
> > ideally we don't want an anonymous drop. The C code does not enforce
> > that, but it would be nice if the rust wrapper to dispose of an skb
> > did enforce it.
>
> It sounds like a destructor with WARN_ON is the best approach right now.
Note, if that WARN_ON fires, you just rebooted the machine as the huge
majority of all Linux systems in the world run with "panic on warn"
enabled :(
So almost NEVER do a WARN* call if at all possible, unless there is no
way back, and you can not recover from the mess, and crashing the system
is your only recourse (instead of locking it up.)
So please, don't do that, recover and report an error to the caller if
possible and let them handle it properly. Yes, in a descructor that's
almost impossible, but then perhaps if this is a real problem, something
needs to be changed somewhere else in the callpath.
thanks,
greg k-h
next prev parent reply other threads:[~2023-06-17 10:15 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 4:53 [PATCH 0/5] Rust abstractions for network device drivers FUJITA Tomonori
2023-06-13 4:53 ` [PATCH 1/5] rust: core " FUJITA Tomonori
2023-06-15 13:01 ` Benno Lossin
2023-06-21 13:13 ` FUJITA Tomonori
2023-06-25 9:52 ` Benno Lossin
2023-06-25 14:27 ` FUJITA Tomonori
2023-06-25 17:06 ` Benno Lossin
2023-06-21 22:44 ` Boqun Feng
2023-06-22 0:19 ` FUJITA Tomonori
2023-06-13 4:53 ` [PATCH 2/5] rust: add support for ethernet operations FUJITA Tomonori
2023-06-13 7:19 ` Ariel Miculas
2023-06-15 13:03 ` Benno Lossin
2023-06-15 13:44 ` Andrew Lunn
2023-06-13 4:53 ` [PATCH 3/5] rust: add support for get_stats64 in struct net_device_ops FUJITA Tomonori
2023-06-13 4:53 ` [PATCH 4/5] rust: add methods for configure net_device FUJITA Tomonori
2023-06-15 13:06 ` Benno Lossin
2023-06-13 4:53 ` [PATCH 5/5] samples: rust: add dummy network driver FUJITA Tomonori
2023-06-15 13:08 ` Benno Lossin
2023-06-22 0:23 ` FUJITA Tomonori
2023-06-15 6:01 ` [PATCH 0/5] Rust abstractions for network device drivers Jakub Kicinski
2023-06-15 8:58 ` Miguel Ojeda
2023-06-16 2:19 ` Jakub Kicinski
2023-06-16 12:18 ` FUJITA Tomonori
2023-06-16 13:23 ` Miguel Ojeda
2023-06-16 13:41 ` FUJITA Tomonori
2023-06-16 18:26 ` Jakub Kicinski
2023-06-16 20:05 ` Miguel Ojeda
2023-06-16 13:04 ` Andrew Lunn
2023-06-16 18:31 ` Jakub Kicinski
2023-06-16 13:18 ` Miguel Ojeda
2023-06-15 12:51 ` Andrew Lunn
2023-06-16 2:02 ` Jakub Kicinski
2023-06-16 3:47 ` Richard Cochran
2023-06-16 17:59 ` Andrew Lunn
2023-06-16 13:02 ` FUJITA Tomonori
2023-06-16 13:14 ` Andrew Lunn
2023-06-16 13:48 ` Miguel Ojeda
2023-06-16 14:43 ` Andrew Lunn
2023-06-16 16:01 ` Miguel Ojeda
2023-06-19 11:27 ` Emilio Cobos Álvarez
2023-06-20 18:09 ` Miguel Ojeda
2023-06-20 19:12 ` Andreas Hindborg (Samsung)
2023-06-21 12:30 ` Andreas Hindborg (Samsung)
2023-06-16 18:40 ` Jakub Kicinski
2023-06-16 19:00 ` Alice Ryhl
2023-06-16 19:10 ` Jakub Kicinski
2023-06-16 19:23 ` Alice Ryhl
2023-06-16 20:04 ` Andrew Lunn
2023-06-17 10:08 ` Alice Ryhl
2023-06-17 10:15 ` Greg KH [this message]
2023-06-19 8:50 ` FUJITA Tomonori
2023-06-19 9:46 ` Greg KH
2023-06-19 11:05 ` FUJITA Tomonori
2023-06-19 11:14 ` Greg KH
2023-06-19 13:20 ` Andrew Lunn
2023-06-20 11:16 ` David Laight
2023-06-20 15:47 ` Jakub Kicinski
2023-06-20 16:56 ` Alice Ryhl
2023-06-20 17:44 ` Miguel Ojeda
2023-06-20 17:55 ` Miguel Ojeda
2023-06-16 12:28 ` Alice Ryhl
2023-06-16 13:20 ` Andrew Lunn
2023-06-16 13:24 ` Alice Ryhl
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=2023061743-reverb-movie-969e@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=alice@ryhl.io \
--cc=aliceryhl@google.com \
--cc=andrew@lunn.ch \
--cc=fujita.tomonori@gmail.com \
--cc=kuba@kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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).