From patchwork Fri Nov 11 13:56:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 18808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp757058wru; Fri, 11 Nov 2022 06:04:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7aO+J5gfT7Vz2nWVi6Iook9O0XxFt1sv+d8BIpxDZcFmxBTOcAsikoyhczlgCm6fzbJNdG X-Received: by 2002:a17:902:b7c3:b0:186:c372:8e09 with SMTP id v3-20020a170902b7c300b00186c3728e09mr2764486plz.74.1668175447902; Fri, 11 Nov 2022 06:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668175447; cv=none; d=google.com; s=arc-20160816; b=Q7iFSBNHqV0vdqOWNCFQeMaSgwdzxB3ViOLfUdhpxpmFwZvpIcOyb2rzapDQGPM4DJ a7R3Mu28fZEG2tIwJbpYxhfz2jbFXGnB6a5AkGw1h2ka73pW9TzXGpvB+mZNjk2/eNft zKyVN3DZg9kWSvJnnNnmCyxXRevxMwWA1RYIxggKwGRcxbgdGBvPDLQEK7sIekbgVfcv vaXLiA1NDZyIsO23oOZ6WNTaSCWSYz3nbrwP2LvdRwuQPPaypTRoJ6o20EkVMUrSz3qF LfqZfm/5+FDiT+cVNTCcFVyttXo3YfyclwYDFwZZkG/kR0zyBA4SWvQ4+WZQAruFKrxJ OqIA== 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=8VY0WlPNbaPO/N862hvT4P/0JGamuqTySDiEq2psBhM=; b=lEMLpzF0s/rrPeA2cUFQep3L3EBL93NgWYb87791FPcSLUnYbezSGUNpOJdsxcfP8d hRYQWuva9/U90jzkctn//ZKaBMRIvnGF5QIMyYlbQEEyPa/huwtSVUaM+ZRM03BcsBLN 2YvHVebvjIeBhSKWr4gdl49f2ALWcKgLIcZo3t5aCMdq0NHJOFPqmLBvviW66Q6qgf3P WGqWgxpPV/5wi539WA+ikKPuopIgvOSU/TvCQhm+qV9+4hQJ8HwM2JyKwIdTt2kMrL9F CmEZsZuTLktRns/V7R0B+Me9fSA8/YQdTQYVURCNceuFNOgxP/q33okUWXbhFZJfwdoG u0SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vQ3lgcgf; dkim=neutral (no key) header.i=@linutronix.de header.b=UgjpGjR3; 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 il12-20020a17090b164c00b00212f92957d5si8913920pjb.167.2022.11.11.06.03.21; Fri, 11 Nov 2022 06:04:07 -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=vQ3lgcgf; dkim=neutral (no key) header.i=@linutronix.de header.b=UgjpGjR3; 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 S234341AbiKKOCA (ORCPT + 99 others); Fri, 11 Nov 2022 09:02:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234167AbiKKOBM (ORCPT ); Fri, 11 Nov 2022 09:01:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4463845EE; Fri, 11 Nov 2022 05:56:56 -0800 (PST) Message-ID: <20221111132706.670241974@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668175015; 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=8VY0WlPNbaPO/N862hvT4P/0JGamuqTySDiEq2psBhM=; b=vQ3lgcgffVuzDcIPPmJPQzk3wBklFqvXva0o7ABF8VTKJH3XYL+oJzDyVFO4MIaPqme0ma tULBhHr4vHtCDZ2axZMydQUEC8XpXDnGSrZu6uEo9ro/IyiUC6A60K6YQd2QuNMXxsXalD Xf5Psro7OoQY/RkfQ/ePBoogH1qL9wUSQGHUhIabIcKmO15NlyXuNRAnPE91I5IFh0Efpi I2d9TQgQ5VOXou35y7xfcYR4MLo1OV7GRAyXEyx1TWnWkt8fYOlF5zR73G+Kd9Cug9F11y jJ5CJcEOUGkNvn/yYX+XZFbv4kthHrVncKJjYYErAkEdfEBr1I6F52ILfnYs5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668175015; 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=8VY0WlPNbaPO/N862hvT4P/0JGamuqTySDiEq2psBhM=; b=UgjpGjR3YALnEENedrFuTqyZjT9U+KlIu4668jQ4UNC9G62TNloZbk8cxOrd/XzsGE0tjy bujACfmPoZ0070Ag== 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 , "Ahmed S. Darwish" , Reinette Chatre Subject: [patch 11/20] genirq/msi: Make descriptor allocation device domain aware References: <20221111131813.914374272@linutronix.de> MIME-Version: 1.0 Date: Fri, 11 Nov 2022 14:56:54 +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?1749208738098395639?= X-GMAIL-MSGID: =?utf-8?q?1749208738098395639?= 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 | 15 ++++++++++++++- kernel/irq/msi.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 10 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -274,7 +274,20 @@ 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 domain + * @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,39 +88,58 @@ 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; lockdep_assert_held(&dev->msi.data->mutex); + if (WARN_ON_ONCE(init_desc->msi_index >= MSI_MAX_INDEX)) + return -EINVAL; + desc = msi_alloc_desc(dev, init_desc->nvec_used, init_desc->affinity); if (!desc) return -ENOMEM; /* 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 +162,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; } @@ -183,6 +202,9 @@ void msi_free_msi_descs_range(struct dev struct msi_desc *desc; unsigned long idx; + if (WARN_ON_ONCE(first_index >= MSI_MAX_INDEX || last_index >= MSI_MAX_INDEX)) + return; + lockdep_assert_held(&dev->msi.data->mutex); xa_for_each_range(xa, idx, desc, first_index, last_index) { @@ -779,6 +801,10 @@ int msi_domain_populate_irqs(struct irq_ struct msi_desc *desc; int ret, virq; + if (WARN_ON_ONCE(virq_base >= MSI_MAX_INDEX || + (virq_base + nvec) >= MSI_MAX_INDEX)) + return 0; + msi_lock_descs(dev); ret = msi_add_simple_msi_descs(dev, virq_base, nvec); if (ret)