From nobody Thu Nov 28 23:59:46 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=1655199741; cv=none; d=zohomail.com; s=zohoarc; b=K8q84YAgOQNKCwYfQJFbP1McX7+Dc1Pf0VLCWyiKdWibbxe3EeD4wigTLJkOK8Jt/Yjfc3AGwKtRiJxc1xALtGK1y+6yXrc/DldVNb7NsL5LQlDthhn1N6tiQC+ZTfkSkov7xYWBw4zXt27wJIxvKq6OZOPz3ugmo2+vb2kfh2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655199741; 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=KV7y7Yscv6Q5zqvYArQUIKkkXlBEZv6KbcKb+feLfL8=; b=eHRqnjRMEz6KGEt+81SaNH0dMPIa3WuzynbH83JVhD+CK+dVznK86Lj8IOhbJNX7HBoUTK8zv7Wl6+4ufjLAXIUXaXMcRZY0Z9RqKah4dn/7Z9uyiPrzXDkpYP+zhRff4WTsm1GISBkP0ciR7C+anAFXxMA0smdShZE1SKWxjOY= 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 1655199741133729.0416781872844; Tue, 14 Jun 2022 02:42:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.348735.574925 (Exim 4.92) (envelope-from ) id 1o133i-0003AV-6V; Tue, 14 Jun 2022 09:42:02 +0000 Received: by outflank-mailman (output) from mailman id 348735.574925; Tue, 14 Jun 2022 09:42:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o133i-0003AO-2v; Tue, 14 Jun 2022 09:42:02 +0000 Received: by outflank-mailman (input) for mailman id 348735; Tue, 14 Jun 2022 09:42:01 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o133h-0003AB-7B for xen-devel@lists.xenproject.org; Tue, 14 Jun 2022 09:42:01 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o133g-0003st-S3; Tue, 14 Jun 2022 09:42:00 +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 1o133g-00041E-Jf; Tue, 14 Jun 2022 09:42:00 +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=KV7y7Yscv6Q5zqvYArQUIKkkXlBEZv6KbcKb+feLfL8=; b=559BT/ Xj8vKHcVDGEdbl+hBB3b+o//fa1Um2TLOCZFjkImKoMIZNEovakgFmDfT6hLnmZtArqhMKCkB9bgB bAKrGp8YpC5kqszuvgQ1eBX3Wmt9sSdELtXg2B0w2AVbSyS+Jyw6dPG6ZrOvZL5pHDiZyVe6QGOav O6hHORYe7C4=; 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: irq: Initialize the per-CPU IRQs while preparing the CPU Date: Tue, 14 Jun 2022 10:41:57 +0100 Message-Id: <20220614094157.95631-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: 1655199741999100001 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 initializing the per-CPU IRQs: (XEN) Xen call trace: (XEN) [<002389f4>] _xmalloc+0xfc/0x314 (PC) (XEN) [<00000000>] 00000000 (LR) (XEN) [<0021a7c4>] init_one_irq_desc+0x48/0xd0 (XEN) [<002807a8>] irq.c#init_local_irq_data+0x48/0xa4 (XEN) [<00280834>] init_secondary_IRQ+0x10/0x2c (XEN) [<00288fa4>] start_secondary+0x194/0x274 (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 BUG_ON() in the secondary CPU code. Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis Reviewed-by: Michal Orzel Tested-by: Bertrand Marquis --- xen/arch/arm/include/asm/irq.h | 1 - xen/arch/arm/irq.c | 35 +++++++++++++++++++++++++++------- xen/arch/arm/smpboot.c | 2 -- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/include/asm/irq.h b/xen/arch/arm/include/asm/irq.h index e45d57459899..245f49dcbac5 100644 --- a/xen/arch/arm/include/asm/irq.h +++ b/xen/arch/arm/include/asm/irq.h @@ -73,7 +73,6 @@ static inline bool is_lpi(unsigned int irq) bool is_assignable_irq(unsigned int irq); =20 void init_IRQ(void); -void init_secondary_IRQ(void); =20 int route_irq_to_guest(struct domain *d, unsigned int virq, unsigned int irq, const char *devname); diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index b761d90c4063..56bdcb95335d 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -17,6 +17,7 @@ * GNU General Public License for more details. */ =20 +#include #include #include #include @@ -100,7 +101,7 @@ static int __init init_irq_data(void) return 0; } =20 -static int init_local_irq_data(void) +static int init_local_irq_data(unsigned int cpu) { int irq; =20 @@ -108,7 +109,7 @@ static int init_local_irq_data(void) =20 for ( irq =3D 0; irq < NR_LOCAL_IRQS; irq++ ) { - struct irq_desc *desc =3D irq_to_desc(irq); + struct irq_desc *desc =3D &per_cpu(local_irq_desc, cpu)[irq]; int rc =3D init_one_irq_desc(desc); =20 if ( rc ) @@ -131,6 +132,29 @@ static int init_local_irq_data(void) return 0; } =20 +static int cpu_callback(struct notifier_block *nfb, unsigned long action, + void *hcpu) +{ + unsigned long cpu =3D (unsigned long)hcpu; + int rc =3D 0; + + switch ( action ) + { + case CPU_UP_PREPARE: + rc =3D init_local_irq_data(cpu); + if ( rc ) + printk(XENLOG_ERR "Unable to allocate local IRQ for CPU%lu\n", + cpu); + break; + } + + return !rc ? NOTIFY_DONE : notifier_from_errno(rc); +} + +static struct notifier_block cpu_nfb =3D { + .notifier_call =3D cpu_callback, +}; + void __init init_IRQ(void) { int irq; @@ -140,13 +164,10 @@ void __init init_IRQ(void) local_irqs_type[irq] =3D IRQ_TYPE_INVALID; spin_unlock(&local_irqs_type_lock); =20 - BUG_ON(init_local_irq_data() < 0); + BUG_ON(init_local_irq_data(smp_processor_id()) < 0); BUG_ON(init_irq_data() < 0); -} =20 -void init_secondary_IRQ(void) -{ - BUG_ON(init_local_irq_data() < 0); + register_cpu_notifier(&cpu_nfb); } =20 static inline struct irq_guest *irq_get_guest_info(struct irq_desc *desc) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 9bb32a301a70..4888bcd78a5a 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -359,8 +359,6 @@ void start_secondary(void) =20 gic_init_secondary_cpu(); =20 - init_secondary_IRQ(); - set_current(idle_vcpu[cpuid]); =20 setup_cpu_sibling_map(cpuid); --=20 2.32.0