All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@zip.com.au>
To: Jesse Barnes <jbarnes@sgi.com>
Cc: phillips@arcor.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lock assertion macros for 2.5.31
Date: Wed, 21 Aug 2002 11:40:10 -0700	[thread overview]
Message-ID: <3D63DE8A.9F139B42@zip.com.au> (raw)
In-Reply-To: <20020808172335.GA29509@sgi.com> <Pine.LNX.4.44L.0208081435400.2589-100000@duckman.distro.conectiva> <20020808173933.GA29474@sgi.com> <E17czxG-0000e8-00@starship> <20020812210336.GA40112@sgi.com> <3D5829B9.D281B855@zip.com.au> <20020812223645.GB40343@sgi.com> <3D5840E9.89C8680C@zip.com.au> <20020821182627.GA62297@sgi.com>

Jesse Barnes wrote:
> 
> On Mon, Aug 12, 2002 at 04:12:41PM -0700, Andrew Morton wrote:
> > ...
> > #define might_sleep() BUG_ON(preempt_count())
> >
> > _this_ would catch numerous bugs, including code which is not buggy
> > in 2.4, but became buggy when wild-eyed loonies changed core kernel
> > rules without even looking at what drivers were doing (rant).
> >
> > I expect something like this will fall out of the wash soon, at
> > least for preemptible kernels.
> 
> Is it really that simple?

It sure is:

/**
 * in_atomic_region() - determine whether it is legal to perform a context
 *                      switch
 *
 * The in_atomic_region() predicate returns true if the current task is
 * executing atomically, and may not perform a context switch.
 *
 * If preemption is enabled, in_atomic_region() is most accurate, because it
 * returns true if this task has taken any spinlocks.
 *
 * If preemption is disabled then there is no spinlocking record available, and
 * we can only look at the interrupt state.
 *
 * If the task has taken a lock_kernel() then it is still legal to perform a
 * context switch.
 */
#ifdef CONFIG_PREEMPT
#define in_atomic_region() (preempt_count() - !!(current->lock_depth + 1))
#else
#define in_atomic_region() in_interrupt()
#endif

/**
 * may_sleep() - debugging check for possible illegal scheduling.
 *
 * may_sleep() is to be used in code paths which _may_ perform a context switch.
 * It will force a BUG if the caller is executing in an atomic region.
 */
extern void __in_atomic_region(char *file, int line);
#define may_sleep()							\
	do {								\
		if (in_atomic_region())					\
			__in_atomic_region(__FILE__, __LINE__);		\
	} while (0)

>  Maybe it should go into sched.h sometime
> soon?  I guess the real work is sprinkling it in all the places where
> it needs to go.

Well I added checks just to kmalloc, kmem_cache_alloc, __alloc_pages
and saw a shower of bloopers during bootup.  Such as drivers/ide/probe.c:init_irq()
calling request_irq() inside ide_lock.

> Anyway, here's an updated version of the lock assertion patch.

Well I like it.  It's unintrusive, imparts useful info to the reader
and checks stuff at runtime.

>  Should
> it be split into two patches, one that implements the macros and
> another that puts checks everywhere?

I don't think it needs splitting.  You have the core infrastructure plus
a couple of example applications.

>  Should I add a small doc to
> Documentation/ (maybe the might_sleep() could be documented there
> too)?

These things are self-evident and even self-checking.  They don't need
supporting documentation.   I'll put out a test tree RSN, include this
in it.

  reply	other threads:[~2002-08-21 18:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07 20:51 [PATCH] lock assertion macros for 2.5.30 Jesse Barnes
2002-08-07 21:02 ` Rik van Riel
2002-08-07 21:08   ` Jesse Barnes
2002-08-07 21:21     ` Rik van Riel
2002-08-07 21:39       ` Jesse Barnes
2002-08-07 21:44         ` Rik van Riel
2002-08-08  7:58         ` Marcin Dalecki
2002-08-08 11:09           ` Daniel Phillips
2002-08-07 22:15       ` Jesse Barnes
2002-08-07 22:19         ` Rik van Riel
2002-08-08 17:23           ` Jesse Barnes
2002-08-08 17:36             ` Rik van Riel
2002-08-08 17:39               ` Jesse Barnes
2002-08-09  2:56                 ` Daniel Phillips
2002-08-12 21:03                   ` [PATCH] lock assertion macros for 2.5.31 Jesse Barnes
     [not found]                     ` <3D5829B9.D281B855@zip.com.au>
     [not found]                       ` <20020812223645.GB40343@sgi.com>
     [not found]                         ` <3D5840E9.89C8680C@zip.com.au>
2002-08-21 18:26                           ` Jesse Barnes
2002-08-21 18:40                             ` Andrew Morton [this message]
2002-08-21 18:46                               ` Jesse Barnes
2002-08-09  3:04             ` [PATCH] lock assertion macros for 2.5.30 Daniel Phillips
2002-08-09  4:12               ` Bernd Eckenfels
2002-08-07 22:30         ` Daniel Phillips
2002-08-07 22:41           ` Roman Zippel
2002-08-08  0:07           ` Thunder from the hill
2002-08-07 21:37     ` Oliver Xymoron
2002-08-08 12:55       ` Joshua MacDonald
2002-08-08 13:23         ` Jens Axboe
2002-08-08  6:00     ` Jens Axboe
2002-08-08 17:08       ` Jesse Barnes
2002-08-08 17:31         ` Rik van Riel
2002-08-08 17:35           ` Jesse Barnes
2002-08-08 17:43           ` Joshua MacDonald
2002-08-08 17:47             ` Rik van Riel

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=3D63DE8A.9F139B42@zip.com.au \
    --to=akpm@zip.com.au \
    --cc=jbarnes@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillips@arcor.de \
    /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.