[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <66dcc87e-e03f-1043-c91d-25d6fa7130a1@ryhl.io>
Date: Fri, 16 Jun 2023 21:00:36 +0200
From: Alice Ryhl <alice@...l.io>
To: Jakub Kicinski <kuba@...nel.org>,
FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: andrew@...n.ch, netdev@...r.kernel.org, rust-for-linux@...r.kernel.org,
aliceryhl@...gle.com, miguel.ojeda.sandonis@...il.com
Subject: Re: [PATCH 0/5] Rust abstractions for network device drivers
On 6/16/23 20:40, Jakub Kicinski wrote:
> On Fri, 16 Jun 2023 22:02:20 +0900 (JST) FUJITA Tomonori wrote:
>>> The skb freeing looks shady from functional perspective.
>>> I'm guessing some form of destructor frees the skb automatically
>>> in xmit handler(?), but (a) no reason support, (b) kfree_skb_reason()
>>> is most certainly not safe to call on all xmit paths...
>>
>> Yeah, I assume that a driver keeps a skb in private data structure
>> (such as tx ring) then removes the skb from it after the completion of
>> tx; automatically the drop() method runs (where we need to free the
>> skb).
>>
>> I thought that calling dev_kfree_skb() is fine but no? We also need
>> something different for drivers that use other ways to free the skb
>> though.
>>
>> I use kfree_skb_reason() because dev_kfree_skb() is a macro so it
>> can't be called directly from Rust. But I should have used
>> dev_kfree_skb() with a helper function.
>
> skbs (generally) can't be freed in an interrupt context.
> dev_kfree_skb_any_reason() is probably the most general implementation.
> But then we also have a set of functions used in known contexts for fast
> object recycling like napi_consume_skb().
> How would complex object destruction rules fit in in the Rust world?
A Rust method can be defined to take the struct "by value", which
consumes the struct and prevents you from using it again. This can let
you provide many different cleanup methods that each clean it up in
different ways.
However, you cannot force the user to use one of those methods. They
always have the option of letting the value go out of scope, which calls
the destructor. And they can do this at any time.
That said, the destructor of the value does not necessarily *have* to
translate to immediately freeing the value. If the value if refcounted,
the destructor could just drop the refcount. It would also be possible
for a destructor to schedule the cleanup operation to a workqueue. Or
you could do something more clever.
Alice
Powered by blists - more mailing lists