rust: pci: impl Send + Sync for pci::Device
Subsystems (4)
Danilo Krummrich
maintainerPATCH 1/2 rust: pci: impl Send + Sync for pci::Device
Commit 7b948a2af6b5 ("rust: pci: fix unrestricted &mut pci::Device") changed the definition of pci::Device and discarded the implicitly derived Send and Sync traits.
This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
--- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+)
rust/kernel/pci.rs +7 -0
@@ -465,3 +465,10 @@ fn as_ref(&self) -> &device::Device {unsafe { device::Device ::as_ref (dev) } } } + +// SAFETY: A `Device` is always reference-counted and can be released from any thread. +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 {}
base-commit: 4d320e30ee04c25c660eca2bb33e846ebb71a79a
Signature · 1 line
2.48.1
Danilo Krummrich
maintainerPATCH 2/2 rust: platform: impl Send + Sync for platform::Device
Commit 4d320e30ee04 ("rust: platform: fix unrestricted &mut platform::Device") changed the definition of platform::Device and discarded the implicitly derived Send and Sync traits.
This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
--- rust/kernel/platform.rs | 7 +++++++ 1 file changed, 7 insertions(+)
rust/kernel/platform.rs +7 -0
@@ -233,3 +233,10 @@ fn as_ref(&self) -> &device::Device {unsafe { device::Device ::as_ref (dev) } } } + +// SAFETY: A `Device` is always reference-counted and can be released from any thread. +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 {}
Signature · 1 line
2.48.1
Re: [PATCH 2/2] rust: platform: impl Send + Sync for platform::Device
Quoted 18 lines · Danilo Krummrich
Commit
4d320e30ee04("rust: platform: fix unrestricted &mutplatform::Device") changed the definition ofplatform::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Signed-off-by Danilo Krummrich <[email protected]>--- rust/kernel/platform.rs | 7 +++++++ 1 file changed, 7 insertions(+)rust/kernel/platform.rs +0
-0
rust/kernel/platform.rs fn as_ref(&self) -> &device::Device { · line 242
Quoted 10 lines
rust/kernel/platform.rs +7
-0@@ -233,3 +233,10 @@ fn as_ref(&self) -> &device::Device {unsafe { device::Device ::as_ref (dev) } } } + +// SAFETY: A `Device` is always reference-counted and can be released from any thread. +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 {}
Same as for 1/2:
# git am --show-current-patch=diff | patch -p1 patching file rust/kernel/platform.rs Hunk #1 succeeded at 198 with fuzz 1 (offset -35 lines).
Best regards,
Andreas Hindborg
Re: [PATCH 2/2] rust: platform: impl Send + Sync for platform::Device
In reply to Danilo KrummrichQuoted 9 lines · Danilo Krummrich
Commit
4d320e30ee04("rust: platform: fix unrestricted &mutplatform::Device") changed the definition ofplatform::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Signed-off-by Danilo Krummrich <[email protected]>
Quoted 29 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Signed-off-by Danilo Krummrich <[email protected]>--- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+)rust/kernel/pci.rs +7
-0@@ -465,3 +465,10 @@ fn as_ref(&self) -> &device::Device {unsafe { device::Device ::as_ref (dev) } } } + +// SAFETY: A `Device` is always reference-counted and can be released from any thread. +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 {}
Quoted 1 line
base-commit:
4d320e30ee04c25c660eca2bb33e846ebb71a79a
I can't find the base-commit and the patch does not apply clean on v6.14-rc7:
patching file rust/kernel/pci.rs
Hunk #1 succeeded at 432 with fuzz 1 (offset -33 lines).
Otherwise looks good. You might want to rebase?
Best regards,
Andreas Hindborg
Danilo Krummrich
maintainerQuoted 31 lines · Andreas Hindborg
Quoted 29 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Signed-off-by Danilo Krummrich <[email protected]>--- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+)rust/kernel/pci.rs +7
-0@@ -465,3 +465,10 @@ fn as_ref(&self) -> &device::Device {unsafe { device::Device ::as_ref (dev) } } } + +// SAFETY: A `Device` is always reference-counted and can be released from any thread. +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 {}
Quoted 8 lines
Quoted 1 line
base-commit:
4d320e30ee04c25c660eca2bb33e846ebb71a79aI can't find the base-commit and the patch does not apply clean on v6.14-rc7:
patching file
rust/kernel/pci.rs
Hunk #1 succeeded at 432 with fuzz 1 (offset -33 lines).Otherwise looks good. You might want to rebase?
This is intentional, the base commit is from the driver-core tree, where also commit 7b948a2af6b5 ("rust: pci: fix unrestricted &mut pci::Device") landed.
Quoted 7 lines
Reviewed-by Andreas Hindborg <[email protected]>Best regards,
Andreas Hindborg
Quoted 9 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Signed-off-by Danilo Krummrich <[email protected]>
I have a question related to this ... does the Driver trait need to require T: Send?
The change itself LGTM, so:
Alice
Danilo Krummrich
maintainerQuoted 5 lines · Alice Ryhl
Quoted 4 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.
Quoted 8 lines
Quoted 5 lines
This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Signed-off-by Danilo Krummrich <[email protected]>I have a question related to this ... does the Driver trait need to require T: Send?
The driver trait does not have a generic, it doesn't need one. But I think I still get what you're asking.
The driver trait never owns a shared reference of the device, it only ever gives out a reference that the driver core guarantees to be valid.
Quoted 5 lines
The change itself LGTM, so:
Reviewed-by Alice Ryhl <[email protected]>Alice
Alice Ryhl
reviewerQuoted 10 lines · Danilo Krummrich
Quoted 9 lines · Alice Ryhl
Quoted 8 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Danilo Krummrich <[email protected]>I have a question related to this ... does the Driver trait need to require T: Send?
The driver trait does not have a generic, it doesn't need one. But I think I still get what you're asking.
Right I mean, should it be:
trait Driver: Send + Sync {
...
}Quoted 8 lines
The driver trait never owns a shared reference of the device, it only ever gives out a reference that the driver core guarantees to be valid.
Quoted 5 lines
The change itself LGTM, so:
Reviewed-by Alice Ryhl <[email protected]>Alice
Danilo Krummrich
maintainerQuoted 11 lines · Alice Ryhl
Quoted 10 lines · Danilo Krummrich
Quoted 9 lines · Alice Ryhl
Quoted 8 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Danilo Krummrich <[email protected]>I have a question related to this ... does the Driver trait need to require T: Send?
The driver trait does not have a generic, it doesn't need one. But I think I still get what you're asking.
Turns out I did not. :)
Quoted 5 lines
Right I mean, should it be:
trait Driver: Send + Sync { ... }
Yes, you're absolutely right with this, thanks for pointing this out.
Quoted 9 lines
Quoted 9 lines
The driver trait never owns a shared reference of the device, it only ever gives out a reference that the driver core guarantees to be valid.
Quoted 5 lines
The change itself LGTM, so:
Reviewed-by Alice Ryhl <[email protected]>Alice
Danilo Krummrich
maintainerQuoted 22 lines · Danilo Krummrich
Quoted 11 lines · Alice Ryhl
Quoted 10 lines · Danilo Krummrich
Quoted 9 lines · Alice Ryhl
Quoted 8 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Danilo Krummrich <[email protected]>I have a question related to this ... does the Driver trait need to require T: Send?
The driver trait does not have a generic, it doesn't need one. But I think I still get what you're asking.
Turns out I did not. :)
Quoted 7 lines
Quoted 5 lines
Right I mean, should it be:
trait Driver: Send + Sync { ... }Yes, you're absolutely right with this, thanks for pointing this out.
Just to clarify, the reason we need Sync is that we want to be able to access the driver's private data from an IRQ handler. Otherwise, we can only ever safely access the driver's private data from bus callbacks, which should be synchronized by the device' mutex.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
The driver trait never owns a shared reference of the device, it only ever gives out a reference that the driver core guarantees to be valid.
Quoted 5 lines
The change itself LGTM, so:
Reviewed-by Alice Ryhl <[email protected]>Alice
Danilo Krummrich
maintainerQuoted 29 lines · Danilo Krummrich
Quoted 28 lines · Danilo Krummrich
Quoted 11 lines · Alice Ryhl
Quoted 10 lines · Danilo Krummrich
Quoted 9 lines · Alice Ryhl
Quoted 8 lines · Danilo Krummrich
Commit
7b948a2af6b5("rust: pci: fix unrestricted &mutpci::Device") changed the definition ofpci::Deviceand discarded the implicitly derived Send and Sync traits.This isn't required by upstream code yet, and hence did not cause any issues. However, it is relied on by upcoming drivers, hence add it back in.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Danilo Krummrich <[email protected]>I have a question related to this ... does the Driver trait need to require T: Send?
The driver trait does not have a generic, it doesn't need one. But I think I still get what you're asking.
Turns out I did not. :)
Quoted 5 lines
Right I mean, should it be:
trait Driver: Send + Sync { ... }
Quoted 6 lines
Quoted 1 line
Yes, you're absolutely right with this, thanks for pointing this out.
Just to clarify, the reason we need Sync is that we want to be able to access the driver's private data from an IRQ handler. Otherwise, we can only ever safely access the driver's private data from bus callbacks, which should be synchronized by the device' mutex.
On the other hand, that's up to the IRQ handler abstraction. So, we really should be good with only requiring Send.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
The driver trait never owns a shared reference of the device, it only ever gives out a reference that the driver core guarantees to be valid.
Quoted 5 lines
The change itself LGTM, so:
Reviewed-by Alice Ryhl <[email protected]>Alice