From nobody Thu Nov 28 22:39:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1655199702; cv=none; d=zohomail.com; s=zohoarc; b=HoHqnygHgBdQhQXIMtaWGnKXBRbRyIzNf15V4GrOGgagJ38vdytLFzBn0nuakNanj0T2Gbh5FEYCpbgx3TZ7X4eIwsVFyQx+P4iMWmYQRqgPTMf0EIO4jexF/ZEzuyUBLBT+BfX0ZanxOSzH89h/Gmkpc1s6VNBnxR4YREK5Jrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655199702; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ceUU4HToCnfJLUQnb0zPb4pnqugghgbeuw1i+l4yi0k=; b=PCPJC+HZL5VfP19RB1JxpHFOq1NcdwyY5fCktx+dIjjuOoxfV6wOOIhYzyZJFQxu7zqnsApMFmAPbdRKlh3+aGc2ESqCfev0aFBfPV4MBdw8zFUaSCScAyjeZwnOkH6nFFS6EitbsFWjcDqxM4irSX1YyAanoYLtjTZjFEi+EAQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1655199702548738.841009787698; Tue, 14 Jun 2022 02:41:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.348728.574913 (Exim 4.92) (envelope-from ) id 1o1336-0002as-TW; Tue, 14 Jun 2022 09:41:24 +0000 Received: by outflank-mailman (output) from mailman id 348728.574913; Tue, 14 Jun 2022 09:41:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o1336-0002al-Qn; Tue, 14 Jun 2022 09:41:24 +0000 Received: by outflank-mailman (input) for mailman id 348728; Tue, 14 Jun 2022 09:41:23 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o1335-0002aY-HO for xen-devel@lists.xenproject.org; Tue, 14 Jun 2022 09:41:23 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o1335-0003s2-2f; Tue, 14 Jun 2022 09:41:23 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o1334-00040G-QA; Tue, 14 Jun 2022 09:41:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=ceUU4HToCnfJLUQnb0zPb4pnqugghgbeuw1i+l4yi0k=; b=1teTMS y0X5nRBFHGsSMzsYWNOHGKjDbRUETY7iC5lbzr5U38+l1zjLGJOH1LPwVWmszmlZXDPR/QNzR1iJB uJUMN3GPJ3kpT+4eXO5Xe0HBuW2bmBIucaaz/xp4blRttFKpzXPkBsQRSZ9XHgD11LifOp39+lSY9 3RRFn7g+qb4=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: andrew.cooper3@citrix.com, Julien Grall , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH] xen/arm: smpboot: Allocate the CPU sibling/core maps while preparing the CPU Date: Tue, 14 Jun 2022 10:41:19 +0100 Message-Id: <20220614094119.94720-1-julien@xen.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1655199703930100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall Commit 5047cd1d5dea "xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in xmalloc()" extended the checks in _xmalloc() to catch any use of the helpers from context with interrupts disabled. Unfortunately, the rule is not followed when allocating the CPU sibling/core maps. (XEN) Xen call trace: (XEN) [<00238a5c>] _xmalloc+0xfc/0x314 (PC) (XEN) [<00000000>] 00000000 (LR) (XEN) [<00238c8c>] _xzalloc+0x18/0x4c (XEN) [<00288cb4>] smpboot.c#setup_cpu_sibling_map+0x38/0x138 (XEN) [<00289024>] start_secondary+0x1b4/0x270 (XEN) [<40010170>] 40010170 (XEN) (XEN) (XEN) **************************************** (XEN) Panic on CPU 2: (XEN) Assertion '!in_irq() && (local_irq_is_enabled() || num_online_cpus() = <=3D 1)' failed at common/xmalloc_tlsf.c:601 (XEN) **************************************** This is happening because zalloc_cpumask_var() may allocate memory if NR_CPUS is > 2 * sizeof(unsigned long). Avoid the problem by allocate the per-CPU IRQs while preparing the CPU. This also has the benefit to remove a panic() in the secondary CPU code. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- xen/arch/arm/smpboot.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 4888bcd78a5a..2b0c92cd369b 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -79,15 +79,17 @@ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask= ); static bool __read_mostly opt_hmp_unsafe =3D false; boolean_param("hmp-unsafe", opt_hmp_unsafe); =20 -static void setup_cpu_sibling_map(int cpu) +static int setup_cpu_sibling_map(int cpu) { if ( !zalloc_cpumask_var(&per_cpu(cpu_sibling_mask, cpu)) || !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) ) - panic("No memory for CPU sibling/core maps\n"); + return -ENOMEM; =20 /* A CPU is a sibling with itself and is always on its own core. */ cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu)); cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu)); + + return 0; } =20 static void remove_cpu_sibling_map(int cpu) @@ -292,9 +294,14 @@ smp_get_max_cpus (void) void __init smp_prepare_cpus(void) { + int rc; + cpumask_copy(&cpu_present_map, &cpu_possible_map); =20 - setup_cpu_sibling_map(0); + rc =3D setup_cpu_sibling_map(0); + if ( rc ) + panic("Unable to allocate CPU sibling/core maps\n"); + } =20 /* Boot the current CPU */ @@ -361,8 +368,6 @@ void start_secondary(void) =20 set_current(idle_vcpu[cpuid]); =20 - setup_cpu_sibling_map(cpuid); - /* Run local notifiers */ notify_cpu_starting(cpuid); /* @@ -530,9 +535,19 @@ static int cpu_smpboot_callback(struct notifier_block = *nfb, void *hcpu) { unsigned int cpu =3D (unsigned long)hcpu; + unsigned int rc =3D 0; =20 switch ( action ) { + case CPU_UP_PREPARE: + rc =3D setup_cpu_sibling_map(cpu); + if ( rc ) + printk(XENLOG_ERR + "Unable to allocate CPU sibling/core map for CPU%u\n", + cpu); + + break; + case CPU_DEAD: remove_cpu_sibling_map(cpu); break; --=20 2.32.0