Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp968991lqs; Fri, 14 Jun 2024 10:36:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCo8NiGQQnuzuoG0jaGy92zFsjbiMdjrUbxBa0qzN8lXxxyZMkXOxnsicRNNIfNh0Ls97PIFoxzqMfszbD0eQk1PfUhAiAiNWbglI1lQ== X-Google-Smtp-Source: AGHT+IHVjSNncXiVfgKDnfxqm60rlZyq/isTVTzOPjpOlYYVwuphALE/jmu1HvDBoNAHu5/DJkLM X-Received: by 2002:a17:906:6a91:b0:a6f:1ad5:20e0 with SMTP id a640c23a62f3a-a6f60d42874mr209472366b.45.1718386586906; Fri, 14 Jun 2024 10:36:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718386586; cv=pass; d=google.com; s=arc-20160816; b=jpC5EF4+hy9yCkHtpwZsE9jj5V8aX3KsRpS+1yIEQAqU7Tx5etAfGXg0/v5AcedvPt DHZ0xWNHlogMH5+2SmytPpYt2BMV7XfaTOVxzbjMHuVc0XLi+2UuezOK75973bU85J0c 9WEva/aoG33KjliNdj/4CfSYJJo1xOWZ2h57ViWFsvluHcE8UF+ZC83mTnaYOknE+b44 PJcPxKPIVMis1AxCgLgQ/oxGHrQcRJaO18Z5oqir8ThXS/TT8gxtf/wOs+QLQMoE8fdj emWwDvfoXu4O58w55sZY9/Z2Jjoolc7ylCK0zASz4xWHV9+k9HSQTWmgkS8vYe4V0bU/ C2ZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bCrIqBOqgd8IhI1XvRqpnH65nvLXt6DnzPIXbQl0ooU=; fh=bujJSrd+k1h/0aZbC1LeFD2/cY2NpcCgJFppOaBslqM=; b=Wu6Vt5xo55ddeFOXmESbYNhPQgbZu52oYqHeZbxlqDWQK3BgbVsyEK/SduN5/26GLf OjGATZufOrfroEO9fK+bVVxeYZtTaG19nGKvFpemGbkx6oF1T14Cdq6KGr2B5dP6NNnO u+J49Myd66yoaA41WpjIPc2BC5NenTFoHuAekM031UCzB/7ahY5R45ZvHf1FvvtfDZZD f04MEHQ36tYMcq9NfTjtsulEXRCm4MPvyORiKGErYYd3IzEkFm2EK7SQoMgC49Tod0xP v1Puor/EBYph+FliP03gkUOECBLAb8lUnFlOFYD8HZYMc/LwGhTd1eUDn1cIU+TJG1D6 bYOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lKjvYVPR; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-215373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d21ba7si192236666b.38.2024.06.14.10.36.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 10:36:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lKjvYVPR; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-215373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com 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 80E5C1F23CAA for ; Fri, 14 Jun 2024 17:36:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04BC11AD9E6; Fri, 14 Jun 2024 17:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="lKjvYVPR" Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 CA04D1AB8E1; Fri, 14 Jun 2024 17:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718386380; cv=none; b=YHjsdDXya0YexV/fESHeB/osYm9/s+/VhvWCGO5KysaliHNME+MU911LADHhBdOwAdU6BGYjZOazxRdU9CabXQJmzuWLXAqOEgxD1I75cXpmkznX6uo1gVt4sJTQjblO4Ii3lP5+pCa1ihOrrorKY3kdm1LC73kay3z503+P5Co= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718386380; c=relaxed/simple; bh=3/cVlx907MzcG9vrQ3DE0pKe7Qu2ZlekB/sarfJHvP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ard8EhuXeZAT80Syc27U5u34DV8CMIc/LgpQnBYpDgnXQOpVwgOiggNhY4CZX4IJJ3t73Ioq+Jvi8iTbJ7ZQh7fR4lVEbnhO7rAiIYbNdXtaO2XKjPkalbaYP6IKEYONnyVBxhpg90i8vkqXFOuMzu0oyuPz/S68CPDC6/2r/cg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=lKjvYVPR; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 97823FF805; Fri, 14 Jun 2024 17:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718386376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bCrIqBOqgd8IhI1XvRqpnH65nvLXt6DnzPIXbQl0ooU=; b=lKjvYVPRbwgWGiXtVyYKgzayJgQnlEq99TCZ2S90A2zRcZKPLUMG57o2C+Bqs3YVLxQ75b v+mbvSRxvEw60jOeDANphC7wTr/NggD0ZQaLgOdLB7V2PRg4OoueEPT44gRJ4xpam0WoP6 BzIuaxb8+IZ0T4rV4St3oiO1tpkW8YbOH+if7Jrj0qK3AgM7PeU76pb9Tz44jySjHBnBbp Ew+xB06m7amr/lpmIqo4yWNv/TLS+T4ru/C1bPNW0mEPdslWQFgO1IDzmruDmQ0BeSeu9i /a3z35N9d0ECq9wDzBOBAWMtVxq7jI0cx/nLbt9Zd7LBHpejcrS3PdBgZ+4vEA== From: Herve Codina To: Matti Vaittinen , Herve Codina , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Richard Weinberger , Anton Ivanov , Johannes Berg , Marc Zyngier Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-um@lists.infradead.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Subject: [PATCH 12/23] irqdomain: Introduce init() and exit() hooks Date: Fri, 14 Jun 2024 19:32:13 +0200 Message-ID: <20240614173232.1184015-13-herve.codina@bootlin.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240614173232.1184015-1-herve.codina@bootlin.com> References: <20240614173232.1184015-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com The current API does not allow additional initialization before the domain is published. This can lead to a race condition between consumers and supplier as a domain can be available for consumers before being fully ready. Introduce the init() hook to allow additional initialization before plublishing the domain. Also introduce the exit() hook to revert operations done in init() on domain removal. Suggested-by: Thomas Gleixner Signed-off-by: Herve Codina --- include/linux/irqdomain.h | 8 ++++++++ kernel/irq/irqdomain.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index 52bed23e5c61..2c927edc4d43 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -141,6 +141,7 @@ struct irq_domain_chip_generic; * purposes related to the irq domain. * @parent: Pointer to parent irq_domain to support hierarchy irq_domains * @msi_parent_ops: Pointer to MSI parent domain methods for per device domain init + * @exit: Function called when the domain is destroyed * * Revmap data, used internally by the irq domain code: * @revmap_size: Size of the linear map table @revmap[] @@ -169,6 +170,7 @@ struct irq_domain { #ifdef CONFIG_GENERIC_MSI_IRQ const struct msi_parent_ops *msi_parent_ops; #endif + void (*exit)(struct irq_domain *d); /* reverse map data. The linear map gets appended to the irq_domain */ irq_hw_number_t hwirq_max; @@ -268,6 +270,10 @@ void irq_domain_free_fwnode(struct fwnode_handle *fwnode); * @bus_token: Domain bus token * @ops: Domain operation callbacks * @host_data: Controller private data pointer + * @init: Function called when the domain is created. + * Allow to do some additional domain initialisation. + * @exit: Function called when the domain is destroyed. + * Allow to do some additional cleanup operation. */ struct irq_domain_info { struct fwnode_handle *fwnode; @@ -284,6 +290,8 @@ struct irq_domain_info { */ struct irq_domain *parent; #endif + int (*init)(struct irq_domain *d); + void (*exit)(struct irq_domain *d); }; struct irq_domain *irq_domain_instantiate(const struct irq_domain_info *info); diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index d05aeb9c0a67..9efc9f180308 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -276,12 +276,14 @@ static void irq_domain_free(struct irq_domain *domain) struct irq_domain *irq_domain_instantiate(const struct irq_domain_info *info) { struct irq_domain *domain; + int err; domain = __irq_domain_create(info); if (IS_ERR(domain)) return ERR_CAST(domain); domain->flags |= info->domain_flags; + domain->exit = info->exit; #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY if (info->parent) { @@ -290,9 +292,19 @@ struct irq_domain *irq_domain_instantiate(const struct irq_domain_info *info) } #endif + if (info->init) { + err = info->init(domain); + if (err) + goto err_domain_free; + } + __irq_domain_publish(domain); return domain; + +err_domain_free: + irq_domain_free(domain); + return ERR_PTR(err); } EXPORT_SYMBOL_GPL(irq_domain_instantiate); @@ -339,6 +351,9 @@ EXPORT_SYMBOL_GPL(__irq_domain_add); */ void irq_domain_remove(struct irq_domain *domain) { + if (domain->exit) + domain->exit(domain); + mutex_lock(&irq_domain_mutex); debugfs_remove_domain_dir(domain); -- 2.45.0