From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.228 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391133; b=MinE5qM0g4240tBLtE/oZ5JQ5elY3C1ThixA7JH203vryCVlJwQTUVvFEiU5UsPOMHyw MQjD1CdTRxrvJ5ujyXdqyEvUFfbYNdgpTLh/OochUsmCpfl4VjabaWIXlGFckEno6R5Ie Zdb3K8Hfu4+nJHi3o20CyTFhnqSHEmmkGXBlG/V0Yz0aFvb7Q5CW7Akektb8Sa9o3noRq 36Ah2+J7V0dIKKpUKk2BqwVDROpEfhtv1DEv+pjyphiPEi2wca0GRjXi8e218Qbb99RdK vKk2ymZTMT8osTssVXdaqw/lYCTzMCTAy+885rudWqRoZ4N1qKGt1YQKXbZr0ngX60A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391133; 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=azJw1fmxf/5SSXKmu3bwoLZITxOK9eR4n5oqSnmOgv8=; b=jWYRGpw8k8SjztLwyW7u3uEV5El1jlzM83CUcqe6XIqzbgd6xxfmWEj5abMs64B3Ukt9 bP1/gdOSfTcP6FRGGVIhhgwn3K0ZYo99bPes+H8iZV+5D9TS0mHbdtm+2L6sk66AlpBM/ YMzAxEWnm917z6aCeq9Gz2mKax2mfRrVanKvxXlXHbiVwS0AKVx5EnBzSnvxtR8ISyPIM tgg3gyyImYN/ae6W6hLKDe2+/VXT88Shhq1oIOmTnaf/Z6Kr1LOfVvgvxYNJc2CATBFjO gg8eBn42Im/cd4kF6ZL6uapEd+uMjoeRK/pfm7wzjqDwG5W6wDJUePwaR1LgByh+aBQ== 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=Jxp3EOGV; arc=none smtp.remote-ip=91.218.175.228 Received: from mta0.migadu.com (out-228.mta0.migadu.com [91.218.175.228]) (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 1AD41606A33D for ; Fri, 4 Dec 2026 13:32:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1AD41606A33D 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=Jxp3EOGV X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=uz6yJZIwBgzm/JRLfFIpz+5kxqpZweNtDmpWA2ZAxe4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796391131; v=1; x=1796995931; b=Jxp3EOGVu5W3uZ1fCRdL8RUl6CSvYZfnWoS+35Zds8+GPhMPFmnmBVQFCFMu+iviBVXyusZX nKe0SJ7iGYS94gJNeM7Dm8lP+UiQW5RuU4NqKRByYd2e5hF018ZI6W64HoaKqr2WXAl7iG57RMp kOTIfH290+i0hsaaZgm2TSvk= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 77db7664d06296a8; Fri, 04 Dec 2026 13:32:11 +0000 X-Mizu-Trace-ID: 77db7664d06296a8 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 4/6] irqchip/riscv-imsic: Add MSI address list Date: Fri, 4 Dec 2026 14:31:04 +0100 Message-ID: <20261204133106.664239-5-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 Upcoming RISC-V IOMMU interrupt remapping needs to map every possible host IMSIC target into one contiguous MSI IOVA range. MSI message composition then uses the target CPU's position within that range. Build an IMSIC physical address array indexed by logical CPU. Require every possible CPU to have an initialized IMSIC page before publishing the array. This preserves physical address zero as a valid target and guarantees the array has num_possible_cpus() entries. The array size and each target's index can therefore be derived directly, without storing duplicate count or per-CPU index metadata. 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 Reviewed-by: Jason Gunthorpe --- drivers/irqchip/irq-riscv-imsic-state.c | 32 +++++++++++++++++++++++++ drivers/irqchip/irq-riscv-imsic-state.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index 01620373b43a..d9ee38f9c34b 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -688,6 +688,31 @@ static int __init imsic_get_mmio_resource(struct fwnode_handle *fwnode, return of_address_to_resource(to_of_node(fwnode), index, res); } +static int __init imsic_init_msi_pa_list(void) +{ + struct imsic_global_config *global = &imsic->global; + phys_addr_t *msi_pa_list; + unsigned int cpu; + + msi_pa_list = kzalloc_objs(*msi_pa_list, num_possible_cpus()); + if (!msi_pa_list) + return -ENOMEM; + + for_each_possible_cpu(cpu) { + struct imsic_local_config *local = per_cpu_ptr(global->local, cpu); + + if (!local->msi_va) { + kfree(msi_pa_list); + return -ENODEV; + } + + msi_pa_list[cpu] = local->msi_pa; + } + + imsic->msi_pa_list = msi_pa_list; + return 0; +} + static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode, struct imsic_global_config *global, u32 *nr_parent_irqs, @@ -946,6 +971,12 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque) goto out_local_cleanup; } + rc = imsic_init_msi_pa_list(); + if (rc) { + pr_err("%pfwP: failed to initialize MSI address list\n", fwnode); + goto out_local_cleanup; + } + /* Initialize matrix allocator */ rc = imsic_matrix_init(); if (rc) { @@ -971,6 +1002,7 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque) out_free_local: free_percpu(imsic->global.local); out_free_priv: + kfree(imsic->msi_pa_list); kfree(imsic); imsic = NULL; return rc; diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-riscv-imsic-state.h index 189829b8673a..d4da6e50afb4 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -46,6 +46,9 @@ struct imsic_priv { /* Global configuration common for all HARTs */ struct imsic_global_config global; + /* MSI target physical addresses indexed by logical CPU for IOMMU mapping */ + phys_addr_t *msi_pa_list; + /* Per-CPU state */ struct imsic_local_priv __percpu *lpriv; -- 2.56.1