From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.150 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391136; b=Ws4mH/lDrDa/hCel7m7x5Sj4DGeiVGKWhBYSJZUZU5dK4fjEp6Pe0RZqOd+T2g85N/wi 7Fj84G6bq/Fzn29+UT1ibI7gQepSFZCAxw1feXbeNUQmcYszw75EQPq+b/CLoQMj+DtSt VmudGA7RucLznL1EoYh92vLwuXRhnVls/tfL9SCVnFcjKH2tcvAJl1wC2BPLJJ9KDweui RjFlAOFy1r+xX7p2fpPO/03CNkA6zeLBL22t+kjagwuTVkRBiyatDQqCJF5KL72ep+ro2 9kPIuUOtDps4HNh7TnPdwp4ADRZ9SRz8qbYwN7f+VW4d1EUQEtyHuHt7I+c0alyP3kg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391136; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=NEmK6xpeVejGBUY1VDw3LjXagtBvEQYj0PNxBUJET3M=; b=vhCsXXMnJsTaBlcJ582mMYHd2D3XbDa3JyWtyws6Agk8JwILGiRr5cApuCP/sw2MISQ9 X3Y9Y+fR5P74H8TkkJWcO68dzlW1ASUr1z0SuPqUYv8bw1OHFI+CSJPB/ZOKXHUMp6wZt kwuRRTH5lvmMmcMStlwXROMa7kI4vS3eMtTXHEqrKqtkzo3zzHVh9exqu0+qBDURhcRN5 WFTfbNVQCGP+MI+G+Kzv42OP6057ZxddqujwRmjF0xuASVyg9QmqXLq8lyWGGo6RoZOfT zvlD6CAkF80wqvCRNhfUnHzj1o6WX261zvmeOJPDcZxeBkGG70qRLfoEPjqSMkhShKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FUQCmdL8; arc=none smtp.remote-ip=95.215.58.150 Received: from mta1.migadu.com (out-150.mta1.migadu.com [95.215.58.150]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88AEE606A32C for ; Fri, 4 Dec 2026 13:32:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88AEE606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FUQCmdL8 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Ceusz8JwpKd5jIA05Y3ZMdjW0UxMGrdHfsSRID9OEdk=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796391133; v=1; x=1796995933; b=FUQCmdL8q5fgUdYnPgiV8StyIVV9W8Gvd0NrXPfiRqlp32u3Z+R1MtibghHV7ZBvaYqaln11 Gi05lv85O1NALPnVOCQY7wbGll0AR5ChnA6w2iw2+7guu2CTlhJB8l0ruzkO6kNCFeWuQxeK1rt nYlvs+zrrwdVQEZOtjTAondA= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 29b0a22ca122607b; Fri, 04 Dec 2026 13:32:13 +0000 X-Mizu-Trace-ID: 29b0a22ca122607b 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 5/6] irqchip/riscv-imsic: Support IOMMU MSI address lists Date: Fri, 4 Dec 2026 14:31:05 +0100 Message-ID: <20261204133106.664239-6-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrew Jones RISC-V IOMMU host interrupt remapping maps every possible host IMSIC target into one contiguous IOVA range. MSI message composition therefore needs each target's position within that range. Prepare the complete IMSIC address list while allocating an IRQ. The list is guaranteed to exist after IMSIC state initialization. The IOMMU backend maps the pages and caches the contiguous base IOVA in the MSI descriptor when translation is needed. Compose messages with msi_msg_set_addr_iova_offset(), using the selected logical CPU directly as the page index within the IOVA range. Use the same path for initial composition and affinity updates. The helper also covers messages that need no translation, so it replaces setting address_hi/lo directly. Signed-off-by: Andrew Jones Signed-off-by: Andrew Jones Tested-by: Fangyu Yu Acked-by: Thomas Gleixner Reviewed-by: Nutty Liu Reviewed-by: Anup Patel Acked-by: Anup Patel --- drivers/irqchip/Kconfig | 1 + drivers/irqchip/irq-riscv-imsic-platform.c | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index ca915fca0ef5..f976c312ad94 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -653,6 +653,7 @@ config RISCV_IMSIC select IRQ_DOMAIN_HIERARCHY select GENERIC_IRQ_MATRIX_ALLOCATOR select GENERIC_MSI_IRQ + select IRQ_MSI_IOMMU select IRQ_MSI_LIB config RISCV_RPMI_SYSMSI diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index 5f72b2a80887..f424a04a03c5 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -69,7 +70,8 @@ static void imsic_irq_ack(struct irq_data *d) irq_move_irq(d); } -static void imsic_irq_compose_vector_msg(struct imsic_vector *vec, struct msi_msg *msg) +static void imsic_irq_compose_vector_msg(struct irq_data *d, struct imsic_vector *vec, + struct msi_msg *msg) { phys_addr_t msi_addr; @@ -79,14 +81,14 @@ static void imsic_irq_compose_vector_msg(struct imsic_vector *vec, struct msi_ms if (WARN_ON(!imsic_cpu_page_phys(vec->cpu, 0, &msi_addr))) return; - msg->address_hi = upper_32_bits(msi_addr); - msg->address_lo = lower_32_bits(msi_addr); + msi_msg_set_addr_iova_offset(irq_data_get_msi_desc(d), msg, msi_addr, + (u64)vec->cpu * IMSIC_MMIO_PAGE_SZ); msg->data = vec->local_id; } static void imsic_irq_compose_msg(struct irq_data *d, struct msi_msg *msg) { - imsic_irq_compose_vector_msg(irq_data_get_irq_chip_data(d), msg); + imsic_irq_compose_vector_msg(d, irq_data_get_irq_chip_data(d), msg); } #ifdef CONFIG_SMP @@ -94,7 +96,7 @@ static void imsic_msi_update_msg(struct irq_data *d, struct imsic_vector *vec) { struct msi_msg msg = { }; - imsic_irq_compose_vector_msg(vec, &msg); + imsic_irq_compose_vector_msg(d, vec, &msg); irq_data_get_irq_chip(d)->irq_write_msi_msg(d, &msg); } @@ -225,7 +227,9 @@ static struct irq_chip imsic_irq_base_chip = { static int imsic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs, void *args) { + msi_alloc_info_t *info = args; struct imsic_vector *vec; + int ret; /* Multi-MSI is not supported yet. */ if (nr_irqs > 1) @@ -235,6 +239,13 @@ static int imsic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, if (!vec) return -ENOSPC; + ret = iommu_dma_prepare_msi_list(info->desc, imsic->msi_pa_list, + num_possible_cpus(), IMSIC_MMIO_PAGE_SZ); + if (ret) { + imsic_vector_free(vec); + return ret; + } + irq_domain_set_info(domain, virq, virq, &imsic_irq_base_chip, vec, handle_edge_irq, NULL, NULL); irq_set_noprobe(virq); -- 2.56.1