fb: rework locking to fix lock ordering on takeover
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> Cc: stable <stable@vger.kernel.org> 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>
This commit is contained in:
parent
84b603abd2
commit
50e244cc79
|
@ -2987,7 +2987,7 @@ int __init vty_init(const struct file_operations *console_fops)
|
||||||
|
|
||||||
static struct class *vtconsole_class;
|
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)
|
int deflt)
|
||||||
{
|
{
|
||||||
struct module *owner = csw->owner;
|
struct module *owner = csw->owner;
|
||||||
|
@ -2998,7 +2998,7 @@ static int bind_con_driver(const struct consw *csw, int first, int last,
|
||||||
if (!try_module_get(owner))
|
if (!try_module_get(owner))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
console_lock();
|
WARN_CONSOLE_UNLOCKED();
|
||||||
|
|
||||||
/* check if driver is registered */
|
/* check if driver is registered */
|
||||||
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
|
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
|
||||||
|
@ -3083,11 +3083,22 @@ static int bind_con_driver(const struct consw *csw, int first, int last,
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
err:
|
err:
|
||||||
console_unlock();
|
|
||||||
module_put(owner);
|
module_put(owner);
|
||||||
return retval;
|
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
|
#ifdef CONFIG_VT_HW_CONSOLE_BINDING
|
||||||
static int con_is_graphics(const struct consw *csw, int first, int last)
|
static int con_is_graphics(const struct consw *csw, int first, int last)
|
||||||
{
|
{
|
||||||
|
@ -3199,9 +3210,9 @@ int unbind_con_driver(const struct consw *csw, int first, int last, int deflt)
|
||||||
if (!con_is_bound(csw))
|
if (!con_is_bound(csw))
|
||||||
con_driver->flag &= ~CON_DRIVER_FLAG_INIT;
|
con_driver->flag &= ~CON_DRIVER_FLAG_INIT;
|
||||||
|
|
||||||
console_unlock();
|
|
||||||
/* ignore return value, binding should not fail */
|
/* 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:
|
err:
|
||||||
module_put(owner);
|
module_put(owner);
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -3492,28 +3503,18 @@ int con_debug_leave(void)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(con_debug_leave);
|
EXPORT_SYMBOL_GPL(con_debug_leave);
|
||||||
|
|
||||||
/**
|
static int do_register_con_driver(const struct consw *csw, int first, int last)
|
||||||
* 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)
|
|
||||||
{
|
{
|
||||||
struct module *owner = csw->owner;
|
struct module *owner = csw->owner;
|
||||||
struct con_driver *con_driver;
|
struct con_driver *con_driver;
|
||||||
const char *desc;
|
const char *desc;
|
||||||
int i, retval = 0;
|
int i, retval = 0;
|
||||||
|
|
||||||
|
WARN_CONSOLE_UNLOCKED();
|
||||||
|
|
||||||
if (!try_module_get(owner))
|
if (!try_module_get(owner))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
console_lock();
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
|
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
|
||||||
con_driver = ®istered_con_driver[i];
|
con_driver = ®istered_con_driver[i];
|
||||||
|
|
||||||
|
@ -3566,10 +3567,29 @@ int register_con_driver(const struct consw *csw, int first, int last)
|
||||||
}
|
}
|
||||||
|
|
||||||
err:
|
err:
|
||||||
console_unlock();
|
|
||||||
module_put(owner);
|
module_put(owner);
|
||||||
return retval;
|
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);
|
EXPORT_SYMBOL(register_con_driver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3623,17 +3643,44 @@ EXPORT_SYMBOL(unregister_con_driver);
|
||||||
* when a driver wants to take over some existing consoles
|
* when a driver wants to take over some existing consoles
|
||||||
* and become default driver for newly opened ones.
|
* 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 take_over_console(const struct consw *csw, int first, int last, int deflt)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = register_con_driver(csw, first, last);
|
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
|
* and return success, as we may have unbound the console driver
|
||||||
* but not unregistered it.
|
* but not unregistered it.
|
||||||
*/
|
*/
|
||||||
if (err == -EBUSY)
|
if (err == -EBUSY)
|
||||||
err = 0;
|
err = 0;
|
||||||
if (!err)
|
if (!err)
|
||||||
|
|
|
@ -529,6 +529,33 @@ static int search_for_mapped_con(void)
|
||||||
return retval;
|
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)
|
static int fbcon_takeover(int show_logo)
|
||||||
{
|
{
|
||||||
int err, i;
|
int err, i;
|
||||||
|
@ -3115,7 +3142,7 @@ static int fbcon_fb_registered(struct fb_info *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info_idx != -1)
|
if (info_idx != -1)
|
||||||
ret = fbcon_takeover(1);
|
ret = do_fbcon_takeover(1);
|
||||||
} else {
|
} else {
|
||||||
for (i = first_fb_vc; i <= last_fb_vc; i++) {
|
for (i = first_fb_vc; i <= last_fb_vc; i++) {
|
||||||
if (con2fb_map_boot[i] == idx)
|
if (con2fb_map_boot[i] == idx)
|
||||||
|
|
|
@ -1650,7 +1650,9 @@ static int do_register_framebuffer(struct fb_info *fb_info)
|
||||||
event.info = fb_info;
|
event.info = fb_info;
|
||||||
if (!lock_fb_info(fb_info))
|
if (!lock_fb_info(fb_info))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
console_lock();
|
||||||
fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
|
fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
|
||||||
|
console_unlock();
|
||||||
unlock_fb_info(fb_info);
|
unlock_fb_info(fb_info);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1853,11 +1855,8 @@ int fb_new_modelist(struct fb_info *info)
|
||||||
err = 1;
|
err = 1;
|
||||||
|
|
||||||
if (!list_empty(&info->modelist)) {
|
if (!list_empty(&info->modelist)) {
|
||||||
if (!lock_fb_info(info))
|
|
||||||
return -ENODEV;
|
|
||||||
event.info = info;
|
event.info = info;
|
||||||
err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
|
err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
|
||||||
unlock_fb_info(info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -177,6 +177,8 @@ static ssize_t store_modes(struct device *device,
|
||||||
if (i * sizeof(struct fb_videomode) != count)
|
if (i * sizeof(struct fb_videomode) != count)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (!lock_fb_info(fb_info))
|
||||||
|
return -ENODEV;
|
||||||
console_lock();
|
console_lock();
|
||||||
list_splice(&fb_info->modelist, &old_list);
|
list_splice(&fb_info->modelist, &old_list);
|
||||||
fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
|
fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
|
||||||
|
@ -188,6 +190,7 @@ static ssize_t store_modes(struct device *device,
|
||||||
fb_destroy_modelist(&old_list);
|
fb_destroy_modelist(&old_list);
|
||||||
|
|
||||||
console_unlock();
|
console_unlock();
|
||||||
|
unlock_fb_info(fb_info);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 register_con_driver(const struct consw *csw, int first, int last);
|
||||||
int unregister_con_driver(const struct consw *csw);
|
int unregister_con_driver(const struct consw *csw);
|
||||||
int take_over_console(const struct consw *sw, int first, int last, int deflt);
|
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);
|
void give_up_console(const struct consw *sw);
|
||||||
#ifdef CONFIG_HW_CONSOLE
|
#ifdef CONFIG_HW_CONSOLE
|
||||||
int con_debug_enter(struct vc_data *vc);
|
int con_debug_enter(struct vc_data *vc);
|
||||||
|
|
Loading…
Reference in New Issue