mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikita Danilov <nikita@clusterfs.com>
To: Paul Jackson <pj@sgi.com>
Cc: Linus Torvalds <torvalds@osdl.org>,
	Simon Derr <Simon.Derr@bull.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpuset semaphore depth check deadlock fix
Date: Sat, 10 Sep 2005 11:27:30 +0400	[thread overview]
Message-ID: <17186.35554.43089.674075@gargle.gargle.HOWL> (raw)
In-Reply-To: <20050909220116.26993.9674.sendpatchset@jackhammer.engr.sgi.com>

Paul Jackson writes:
 > The cpusets-formalize-intermediate-gfp_kernel-containment patch
 > has a deadlock problem.

[...]

 >  
 >  /*
 > + * The global cpuset semaphore cpuset_sem can be needed by the
 > + * memory allocator to update a tasks mems_allowed (see the calls
 > + * to cpuset_update_current_mems_allowed()) or to walk up the
 > + * cpuset hierarchy to find a mem_exclusive cpuset see the calls
 > + * to cpuset_excl_nodes_overlap()).
 > + *
 > + * But if the memory allocation is being done by cpuset.c code, it
 > + * usually already holds cpuset_sem.  Double tripping on a kernel
 > + * semaphore deadlocks the current task, and any other task that
 > + * subsequently tries to obtain the lock.
 > + *
 > + * Run all up's and down's on cpuset_sem through the following
 > + * wrappers, which will detect this nested locking, and avoid
 > + * deadlocking.
 > + */
 > +
 > +static inline void cs_down(struct semaphore *psem)
 > +{
 > +	if (current->cpuset_sem_nest_depth == 0)
 > +		down(psem);
 > +	current->cpuset_sem_nest_depth++;
 > +}
 > +
 > +static inline void cs_up(struct semaphore *psem)
 > +{
 > +	current->cpuset_sem_nest_depth--;
 > +	if (current->cpuset_sem_nest_depth == 0)
 > +		up(psem);
 > +}

I am somewhat concerned that new fields are added to the struct
task_struct all the time: it's already over 1.3KB.

In that particular case, it seems that cs_{up,down}() (or however they
end up being named), are used only on &cpuset_sem, and adding new field
to the thread struct can be avoided by doing:

static DECLARE_MUTEX(cpuset_sem);
static struct task_struct *cpuset_sem_owner = NULL;
static int cpuset_sem_depth = 0;

static void cpusets_lock(void)
{
	if (cpuset_sem_owner != current) {
		down(&cpuset_sem);
		cpuset_sem_owner = current;
	}
	cpuset_sem_depth ++;
}

static void cpusets_unlock(void)
{
	if (-- cpuset_sem_depth == 0) {
		cpuset_sem_owner = NULL;
		up(&cpuset_sem);
	}
}

Nikita.

  parent reply	other threads:[~2005-09-10  7:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-09 22:01 Paul Jackson
2005-09-09 22:15 ` Linus Torvalds
2005-09-09 23:35   ` Paul Jackson
2005-09-10  7:27 ` Nikita Danilov [this message]
2005-09-12  9:47   ` Paul Jackson
2005-09-12  9:54     ` Paul Jackson

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=17186.35554.43089.674075@gargle.gargle.HOWL \
    --to=nikita@clusterfs.com \
    --cc=Simon.Derr@bull.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pj@sgi.com \
    --cc=torvalds@osdl.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

all inboxes | Powered by JetHome®