From patchwork Mon Nov 21 14:36:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1626961wrr; Mon, 21 Nov 2022 06:38:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5M6Rs/AI7TXHGyQ3lXtAHQlC8J9CliD5SXMtgkT+1sXmsOdcTf5rJvxqs/1fQDp/c3IWiL X-Received: by 2002:a17:90a:4049:b0:210:5de0:f3e3 with SMTP id k9-20020a17090a404900b002105de0f3e3mr20459130pjg.61.1669041515247; Mon, 21 Nov 2022 06:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041515; cv=none; d=google.com; s=arc-20160816; b=aAsqP2WJV2Q0wM36WZNlh3u17rBWmrPa/ZLV/FpRg1wcS0CeOtu55QzozzFBK6R0aH n3tLLO0k2wF1NONFAwNT7X7VqmvbtO2GxJC8Gj11hvEF6zRL5uSo+/7eTGkK+mznA/fF 9UtM8wj0yrZW4GiH6JH7LvXjq3jSnf9Dea92PfOPoncjC7EtanjDiJm5kFKq6OQ1oQiL hu0blbqw/jc4YwTMcdADKVyQqatDZVvMn8pVZ0miptTERt6O/Uju4d/Lwj97CPhGqGgN Z3dBW6Aod7vDbr9mz9swb9z5aKYdQVQ9PH54LubKjmpPM50VEii4fAfiUefiOFFyYnTr EcYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=A5WJRb2/4teczUo5tLJ1BYRZTZjOFdwhWlgYTs4xkWo=; b=LjVtuNjO7kxSFB7jHxt9dH1oyoQsSp9DU+C3lV2NFOLF0H9F0vgdQP71ulNRtg2kJK vfSyLZEx8sWcGov6I18TGqc4TU+/oEWkECG2KS9XaaPJ+c0IcruvDOei3gKBAwnyRh6e TCgJyVnaJAw8su7ew72L5xNqHrLpW+N2P2WbiM0SDJelCdkVTNHt1jCKxC7YtVTG42/C N7tEg4/sVW+8zaS3cYydiKn8noms6JCqQHWzjYDoCoL/lq+1ClNSgGc3a9BQK4OUFF4p LH6I/a/8Bz4unXqAZD8/3xMwHOqtqJF//GKR3o57fjZo8U2h7aQgiaDfCR8Ub0uxQHsG Kw9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GqcsxI4U; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bP6WwDkZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w189-20020a6382c6000000b00477632e6011si2485055pgd.308.2022.11.21.06.38.18; Mon, 21 Nov 2022 06:38:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GqcsxI4U; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bP6WwDkZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230505AbiKUOhr (ORCPT + 99 others); Mon, 21 Nov 2022 09:37:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbiKUOgn (ORCPT ); Mon, 21 Nov 2022 09:36:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26229C72E2; Mon, 21 Nov 2022 06:36:35 -0800 (PST) Message-ID: <20221121083326.172418628@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=A5WJRb2/4teczUo5tLJ1BYRZTZjOFdwhWlgYTs4xkWo=; b=GqcsxI4UBE4uCcl41WHYFRRjiTlVU3Rty+qxgKvdKG2bvTdRbVKRURNgNxXS3TGRw6OyIV wUYQq5i4ItodyAogUXTBzcHuHa1MjHoY4Vvy3j7k/nQ1nXWD+UPs17Z5NYQ4vc8R3V+brM XCETZUE4KCPo8z7gsWMz7KQUMW9tyGTP8vDT69Ns+Qb/ViLa5SYzKf6HO1vcn7RXbuuW/V 1J0ybhVeHoSA5VwIAynQUeCYYPb8kPWET5qWThLRgWFbToHJBL/bv9dEEIGv+lZWANfQgi l1MIEgMHavoXdPPJ9C2QJuQu6ljOv2YdFDHz44AWHMgG9yIRjwyUIqpHmxfJMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=A5WJRb2/4teczUo5tLJ1BYRZTZjOFdwhWlgYTs4xkWo=; b=bP6WwDkZXkBORZ2Vav6whh5bDM9I958EHSnWwhNTHSuWRimb4swaIHfet++FUEnDbiovOk ldRkeQ3UG39FD4DA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 12/21] genirq/msi: Make descriptor allocation device domain aware References: <20221121083210.309161925@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:36:33 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750116876168477488?= X-GMAIL-MSGID: =?utf-8?q?1750116876168477488?= Change the descriptor allocation and insertion functions to take a domain id to prepare for the upcoming multi MSI domain per device support. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 16 +++++++++++++++- kernel/irq/msi.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 10 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -278,7 +278,21 @@ static inline void msi_desc_set_iommu_co } #endif -int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_desc); +int msi_domain_insert_msi_desc(struct device *dev, unsigned int domid, + struct msi_desc *init_desc); +/** + * msi_insert_msi_desc - Allocate and initialize a MSI descriptor in the + * default irqdomain and insert it at @init_desc->msi_index + * @dev: Pointer to the device for which the descriptor is allocated + * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor + * + * Return: 0 on success or an appropriate failure code. + */ +static inline int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_desc) +{ + return msi_domain_insert_msi_desc(dev, MSI_DEFAULT_DOMAIN, init_desc); +} + void msi_free_msi_descs_range(struct device *dev, unsigned int first_index, unsigned int last_index); /** --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -63,7 +63,7 @@ static int msi_get_domain_base_index(str * Return: pointer to allocated &msi_desc on success or %NULL on failure */ static struct msi_desc *msi_alloc_desc(struct device *dev, int nvec, - const struct irq_affinity_desc *affinity) + const struct irq_affinity_desc *affinity) { struct msi_desc *desc = kzalloc(sizeof(*desc), GFP_KERNEL); @@ -88,27 +88,42 @@ static void msi_free_desc(struct msi_des kfree(desc); } -static int msi_insert_desc(struct msi_device_data *md, struct msi_desc *desc, unsigned int index) +static int msi_insert_desc(struct device *dev, struct msi_desc *desc, + unsigned int domid, unsigned int index) { - int ret; + struct msi_device_data *md = dev->msi.data; + int baseidx, ret; + + baseidx = msi_get_domain_base_index(dev, domid); + if (baseidx < 0) { + ret = baseidx; + goto fail; + } desc->msi_index = index; + index += baseidx; ret = xa_insert(&md->__store, index, desc, GFP_KERNEL); if (ret) - msi_free_desc(desc); + goto fail; + return 0; + +fail: + msi_free_desc(desc); return ret; } /** - * msi_insert_msi_desc - Allocate and initialize a MSI descriptor and - * insert it at @init_desc->msi_index + * msi_domain_insert_msi_desc - Allocate and initialize a MSI descriptor and + * insert it at @init_desc->msi_index * * @dev: Pointer to the device for which the descriptor is allocated + * @domid: The id of the interrupt domain to which the desriptor is added * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor * * Return: 0 on success or an appropriate failure code. */ -int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_desc) +int msi_domain_insert_msi_desc(struct device *dev, unsigned int domid, + struct msi_desc *init_desc) { struct msi_desc *desc; @@ -120,7 +135,8 @@ int msi_insert_msi_desc(struct device *d /* Copy type specific data to the new descriptor. */ desc->pci = init_desc->pci; - return msi_insert_desc(dev->msi.data, desc, init_desc->msi_index); + + return msi_insert_desc(dev, desc, domid, init_desc->msi_index); } /** @@ -143,7 +159,7 @@ static int msi_add_simple_msi_descs(stru desc = msi_alloc_desc(dev, 1, NULL); if (!desc) goto fail_mem; - ret = msi_insert_desc(dev->msi.data, desc, idx); + ret = msi_insert_desc(dev, desc, MSI_DEFAULT_DOMAIN, idx); if (ret) goto fail; }