Re: [PATCH] rust: file: handle fd table teardown in file descriptor APIs

From: Georgios Androutsopoulos

Date: Tue Sep 22 2026 - 14:32:38 EST


On Sun, Sep 20, 2026 at 4:48 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
> I think we want to add `unlikely()` on them (which is being added by
> https://lore.kernel.org/rust-for-linux/20260406095820.465994-2-ojeda@xxxxxxxxxx/).

I checked current `linux-next` and `rust-next`, but this does not seem to
have landed yet. Should I leave these as regular checks for now and add a
`TODO:` to use `unlikely()` once it is available?

> I wonder if we should upgrade this to `WARN_ONCE`. As code being executed when
> exiting are cleanup code, for this code path to be hit, it would mean that some
> code is installing FD descriptor while being dropped -- which is likely a bug.
>
> Putting a "BTW, some Rust code is installing a FD when process is exiting" in
> dmesg is not going to be useful to understand what's going on. We'd want a full
> backtrace.

`WARN_ONCE` does not seem to be available on the Rust side yet either.
`warn_on!()` is available on the current base and would give us the
backtrace. Would you prefer using that here for now?

> I think we can remove this warning. Skipping put_unused_fd isn't actually
> leaking anything as the files_struct is cleaned up.

Agreed. I'll treat dropping the reservation after fd table teardown as
normal cleanup, skip `put_unused_fd()`, and document that this can happen.

Best,
George