From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Dmitry Safonov <dima@arista.com>
Cc: linux-kernel@vger.kernel.org,
Dmitry Safonov <0x7f454c46@gmail.com>,
Jiri Slaby <jslaby@suse.com>,
Vasiliy Khoruzhick <vasilykh@arista.com>,
linux-serial@vger.kernel.org, Iurii Zaikin <yzaikin@google.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH-next 2/3] sysctl/sysrq: Remove __sysrq_enabled copy
Date: Fri, 10 Jan 2020 17:40:35 +0100 [thread overview]
Message-ID: <20200110164035.GA1822445@kroah.com> (raw)
In-Reply-To: <20200109215444.95995-3-dima@arista.com>
On Thu, Jan 09, 2020 at 09:54:43PM +0000, Dmitry Safonov wrote:
> Many embedded boards have a disconnected TTL level serial which can
> generate some garbage that can lead to spurious false sysrq detects.
>
> Currently, sysrq can be either completely disabled for serial console
> or always disabled (with CONFIG_MAGIC_SYSRQ_SERIAL), since
> commit 732dbf3a6104 ("serial: do not accept sysrq characters via serial port")
>
> At Arista, we have such boards that can generate BREAK and random
> garbage. While disabling sysrq for serial console would solve
> the problem with spurious false sysrq triggers, it's also desirable
> to have a way to enable sysrq back.
>
> Having the way to enable sysrq was beneficial to debug lockups with
> a manual investigation in field and on the other side preventing false
> sysrq detections.
>
> As a preparation to add sysrq_toggle_support() call into uart,
> remove a private copy of sysrq_enabled from sysctl - it should reflect
> the actual status of sysrq.
>
> Furthermore, the private copy isn't correct already in case
> sysrq_always_enabled is true. So, remove __sysrq_enabled and use a
> getter-helper for sysrq enabled status.
>
> Cc: Iurii Zaikin <yzaikin@google.com>
> Cc: Jiri Slaby <jslaby@suse.com>
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: linux-fsdevel@vger.kernel.org
> Signed-off-by: Dmitry Safonov <dima@arista.com>
> ---
> drivers/tty/sysrq.c | 7 +++++++
> include/linux/sysrq.h | 1 +
> kernel/sysctl.c | 41 ++++++++++++++++++++++-------------------
> 3 files changed, 30 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
> index f724962a5906..ef3e78967146 100644
> --- a/drivers/tty/sysrq.c
> +++ b/drivers/tty/sysrq.c
> @@ -73,6 +73,13 @@ static bool sysrq_on_mask(int mask)
> (sysrq_enabled & mask);
> }
>
> +int sysrq_get_mask(void)
> +{
> + if (sysrq_always_enabled)
> + return 1;
> + return sysrq_enabled;
> +}
> +
> static int __init sysrq_always_enabled_setup(char *str)
> {
> sysrq_always_enabled = true;
> diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
> index 8c71874e8485..4a0b351fa2d3 100644
> --- a/include/linux/sysrq.h
> +++ b/include/linux/sysrq.h
> @@ -50,6 +50,7 @@ int unregister_sysrq_key(int key, struct sysrq_key_op *op);
> struct sysrq_key_op *__sysrq_get_key_op(int key);
>
> int sysrq_toggle_support(int enable_mask);
> +int sysrq_get_mask(void);
>
> #else
>
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index d396aaaf19a3..6ddb4d7df0e1 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -229,25 +229,8 @@ static int proc_dopipe_max_size(struct ctl_table *table, int write,
> void __user *buffer, size_t *lenp, loff_t *ppos);
>
> #ifdef CONFIG_MAGIC_SYSRQ
> -/* Note: sysrq code uses its own private copy */
> -static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
> -
> static int sysrq_sysctl_handler(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp,
> - loff_t *ppos)
> -{
> - int error;
> -
> - error = proc_dointvec(table, write, buffer, lenp, ppos);
> - if (error)
> - return error;
> -
> - if (write)
> - sysrq_toggle_support(__sysrq_enabled);
> -
> - return 0;
> -}
> -
> + void __user *buffer, size_t *lenp, loff_t *ppos);
> #endif
>
> static struct ctl_table kern_table[];
> @@ -747,7 +730,7 @@ static struct ctl_table kern_table[] = {
> #ifdef CONFIG_MAGIC_SYSRQ
> {
> .procname = "sysrq",
> - .data = &__sysrq_enabled,
> + .data = NULL,
> .maxlen = sizeof (int),
> .mode = 0644,
> .proc_handler = sysrq_sysctl_handler,
> @@ -2844,6 +2827,26 @@ static int proc_dostring_coredump(struct ctl_table *table, int write,
> }
> #endif
>
> +#ifdef CONFIG_MAGIC_SYSRQ
> +static int sysrq_sysctl_handler(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> +{
> + int tmp, ret;
> +
> + tmp = sysrq_get_mask();
> +
> + ret = __do_proc_dointvec(&tmp, table, write, buffer,
> + lenp, ppos, NULL, NULL);
> + if (ret || !write)
> + return ret;
> +
> + if (write)
> + sysrq_toggle_support(tmp);
> +
> + return 0;
> +}
> +#endif
Why did you move this function down here? Can't it stay where it is and
you can just fix the logic there? Now you have two different #ifdef
blocks intead of just one :(
thanks,
greg k-h
next prev parent reply other threads:[~2020-01-10 16:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 21:54 [PATCH-next 0/3] serial/sysrq: Add MAGIC_SYSRQ_SERIAL_SEQUENCE Dmitry Safonov
2020-01-09 21:54 ` [PATCH-next 1/3] serial_core: Move sysrq functions from header file Dmitry Safonov
2020-01-10 16:50 ` Greg Kroah-Hartman
2020-01-09 21:54 ` [PATCH-next 2/3] sysctl/sysrq: Remove __sysrq_enabled copy Dmitry Safonov
2020-01-10 3:19 ` Iurii Zaikin
2020-01-10 21:48 ` Dmitry Safonov
2020-01-10 16:40 ` Greg Kroah-Hartman [this message]
2020-01-10 21:45 ` Dmitry Safonov
2020-01-10 22:01 ` Greg Kroah-Hartman
2020-01-09 21:54 ` [PATCH-next 3/3] serial/sysrq: Add MAGIC_SYSRQ_SERIAL_SEQUENCE Dmitry Safonov
2020-01-09 23:53 ` Randy Dunlap
2020-01-10 22:02 ` Dmitry Safonov
2020-01-10 16:46 ` Greg Kroah-Hartman
2020-01-10 22:32 ` Dmitry Safonov
2020-01-14 19:10 ` Dmitry Safonov
2020-01-15 12:42 ` Greg Kroah-Hartman
2020-01-10 16:50 ` Joe Perches
2020-01-10 22:10 ` Dmitry Safonov
2020-01-11 14:08 ` Joe Perches
2020-01-10 19:01 ` kbuild test robot
2020-01-10 19:20 ` kbuild test robot
2020-01-11 10:52 ` kbuild test robot
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=20200110164035.GA1822445@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=0x7f454c46@gmail.com \
--cc=dima@arista.com \
--cc=jslaby@suse.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=vasilykh@arista.com \
--cc=yzaikin@google.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;
as well as URLs for NNTP newsgroup(s).