[v2] hrtimer: select housekeeping CPU during migration

Message ID 20240213164650.2935909-3-costa.shul@redhat.com
State New
Headers
Series [v2] hrtimer: select housekeeping CPU during migration |

Commit Message

Costa Shulyupin Feb. 13, 2024, 4:46 p.m. UTC
  During CPU-down hotplug, hrtimers may migrate to isolated CPUs,
compromising CPU isolation. This commit addresses this issue by
masking valid CPUs for hrtimers using housekeeping_cpumask(HK_TYPE_TIMER).

Suggested-by: Waiman Long <longman@redhat.com>
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
Reviewed-by: Waiman Long <longman@redhat.com>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
---

Changes in v2:
- [v1] https://lore.kernel.org/all/20240211135213.2518068-1-costa.shul@redhat.com/
- reworded and rebased on linux-next
---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Thomas Gleixner Feb. 13, 2024, 7:41 p.m. UTC | #1
On Tue, Feb 13 2024 at 18:46, Costa Shulyupin wrote:

Way better now. Two nitpicks though:

> During CPU-down hotplug, hrtimers may migrate to isolated CPUs,
> compromising CPU isolation. This commit addresses this issue by
> masking valid CPUs for hrtimers using housekeeping_cpumask(HK_TYPE_TIMER).

'This commit' is pointless.

 # git grep 'This patch' Documentation/process/

gives you an hint.

> Suggested-by: Waiman Long <longman@redhat.com>
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
> Reviewed-by: Waiman Long <longman@redhat.com>
> Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
> ---
>
> Changes in v2:
> - [v1] https://lore.kernel.org/all/20240211135213.2518068-1-costa.shul@redhat.com/
> - reworded and rebased on linux-next
> ---
>  kernel/time/hrtimer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index edb0f821dcea..947bd6cf7105 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -2224,7 +2224,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
>  int hrtimers_cpu_dying(unsigned int dying_cpu)
>  {
>  	struct hrtimer_cpu_base *old_base, *new_base;
> -	int i, ncpu = cpumask_first(cpu_active_mask);
> +	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));

The tip tree managed code has rules for variable declarations (and more):

  https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#variable-declarations

No need to send a v3, I fix it up this time.

Thanks,

        tglx
  
Borislav Petkov Feb. 14, 2024, 9:01 a.m. UTC | #2
On Tue, Feb 13, 2024 at 06:46:51PM +0200, Costa Shulyupin wrote:
> During CPU-down hotplug, hrtimers may migrate to isolated CPUs,
> compromising CPU isolation. This commit addresses this issue by
> masking valid CPUs for hrtimers using housekeeping_cpumask(HK_TYPE_TIMER).
> 
> Suggested-by: Waiman Long <longman@redhat.com>
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
> Reviewed-by: Waiman Long <longman@redhat.com>
> Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
> ---
> 
> Changes in v2:
> - [v1] https://lore.kernel.org/all/20240211135213.2518068-1-costa.shul@redhat.com/
> - reworded and rebased on linux-next
> ---
>  kernel/time/hrtimer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index edb0f821dcea..947bd6cf7105 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -2224,7 +2224,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
>  int hrtimers_cpu_dying(unsigned int dying_cpu)
>  {
>  	struct hrtimer_cpu_base *old_base, *new_base;
> -	int i, ncpu = cpumask_first(cpu_active_mask);
> +	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
							^^^^^^^^^^^^^^
How was this patch tested?

It even says housekeeping_cpumask() in the commit message so the
*intent* to use the correct function is there:

kernel/time/hrtimer.c: In function ‘hrtimers_cpu_dying’:
kernel/time/hrtimer.c:2226:56: error: implicit declaration of function ‘housekeeping’ [-Werror=implicit-function-declaration]
 2226 |         int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
      |                                                        ^~~~~~~~~~~~
/include/linux/cpumask.h:774:67: note: in definition of macro ‘cpumask_any_and’
  774 | #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
      |                                                                   ^~~~~
kernel/time/hrtimer.c:2226:69: error: ‘HK_TYPE_TIMER’ undeclared (first use in this function)
 2226 |         int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
      |                                                                     ^~~~~~~~~~~~~
/include/linux/cpumask.h:774:67: note: in definition of macro ‘cpumask_any_and’
  774 | #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
      |                                                                   ^~~~~
kernel/time/hrtimer.c:2226:69: note: each undeclared identifier is reported only once for each function it appears in
 2226 |         int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
      |                                                                     ^~~~~~~~~~~~~
/include/linux/cpumask.h:774:67: note: in definition of macro ‘cpumask_any_and’
  774 | #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
      |                                                                   ^~~~~
cc1: some warnings being treated as errors
make[4]: *** [scripts/Makefile.build:243: kernel/time/hrtimer.o] Error 1
make[3]: *** [scripts/Makefile.build:481: kernel/time] Error 2
make[2]: *** [scripts/Makefile.build:481: kernel] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/mnt/kernel/kernel/2nd/linux/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2

This makes it build again at least:

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 2cbdf64d746c..6057fe2e179b 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -38,6 +38,7 @@
 #include <linux/sched/deadline.h>
 #include <linux/sched/nohz.h>
 #include <linux/sched/debug.h>
+#include <linux/sched/isolation.h>
 #include <linux/timer.h>
 #include <linux/freezer.h>
 #include <linux/compat.h>
@@ -2223,7 +2224,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
 
 int hrtimers_cpu_dying(unsigned int dying_cpu)
 {
-	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
+	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping_cpumask(HK_TYPE_TIMER));
 	struct hrtimer_cpu_base *old_base, *new_base;
 
 	tick_cancel_sched_timer(dying_cpu);
  
Thomas Gleixner Feb. 14, 2024, 9:10 a.m. UTC | #3
On Tue, Feb 13 2024 at 18:46, Costa Shulyupin wrote:
> @@ -2224,7 +2224,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
>  int hrtimers_cpu_dying(unsigned int dying_cpu)
>  {
>  	struct hrtimer_cpu_base *old_base, *new_base;
> -	int i, ncpu = cpumask_first(cpu_active_mask);
> +	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));

kernel/time/hrtimer.c:2224:56: error: implicit declaration of function ‘housekeeping’ [-Werror=implicit-function-declaration]

Sigh,
  

Patch

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index edb0f821dcea..947bd6cf7105 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -2224,7 +2224,7 @@  static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
 int hrtimers_cpu_dying(unsigned int dying_cpu)
 {
 	struct hrtimer_cpu_base *old_base, *new_base;
-	int i, ncpu = cpumask_first(cpu_active_mask);
+	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
 
 	tick_cancel_sched_timer(dying_cpu);