Re: [PATCH 06/24] rust: pci: implement Sync for Device<Bound>

From: Gary Guo

Date: Mon Apr 27 2026 - 19:53:17 EST


On Mon Apr 27, 2026 at 11:11 PM BST, Danilo Krummrich wrote:
> Implement Sync for Device<Bound> in addition to Device<Normal>. The
> underlying struct pci_dev is the same; Bound is a zero-sized type-state
> marker that does not affect thread safety.
>
> This is needed for pci::Bar to hold &'a Device<Bound> (required for
> Bar::into_devres()) while remaining Send.
>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> rust/kernel/pci.rs | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index fe5148f41d8b..6f82f2e6c74f 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -526,3 +526,7 @@ unsafe impl Send for Device {}
> // SAFETY: `Device` can be shared among threads because all methods of `Device`
> // (i.e. `Device<Normal>) are thread safe.
> unsafe impl Sync for Device {}
> +
> +// SAFETY: Same as `Device<Normal>` -- the underlying `struct pci_dev` is the same;
> +// `Bound` is a zero-sized type-state marker that does not affect thread safety.
> +unsafe impl Sync for Device<device::Bound> {}

Given that you're now implementing for two ctx marker types, it might worth changing
the existing one to spell out the `Normal` explicitly (also saves you from
having to spell it out in the comment).

It might also make sense to write a comment to say that why it's not the case
for `Device<Core>`.

Best,
Gary