Skip to contentSkip to conversation

lib: Check for migrate_disable only on SMP systems

PATCH In review Daniel Wagner 3 participants 9 messages Dec 6, 2019 – Dec 16, 2019 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: Check for migrate_disable only on SMP systems

In case the kernel configuration is UP is, the migrate_disable member in task_struct is missing.

linux/lib/smp_processor_id.c: In function ‘check_preemption_disabled’:
linux/lib/smp_processor_id.c:26:13: error: ‘struct task_struct’ has no member named ‘migrate_disable’

    26 |  if (current->migrate_disable)
       |             ^~
Fixes 425c5b38779a ("sched: Lazy migrate_disable processing")
Cc Scott Wood <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
---
 lib/smp_processor_id.c | 2 ++
 1 file changed, 2 insertions(+)
lib/smp_processor_id.c +2 -0
index 5f2618d346c4..a914f73e3652 100644
@@ -23,8 +23,10 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
 	 * Kernel threads bound to a single CPU can safely use
 	 * smp_processor_id():
 	 */
+#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT_BASE)
 	if (current->migrate_disable)
 		goto out;
+#endif
 
 	if (current->nr_cpus_allowed == 1)
 		goto out;
Signature · 1 line
2.24.0
#1 lore raw
Quoted 22 lines · Daniel Wagner

In case the kernel configuration is UP is, the migrate_disable member in task_struct is missing.

linux/lib/smp_processor_id.c: In function ‘check_preemption_disabled’:
linux/lib/smp_processor_id.c:26:13: error: ‘struct task_struct’ has no member named ‘migrate_disable’

    26 |  if (current->migrate_disable)
       |             ^~
Fixes 425c5b38779a ("sched: Lazy migrate_disable processing")
Cc Scott Wood <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
---
 lib/smp_processor_id.c | 2 ++
 1 file changed, 2 insertions(+)
lib/smp_processor_id.c +0 -0
index 5f2618d346c4..a914f73e3652 100644

lib/smp_processor_id.c unsigned int check_preemption_disabled(const char · line 30

Quoted 8 lines
lib/smp_processor_id.c +2 -0
@@ -23,8 +23,10 @@ unsigned int check_preemption_disabled(const char
 *what1, const char *what2)
 	 * Kernel threads bound to a single CPU can safely use
 	 * smp_processor_id():
 	 */
+#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT_BASE)
 	if (current->migrate_disable)
 		goto out;
+#endif

Won't this give false positives on UP with CONFIG_PREEMPT_RT_BASE and CONFIG_DEBUG_PREEMPT? If we have CONFIG_SCHED_DEBUG then we can still check migrate_disable. Without that, we don't have enough information to tell whether it's safe to do smp_processor_id() and would have to skip check_preemption_disabled() entirely.

-Scott

#2 lore raw

Hi Scott,

Quoted 27 lines · Scott Wood
Quoted 26 lines · Daniel Wagner

In case the kernel configuration is UP is, the migrate_disable member in task_struct is missing.

linux/lib/smp_processor_id.c: In function ‘check_preemption_disabled’:
linux/lib/smp_processor_id.c:26:13: error: ‘struct task_struct’ has no member named ‘migrate_disable’

    26 |  if (current->migrate_disable)
       |             ^~
Fixes 425c5b38779a ("sched: Lazy migrate_disable processing")
Cc Scott Wood <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
---
 lib/smp_processor_id.c | 2 ++
 1 file changed, 2 insertions(+)
lib/smp_processor_id.c +0 -0
index 5f2618d346c4..a914f73e3652 100644
@@ -23,8 +23,10 @@ unsigned int check_preemption_disabled(const char
 *what1, const char *what2)
 	 * Kernel threads bound to a single CPU can safely use
 	 * smp_processor_id():
 	 */
Quoted 8 lines

lib/smp_processor_id.c unsigned int check_preemption_disabled(const char *what1, const char *what2) · line 29

Quoted 4 lines
lib/smp_processor_id.c +2 -0
+#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT_BASE)
 	if (current->migrate_disable)
 		goto out;
+#endif

Won't this give false positives on UP with CONFIG_PREEMPT_RT_BASE and CONFIG_DEBUG_PREEMPT? If we have CONFIG_SCHED_DEBUG then we can still check migrate_disable.

Ohhh, I see what you mean. I didn't realize that migrate_disable is also available with CONFIG_SCHED_DEBUG. So the ifdef should be something like:

#if defined(CONFIG_PREEMP_RT_BASE) && \
    (defined(CONFIG_SMP) || \
      (!defined(CONFIG_SMP) && defined(CONFIG_SCHED_DEBUG)))

?

Hmm, looks a bit ugly but I haven't found a simplification. Long time since I did logic algebra...

Thanks,
Daniel

#3 lore raw
Quoted 40 lines · Daniel Wagner

Hi Scott,

Quoted 28 lines · Scott Wood
Quoted 27 lines · Daniel Wagner

In case the kernel configuration is UP is, the migrate_disable member in task_struct is missing.

linux/lib/smp_processor_id.c: In function ‘check_preemption_disabled’:
linux/lib/smp_processor_id.c:26:13: error: ‘struct task_struct’ has no member named ‘migrate_disable’

    26 |  if (current->migrate_disable)
       |             ^~
Fixes 425c5b38779a ("sched: Lazy migrate_disable processing")
Cc Scott Wood <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
---
 lib/smp_processor_id.c | 2 ++
 1 file changed, 2 insertions(+)
lib/smp_processor_id.c +1 -0
index 5f2618d346c4..a914f73e3652 100644
@@ -23,8 +23,10 @@ unsigned int check_preemption_disabled(const char
 *what1, const char *what2)
 	 * Kernel threads bound to a single CPU can safely use
 	 * smp_processor_id():
 	 */
+#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT_BASE)
Quoted 8 lines

lib/smp_processor_id.c unsigned int check_preemption_disabled(const char *what1, const char *what2) · line 29

Quoted 3 lines
lib/smp_processor_id.c +1 -0
 	if (current->migrate_disable)
 		goto out;
+#endif

Won't this give false positives on UP with CONFIG_PREEMPT_RT_BASE and CONFIG_DEBUG_PREEMPT? If we have CONFIG_SCHED_DEBUG then we can still check
migrate_disable.

Quoted 7 lines

Ohhh, I see what you mean. I didn't realize that migrate_disable is also available with CONFIG_SCHED_DEBUG. So the ifdef should be something like:

#if defined(CONFIG_PREEMP_RT_BASE) && \
    (defined(CONFIG_SMP) || \
      (!defined(CONFIG_SMP) && defined(CONFIG_SCHED_DEBUG)))

That would still leave the issue with false positives if you have CONFIG_DEBUG_PREEMPT but not CONFIG_SCHED_DEBUG (which should be the only config currently experiencing build problems).

-Scott

#4 lore raw

Hi Scott,

Quoted 11 lines · Scott Wood
Quoted 10 lines · Daniel Wagner
Quoted 4 lines · Scott Wood

On Fri, 2019-12-06 at 15:21 +0100, Daniel Wagner wrote:
Won't this give false positives on UP with CONFIG_PREEMPT_RT_BASE and CONFIG_DEBUG_PREEMPT? If we have CONFIG_SCHED_DEBUG then we can still check migrate_disable.

Ohhh, I see what you mean. I didn't realize that migrate_disable is also available with CONFIG_SCHED_DEBUG. So the ifdef should be something like:

Quoted 7 lines
Quoted 3 lines
#if defined(CONFIG_PREEMP_RT_BASE) && \
    (defined(CONFIG_SMP) || \
      (!defined(CONFIG_SMP) && defined(CONFIG_SCHED_DEBUG)))

That would still leave the issue with false positives if you have CONFIG_DEBUG_PREEMPT but not CONFIG_SCHED_DEBUG (which should be the only config currently experiencing build problems).

I didn't realize that smp_processor_id.c is only build with CONFIG_DEBUG_PREEMPT. It should be enough to add

	#if defined(CONFIG_SCHED_DEBUG)

Did I get it finally correct? :)

Thanks,
Daniel

#5 lore raw
Quoted 24 lines · Daniel Wagner

Hi Scott,

Quoted 21 lines · Scott Wood
Quoted 8 lines · Daniel Wagner
Quoted 6 lines · Scott Wood

On Fri, 2019-12-06 at 15:21 +0100, Daniel Wagner wrote:
Won't this give false positives on UP with CONFIG_PREEMPT_RT_BASE and
CONFIG_DEBUG_PREEMPT? If we have CONFIG_SCHED_DEBUG then we can still
check migrate_disable.

Quoted 7 lines

Ohhh, I see what you mean. I didn't realize that migrate_disable is also available with CONFIG_SCHED_DEBUG. So the ifdef should be something like:

#if defined(CONFIG_PREEMP_RT_BASE) && \
    (defined(CONFIG_SMP) || \
      (!defined(CONFIG_SMP) && defined(CONFIG_SCHED_DEBUG)))

That would still leave the issue with false positives if you have CONFIG_DEBUG_PREEMPT but not CONFIG_SCHED_DEBUG (which should be the only
config currently experiencing build problems).

Actually it looks like we're saved from the false positives by the following check for nr_cpus_allowed == 1, which should always be true on UP.

If we want this check to be effective on UP we'd need some way to keep track of whether a thread is forced by the kernel to be bound to one CPU, rather than whether it just happens to have only one CPU in the mask. Barring that, we should just stub out check_preemption_disabled() as a whole on UP.

Quoted 6 lines

I didn't realize that smp_processor_id.c is only build with CONFIG_DEBUG_PREEMPT. It should be enough to add

	#if defined(CONFIG_SCHED_DEBUG)

Did I get it finally correct? :)

No, then we *would* get those false positives on SMP without CONFIG_SCHED_DEBUG, and it wouldn't build without CONFIG_PREEMPT_RT_BASE.

-Scott

#6 lore raw
Quoted 3 lines · Scott Wood

Actually it looks like we're saved from the false positives by the following check for nr_cpus_allowed == 1, which should always be true on UP.

we currently don't.

Quoted 9 lines

If we want this check to be effective on UP we'd need some way to keep track of whether a thread is forced by the kernel to be bound to one CPU, rather than whether it just happens to have only one CPU in the mask. Barring that, we should just stub out check_preemption_disabled() as a whole on UP.

Quoted 3 lines

I didn't realize that smp_processor_id.c is only build with CONFIG_DEBUG_PREEMPT. It should be enough to add

Quoted 6 lines
Quoted 3 lines
	#if defined(CONFIG_SCHED_DEBUG)

Did I get it finally correct? :)

No, then we *would* get those false positives on SMP without CONFIG_SCHED_DEBUG, and it wouldn't build without CONFIG_PREEMPT_RT_BASE.

this should be enough ->

From: Daniel Wagner <[email protected]>
Date: Mon, 16 Dec 2019 16:15:57 +0100
Subject: [PATCH] lib/smp_processor_id: Adjust check_preemption_disabled()

The current->migrate_disable counter is not always defined leading to build failures with DEBUG_PREEMPT && !PREEMPT_RT_BASE.

Restrict the access to ->migrate_disable to same set where ->migrate_disable is modified.

[bigeasy: adjust condition + description]
---
 lib/smp_processor_id.c | 2 ++
 1 file changed, 2 insertions(+)
lib/smp_processor_id.c +2 -0
index 5f2618d346c42..c2f5b0f8cacd0 100644
@@ -23,8 +23,10 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
 	 * Kernel threads bound to a single CPU can safely use
 	 * smp_processor_id():
 	 */
+#if defined(CONFIG_PREEMPT_RT_BASE) && (defined(CONFIG_SMP) || defined(CONFIG_SCHED_DEBUG))
 	if (current->migrate_disable)
 		goto out;
+#endif
 
 	if (current->nr_cpus_allowed == 1)
 		goto out;
Signature · 1 line
2.24.0
#7 lore raw
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Scott Wood

Actually it looks like we're saved from the false positives by the following check for nr_cpus_allowed == 1, which should always be true on UP.

we currently don't.

Currently don't what?

-Scott

#8 lore raw
Quoted 9 lines · Scott Wood
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Scott Wood

Actually it looks like we're saved from the false positives by the following check for nr_cpus_allowed == 1, which should always be true on UP.

we currently don't.

Currently don't what?

Update the migrate_disable counter for UP without CONFIG_SCHED_DEBUG.

Quoted 1 line

-Scott

Sebastian