All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: david@redhat.com, patches@lists.linux.dev,
	linux-modules@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, pmladek@suse.com,
	petr.pavlu@suse.com, prarit@redhat.com,
	torvalds@linux-foundation.org, gregkh@linuxfoundation.org,
	rafael@kernel.org, christophe.leroy@csgroup.eu,
	tglx@linutronix.de, peterz@infradead.org, song@kernel.org,
	rppt@kernel.org, dave@stgolabs.net, vbabka@suse.cz,
	mhocko@suse.com, dave.hansen@linux.intel.com,
	colin.i.king@gmail.com, jim.cromie@gmail.com,
	catalin.marinas@arm.com, jbaron@akamai.com,
	rick.p.edgecombe@intel.com
Subject: Re: [PATCH v2 1/2] Change DEFINE_SEMAPHORE() to take a number argument
Date: Fri, 7 Apr 2023 21:36:30 +0100	[thread overview]
Message-ID: <ZDB+zn3X4sac9DFU@casper.infradead.org> (raw)
In-Reply-To: <20230405203505.1343562-2-mcgrof@kernel.org>

On Wed, Apr 05, 2023 at 01:35:04PM -0700, Luis Chamberlain wrote:
> diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
> index 6694d0019a68..2d6aa3fd7861 100644
> --- a/include/linux/semaphore.h
> +++ b/include/linux/semaphore.h
> @@ -25,8 +25,15 @@ struct semaphore {
>  	.wait_list	= LIST_HEAD_INIT((name).wait_list),		\
>  }
>  
> -#define DEFINE_SEMAPHORE(name)	\
> -	struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
> +/*
> + * There is a big difference between a binary semaphore and a mutex.
> + * You cannot call mutex_unlock() from IRQ context because it takes an
> + * internal mutex spin_lock in a non-IRQ-safe manner. Both try_lock()
> + * and unlock() can be called from IRQ context. A mutex must also be
> + * released in the same context that locked it.
> + */

I think this confuses cause and effect.  How about this:

/*
 * Binary semaphores and mutexes differ in that mutexes have an owner
 * so they cannot be used from interrupt context and cannot be passed
 * from one thread to another.  down_trylock() and up() can be called
 * from interrupt context.
 */

Or this:

/*
 * Unlike mutexes, binary semaphores do not have an owner, so up() can
 * be called in a different thread from the one which called down().
 * It is also safe to call down_trylock() and up() from interrupt
 * context.
 */

I'd like to mention completions as an alternative to semaphores, but
can't figure out a nice way to fit that in.

  parent reply	other threads:[~2023-04-07 20:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-05 20:35 [PATCH v2 0/2] kmod: simplify with a semaphore Luis Chamberlain
2023-04-05 20:35 ` [PATCH v2 1/2] Change DEFINE_SEMAPHORE() to take a number argument Luis Chamberlain
2023-04-07 16:38   ` Davidlohr Bueso
2023-04-07 20:36   ` Matthew Wilcox [this message]
2023-04-07 20:52     ` Linus Torvalds
2023-04-12  4:05     ` Luis Chamberlain
2023-04-08  8:22   ` Sergey Senozhatsky
2023-04-05 20:35 ` [PATCH v2 2/2] modules/kmod: replace implementation with a sempahore Luis Chamberlain
2023-04-07 17:19   ` Davidlohr Bueso
2023-04-11  8:42   ` David Hildenbrand
2023-04-13  9:44   ` Miroslav Benes
2023-04-13 16:38     ` Luis Chamberlain

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=ZDB+zn3X4sac9DFU@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=catalin.marinas@arm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=colin.i.king@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave@stgolabs.net \
    --cc=david@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbaron@akamai.com \
    --cc=jim.cromie@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mhocko@suse.com \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=petr.pavlu@suse.com \
    --cc=pmladek@suse.com \
    --cc=prarit@redhat.com \
    --cc=rafael@kernel.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=rppt@kernel.org \
    --cc=song@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.