rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Sven Van Asbroeck <thesven73@gmail.com>
Cc: Carlos <carloscarral13@gmail.com>, rust-for-linux@vger.kernel.org
Subject: Re: Exposing semaphores
Date: Tue, 27 Apr 2021 12:58:31 +0200	[thread overview]
Message-ID: <YIfuV+S7Umsuqz9C@kroah.com> (raw)
In-Reply-To: <CAGngYiUMFuzRmjM5__RUTZsp9N63zr+Y6R7kVuMU5BxRS17wcw@mail.gmail.com>

On Tue, Apr 27, 2021 at 06:18:52AM -0400, Sven Van Asbroeck wrote:
> Hi Carlos,
> 
> On Mon, Apr 26, 2021 at 8:02 PM Carlos <carloscarral13@gmail.com> wrote:
> >
> > I recently began assessing what functionality from the kernel is missing
> > for implementing a basic scull driver.
> >
> > Semaphores are the first missing primitive that caught my attention, and
> > being such an important part of the kernel itself, I will make exposing
> > this functionality my first priority instead.
> 
> Isn't scull's semaphore used exclusively in mutex mode, i.e.
> initialized using init_MUTEX?
> 
> If so, prefer "struct mutex" instead. At the time scull was written
> (over 15 years ago) it did not yet exist.
> A Rust-for-Linux abstraction is already available:
> https://github.com/Rust-for-Linux/linux/blob/rust/rust/kernel/sync/mutex.rs
> 
> This is before my time, but I believe that the use of "bare" struct
> semaphores in drivers used to be a common anti-pattern, often
> resulting in buggy code and/or performance issues - most semaphores
> have been replaced by conceptually safer, higher-level primitives, and
> today one needs a valid excuse to use them in new or even refactored
> driver code. But I do not know the full story.

I agree, never try to ab-use a semaphore in the way we did it in the
book, that is not a good "pattern" to follow for the majority of kernel
drivers.

A simple mutex should be all that is necessary.

But also, while the CUSE driver has a lot of history, it really was only
created as an example to show how things could work, it isn't all that
useful in the real world :)

thanks,

greg k-h

      reply	other threads:[~2021-04-27 10:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27  0:02 Exposing semaphores Carlos
2021-04-27  0:08 ` Alex Gaynor
2021-04-27  0:12 ` Wedson Almeida Filho
2021-04-27  1:43   ` Samantha Miller
2021-04-27 11:00   ` Sven Van Asbroeck
2021-04-27 10:18 ` Sven Van Asbroeck
2021-04-27 10:58   ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YIfuV+S7Umsuqz9C@kroah.com \
    --to=greg@kroah.com \
    --cc=carloscarral13@gmail.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=thesven73@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).