From: Andrew Jones Subject: [PATCH kvm-unit-tests 1/3] arm/arm64: smp: assert secondaries only boot once Date: Mon, 29 May 2017 15:58:02 +0200 Message-ID: <20170529135804.22891-2-drjones@redhat.com> References: <20170529135804.22891-1-drjones@redhat.com> Cc: rkrcmar@redhat.com To: kvm@vger.kernel.org, pbonzini@redhat.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:33696 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751025AbdE2N6J (ORCPT ); Mon, 29 May 2017 09:58:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01E284E4D3 for ; Mon, 29 May 2017 13:58:09 +0000 (UTC) In-Reply-To: <20170529135804.22891-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: It's tempting to try running smp_run() more than once, but that won't currently work. In the meantime, let's fail better. Also, there's no reason to expose the structure in smp.h Signed-off-by: Andrew Jones --- lib/arm/asm/smp.h | 8 -------- lib/arm/smp.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/arm/asm/smp.h b/lib/arm/asm/smp.h index 1d1cd7a29991..a3551a40e4c5 100644 --- a/lib/arm/asm/smp.h +++ b/lib/arm/asm/smp.h @@ -37,14 +37,6 @@ static inline void set_cpu_online(int cpu, bool online) } typedef void (*secondary_entry_fn)(void); - -/* secondary_data is reused for each cpu, so only boot one at a time */ -struct secondary_data { - void *stack; /* must be first member of struct */ - secondary_entry_fn entry; -}; -extern struct secondary_data secondary_data; - extern void smp_boot_secondary(int cpu, secondary_entry_fn entry); extern void smp_run(void (*func)(void)); diff --git a/lib/arm/smp.c b/lib/arm/smp.c index 8528aa454108..fe64ed410377 100644 --- a/lib/arm/smp.c +++ b/lib/arm/smp.c @@ -7,6 +7,7 @@ */ #include #include +#include #include #include #include @@ -16,7 +17,13 @@ cpumask_t cpu_present_mask; cpumask_t cpu_online_mask; cpumask_t cpu_halted_mask; + +struct secondary_data { + void *stack; /* must be first member of struct */ + secondary_entry_fn entry; +}; struct secondary_data secondary_data; +static struct spinlock lock; secondary_entry_fn secondary_cinit(void) { @@ -45,6 +52,10 @@ void smp_boot_secondary(int cpu, secondary_entry_fn entry) { int ret; + spin_lock(&lock); + + assert_msg(!cpu_online(cpu), "CPU%d already boot once", cpu); + secondary_data.stack = thread_stack_alloc(); secondary_data.entry = entry; mmu_mark_disabled(cpu); @@ -53,6 +64,8 @@ void smp_boot_secondary(int cpu, secondary_entry_fn entry) while (!cpu_online(cpu)) wfe(); + + spin_unlock(&lock); } void secondary_halt(void) -- 2.9.4