2019-05-24 08:59:09

by Daniel Vetter

[permalink] [raw]
Subject: [PATCH 04/33] vt: More locking checks

I honestly have no idea what the subtle differences between
con_is_visible, con_is_fg (internal to vt.c) and con_is_bound are. But
it looks like both vc->vc_display_fg and con_driver_map are protected
by the console_lock, so probably better if we hold that when checking
this.

To do that I had to deinline the con_is_visible function.

Signed-off-by: Daniel Vetter <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Nicolas Pitre <[email protected]>
Cc: Martin Hostettler <[email protected]>
Cc: Adam Borowski <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Mikulas Patocka <[email protected]>
---
drivers/tty/vt/vt.c | 16 ++++++++++++++++
include/linux/console_struct.h | 5 +----
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index bc9813b14c58..a8988a085138 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3815,6 +3815,8 @@ int con_is_bound(const struct consw *csw)
{
int i, bound = 0;

+ WARN_CONSOLE_UNLOCKED();
+
for (i = 0; i < MAX_NR_CONSOLES; i++) {
if (con_driver_map[i] == csw) {
bound = 1;
@@ -3826,6 +3828,20 @@ int con_is_bound(const struct consw *csw)
}
EXPORT_SYMBOL(con_is_bound);

+/**
+ * con_is_visible - checks whether the current console is visible
+ * @vc: virtual console
+ *
+ * RETURNS: zero if not visible, nonzero if visible
+ */
+bool con_is_visible(const struct vc_data *vc)
+{
+ WARN_CONSOLE_UNLOCKED();
+
+ return *vc->vc_display_fg == vc;
+}
+EXPORT_SYMBOL(con_is_visible);
+
/**
* con_debug_enter - prepare the console for the kernel debugger
* @sw: console driver
diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h
index ed798e114663..24d4c16e3ae0 100644
--- a/include/linux/console_struct.h
+++ b/include/linux/console_struct.h
@@ -168,9 +168,6 @@ extern void vc_SAK(struct work_struct *work);

#define CUR_DEFAULT CUR_UNDERLINE

-static inline bool con_is_visible(const struct vc_data *vc)
-{
- return *vc->vc_display_fg == vc;
-}
+bool con_is_visible(const struct vc_data *vc);

#endif /* _LINUX_CONSOLE_STRUCT_H */
--
2.20.1


2019-05-27 07:11:38

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH 04/33] vt: More locking checks

On Fri, May 24, 2019 at 10:53:25AM +0200, Daniel Vetter wrote:
> I honestly have no idea what the subtle differences between
> con_is_visible, con_is_fg (internal to vt.c) and con_is_bound are. But
> it looks like both vc->vc_display_fg and con_driver_map are protected
> by the console_lock, so probably better if we hold that when checking
> this.
>
> To do that I had to deinline the con_is_visible function.
>
> Signed-off-by: Daniel Vetter <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Nicolas Pitre <[email protected]>
> Cc: Martin Hostettler <[email protected]>
> Cc: Adam Borowski <[email protected]>
> Cc: Daniel Vetter <[email protected]>
> Cc: Mikulas Patocka <[email protected]>

Hi Greg,

Do you want to merge this through your console tree or ack for merging
through drm/fbdev? It's part of a bigger series, and I'd like to have more
testing with this in our trees, but also ok to merge stand-alone if you
prefer that. It's just locking checks and some docs.

Same for the preceeding patch in this series here.

Thanks, Daniel


> ---
> drivers/tty/vt/vt.c | 16 ++++++++++++++++
> include/linux/console_struct.h | 5 +----
> 2 files changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index bc9813b14c58..a8988a085138 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -3815,6 +3815,8 @@ int con_is_bound(const struct consw *csw)
> {
> int i, bound = 0;
>
> + WARN_CONSOLE_UNLOCKED();
> +
> for (i = 0; i < MAX_NR_CONSOLES; i++) {
> if (con_driver_map[i] == csw) {
> bound = 1;
> @@ -3826,6 +3828,20 @@ int con_is_bound(const struct consw *csw)
> }
> EXPORT_SYMBOL(con_is_bound);
>
> +/**
> + * con_is_visible - checks whether the current console is visible
> + * @vc: virtual console
> + *
> + * RETURNS: zero if not visible, nonzero if visible
> + */
> +bool con_is_visible(const struct vc_data *vc)
> +{
> + WARN_CONSOLE_UNLOCKED();
> +
> + return *vc->vc_display_fg == vc;
> +}
> +EXPORT_SYMBOL(con_is_visible);
> +
> /**
> * con_debug_enter - prepare the console for the kernel debugger
> * @sw: console driver
> diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h
> index ed798e114663..24d4c16e3ae0 100644
> --- a/include/linux/console_struct.h
> +++ b/include/linux/console_struct.h
> @@ -168,9 +168,6 @@ extern void vc_SAK(struct work_struct *work);
>
> #define CUR_DEFAULT CUR_UNDERLINE
>
> -static inline bool con_is_visible(const struct vc_data *vc)
> -{
> - return *vc->vc_display_fg == vc;
> -}
> +bool con_is_visible(const struct vc_data *vc);
>
> #endif /* _LINUX_CONSOLE_STRUCT_H */
> --
> 2.20.1
>

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

2019-05-27 07:24:42

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 04/33] vt: More locking checks

On Mon, May 27, 2019 at 09:08:58AM +0200, Daniel Vetter wrote:
> On Fri, May 24, 2019 at 10:53:25AM +0200, Daniel Vetter wrote:
> > I honestly have no idea what the subtle differences between
> > con_is_visible, con_is_fg (internal to vt.c) and con_is_bound are. But
> > it looks like both vc->vc_display_fg and con_driver_map are protected
> > by the console_lock, so probably better if we hold that when checking
> > this.
> >
> > To do that I had to deinline the con_is_visible function.
> >
> > Signed-off-by: Daniel Vetter <[email protected]>
> > Cc: Greg Kroah-Hartman <[email protected]>
> > Cc: Nicolas Pitre <[email protected]>
> > Cc: Martin Hostettler <[email protected]>
> > Cc: Adam Borowski <[email protected]>
> > Cc: Daniel Vetter <[email protected]>
> > Cc: Mikulas Patocka <[email protected]>
>
> Hi Greg,
>
> Do you want to merge this through your console tree or ack for merging
> through drm/fbdev? It's part of a bigger series, and I'd like to have more
> testing with this in our trees, but also ok to merge stand-alone if you
> prefer that. It's just locking checks and some docs.
>
> Same for the preceeding patch in this series here.

For all of these, please take them through your tree(s):

Acked-by: Greg Kroah-Hartman <[email protected]>