Re: [TECH TOPIC] Rust for Linux

Greg KH
2021-07-08T18:44:13Z

On Thu, Jul 08, 2021 at 08:00:15PM +0200, Miguel Ojeda wrote:
> On Thu, Jul 8, 2021 at 4:58 PM Greg KH <greg@kroah.com> wrote:
> >
> > Ok, great, then how would you handle the kref issue where you need an
> > external lock to properly handle the reference counting logic in Rust?
> > Why is C so "bad" here that we require a lock but Rust would not?
>
> That's the thing: neither C nor Rust need a lock to handle the
> refcount itself, i.e. `kref` does not contain a lock, neither `Ref<T>`
> does.

kref does not contain the lock, but you need to use a lock lots of time
when dealing with them. See my response to Andy for why.

> A lock is needed when you actually interact with the contents that are
> refcounted (see my previous message about `Ref<T>`) -- and this
> applies the same way to Rust and C.
>
> What Rust is buying is, though, and this is the critical point, is
> that we cannot make a mistake forgetting that we need to have some
> form of lock to concurrently mutate things nor forgetting we need to
> actually lock it.
>
> Thus, in a way, you could think that the rules in `Doc/kref.txt` would
> be now enforced statically -- that is the difference.

Ok, fair enough, thanks.

greg k-h