From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Alan Cox <alan@linux.intel.com>,
Florian Tobias Schandinat <FlorianSchandinat@gmx.de>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Jiri Kosina <jkosina@suse.cz>,
Sedat Dilek <sedat.dilek@gmail.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Andrew Morton <akpm@linux-foundation.org>,
Dave Airlie <airlied@redhat.com>
Subject: [ 40/53] fb: rework locking to fix lock ordering on takeover
Date: Tue, 26 Feb 2013 15:58:09 -0800 [thread overview]
Message-ID: <20130226235624.021862294@linuxfoundation.org> (raw)
In-Reply-To: <20130226235619.844721947@linuxfoundation.org>
3.0-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Cox <alan@linux.intel.com>
commit 50e244cc793d511b86adea24972f3a7264cae114 upstream.
Adjust the console layer to allow a take over call where the caller
already holds the locks. Make the fb layer lock in order.
This is partly a band aid, the fb layer is terminally confused about the
locking rules it uses for its notifiers it seems.
[akpm@linux-foundation.org: remove stray non-ascii char, tidy comment]
[akpm@linux-foundation.org: export do_take_over_console()]
[airlied: cleanup another non-ascii char]
Signed-off-by: Alan Cox <alan@linux.intel.com>
Cc: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Jiri Kosina <jkosina@suse.cz>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/tty/vt/vt.c | 93 +++++++++++++++++++++++++++++++-----------
drivers/video/console/fbcon.c | 29 ++++++++++++-
drivers/video/fbmem.c | 5 --
drivers/video/fbsysfs.c | 3 +
include/linux/console.h | 1
5 files changed, 104 insertions(+), 27 deletions(-)
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3016,7 +3016,7 @@ int __init vty_init(const struct file_op
static struct class *vtconsole_class;
-static int bind_con_driver(const struct consw *csw, int first, int last,
+static int do_bind_con_driver(const struct consw *csw, int first, int last,
int deflt)
{
struct module *owner = csw->owner;
@@ -3027,7 +3027,7 @@ static int bind_con_driver(const struct
if (!try_module_get(owner))
return -ENODEV;
- console_lock();
+ WARN_CONSOLE_UNLOCKED();
/* check if driver is registered */
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
@@ -3112,11 +3112,22 @@ static int bind_con_driver(const struct
retval = 0;
err:
- console_unlock();
module_put(owner);
return retval;
};
+
+static int bind_con_driver(const struct consw *csw, int first, int last,
+ int deflt)
+{
+ int ret;
+
+ console_lock();
+ ret = do_bind_con_driver(csw, first, last, deflt);
+ console_unlock();
+ return ret;
+}
+
#ifdef CONFIG_VT_HW_CONSOLE_BINDING
static int con_is_graphics(const struct consw *csw, int first, int last)
{
@@ -3228,9 +3239,9 @@ int unbind_con_driver(const struct consw
if (!con_is_bound(csw))
con_driver->flag &= ~CON_DRIVER_FLAG_INIT;
- console_unlock();
/* ignore return value, binding should not fail */
- bind_con_driver(defcsw, first, last, deflt);
+ do_bind_con_driver(defcsw, first, last, deflt);
+ console_unlock();
err:
module_put(owner);
return retval;
@@ -3508,28 +3519,18 @@ int con_debug_leave(void)
}
EXPORT_SYMBOL_GPL(con_debug_leave);
-/**
- * register_con_driver - register console driver to console layer
- * @csw: console driver
- * @first: the first console to take over, minimum value is 0
- * @last: the last console to take over, maximum value is MAX_NR_CONSOLES -1
- *
- * DESCRIPTION: This function registers a console driver which can later
- * bind to a range of consoles specified by @first and @last. It will
- * also initialize the console driver by calling con_startup().
- */
-int register_con_driver(const struct consw *csw, int first, int last)
+static int do_register_con_driver(const struct consw *csw, int first, int last)
{
struct module *owner = csw->owner;
struct con_driver *con_driver;
const char *desc;
int i, retval = 0;
+ WARN_CONSOLE_UNLOCKED();
+
if (!try_module_get(owner))
return -ENODEV;
- console_lock();
-
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
con_driver = ®istered_con_driver[i];
@@ -3582,10 +3583,29 @@ int register_con_driver(const struct con
}
err:
- console_unlock();
module_put(owner);
return retval;
}
+
+/**
+ * register_con_driver - register console driver to console layer
+ * @csw: console driver
+ * @first: the first console to take over, minimum value is 0
+ * @last: the last console to take over, maximum value is MAX_NR_CONSOLES -1
+ *
+ * DESCRIPTION: This function registers a console driver which can later
+ * bind to a range of consoles specified by @first and @last. It will
+ * also initialize the console driver by calling con_startup().
+ */
+int register_con_driver(const struct consw *csw, int first, int last)
+{
+ int retval;
+
+ console_lock();
+ retval = do_register_con_driver(csw, first, last);
+ console_unlock();
+ return retval;
+}
EXPORT_SYMBOL(register_con_driver);
/**
@@ -3639,17 +3659,44 @@ EXPORT_SYMBOL(unregister_con_driver);
* when a driver wants to take over some existing consoles
* and become default driver for newly opened ones.
*
- * take_over_console is basically a register followed by unbind
+ * take_over_console is basically a register followed by unbind
+ */
+int do_take_over_console(const struct consw *csw, int first, int last, int deflt)
+{
+ int err;
+
+ err = do_register_con_driver(csw, first, last);
+ /*
+ * If we get an busy error we still want to bind the console driver
+ * and return success, as we may have unbound the console driver
+ * but not unregistered it.
+ */
+ if (err == -EBUSY)
+ err = 0;
+ if (!err)
+ do_bind_con_driver(csw, first, last, deflt);
+
+ return err;
+}
+EXPORT_SYMBOL_GPL(do_take_over_console);
+
+/*
+ * If we support more console drivers, this function is used
+ * when a driver wants to take over some existing consoles
+ * and become default driver for newly opened ones.
+ *
+ * take_over_console is basically a register followed by unbind
*/
int take_over_console(const struct consw *csw, int first, int last, int deflt)
{
int err;
err = register_con_driver(csw, first, last);
- /* if we get an busy error we still want to bind the console driver
+ /*
+ * If we get an busy error we still want to bind the console driver
* and return success, as we may have unbound the console driver
- * but not unregistered it.
- */
+ * but not unregistered it.
+ */
if (err == -EBUSY)
err = 0;
if (!err)
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -530,6 +530,33 @@ static int search_for_mapped_con(void)
return retval;
}
+static int do_fbcon_takeover(int show_logo)
+{
+ int err, i;
+
+ if (!num_registered_fb)
+ return -ENODEV;
+
+ if (!show_logo)
+ logo_shown = FBCON_LOGO_DONTSHOW;
+
+ for (i = first_fb_vc; i <= last_fb_vc; i++)
+ con2fb_map[i] = info_idx;
+
+ err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
+ fbcon_is_default);
+
+ if (err) {
+ for (i = first_fb_vc; i <= last_fb_vc; i++)
+ con2fb_map[i] = -1;
+ info_idx = -1;
+ } else {
+ fbcon_has_console_bind = 1;
+ }
+
+ return err;
+}
+
static int fbcon_takeover(int show_logo)
{
int err, i;
@@ -3122,7 +3149,7 @@ static int fbcon_fb_registered(struct fb
}
if (info_idx != -1)
- ret = fbcon_takeover(1);
+ ret = do_fbcon_takeover(1);
} else {
for (i = first_fb_vc; i <= last_fb_vc; i++) {
if (con2fb_map_boot[i] == idx)
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1628,7 +1628,9 @@ static int do_register_framebuffer(struc
event.info = fb_info;
if (!lock_fb_info(fb_info))
return -ENODEV;
+ console_lock();
fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
+ console_unlock();
unlock_fb_info(fb_info);
return 0;
}
@@ -1831,11 +1833,8 @@ int fb_new_modelist(struct fb_info *info
err = 1;
if (!list_empty(&info->modelist)) {
- if (!lock_fb_info(info))
- return -ENODEV;
event.info = info;
err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
- unlock_fb_info(info);
}
return err;
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -175,6 +175,8 @@ static ssize_t store_modes(struct device
if (i * sizeof(struct fb_videomode) != count)
return -EINVAL;
+ if (!lock_fb_info(fb_info))
+ return -ENODEV;
console_lock();
list_splice(&fb_info->modelist, &old_list);
fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
@@ -186,6 +188,7 @@ static ssize_t store_modes(struct device
fb_destroy_modelist(&old_list);
console_unlock();
+ unlock_fb_info(fb_info);
return 0;
}
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -78,6 +78,7 @@ int con_is_bound(const struct consw *csw
int register_con_driver(const struct consw *csw, int first, int last);
int unregister_con_driver(const struct consw *csw);
int take_over_console(const struct consw *sw, int first, int last, int deflt);
+int do_take_over_console(const struct consw *sw, int first, int last, int deflt);
void give_up_console(const struct consw *sw);
#ifdef CONFIG_HW_CONSOLE
int con_debug_enter(struct vc_data *vc);
next prev parent reply other threads:[~2013-02-27 0:01 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-26 23:57 [ 00/53] 3.0.67-stable review Greg Kroah-Hartman
2013-02-26 23:57 ` [ 01/53] x86-32, mm: Remove reference to resume_map_numa_kva() Greg Kroah-Hartman
2013-02-26 23:57 ` [ 02/53] mm: fix pageblock bitmap allocation Greg Kroah-Hartman
2013-02-26 23:57 ` [ 03/53] timeconst.pl: Eliminate Perl warning Greg Kroah-Hartman
2013-02-27 2:46 ` Rob Landley
2013-02-26 23:57 ` [ 04/53] genirq: Avoid deadlock in spurious handling Greg Kroah-Hartman
2013-02-26 23:57 ` [ 05/53] posix-cpu-timers: Fix nanosleep task_struct leak Greg Kroah-Hartman
2013-02-26 23:57 ` [ 06/53] hrtimer: Prevent hrtimer_enqueue_reprogram race Greg Kroah-Hartman
2013-02-26 23:57 ` [ 07/53] ALSA: ali5451: remove irq enabling in pointer callback Greg Kroah-Hartman
2013-02-26 23:57 ` [ 08/53] ALSA: rme32.c irq enabling after spin_lock_irq Greg Kroah-Hartman
2013-02-26 23:57 ` [ 09/53] tty: set_termios/set_termiox should not return -EINTR Greg Kroah-Hartman
2013-02-26 23:57 ` [ 10/53] xen/netback: check correct frag when looking for head frag Greg Kroah-Hartman
2013-02-26 23:57 ` [ 11/53] xen: Send spinlock IPI to all waiters Greg Kroah-Hartman
2013-02-26 23:57 ` [ 12/53] Driver core: treat unregistered bus_types as having no devices Greg Kroah-Hartman
2013-02-26 23:57 ` [ 13/53] mm: mmu_notifier: have mmu_notifiers use a global SRCU so they may safely schedule Greg Kroah-Hartman
2013-02-26 23:57 ` [ 14/53] mm: mmu_notifier: make the mmu_notifier srcu static Greg Kroah-Hartman
2013-02-26 23:57 ` [ 15/53] mmu_notifier_unregister NULL Pointer deref and multiple ->release() callouts Greg Kroah-Hartman
2013-02-26 23:57 ` [ 16/53] KVM: s390: Handle hosts not supporting s390-virtio Greg Kroah-Hartman
2013-02-26 23:57 ` [ 17/53] s390/kvm: Fix store status for ACRS/FPRS Greg Kroah-Hartman
2013-02-28 22:26 ` Jiri Slaby
2013-03-01 7:50 ` Christian Borntraeger
2013-03-01 9:22 ` Jiri Slaby
2013-03-01 19:16 ` Greg Kroah-Hartman
2013-02-26 23:57 ` [ 18/53] inotify: remove broken mask checks causing unmount to be EINVAL Greg Kroah-Hartman
2013-02-26 23:57 ` [ 19/53] ocfs2: unlock super lock if lockres refresh failed Greg Kroah-Hartman
2013-02-26 23:57 ` [ 20/53] drivers/video/backlight/adp88?0_bl.c: fix resume Greg Kroah-Hartman
2013-02-26 23:57 ` [ 21/53] tmpfs: fix use-after-free of mempolicy object Greg Kroah-Hartman
2013-02-26 23:57 ` [ 22/53] mm/fadvise.c: drain all pagevecs if POSIX_FADV_DONTNEED fails to discard all pages Greg Kroah-Hartman
2013-02-26 23:57 ` [ 23/53] NLM: Ensure that we resend all pending blocking locks after a reclaim Greg Kroah-Hartman
2013-02-26 23:57 ` [ 24/53] p54usb: corrected USB ID for T-Com Sinus 154 data II Greg Kroah-Hartman
2013-02-26 23:57 ` [ 25/53] ALSA: usb-audio: fix Roland A-PRO support Greg Kroah-Hartman
2013-02-26 23:57 ` [ 26/53] ALSA: usb: Fix Processing Unit Descriptor parsers Greg Kroah-Hartman
2013-02-26 23:57 ` [ 27/53] ext4: Free resources in some error path in ext4_fill_super Greg Kroah-Hartman
2013-02-26 23:57 ` [ 28/53] ext4: add missing kfree() on error return path in add_new_gdb() Greg Kroah-Hartman
2013-02-26 23:57 ` [ 29/53] sunvdc: Fix off-by-one in generic_request() Greg Kroah-Hartman
2013-02-26 23:57 ` [ 30/53] drm/usb: bind driver to correct device Greg Kroah-Hartman
2013-02-26 23:58 ` [ 31/53] NLS: improve UTF8 -> UTF16 string conversion routine Greg Kroah-Hartman
2013-02-26 23:58 ` [ 32/53] drm/i915: disable shared panel fitter for pipe Greg Kroah-Hartman
2013-02-26 23:58 ` [ 33/53] staging: comedi: disallow COMEDI_DEVCONFIG on non-board minors Greg Kroah-Hartman
2013-02-26 23:58 ` [ 34/53] staging: vt6656: Fix URB submitted while active warning Greg Kroah-Hartman
2013-02-26 23:58 ` [ 35/53] ARM: PXA3xx: program the CSMSADRCFG register Greg Kroah-Hartman
2013-02-26 23:58 ` [ 36/53] powerpc/kexec: Disable hard IRQ before kexec Greg Kroah-Hartman
2013-02-26 23:58 ` [ 37/53] [PARISC] Purge existing TLB entries in set_pte_at and ptep_set_wrprotect Greg Kroah-Hartman
2013-02-26 23:58 ` [ 38/53] pcmcia/vrc4171: Add missing spinlock init Greg Kroah-Hartman
2013-02-26 23:58 ` [ 39/53] fbcon: dont lose the console font across generic->chip driver switch Greg Kroah-Hartman
2013-02-26 23:58 ` Greg Kroah-Hartman [this message]
2013-02-26 23:58 ` [ 41/53] fb: Yet another band-aid for fixing lockdep mess Greg Kroah-Hartman
2013-02-26 23:58 ` [ 42/53] bridge: set priority of STP packets Greg Kroah-Hartman
2013-02-26 23:58 ` [ 43/53] xen-netback: correctly return errors from netbk_count_requests() Greg Kroah-Hartman
2013-02-26 23:58 ` [ 44/53] xen-netback: cancel the credit timer when taking the vif down Greg Kroah-Hartman
2013-02-26 23:58 ` [ 45/53] ipv4: fix a bug in ping_err() Greg Kroah-Hartman
2013-02-26 23:58 ` [ 46/53] ipv6: use a stronger hash for tcp Greg Kroah-Hartman
2013-02-26 23:58 ` [ 47/53] dca: check against empty dca_domains list before unregister provider Greg Kroah-Hartman
2013-02-28 22:04 ` Jiri Slaby
2013-02-28 22:17 ` Jiri Slaby
2013-03-01 19:17 ` Greg Kroah-Hartman
2013-02-26 23:58 ` [ 48/53] USB: option: add and update Alcatel modems Greg Kroah-Hartman
2013-02-26 23:58 ` [ 49/53] USB: option: add Yota / Megafon M100-1 4g modem Greg Kroah-Hartman
2013-02-26 23:58 ` [ 50/53] USB: option: add Huawei "ACM" devices using protocol = vendor Greg Kroah-Hartman
2013-02-26 23:58 ` [ 51/53] USB: ehci-omap: Fix autoloading of module Greg Kroah-Hartman
2013-02-26 23:58 ` [ 52/53] USB: storage: properly handle the endian issues of idProduct Greg Kroah-Hartman
2013-02-26 23:58 ` [ 53/53] USB: usb-storage: unusual_devs update for Super TOP SATA bridge Greg Kroah-Hartman
2013-02-27 16:51 ` [ 00/53] 3.0.67-stable review Shuah Khan
2013-02-27 16:54 ` Greg Kroah-Hartman
2013-02-28 14:56 ` Satoru Takeuchi
2013-02-28 14:59 ` Greg Kroah-Hartman
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=20130226235624.021862294@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=FlorianSchandinat@gmx.de \
--cc=airlied@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alan@linux.intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=sedat.dilek@gmail.com \
--cc=sfr@canb.auug.org.au \
--cc=stable@vger.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