From patchwork Wed Jan 24 18:35:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 191702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1181126dyi; Wed, 24 Jan 2024 10:36:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR2VzoDMZ9gU2k9rbMxvsXQPfjPZWhowPI+tqCZEXVHleqpDyhcRxVBxjIh3UcodUmHXIP X-Received: by 2002:a17:906:dcc:b0:a28:ccb4:6ba7 with SMTP id p12-20020a1709060dcc00b00a28ccb46ba7mr1225594eji.11.1706121397553; Wed, 24 Jan 2024 10:36:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706121397; cv=pass; d=google.com; s=arc-20160816; b=ab4np95PN+0aMNfSOKYrVGkMi9vBmAeLtY0Xcb6vhy6/VlW+nO9zgCeNXgtmYw0WpD tKUAbNvlz8FYVSJatSe7i+q+rt/vPtQ/JCYJjxHhilxnKMpOCctf7UBRhYM8bVH9/E+C RpJvO0YGi8jn8v1LHk8Mo+DcglPQ/jfrDjO4B7vriZl0XLHRED5DwUFu81As1XGkA5Ct r/UvcFsUXZ72auZ22dvcw7umn68ivK8/Wp+uqBKtGtpaHqGw8xgBmwLPmkzyaHD5UIWX WTE60mE13qCjtY0By9GKDxHwHNLchwS7suSKDZTX6zf8OQJ3WDIwU1f8sLR2DzDXoa1p o0lA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=GtrpXp7xwnV1UvsaxL3kfgcJ7wx4/zEhZg0ZY1Ln2H8=; fh=lNXBS+XdlarCa0MBkXw73xjWX+t52NzM7Ews0ZFpZmc=; b=z65EeTxERUdzfyT8tfjoD4ejBMAic+yrnVtfsiIn3ccp6dXCMwefS/X6uBuao61Ayf bXWxAZ4khGirzhE1HKU79ESZwllWpe8yIamMDxoiQ6KKok9aliRr6a/qGM5d4yeLcxY1 Wx06xJLdsN0cC49EDs+7osRLglKijsnGSE/mqav+dcdHco9onb8GpXIu3Rl8yI0cBit0 Ul5etaXyuNY1sY+8U0HMIb7U7LYcSJyLDrfgzDQlw16w9R5/WyK8tiMBPm7roBqDv1J+ aS+5MTZVk5e+Ms5iJCepqcG5w21PzsWipDzinNAsodv9s32pysMBwfrPXm2EM6agPYi3 iZUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="aIu/V8TM"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-37518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jo14-20020a170906f6ce00b00a2d4062fbcesi115589ejb.989.2024.01.24.10.36.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:36:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="aIu/V8TM"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-37518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D5E6E1F25D4B for ; Wed, 24 Jan 2024 18:36:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3BE8132C14; Wed, 24 Jan 2024 18:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aIu/V8TM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fvVO/WWK" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82038131732; Wed, 24 Jan 2024 18:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706121323; cv=none; b=suL2bmAFJLOyywArXoZD8tKmKjTN8SU+TZ/Jow/qRd+7gGUSoubFwt//UndZgq5xtRHsLk4qf5eK5m3SLPTJidz1Ccxh9a+UhxbX3Ba5UP3I7qkNVE4vrl3I6XCQJY63HExq9G6xxluU3fz21NPyiHAsvy55F0LJ/gXEKqh3gI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706121323; c=relaxed/simple; bh=Np2VXXMYurtq5ntQ06E6I5v2cBffeVZzwXfVzOK6rbA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=LTBh7tzgnJsuGzI8Hdw1C5UDjiTX4qMYWjQr3LU6LymU4vj1XHWL+yMZF6ohgvjOghMRjwjItAFaABXdMZJmVFz3XK1NQ+8sXbQgXmuwJMlk47SGnxPSpqSBVGl2GENfUZsEKC/FoFpBnfISAkJndFv7j+NfrwbMfMrTKgf99yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aIu/V8TM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fvVO/WWK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 24 Jan 2024 18:35:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706121319; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GtrpXp7xwnV1UvsaxL3kfgcJ7wx4/zEhZg0ZY1Ln2H8=; b=aIu/V8TMRfd/fw9vm+VNpTX2s88zo8c3eirh3ZTBFmdprRZbSf0p7u5TQe3r/Thxq7yMG2 n4RqWJk4VEIP63MGJAmeVr1GIYksHj6A0ssRmxZylHMAen8uTPQVZCSHqF1ElJPe0jV7nJ mDsSKU+QOh7aeQ5KOdQmr1Iwyv8+b9BYXy+5Xa4tXbeonCmVGoipEtIa35awmv2wPHUzTz MWaB90OTMETxCnQ702FbEr1K7pAJUadq8Ih4+2OpgPqCxiAniTx25imuLvd5Qx7jX21DEH kbGcQg8eSHqnypX8XuY8U0CPDBrbQFmLLOwGqw5MxXB5HqdvXzGAQ1bGKFco0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706121319; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GtrpXp7xwnV1UvsaxL3kfgcJ7wx4/zEhZg0ZY1Ln2H8=; b=fvVO/WWKRwttljesfF5Mh6mzNx5UZ8iYlWfIGUJuwszJcIUCauTngNOgiGKp4Me0aGLOzF fvpcIz8SosLnQcAw== From: "tip-bot2 for Dawei Li" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] genirq: Deduplicate interrupt descriptor initialization Cc: Marc Zyngier , Dawei Li , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240122085716.2999875-6-dawei.li@shingroup.cn> References: <20240122085716.2999875-6-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170612131798.398.11050796782414301853.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788997950404318216 X-GMAIL-MSGID: 1788997950404318216 The following commit has been merged into the irq/core branch of tip: Commit-ID: 22653244a9fed06f2f864b44808a85bf5c4e3ef2 Gitweb: https://git.kernel.org/tip/22653244a9fed06f2f864b44808a85bf5c4e3ef2 Author: Dawei Li AuthorDate: Mon, 22 Jan 2024 16:57:16 +08:00 Committer: Thomas Gleixner CommitterDate: Wed, 24 Jan 2024 16:02:48 +01:00 genirq: Deduplicate interrupt descriptor initialization alloc_desc() and early_irq_init() contain duplicated code to initialize interrupt descriptors. Replace that with a helper function. Suggested-by: Marc Zyngier Signed-off-by: Dawei Li Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240122085716.2999875-6-dawei.li@shingroup.cn --- kernel/irq/irqdesc.c | 112 ++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 371eb17..4c6b323 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -92,11 +92,23 @@ static void desc_smp_init(struct irq_desc *desc, int node, #endif } +static void free_masks(struct irq_desc *desc) +{ +#ifdef CONFIG_GENERIC_PENDING_IRQ + free_cpumask_var(desc->pending_mask); +#endif + free_cpumask_var(desc->irq_common_data.affinity); +#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK + free_cpumask_var(desc->irq_common_data.effective_affinity); +#endif +} + #else static inline int alloc_masks(struct irq_desc *desc, int node) { return 0; } static inline void desc_smp_init(struct irq_desc *desc, int node, const struct cpumask *affinity) { } +static inline void free_masks(struct irq_desc *desc) { } #endif static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node, @@ -166,6 +178,39 @@ static void delete_irq_desc(unsigned int irq) } #ifdef CONFIG_SPARSE_IRQ +static const struct kobj_type irq_kobj_type; +#endif + +static int init_desc(struct irq_desc *desc, int irq, int node, + unsigned int flags, + const struct cpumask *affinity, + struct module *owner) +{ + desc->kstat_irqs = alloc_percpu(unsigned int); + if (!desc->kstat_irqs) + return -ENOMEM; + + if (alloc_masks(desc, node)) { + free_percpu(desc->kstat_irqs); + return -ENOMEM; + } + + raw_spin_lock_init(&desc->lock); + lockdep_set_class(&desc->lock, &irq_desc_lock_class); + mutex_init(&desc->request_mutex); + init_waitqueue_head(&desc->wait_for_threads); + desc_set_defaults(irq, desc, node, affinity, owner); + irqd_set(&desc->irq_data, flags); + irq_resend_init(desc); +#ifdef CONFIG_SPARSE_IRQ + kobject_init(&desc->kobj, &irq_kobj_type); + init_rcu_head(&desc->rcu); +#endif + + return 0; +} + +#ifdef CONFIG_SPARSE_IRQ static void irq_kobj_release(struct kobject *kobj); @@ -384,21 +429,6 @@ struct irq_desc *irq_to_desc(unsigned int irq) EXPORT_SYMBOL_GPL(irq_to_desc); #endif -#ifdef CONFIG_SMP -static void free_masks(struct irq_desc *desc) -{ -#ifdef CONFIG_GENERIC_PENDING_IRQ - free_cpumask_var(desc->pending_mask); -#endif - free_cpumask_var(desc->irq_common_data.affinity); -#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK - free_cpumask_var(desc->irq_common_data.effective_affinity); -#endif -} -#else -static inline void free_masks(struct irq_desc *desc) { } -#endif - void irq_lock_sparse(void) { mutex_lock(&sparse_irq_lock); @@ -414,36 +444,19 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags, struct module *owner) { struct irq_desc *desc; + int ret; desc = kzalloc_node(sizeof(*desc), GFP_KERNEL, node); if (!desc) return NULL; - /* allocate based on nr_cpu_ids */ - desc->kstat_irqs = alloc_percpu(unsigned int); - if (!desc->kstat_irqs) - goto err_desc; - - if (alloc_masks(desc, node)) - goto err_kstat; - raw_spin_lock_init(&desc->lock); - lockdep_set_class(&desc->lock, &irq_desc_lock_class); - mutex_init(&desc->request_mutex); - init_rcu_head(&desc->rcu); - init_waitqueue_head(&desc->wait_for_threads); - - desc_set_defaults(irq, desc, node, affinity, owner); - irqd_set(&desc->irq_data, flags); - kobject_init(&desc->kobj, &irq_kobj_type); - irq_resend_init(desc); + ret = init_desc(desc, irq, node, flags, affinity, owner); + if (unlikely(ret)) { + kfree(desc); + return NULL; + } return desc; - -err_kstat: - free_percpu(desc->kstat_irqs); -err_desc: - kfree(desc); - return NULL; } static void irq_kobj_release(struct kobject *kobj) @@ -583,26 +596,29 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { int __init early_irq_init(void) { int count, i, node = first_online_node; - struct irq_desc *desc; + int ret; init_irq_default_affinity(); printk(KERN_INFO "NR_IRQS: %d\n", NR_IRQS); - desc = irq_desc; count = ARRAY_SIZE(irq_desc); for (i = 0; i < count; i++) { - desc[i].kstat_irqs = alloc_percpu(unsigned int); - alloc_masks(&desc[i], node); - raw_spin_lock_init(&desc[i].lock); - lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); - mutex_init(&desc[i].request_mutex); - init_waitqueue_head(&desc[i].wait_for_threads); - desc_set_defaults(i, &desc[i], node, NULL, NULL); - irq_resend_init(&desc[i]); + ret = init_desc(irq_desc + i, i, node, 0, NULL, NULL); + if (unlikely(ret)) + goto __free_desc_res; } + return arch_early_irq_init(); + +__free_desc_res: + while (--i >= 0) { + free_masks(irq_desc + i); + free_percpu(irq_desc[i].kstat_irqs); + } + + return ret; } struct irq_desc *irq_to_desc(unsigned int irq)