Skip to contentSkip to conversation

sched/isolation: Allow "isolcpus=" to skip unknown sub-parameters

PATCH Superseded Peter Xu 2 participants 3 messages Apr 2, 2020 – Apr 3, 2020 Scheduler

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH v2 1/1 sched/isolation: Allow "isolcpus=" to skip unknown sub-parameters

The "isolcpus=" parameter allows sub-parameters to exist before the cpulist is specified, and if it sees unknown sub-parameters the whole parameter will be ignored. This design is incompatible with itself when we add more sub-parameters to "isolcpus=", because the old kernels will not recognize the new "isolcpus=" sub-parameters, then it will invalidate the whole parameter so the CPU isolation will not really take effect if we start to use the new sub-parameters while later we reboot into an old kernel. Instead we will see this when booting the old kernel:

isolcpus: Error, unknown flag

The better and compatible way is to allow "isolcpus=" to skip unknown sub-parameters, so that even if we add new sub-parameters to it the old kernel will still be able to behave as usual even if with the new sub-parameter is specified.

Ideally this patch should be there when we introduce the first sub-parameter for "isolcpus=", so it's already a bit late. However late is better than nothing.

CC Ming Lei <[email protected]>
CC Ingo Molnar <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Juri Lelli <[email protected]>
CC Luiz Capitulino <[email protected]>

---
v2:
- only allow isalpha() for sub-parameters [tglx]

---
 kernel/sched/isolation.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
kernel/sched/isolation.c +18 -2
index 008d6ac2342b..c2e8b4a778d6 100644
@@ -149,6 +149,9 @@ __setup("nohz_full=", housekeeping_nohz_full_setup);
 static int __init housekeeping_isolcpus_setup(char *str)
 {
 	unsigned int flags = 0;
+	char *par;
+	int len;
+	bool illegal = false;
 
 	while (isalpha(*str)) {
 		if (!strncmp(str, "nohz,", 5)) {
@@ -169,8 +172,21 @@ static int __init housekeeping_isolcpus_setup(char *str)
 			continue;
 		}
 
-		pr_warn("isolcpus: Error, unknown flag\n");
-		return 0;
+		/*
+		 * Skip unknown sub-parameter and validate that it is not
+		 * containing an invalid character.
+		 */
+		for (par = str, len = 0; *str && *str != ','; str++, len++)
+			if (!isalpha(*str))
+				illegal = true;
+
+		if (illegal) {
+			pr_warn("isolcpus: Invalid flag %.*s\n", len, par);
+			return 0;
+		}
+
+		pr_info("isolcpus: Skipped unknown flag %.*s\n", len, par);
+		str++;
 	}
 
 	/* Default behaviour for isolcpus without flags */
Signature · 1 line
2.24.1
author
#1 lore raw
Quoted 61 lines · Peter Xu

The "isolcpus=" parameter allows sub-parameters to exist before the cpulist is specified, and if it sees unknown sub-parameters the whole parameter will be ignored. This design is incompatible with itself when we add more sub-parameters to "isolcpus=", because the old kernels will not recognize the new "isolcpus=" sub-parameters, then it will invalidate the whole parameter so the CPU isolation will not really take effect if we start to use the new sub-parameters while later we reboot into an old kernel. Instead we will see this when booting the old kernel:

isolcpus: Error, unknown flag

The better and compatible way is to allow "isolcpus=" to skip unknown sub-parameters, so that even if we add new sub-parameters to it the old kernel will still be able to behave as usual even if with the new sub-parameter is specified.

Ideally this patch should be there when we introduce the first sub-parameter for "isolcpus=", so it's already a bit late. However late is better than nothing.

CC Ming Lei <[email protected]>
CC Ingo Molnar <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Juri Lelli <[email protected]>
CC Luiz Capitulino <[email protected]>

---
v2:
- only allow isalpha() for sub-parameters [tglx]

---
 kernel/sched/isolation.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
kernel/sched/isolation.c +9 -2
index 008d6ac2342b..c2e8b4a778d6 100644
@@ -149,6 +149,9 @@ __setup("nohz_full=", housekeeping_nohz_full_setup);
 static int __init housekeeping_isolcpus_setup(char *str)
 {
 	unsigned int flags = 0;
+	char *par;
+	int len;
+	bool illegal = false;
 
 	while (isalpha(*str)) {
 		if (!strncmp(str, "nohz,", 5)) {
@@ -169,8 +172,21 @@ static int __init housekeeping_isolcpus_setup(char *str)
 			continue;
 		}
 
-		pr_warn("isolcpus: Error, unknown flag\n");
-		return 0;
+		/*
+		 * Skip unknown sub-parameter and validate that it is not
+		 * containing an invalid character.
+		 */
+		for (par = str, len = 0; *str && *str != ','; str++, len++)
+			if (!isalpha(*str))

kernel/sched/isolation.c static int __init housekeeping_isolcpus_setup(char *str) · line 190

Quoted 10 lines
kernel/sched/isolation.c +9 -0
+				illegal = true;
+
+		if (illegal) {
+			pr_warn("isolcpus: Invalid flag %.*s\n", len, par);
+			return 0;
+		}
+
+		pr_info("isolcpus: Skipped unknown flag %.*s\n", len, par);
+		str++;
 	}

I just noticed this is still problematic if we want to mark this as stable, because "managed_irq" violate the "isalpha()" rule already... It means even if we apply this patch to the stable trees it'll still think managed_irq as illegal and ignore the whole isolcpus=.

Thomas, do you want me to repost a v3 as v1 plus some pr_warn()s?

Thanks,

Signature · 1 line
Peter Xu
#2 lore raw
Quoted 8 lines · Peter Xu

kernel/sched/isolation.c static int __init housekeeping_isolcpus_setup(char *str) · line 179

Quoted 7 lines · Peter Xu
kernel/sched/isolation.c +5 -2
-		pr_warn("isolcpus: Error, unknown flag\n");
-		return 0;
+		/*
+		 * Skip unknown sub-parameter and validate that it is not
+		 * containing an invalid character.
+		 */
+		for (par = str, len = 0; *str && *str != ','; str++, len++)

lacks {

Quoted 2 lines

kernel/sched/isolation.c static int __init housekeeping_isolcpus_setup(char *str) · line 181

Quoted 2 lines
kernel/sched/isolation.c +2 -0
+			if (!isalpha(*str))
+				illegal = true;

lacks }

Quoted 6 lines
Quoted 6 lines
kernel/sched/isolation.c +6 -0
+
+		if (illegal) {
+			pr_warn("isolcpus: Invalid flag %.*s\n", len, par);
+			return 0;
+		}
+
Quoted 8 lines

kernel/sched/isolation.c static int __init housekeeping_isolcpus_setup(char *str) · line 190

Quoted 3 lines
kernel/sched/isolation.c +2 -0
+		pr_info("isolcpus: Skipped unknown flag %.*s\n", len, par);
+		str++;
 	}

I just noticed this is still problematic if we want to mark this as stable, because "managed_irq" violate the "isalpha()" rule already... It means even if we apply this patch to the stable trees it'll still think managed_irq as illegal and ignore the whole isolcpus=.

		if (!isalpha(*str) && *str != '_')

which is what I told you a couple of days ago already.

Thanks,

tglx