Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Require KernelModule to be Sync #54

Merged
merged 3 commits into from
Jun 19, 2018
Merged

Require KernelModule to be Sync #54

merged 3 commits into from
Jun 19, 2018

Conversation

alex
Copy link
Member

@alex alex commented Jun 17, 2018

No description provided.

@alex alex requested a review from geofft June 17, 2018 17:47
@geofft
Copy link
Collaborator

geofft commented Jun 19, 2018

Seems promising that this requires no other changes.

Can you add a comment defending

unsafe impl<T: SysctlStorage> Sync for Sysctl<T> {}

? I think the short argument is that the only public methods are constructor, destructor, and get() which returns an &T and we know T: Sync. (But this is probably worth noting if we decide to add other methods, so maybe also move it right next to the impl.)

@alex alex merged commit 5f2be73 into master Jun 19, 2018
@alex alex deleted the require-sync branch June 19, 2018 23:11
@geofft
Copy link
Collaborator

geofft commented Apr 7, 2019

Since it took me a bit to remember why: a KernelModule is basically a global, since it persists across multiple syscall contexts. Therefore, we don't want anything inside a KernelModule to be data-race-unsafe if accessed simultaneously by multiple (kernel) threads: anything that is !Sync (e.g. raw pointers) needs to either be scoped to the lifetime of a syscall and not shared, or needs to be put inside some wrapper structure that handles thread safety and adds Sync.

We aren't strictly depending on this property for correctness (i.e., no APIs exposed in this crate directly make a KernelModule accessible) but it helps us validate that individual kernel modules / APIs exposed in this crate aren't putting things in places where they shouldn't be. (For instance, it forced us to reason out that Sysctl: Sync is sound, despite it containing a raw pointer and therefore not automatically deriving Sync.)

@geofft
Copy link
Collaborator

geofft commented May 6, 2019

@jason-ni - I see you dropped this in jason-ni/linux-kernel-module-rust@e7e4044, do you remember why you needed to do that? (The build is fine on master now without dropping it but maybe it was for something local you were working on?)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants