linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] fix parsing of reboot= cmdline
@ 2020-11-03 21:40 Matteo Croce
  2020-11-03 21:40 ` [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint" Matteo Croce
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Matteo Croce @ 2020-11-03 21:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Guenter Roeck, Petr Mladek, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

From: Matteo Croce <mcroce@microsoft.com>

The parsing of the reboot= cmdline has two major errors:
- a missing bound check can crash the system on reboot
- parsing of the cpu number only works if specified last

Fix both, along with a small code refactor.

v2->v3:
Revert the offending commit first, then fix the other bug.
CC stable
v1->v2:
As Petr suggested, don't force base 10 in simple_strtoul(),
so hex values are accepted as well.

Matteo Croce (3):
  Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint"
  reboot: fix overflow parsing reboot cpu number
  reboot: refactor and comment the cpu selection code

 kernel/reboot.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint"
  2020-11-03 21:40 [PATCH v3 0/3] fix parsing of reboot= cmdline Matteo Croce
@ 2020-11-03 21:40 ` Matteo Croce
  2020-11-05 18:02   ` Petr Mladek
  2020-11-03 21:40 ` [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number Matteo Croce
  2020-11-03 21:40 ` [PATCH v3 3/3] reboot: refactor and comment the cpu selection code Matteo Croce
  2 siblings, 1 reply; 9+ messages in thread
From: Matteo Croce @ 2020-11-03 21:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Guenter Roeck, Petr Mladek, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

From: Matteo Croce <mcroce@microsoft.com>

This reverts commit 616feab753972b9751308f3cd2a68fc57eae8edb.

kstrtoint() and simple_strtoul() have a subtle difference which makes
them non interchangeable: if a non digit character is found amid the
parsing, the former will return an error, while the latter will just
stop parsing, e.g. simple_strtoul("123xyx") = 123.

The kernel cmdline reboot= argument allows to specify the CPU used
for rebooting, with the syntax `s####` among the other flags,
e.g. "reboot=warm,s31,force", so if this flag is not the last given,
it's silently ignored as well as the subsequent ones.

Fixes: 616feab75397 ("kernel/reboot.c: convert simple_strtoul to kstrtoint")
Cc: stable@vger.kernel.org
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 kernel/reboot.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index e7b78d5ae1ab..8fbba433725e 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -551,22 +551,15 @@ static int __init reboot_setup(char *str)
 			break;
 
 		case 's':
-		{
-			int rc;
-
-			if (isdigit(*(str+1))) {
-				rc = kstrtoint(str+1, 0, &reboot_cpu);
-				if (rc)
-					return rc;
-			} else if (str[1] == 'm' && str[2] == 'p' &&
-				   isdigit(*(str+3))) {
-				rc = kstrtoint(str+3, 0, &reboot_cpu);
-				if (rc)
-					return rc;
-			} else
+			if (isdigit(*(str+1)))
+				reboot_cpu = simple_strtoul(str+1, NULL, 0);
+			else if (str[1] == 'm' && str[2] == 'p' &&
+							isdigit(*(str+3)))
+				reboot_cpu = simple_strtoul(str+3, NULL, 0);
+			else
 				*mode = REBOOT_SOFT;
 			break;
-		}
+
 		case 'g':
 			*mode = REBOOT_GPIO;
 			break;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number
  2020-11-03 21:40 [PATCH v3 0/3] fix parsing of reboot= cmdline Matteo Croce
  2020-11-03 21:40 ` [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint" Matteo Croce
@ 2020-11-03 21:40 ` Matteo Croce
  2020-11-05 18:09   ` Petr Mladek
  2020-11-03 21:40 ` [PATCH v3 3/3] reboot: refactor and comment the cpu selection code Matteo Croce
  2 siblings, 1 reply; 9+ messages in thread
From: Matteo Croce @ 2020-11-03 21:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Guenter Roeck, Petr Mladek, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

From: Matteo Croce <mcroce@microsoft.com>

Limit the CPU number to num_possible_cpus(), because setting it
to a value lower than INT_MAX but higher than NR_CPUS produces the
following error on reboot and shutdown:

    BUG: unable to handle page fault for address: ffffffff90ab1bb0
    #PF: supervisor read access in kernel mode
    #PF: error_code(0x0000) - not-present page
    PGD 1c09067 P4D 1c09067 PUD 1c0a063 PMD 0
    Oops: 0000 [#1] SMP
    CPU: 1 PID: 1 Comm: systemd-shutdow Not tainted 5.9.0-rc8-kvm #110
    Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
    RIP: 0010:migrate_to_reboot_cpu+0xe/0x60
    Code: ea ea 00 48 89 fa 48 c7 c7 30 57 f1 81 e9 fa ef ff ff 66 2e 0f 1f 84 00 00 00 00 00 53 8b 1d d5 ea ea 00 e8 14 33 fe ff 89 da <48> 0f a3 15 ea fc bd 00 48 89 d0 73 29 89 c2 c1 e8 06 65 48 8b 3c
    RSP: 0018:ffffc90000013e08 EFLAGS: 00010246
    RAX: ffff88801f0a0000 RBX: 0000000077359400 RCX: 0000000000000000
    RDX: 0000000077359400 RSI: 0000000000000002 RDI: ffffffff81c199e0
    RBP: ffffffff81c1e3c0 R08: ffff88801f41f000 R09: ffffffff81c1e348
    R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
    R13: 00007f32bedf8830 R14: 00000000fee1dead R15: 0000000000000000
    FS:  00007f32bedf8980(0000) GS:ffff88801f480000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: ffffffff90ab1bb0 CR3: 000000001d057000 CR4: 00000000000006a0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    __do_sys_reboot.cold+0x34/0x5b
    ? vfs_writev+0x92/0xc0
    ? do_writev+0x52/0xd0
    do_syscall_64+0x2d/0x40
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f32bfaaecd3
    Code: 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 89 fa be 69 19 12 28 bf ad de e1 fe b8 a9 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 05 c3 0f 1f 40 00 48 8b 15 89 81 0c 00 f7 d8
    RSP: 002b:00007fff6265fb58 EFLAGS: 00000202 ORIG_RAX: 00000000000000a9
    RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f32bfaaecd3
    RDX: 0000000001234567 RSI: 0000000028121969 RDI: 00000000fee1dead
    RBP: 0000000000000000 R08: 0000000000008020 R09: 00007fff6265ef60
    R10: 00007f32bedf8830 R11: 0000000000000202 R12: 0000000000000000
    R13: 0000557bba2c51c0 R14: 0000000000000000 R15: 00007fff6265fbc8
    CR2: ffffffff90ab1bb0
    ---[ end trace b813e80157136563 ]---
    RIP: 0010:migrate_to_reboot_cpu+0xe/0x60
    Code: ea ea 00 48 89 fa 48 c7 c7 30 57 f1 81 e9 fa ef ff ff 66 2e 0f 1f 84 00 00 00 00 00 53 8b 1d d5 ea ea 00 e8 14 33 fe ff 89 da <48> 0f a3 15 ea fc bd 00 48 89 d0 73 29 89 c2 c1 e8 06 65 48 8b 3c
    RSP: 0018:ffffc90000013e08 EFLAGS: 00010246
    RAX: ffff88801f0a0000 RBX: 0000000077359400 RCX: 0000000000000000
    RDX: 0000000077359400 RSI: 0000000000000002 RDI: ffffffff81c199e0
    RBP: ffffffff81c1e3c0 R08: ffff88801f41f000 R09: ffffffff81c1e348
    R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
    R13: 00007f32bedf8830 R14: 00000000fee1dead R15: 0000000000000000
    FS:  00007f32bedf8980(0000) GS:ffff88801f480000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: ffffffff90ab1bb0 CR3: 000000001d057000 CR4: 00000000000006a0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
    Kernel Offset: disabled
    ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009 ]---

Fixes: 1b3a5d02ee07 ("reboot: move arch/x86 reboot= handling to generic kernel")
Cc: stable@vger.kernel.org
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 kernel/reboot.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index 8fbba433725e..af6f23d8bea1 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -558,6 +558,13 @@ static int __init reboot_setup(char *str)
 				reboot_cpu = simple_strtoul(str+3, NULL, 0);
 			else
 				*mode = REBOOT_SOFT;
+			if (reboot_cpu >= num_possible_cpus()) {
+				pr_err("Ignoring the CPU number in reboot= option. "
+				       "CPU %d exceeds possible cpu number %d\n",
+				       reboot_cpu, num_possible_cpus());
+				reboot_cpu = 0;
+				break;
+			}
 			break;
 
 		case 'g':
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 3/3] reboot: refactor and comment the cpu selection code
  2020-11-03 21:40 [PATCH v3 0/3] fix parsing of reboot= cmdline Matteo Croce
  2020-11-03 21:40 ` [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint" Matteo Croce
  2020-11-03 21:40 ` [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number Matteo Croce
@ 2020-11-03 21:40 ` Matteo Croce
  2020-11-05 18:09   ` Petr Mladek
  2 siblings, 1 reply; 9+ messages in thread
From: Matteo Croce @ 2020-11-03 21:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: Guenter Roeck, Petr Mladek, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

From: Matteo Croce <mcroce@microsoft.com>

Small improvements to the code, without changing the way it works:
- use a local variable, to avoid a small time lapse where reboot_cpu
  can have an invalid value
- comment the code which is not easy to understand at a glance
- merge two identical code blocks into one
- replace pointer arithmetics with equivalent array syntax

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 kernel/reboot.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index af6f23d8bea1..dd483bde932b 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -551,20 +551,24 @@ static int __init reboot_setup(char *str)
 			break;
 
 		case 's':
-			if (isdigit(*(str+1)))
-				reboot_cpu = simple_strtoul(str+1, NULL, 0);
-			else if (str[1] == 'm' && str[2] == 'p' &&
-							isdigit(*(str+3)))
-				reboot_cpu = simple_strtoul(str+3, NULL, 0);
-			else
+			/*
+			 * reboot_cpu is s[mp]#### with #### being the processor
+			 * to be used for rebooting. Skip 's' or 'smp' prefix.
+			 */
+			str += str[1] == 'm' && str[2] == 'p' ? 3 : 1;
+
+			if (isdigit(str[0])) {
+				int cpu = simple_strtoul(str, NULL, 0);
+
+				if (cpu >= num_possible_cpus()) {
+					pr_err("Ignoring the CPU number in reboot= option. "
+					"CPU %d exceeds possible cpu number %d\n",
+					cpu, num_possible_cpus());
+					break;
+				}
+				reboot_cpu = cpu;
+			} else
 				*mode = REBOOT_SOFT;
-			if (reboot_cpu >= num_possible_cpus()) {
-				pr_err("Ignoring the CPU number in reboot= option. "
-				       "CPU %d exceeds possible cpu number %d\n",
-				       reboot_cpu, num_possible_cpus());
-				reboot_cpu = 0;
-				break;
-			}
 			break;
 
 		case 'g':
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint"
  2020-11-03 21:40 ` [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint" Matteo Croce
@ 2020-11-05 18:02   ` Petr Mladek
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Mladek @ 2020-11-05 18:02 UTC (permalink / raw)
  To: Matteo Croce
  Cc: linux-kernel, Guenter Roeck, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

On Tue 2020-11-03 22:40:23, Matteo Croce wrote:
> From: Matteo Croce <mcroce@microsoft.com>
> 
> This reverts commit 616feab753972b9751308f3cd2a68fc57eae8edb.
> 
> kstrtoint() and simple_strtoul() have a subtle difference which makes
> them non interchangeable: if a non digit character is found amid the
> parsing, the former will return an error, while the latter will just
> stop parsing, e.g. simple_strtoul("123xyx") = 123.
> 
> The kernel cmdline reboot= argument allows to specify the CPU used
> for rebooting, with the syntax `s####` among the other flags,
> e.g. "reboot=warm,s31,force", so if this flag is not the last given,
> it's silently ignored as well as the subsequent ones.
> 
> Fixes: 616feab75397 ("kernel/reboot.c: convert simple_strtoul to kstrtoint")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matteo Croce <mcroce@microsoft.com>

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number
  2020-11-03 21:40 ` [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number Matteo Croce
@ 2020-11-05 18:09   ` Petr Mladek
  2020-11-05 18:14     ` Matteo Croce
  0 siblings, 1 reply; 9+ messages in thread
From: Petr Mladek @ 2020-11-05 18:09 UTC (permalink / raw)
  To: Matteo Croce
  Cc: linux-kernel, Guenter Roeck, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

On Tue 2020-11-03 22:40:24, Matteo Croce wrote:
> From: Matteo Croce <mcroce@microsoft.com>
> 
> Limit the CPU number to num_possible_cpus(), because setting it
> to a value lower than INT_MAX but higher than NR_CPUS produces the
> following error on reboot and shutdown:
> 
>     BUG: unable to handle page fault for address: ffffffff90ab1bb0
>     #PF: supervisor read access in kernel mode
>     #PF: error_code(0x0000) - not-present page
>     PGD 1c09067 P4D 1c09067 PUD 1c0a063 PMD 0
>     Oops: 0000 [#1] SMP
>     CPU: 1 PID: 1 Comm: systemd-shutdow Not tainted 5.9.0-rc8-kvm #110
>     Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
>     RIP: 0010:migrate_to_reboot_cpu+0xe/0x60
>     Code: ea ea 00 48 89 fa 48 c7 c7 30 57 f1 81 e9 fa ef ff ff 66 2e 0f 1f 84 00 00 00 00 00 53 8b 1d d5 ea ea 00 e8 14 33 fe ff 89 da <48> 0f a3 15 ea fc bd 00 48 89 d0 73 29 89 c2 c1 e8 06 65 48 8b 3c
>     RSP: 0018:ffffc90000013e08 EFLAGS: 00010246
>     RAX: ffff88801f0a0000 RBX: 0000000077359400 RCX: 0000000000000000
>     RDX: 0000000077359400 RSI: 0000000000000002 RDI: ffffffff81c199e0
>     RBP: ffffffff81c1e3c0 R08: ffff88801f41f000 R09: ffffffff81c1e348
>     R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
>     R13: 00007f32bedf8830 R14: 00000000fee1dead R15: 0000000000000000
>     FS:  00007f32bedf8980(0000) GS:ffff88801f480000(0000) knlGS:0000000000000000
>     CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>     CR2: ffffffff90ab1bb0 CR3: 000000001d057000 CR4: 00000000000006a0
>     DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
>     DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
>     Call Trace:
>     __do_sys_reboot.cold+0x34/0x5b
>     ? vfs_writev+0x92/0xc0
>     ? do_writev+0x52/0xd0
>     do_syscall_64+0x2d/0x40
>     entry_SYSCALL_64_after_hwframe+0x44/0xa9
>     RIP: 0033:0x7f32bfaaecd3
>     Code: 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 89 fa be 69 19 12 28 bf ad de e1 fe b8 a9 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 05 c3 0f 1f 40 00 48 8b 15 89 81 0c 00 f7 d8
>     RSP: 002b:00007fff6265fb58 EFLAGS: 00000202 ORIG_RAX: 00000000000000a9
>     RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f32bfaaecd3
>     RDX: 0000000001234567 RSI: 0000000028121969 RDI: 00000000fee1dead
>     RBP: 0000000000000000 R08: 0000000000008020 R09: 00007fff6265ef60
>     R10: 00007f32bedf8830 R11: 0000000000000202 R12: 0000000000000000
>     R13: 0000557bba2c51c0 R14: 0000000000000000 R15: 00007fff6265fbc8
>     CR2: ffffffff90ab1bb0
>     ---[ end trace b813e80157136563 ]---
>     RIP: 0010:migrate_to_reboot_cpu+0xe/0x60
>     Code: ea ea 00 48 89 fa 48 c7 c7 30 57 f1 81 e9 fa ef ff ff 66 2e 0f 1f 84 00 00 00 00 00 53 8b 1d d5 ea ea 00 e8 14 33 fe ff 89 da <48> 0f a3 15 ea fc bd 00 48 89 d0 73 29 89 c2 c1 e8 06 65 48 8b 3c
>     RSP: 0018:ffffc90000013e08 EFLAGS: 00010246
>     RAX: ffff88801f0a0000 RBX: 0000000077359400 RCX: 0000000000000000
>     RDX: 0000000077359400 RSI: 0000000000000002 RDI: ffffffff81c199e0
>     RBP: ffffffff81c1e3c0 R08: ffff88801f41f000 R09: ffffffff81c1e348
>     R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
>     R13: 00007f32bedf8830 R14: 00000000fee1dead R15: 0000000000000000
>     FS:  00007f32bedf8980(0000) GS:ffff88801f480000(0000) knlGS:0000000000000000
>     CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>     CR2: ffffffff90ab1bb0 CR3: 000000001d057000 CR4: 00000000000006a0
>     DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
>     DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
>     Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
>     Kernel Offset: disabled
>     ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009 ]---
> 
> Fixes: 1b3a5d02ee07 ("reboot: move arch/x86 reboot= handling to generic kernel")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matteo Croce <mcroce@microsoft.com>
> ---
>  kernel/reboot.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index 8fbba433725e..af6f23d8bea1 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -558,6 +558,13 @@ static int __init reboot_setup(char *str)
>  				reboot_cpu = simple_strtoul(str+3, NULL, 0);
>  			else
>  				*mode = REBOOT_SOFT;
> +			if (reboot_cpu >= num_possible_cpus()) {
> +				pr_err("Ignoring the CPU number in reboot= option. "
> +				       "CPU %d exceeds possible cpu number %d\n",

./scripts/checkpatch.pl used to complain that printk() format parameter should stay
on a single line (ignoring 80 char limit). It helps when people are
trying to find which code printed a particular message.

It is not a big deal here because %d does not allow to search the
entire message anyway.

I am not sure if Andrew would like to get this fixed. In both cases:

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 3/3] reboot: refactor and comment the cpu selection code
  2020-11-03 21:40 ` [PATCH v3 3/3] reboot: refactor and comment the cpu selection code Matteo Croce
@ 2020-11-05 18:09   ` Petr Mladek
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Mladek @ 2020-11-05 18:09 UTC (permalink / raw)
  To: Matteo Croce
  Cc: linux-kernel, Guenter Roeck, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

On Tue 2020-11-03 22:40:25, Matteo Croce wrote:
> From: Matteo Croce <mcroce@microsoft.com>
> 
> Small improvements to the code, without changing the way it works:
> - use a local variable, to avoid a small time lapse where reboot_cpu
>   can have an invalid value
> - comment the code which is not easy to understand at a glance
> - merge two identical code blocks into one
> - replace pointer arithmetics with equivalent array syntax
> 
> Signed-off-by: Matteo Croce <mcroce@microsoft.com>
> ---
>  kernel/reboot.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index af6f23d8bea1..dd483bde932b 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -551,20 +551,24 @@ static int __init reboot_setup(char *str)
>  			break;
>  
>  		case 's':
> -			if (isdigit(*(str+1)))
> -				reboot_cpu = simple_strtoul(str+1, NULL, 0);
> -			else if (str[1] == 'm' && str[2] == 'p' &&
> -							isdigit(*(str+3)))
> -				reboot_cpu = simple_strtoul(str+3, NULL, 0);
> -			else
> +			/*
> +			 * reboot_cpu is s[mp]#### with #### being the processor
> +			 * to be used for rebooting. Skip 's' or 'smp' prefix.
> +			 */
> +			str += str[1] == 'm' && str[2] == 'p' ? 3 : 1;
> +
> +			if (isdigit(str[0])) {
> +				int cpu = simple_strtoul(str, NULL, 0);
> +
> +				if (cpu >= num_possible_cpus()) {
> +					pr_err("Ignoring the CPU number in reboot= option. "
> +					"CPU %d exceeds possible cpu number %d\n",

Same here. I am not sure if Andrew would like to get this on a single
line.

In both cases:

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number
  2020-11-05 18:09   ` Petr Mladek
@ 2020-11-05 18:14     ` Matteo Croce
  2020-11-06 10:18       ` Petr Mladek
  0 siblings, 1 reply; 9+ messages in thread
From: Matteo Croce @ 2020-11-05 18:14 UTC (permalink / raw)
  To: Petr Mladek
  Cc: linux-kernel, Guenter Roeck, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

On Thu, Nov 5, 2020 at 7:09 PM Petr Mladek <pmladek@suse.com> wrote:
> > +                     if (reboot_cpu >= num_possible_cpus()) {
> > +                             pr_err("Ignoring the CPU number in reboot= option. "
> > +                                    "CPU %d exceeds possible cpu number %d\n",
>
> ./scripts/checkpatch.pl used to complain that printk() format parameter should stay
> on a single line (ignoring 80 char limit). It helps when people are
> trying to find which code printed a particular message.
>
> It is not a big deal here because %d does not allow to search the
> entire message anyway.
>
> I am not sure if Andrew would like to get this fixed. In both cases:
>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
>

Yes, I saw this warning, but to suppress it I had to write a 133 char
line, much beyond even the new 100 char limit.
I expect a smart user to just grep the first half of the string, like
"Ignoring the CPU number in reboot="

Regards,
-- 
per aspera ad upstream

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number
  2020-11-05 18:14     ` Matteo Croce
@ 2020-11-06 10:18       ` Petr Mladek
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Mladek @ 2020-11-06 10:18 UTC (permalink / raw)
  To: Matteo Croce
  Cc: linux-kernel, Guenter Roeck, Arnd Bergmann, Mike Rapoport,
	Kees Cook, Pavel Tatashin, Robin Holt, Fabian Frederick,
	Andrew Morton, Greg Kroah-Hartman

On Thu 2020-11-05 19:14:27, Matteo Croce wrote:
> On Thu, Nov 5, 2020 at 7:09 PM Petr Mladek <pmladek@suse.com> wrote:
> > > +                     if (reboot_cpu >= num_possible_cpus()) {
> > > +                             pr_err("Ignoring the CPU number in reboot= option. "
> > > +                                    "CPU %d exceeds possible cpu number %d\n",
> >
> > ./scripts/checkpatch.pl used to complain that printk() format parameter should stay
> > on a single line (ignoring 80 char limit). It helps when people are
> > trying to find which code printed a particular message.
> >
> > It is not a big deal here because %d does not allow to search the
> > entire message anyway.
> >
> > I am not sure if Andrew would like to get this fixed. In both cases:
> >
> > Reviewed-by: Petr Mladek <pmladek@suse.com>
> >
> 
> Yes, I saw this warning, but to suppress it I had to write a 133 char
> line, much beyond even the new 100 char limit.
> I expect a smart user to just grep the first half of the string, like
> "Ignoring the CPU number in reboot="

I agree with checkpatch in this case. IMHO, the more reliable way to
grep the string is more important than the 80 or 100 chars per-line.

That said, it is not a big deal in this case because of the %d.
It requires to search only part of the string anyway.

I am perfectly fine with keeping it as is.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-11-06 10:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-03 21:40 [PATCH v3 0/3] fix parsing of reboot= cmdline Matteo Croce
2020-11-03 21:40 ` [PATCH v3 1/3] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint" Matteo Croce
2020-11-05 18:02   ` Petr Mladek
2020-11-03 21:40 ` [PATCH v3 2/3] reboot: fix overflow parsing reboot cpu number Matteo Croce
2020-11-05 18:09   ` Petr Mladek
2020-11-05 18:14     ` Matteo Croce
2020-11-06 10:18       ` Petr Mladek
2020-11-03 21:40 ` [PATCH v3 3/3] reboot: refactor and comment the cpu selection code Matteo Croce
2020-11-05 18:09   ` Petr Mladek

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).