From: Peter Zijlstra <peterz@infradead.org>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Petr Mladek <pmladek@suse.com>,
John Ogness <john.ogness@linutronix.de>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
Will Deacon <will.deacon@arm.com>,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH] RFC: console: hack up console_lock more v2
Date: Thu, 9 May 2019 15:05:04 +0200 [thread overview]
Message-ID: <20190509130504.GW2623@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <155739797736.28545.2942646931608459049@skylake-alporthouse-com>
On Thu, May 09, 2019 at 11:32:57AM +0100, Chris Wilson wrote:
> Quoting Daniel Vetter (2019-05-06 08:45:53)
> > +/**
> > + * printk_safe_up - release the semaphore in console_unlock
> > + * @sem: the semaphore to release
> > + *
> > + * Release the semaphore. Unlike mutexes, up() may be called from any
> > + * context and even by tasks which have never called down().
> > + *
> > + * NOTE: This is a special version of up() for console_unlock only. It is only
> > + * safe if there are no killable, interruptible or timing out down() calls.
> > + */
> > +void printk_safe_up(struct semaphore *sem)
> > +{
> > + unsigned long flags;
> > + struct semaphore_waiter *waiter = NULL;
> > +
> > + raw_spin_lock_irqsave(&sem->lock, flags);
> > + if (likely(list_empty(&sem->wait_list))) {
> > + sem->count++;
> > + } else {
> > + waiter = list_first_entry(&sem->wait_list,
> > + struct semaphore_waiter, list);
> > + list_del(&waiter->list);
> > + waiter->up = true;
> > + }
> > + raw_spin_unlock_irqrestore(&sem->lock, flags);
> > +
> > + if (waiter)
> > + wake_up_process(waiter->task);
>
> From comparing against __down_common() there's a risk here that as soon
> as waiter->up == true, the waiter may complete and make the onstack
> struct semaphore_waiter invalid. If you store waiter->task locally under
> the spinlock that problem is resolved.
>
> Then there is the issue of an unprotected dereference of the task in
> wake_up_process() -- I think you can wrap this function with
> rcu_read_lock() to keep that safe, and wake_up_process() should be a
> no-op if it races against process termination.
task_struct is not RCU protected, see task_rcu_dereference() for magic.
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-05-09 13:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 14:16 [PATCH] RFC: console: hack up console_trylock more Daniel Vetter
2019-05-02 15:15 ` ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2019-05-02 15:50 ` ✓ Fi.CI.BAT: success " Patchwork
2019-05-02 20:16 ` ✓ Fi.CI.IGT: " Patchwork
2019-05-03 15:14 ` [PATCH] " Petr Mladek
2019-05-06 7:11 ` Daniel Vetter
2019-05-06 7:48 ` Petr Mladek
2019-05-06 8:40 ` Daniel Vetter
2019-05-06 7:45 ` [PATCH] RFC: console: hack up console_lock more v2 Daniel Vetter
2019-05-06 8:16 ` Petr Mladek
2019-05-06 8:26 ` Petr Mladek
2019-05-06 9:38 ` Daniel Vetter
2019-05-06 11:24 ` Petr Mladek
2019-05-08 8:17 ` [Intel-gfx] " Daniel Vetter
2019-05-09 15:08 ` Petr Mladek
2019-05-06 8:20 ` Petr Mladek
2019-05-09 10:32 ` [Intel-gfx] " Chris Wilson
2019-05-09 13:05 ` Peter Zijlstra [this message]
2019-05-06 8:08 ` ✗ Fi.CI.CHECKPATCH: warning for RFC: console: hack up console_trylock more (rev2) Patchwork
2019-05-06 8:30 ` ✗ Fi.CI.BAT: failure " Patchwork
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=20190509130504.GW2623@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=chris@chris-wilson.co.uk \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=will.deacon@arm.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