All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: paravirt: Initialize steal time when cpu is online
@ 2020-09-16 15:45 Andrew Jones
  2020-09-17  9:13 ` Steven Price
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Jones @ 2020-09-16 15:45 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, steven.price

Steal time initialization requires mapping a memory region which
invokes a memory allocation. Doing this at CPU starting time results
in the following trace when CONFIG_DEBUG_ATOMIC_SLEEP is enabled:

BUG: sleeping function called from invalid context at mm/slab.h:498
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/1
CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.9.0-rc5+ #1
Call trace:
 dump_backtrace+0x0/0x208
 show_stack+0x1c/0x28
 dump_stack+0xc4/0x11c
 ___might_sleep+0xf8/0x130
 __might_sleep+0x58/0x90
 slab_pre_alloc_hook.constprop.101+0xd0/0x118
 kmem_cache_alloc_node_trace+0x84/0x270
 __get_vm_area_node+0x88/0x210
 get_vm_area_caller+0x38/0x40
 __ioremap_caller+0x70/0xf8
 ioremap_cache+0x78/0xb0
 memremap+0x9c/0x1a8
 init_stolen_time_cpu+0x54/0xf0
 cpuhp_invoke_callback+0xa8/0x720
 notify_cpu_starting+0xc8/0xd8
 secondary_start_kernel+0x114/0x180
CPU1: Booted secondary processor 0x0000000001 [0x431f0a11]

However we don't need to initialize steal time at CPU starting time.
We can simply wait until CPU online time, just sacrificing a bit of
accuracy by returning zero for steal time until we know better.

While at it, add __init to the functions that are only called by
pv_time_init() which is __init.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arch/arm64/kernel/paravirt.c | 26 +++++++++++++++-----------
 include/linux/cpuhotplug.h   |  1 -
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/kernel/paravirt.c b/arch/arm64/kernel/paravirt.c
index 295d66490584..c07d7a034941 100644
--- a/arch/arm64/kernel/paravirt.c
+++ b/arch/arm64/kernel/paravirt.c
@@ -50,16 +50,19 @@ static u64 pv_steal_clock(int cpu)
 	struct pv_time_stolen_time_region *reg;
 
 	reg = per_cpu_ptr(&stolen_time_region, cpu);
-	if (!reg->kaddr) {
-		pr_warn_once("stolen time enabled but not configured for cpu %d\n",
-			     cpu);
+
+	/*
+	 * paravirt_steal_clock() may be called before the CPU
+	 * online notification callback runs. Until the callback
+	 * has run we just return zero.
+	 */
+	if (!reg->kaddr)
 		return 0;
-	}
 
 	return le64_to_cpu(READ_ONCE(reg->kaddr->stolen_time));
 }
 
-static int stolen_time_dying_cpu(unsigned int cpu)
+static int stolen_time_cpu_down_prepare(unsigned int cpu)
 {
 	struct pv_time_stolen_time_region *reg;
 
@@ -73,7 +76,7 @@ static int stolen_time_dying_cpu(unsigned int cpu)
 	return 0;
 }
 
-static int init_stolen_time_cpu(unsigned int cpu)
+static int stolen_time_cpu_online(unsigned int cpu)
 {
 	struct pv_time_stolen_time_region *reg;
 	struct arm_smccc_res res;
@@ -103,19 +106,20 @@ static int init_stolen_time_cpu(unsigned int cpu)
 	return 0;
 }
 
-static int pv_time_init_stolen_time(void)
+static int __init pv_time_init_stolen_time(void)
 {
 	int ret;
 
-	ret = cpuhp_setup_state(CPUHP_AP_ARM_KVMPV_STARTING,
-				"hypervisor/arm/pvtime:starting",
-				init_stolen_time_cpu, stolen_time_dying_cpu);
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
+				"hypervisor/arm/pvtime:online",
+				stolen_time_cpu_online,
+				stolen_time_cpu_down_prepare);
 	if (ret < 0)
 		return ret;
 	return 0;
 }
 
-static bool has_pv_steal_clock(void)
+static bool __init has_pv_steal_clock(void)
 {
 	struct arm_smccc_res res;
 
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 3215023d4852..bf9181cef444 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -142,7 +142,6 @@ enum cpuhp_state {
 	/* Must be the last timer callback */
 	CPUHP_AP_DUMMY_TIMER_STARTING,
 	CPUHP_AP_ARM_XEN_STARTING,
-	CPUHP_AP_ARM_KVMPV_STARTING,
 	CPUHP_AP_ARM_CORESIGHT_STARTING,
 	CPUHP_AP_ARM_CORESIGHT_CTI_STARTING,
 	CPUHP_AP_ARM64_ISNDEP_STARTING,
-- 
2.27.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: [PATCH] arm64: paravirt: Initialize steal time when cpu is online
  2020-09-16 15:45 [PATCH] arm64: paravirt: Initialize steal time when cpu is online Andrew Jones
@ 2020-09-17  9:13 ` Steven Price
  2020-09-17 15:22 ` Marc Zyngier
  2020-09-17 17:26 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Price @ 2020-09-17  9:13 UTC (permalink / raw)
  To: Andrew Jones, kvmarm; +Cc: maz

On 16/09/2020 16:45, Andrew Jones wrote:
> Steal time initialization requires mapping a memory region which
> invokes a memory allocation. Doing this at CPU starting time results
> in the following trace when CONFIG_DEBUG_ATOMIC_SLEEP is enabled:
> 
> BUG: sleeping function called from invalid context at mm/slab.h:498
> in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/1
> CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.9.0-rc5+ #1
> Call trace:
>   dump_backtrace+0x0/0x208
>   show_stack+0x1c/0x28
>   dump_stack+0xc4/0x11c
>   ___might_sleep+0xf8/0x130
>   __might_sleep+0x58/0x90
>   slab_pre_alloc_hook.constprop.101+0xd0/0x118
>   kmem_cache_alloc_node_trace+0x84/0x270
>   __get_vm_area_node+0x88/0x210
>   get_vm_area_caller+0x38/0x40
>   __ioremap_caller+0x70/0xf8
>   ioremap_cache+0x78/0xb0
>   memremap+0x9c/0x1a8
>   init_stolen_time_cpu+0x54/0xf0
>   cpuhp_invoke_callback+0xa8/0x720
>   notify_cpu_starting+0xc8/0xd8
>   secondary_start_kernel+0x114/0x180
> CPU1: Booted secondary processor 0x0000000001 [0x431f0a11]
> 
> However we don't need to initialize steal time at CPU starting time.
> We can simply wait until CPU online time, just sacrificing a bit of
> accuracy by returning zero for steal time until we know better.
> 
> While at it, add __init to the functions that are only called by
> pv_time_init() which is __init.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>

The changes look good to me - it simplifies things delaying the startup 
of stolen time and I doubt anyone will notice the accuracy loss.

Reviewed-by: Steven Price <steven.price@arm.com>

Do we need a CC: stable (or Fixes:)?

Steve
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: [PATCH] arm64: paravirt: Initialize steal time when cpu is online
  2020-09-16 15:45 [PATCH] arm64: paravirt: Initialize steal time when cpu is online Andrew Jones
  2020-09-17  9:13 ` Steven Price
@ 2020-09-17 15:22 ` Marc Zyngier
  2020-09-17 17:26 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2020-09-17 15:22 UTC (permalink / raw)
  To: Andrew Jones, catalin.marinas; +Cc: kvmarm, steven.price

+ Catalin,

On 2020-09-16 16:45, Andrew Jones wrote:
> Steal time initialization requires mapping a memory region which
> invokes a memory allocation. Doing this at CPU starting time results
> in the following trace when CONFIG_DEBUG_ATOMIC_SLEEP is enabled:
> 
> BUG: sleeping function called from invalid context at mm/slab.h:498
> in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: 
> swapper/1
> CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.9.0-rc5+ #1
> Call trace:
>  dump_backtrace+0x0/0x208
>  show_stack+0x1c/0x28
>  dump_stack+0xc4/0x11c
>  ___might_sleep+0xf8/0x130
>  __might_sleep+0x58/0x90
>  slab_pre_alloc_hook.constprop.101+0xd0/0x118
>  kmem_cache_alloc_node_trace+0x84/0x270
>  __get_vm_area_node+0x88/0x210
>  get_vm_area_caller+0x38/0x40
>  __ioremap_caller+0x70/0xf8
>  ioremap_cache+0x78/0xb0
>  memremap+0x9c/0x1a8
>  init_stolen_time_cpu+0x54/0xf0
>  cpuhp_invoke_callback+0xa8/0x720
>  notify_cpu_starting+0xc8/0xd8
>  secondary_start_kernel+0x114/0x180
> CPU1: Booted secondary processor 0x0000000001 [0x431f0a11]
> 
> However we don't need to initialize steal time at CPU starting time.
> We can simply wait until CPU online time, just sacrificing a bit of
> accuracy by returning zero for steal time until we know better.
> 
> While at it, add __init to the functions that are only called by
> pv_time_init() which is __init.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Fixes: e0685fa228fd ("arm64: Retrieve stolen time as paravirtualized 
guest")
Cc: stable@vger.kernel.org

Catalin, any chance you could queue this if you are OK with it?

Thanks,

       M.
-- 
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: [PATCH] arm64: paravirt: Initialize steal time when cpu is online
  2020-09-16 15:45 [PATCH] arm64: paravirt: Initialize steal time when cpu is online Andrew Jones
  2020-09-17  9:13 ` Steven Price
  2020-09-17 15:22 ` Marc Zyngier
@ 2020-09-17 17:26 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2020-09-17 17:26 UTC (permalink / raw)
  To: Andrew Jones, kvmarm; +Cc: maz, Will Deacon, steven.price

On Wed, 16 Sep 2020 17:45:30 +0200, Andrew Jones wrote:
> Steal time initialization requires mapping a memory region which
> invokes a memory allocation. Doing this at CPU starting time results
> in the following trace when CONFIG_DEBUG_ATOMIC_SLEEP is enabled:
> 
> BUG: sleeping function called from invalid context at mm/slab.h:498
> in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/1
> CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.9.0-rc5+ #1
> Call trace:
>  dump_backtrace+0x0/0x208
>  show_stack+0x1c/0x28
>  dump_stack+0xc4/0x11c
>  ___might_sleep+0xf8/0x130
>  __might_sleep+0x58/0x90
>  slab_pre_alloc_hook.constprop.101+0xd0/0x118
>  kmem_cache_alloc_node_trace+0x84/0x270
>  __get_vm_area_node+0x88/0x210
>  get_vm_area_caller+0x38/0x40
>  __ioremap_caller+0x70/0xf8
>  ioremap_cache+0x78/0xb0
>  memremap+0x9c/0x1a8
>  init_stolen_time_cpu+0x54/0xf0
>  cpuhp_invoke_callback+0xa8/0x720
>  notify_cpu_starting+0xc8/0xd8
>  secondary_start_kernel+0x114/0x180
> CPU1: Booted secondary processor 0x0000000001 [0x431f0a11]
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: paravirt: Initialize steal time when cpu is online
      https://git.kernel.org/arm64/c/75df529bec91

-- 
Catalin

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

end of thread, other threads:[~2020-09-17 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 15:45 [PATCH] arm64: paravirt: Initialize steal time when cpu is online Andrew Jones
2020-09-17  9:13 ` Steven Price
2020-09-17 15:22 ` Marc Zyngier
2020-09-17 17:26 ` Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.