public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Roland Dreier <roland@kernel.org>
Cc: Joerg Roedel <joerg.roedel@amd.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-debug: Fix deadlock with netconsole or other drivers that use the DMA API
Date: Thu, 19 Apr 2012 16:50:59 -0700	[thread overview]
Message-ID: <20120419165059.c4ca4e1f.akpm@linux-foundation.org> (raw)
In-Reply-To: <CAL1RGDXQ9NPKaNxBcNAYKknpSSScwXVa+gr8jXOFFU4ZjjSJ=A@mail.gmail.com>

On Thu, 19 Apr 2012 16:36:56 -0700
Roland Dreier <roland@kernel.org> wrote:

> On Thu, Apr 19, 2012 at 11:48 AM, Andrew Morton
> <akpm@linux-foundation.org> wrote:
> > So *any* printk can deadlock if free_entries_lock is held and
> > global_disable==false?
> 
> apparently.
> 
> > In that case we're going to need much sterner fixes. __Any list_head
> > operation can do a printk if list_head debugging is enabled.
> > dma_debug_resize_entries() does a kfree() under free_entries_lock(!).
> >
> > Methinks we need a more general fix?
> 
> sigh... no good deed goes unpunished.
> 
> OK, will look at it.  Just to make things even more fun, all the
> err_printk() stuff can potentially deadlock on the hash bucket
> lock, although that requires enough bad luck a collision to happen.

I suppose one could do something like

static DEFINE_SPINLOCK(lock);
static struct task_struct *owner;
static unsigned depth;

/*
 * Nice comments go here
 */
static unsigned long free_entries_lock(void)
{
	unsigned long flags = 0;

	if (owner == current) {
		depth++;
	} else {
		/* Permit recursive locking */
		spin_lock_irqsave(&lock, flags);
		BUG_ON(depth != 0);
		BUG_ON(owner != NULL);
		owner = current;
	}
	return flags;
}

static void free_entries_unlock(unsigned long flags)
{
	BUG_ON(owner != current);
	if (!--depth) {
		owner = NULL;
		spin_lock_irqrestore(&lock, flags);
	}
}

After removing the bugs, I think that's safe wrt interrupts?

  reply	other threads:[~2012-04-19 23:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-19 18:12 [PATCH] dma-debug: Fix deadlock with netconsole or other drivers that use the DMA API Roland Dreier
2012-04-19 18:48 ` Andrew Morton
2012-04-19 23:36   ` Roland Dreier
2012-04-19 23:50     ` Andrew Morton [this message]
2012-04-20 11:22   ` Joerg Roedel

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=20120419165059.c4ca4e1f.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=joerg.roedel@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@kernel.org \
    /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