From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81B58606A322 for ; Fri, 4 Dec 2026 13:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=AZAnQ2Ua; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WAO9ZOOp DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=J1s6Grr78XedCyrRv8/Es+NhiuYGhnZqmD3l0gJnURQ=; b=AZAnQ2UaH87x/U8hW4e5Wj4mgQ m0/VPGGGYzkc7X26gApXgVz2yZCbrkOPw19e0Hf/8JYnnFTLmrbhONiuh4WBF27a3RYjlwnYNEsNH /RSWcc8SowlSmc0vkKClCmmd+8PqmU9VSjHDrYpSMNbagJdYuoS6ienbt93P8NLFUleWziEL+Y+iP y4Knzxlxz++k1d24fDMKQR0XigodC2iPTWs5aB6UVa2HqQSnt08iyRPrXliC9FeCOAWL8loIavs+O BnOc7+ef9GNh5Td+w2i4Gi1B9mLYHFQMo0MLS7EU0TIKaGgFSdImEWBtpcn26LO/zlq5sRlO2jHtq bfAHEDaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZTOX-00000000PTs-0mMc; Fri, 04 Dec 2026 13:32:13 +0000 Received: from out-159.mta1.migadu.com ([2001:41d0:203:375::9f] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZTOR-00000000PPT-344U for linux-riscv@lists.infradead.org; Fri, 04 Dec 2026 13:32:12 +0000 X-Envelope-To: linux-riscv@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=qIh4qMXDDuSlIjoPqW/XyqiJYrgIi0/AbvFxWIq49Ec=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796391125; v=1; x=1796995925; b=WAO9ZOOpPUjJm63qm+pVUJLZ9IthR3AaI1sm1Ard/Li5GYv8p4GbwEyuarKVgWD2jRMNKQuI s6znC3cVDodyuH9BWUYZLwqlGi/fSlou8ox70xWDXern/EyN4x1XLSXsSZ9MxvwGAcVzOvHaq0c 4blNPlxpEX9nOL/AUmNFwdog= X-Envelope-To: linux-riscv@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id 41accc017713ec38; Fri, 04 Dec 2026 13:32:05 +0000 X-Mizu-Trace-ID: 41accc017713ec38 X-Migadu-Flow: FLOW_OUT From: Andrew Jones To: linux-riscv@lists.infradead.org, iommu@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tomasz.jeznach@linux.dev, jgg@ziepe.ca, jgg@nvidia.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, pjw@kernel.org, palmer@dabbelt.com, anup@brainfault.org, tglx@kernel.org, kevin.tian@intel.com, fangyu.yu@linux.alibaba.com, nutty.liu@hotmail.com Subject: [PATCH v8 2/6] iommu/dma: Introduce iommu_dma_prepare_msi_list() Date: Fri, 4 Dec 2026 14:31:02 +0100 Message-ID: <20261204133106.664239-3-andrew.jones@linux.dev> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204133106.664239-1-andrew.jones@linux.dev> References: <20261204133106.664239-1-andrew.jones@linux.dev> X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_053210_876863_4192945F X-CRM114-Status: GOOD ( 13.17 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 IMSIC needs an interface to prepare all MSI targets before an IRQ affinity change can select one in atomic context. Signed-off-by: Andrew Jones Signed-off-by: Andrew Jones Reviewed-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/iommu.h | 9 +++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2dbf691dfb58..a655f575731b 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -4304,4 +4304,47 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr) mutex_unlock(&group->mutex); return ret; } + +/** + * iommu_dma_prepare_msi_list() - Map the complete list of MSI targets + * @desc: MSI descriptor to receive the base IOVA and granule shift + * @phys_addrs: Ordered array of target physical addresses + * @nr_addrs: Number of targets in the array + * @granule: Size and alignment of each target mapping + * + * Every call for a DMA domain must supply the same complete list, order and + * granule. The first call maps the targets into one contiguous IOVA range; + * subsequent calls use the cached base. The array is consumed synchronously + * and is not retained. + * + * Each target must be aligned to @granule, which must match the DMA domain's + * granule and be at least PAGE_SIZE. + * + * Without a translated domain, @desc is left unchanged. Only DMA-IOMMU + * domains currently support translated MSI target lists. + * + * Return: 0 on success, or a negative error code on failure. + */ +int iommu_dma_prepare_msi_list(struct msi_desc *desc, const phys_addr_t *phys_addrs, + unsigned int nr_addrs, size_t granule) +{ + struct device *dev = msi_desc_to_dev(desc); + struct iommu_group *group = dev->iommu_group; + struct iommu_domain *domain; + int ret; + + if (!group) + return 0; + + ret = iommu_deferred_attach(dev, iommu_get_domain_for_dev(dev)); + if (ret) + return ret; + + guard(mutex)(&group->mutex); + domain = group->domain; + if (!domain || domain->type == IOMMU_DOMAIN_IDENTITY) + return 0; + + return iommu_dma_sw_msi_list(domain, desc, phys_addrs, nr_addrs, granule); +} #endif /* CONFIG_IRQ_MSI_IOMMU */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ef5043752a36..aa26cb477ef5 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1562,12 +1562,21 @@ static inline void pci_dev_reset_iommu_done(struct pci_dev *pdev) #ifdef CONFIG_IRQ_MSI_IOMMU #ifdef CONFIG_IOMMU_API int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr); +int iommu_dma_prepare_msi_list(struct msi_desc *desc, const phys_addr_t *phys_addrs, + unsigned int nr_addrs, size_t granule); #else static inline int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr) { return 0; } + +static inline int iommu_dma_prepare_msi_list(struct msi_desc *desc, + const phys_addr_t *phys_addrs, + unsigned int nr_addrs, size_t granule) +{ + return 0; +} #endif /* CONFIG_IOMMU_API */ #endif /* CONFIG_IRQ_MSI_IOMMU */ -- 2.56.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv