From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6216D3E51C5 for ; Thu, 20 Aug 2026 21:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787262120; cv=none; b=oqPSdnDWdx7TdOYla/rDp0HC65uOa7U7+Ui3IWg5WZj8BgyMYyxNM/Y16PpQG4zIY+iFEGALykf67vQ+RljGX+zozfCqxhWq7QBokJA/zE8TqmTi+aEtRLJN8AyBEZF85CIYw6Il0arUaomCCkBsaTEEbaka/1Mmr0q5u1tPwB8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787262120; c=relaxed/simple; bh=GKMcSeCiL0a3g2uOH9WSfrZlngJsKlX/8rmbuIPed8E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YL1JJAjyhjxkJeKwX9eUCvSa8s+WTW7w4sqh/bC9QhzbXXaAtq/JSGHLMUL1X4/v05TmGqHQYjRndAAh0w5C7+/PO1NgOJoMZ/ky/O79JDbpeIyP2+L1alsE6wv0f6pPTaTPuO1pEy1hh4HHSsa6q53eK1DJQXNVb7+A/gFrRmQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=b2nvc7w/; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=iO4JhZXe; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="b2nvc7w/"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="iO4JhZXe" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67KK7XbT250307 for ; Thu, 20 Aug 2026 21:41:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=gu+JFGkyqPx /Q45IWTCbHOfkGmMO1gxqkNte7ZP70m0=; b=b2nvc7w/FnZzkiDM2hLfy1bSh0g j35Ze/etDBeZozYR10+jRRbwRyKESSUY0hTTgF7Q4IAxmwlcpfE+r5Ga1yVMeUC1 X6+c6mjfZZDaxyUnb962DNPn2CqnKU+UwuyFFaLwCJhqETMyR450urlkC+472Zqc 5ryBOQwZrUze4wrCDupHrOJlPPR7eS85wbjNCVFtqGC3XWOmpY12/44OxB7Iu+jb urEE+CFjMyv1m9sItfvHKhWEAag9bFXS8OQL7MXNwcNZXM+/R3H3xAs3AsZvPnJg EZ5aRezNc6vcMNfHU6gK07CCi08UK1amNJZdGHqnFbiQMuB2WfkSwVdnO8w== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g5w49bqp6-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 20 Aug 2026 21:41:58 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-9368f2b7b2bso34263185a.0 for ; Thu, 20 Aug 2026 14:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787262117; x=1787866917; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gu+JFGkyqPx/Q45IWTCbHOfkGmMO1gxqkNte7ZP70m0=; b=iO4JhZXeyi/KC+cVP45vMw8Cr0abYh+YnsgSB225fZ1rWaJNE94f+xOMsDcY8Nc+VQ IgpnHwk+tQBbHaaid/7F9RCfVNJTneQY9LML/3O8UnzQzgtqpaPjoB9601kExuAaFowO sgJBaF25P0hfKf6JhsQkSzn587gxO4Y0Ige22Ud2rqxVJxykAGUne3a5TcV0Ua3F8c3T QOrDiyMPSJHaj0iFfWBS0sdneeiy4xm3kcBsVPYKRxzYE28v5TlRBRjo6CMJjFx8WbPR 6KM22B7hFNdtjtx0pJmS2ycFjdIRMvfFawv+P+53CzIMXZY22iid/KtkFU2fdgnw+5A5 eBOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787262117; x=1787866917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gu+JFGkyqPx/Q45IWTCbHOfkGmMO1gxqkNte7ZP70m0=; b=j0kWSjzV/7bTkKS9nyLqTKLgE3Rwg592tYW0zhi+nZXauWzQEghtXRL/N2F1iImZn9 SDDhXIZWo1FALcBZsUVSoxwkU7shBZaRH5eP2Bz/EG0HZF6HX2CgzUnGNQ/KiIUKBvyo IGTqu6B9AArmjo/QC6+b1gLgEgjojR+OI4Rg9qAd9lV1iX5MDRwtTHnVBpn6o9/0HEI2 YPGkd4Da0Q+ddikceHT7kg1feR+eMW0yrw1tJheySKX83hmCyZSWNZgEJT4AJ36+yj8J ts6YbGwmy53T+95f6j8F4IMacQfNSa0nsTbG7hPT2YqMPDMxO/NMbuJ0VrwC2xdLJJ3S mMOQ== X-Gm-Message-State: AOJu0Yx9ZgMrLJQWPDNbdsnuWbdeQVnJ9tbW1L9VhkH2RvZfStHC9udL LP/tuo2ghI1n3wv5t+vrSAeypwcMddCEiprbFxCZaBzel69zYfLRxrOmMFvk4yPrlc88d4fHnBG yBrAMdOm8ppedl4sVDsLznYB0syjqRkBZVK0M6INr6UZmzWwfmixqq4y+gAAexHCqpsw= X-Gm-Gg: AR+sD13s/lx30ptxGClnAOqMhdyZO+/QmG/p0DWscIW7IyzkPiDjk3pLzzHq0GBzWOd n4oTTxaz001I0eTYWvlx050QjAXwMGsYuuamrknYXEFnZDHcyKFTeDx3nlDTrOywV8CpYYnl7zj qiNsEk13dBP47RBpsXB5bT/KXYqORskI91pB/iqcHePvXIA5kVpx+l0Xx/HahC1697vsFw8K63s 9Z6rY9hxjXD3845XDZMnI72hz15yM7wxVGuFL1vGIB0w6fyKwaDIjp99cv4nhhLigzkKa+NRT1F exSMNkXcoKBsdxYQjWoj6e1e8GWaaW57WBsU+NK2omndMXX4FJCN59fp5mJ9x8m7AF7QOiBArNZ KfEXl18Ao X-Received: by 2002:a05:620a:222c:b0:937:2ec9:c98 with SMTP id af79cd13be357-9373942667bmr103111385a.5.1787262117418; Thu, 20 Aug 2026 14:41:57 -0700 (PDT) X-Received: by 2002:a05:620a:222c:b0:937:2ec9:c98 with SMTP id af79cd13be357-9373942667bmr103108385a.5.1787262116964; Thu, 20 Aug 2026 14:41:56 -0700 (PDT) Received: from localhost ([193.165.40.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499b91173c4sm5335855e9.2.2026.08.20.14.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 14:41:56 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, iommu@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tomasz.jeznach@linux.dev, tjeznach@rivosinc.com, 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 Subject: [PATCH v4 02/21] iommufd: Add iommufd_sw_map_msi() Date: Thu, 20 Aug 2026 23:41:31 +0200 Message-ID: <20260820214150.545737-3-andrew.jones@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260820214150.545737-1-andrew.jones@oss.qualcomm.com> References: <20260820214150.545737-1-andrew.jones@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Info: AW1haW4tMjYwODIwMDE2MiBTYWx0ZWRfX8+v0sdpQqK4m 6bX8NQrYIl9EdL2KXUTqAjvaq4W/CfhIp/MvurH7fd8NgQvVoYHDu40ZuFYNnGWQ5xn0TaUo34G Tf2aq6a3njBkI4fpBKDvZW1D7/wJo5E= X-Authority-Analysis: v=2.4 cv=YP+vDxGx c=1 sm=1 tr=0 ts=6a8774a6 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=CzrpMg+lqiTzknPDBj2tlw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=5IMjXt7tboKol454yg4A:9 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-ORIG-GUID: 42-jXDOd-ffjyr9BnqUwbeDPZ8J7phXZ X-Proofpoint-GUID: 42-jXDOd-ffjyr9BnqUwbeDPZ8J7phXZ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODIwMDE2MiBTYWx0ZWRfXzCig2LkT8YaA Qq89XZMtBRi0RhA3pcnYT/twZXS/dSyZ5bul2YocWY/iePPOEdXoJ2o46KmEOko/+LNib0M4eFt E6b51tWMhYQrjK9uS5RtvArYy7tBKx+J5b0ojWhblYXECQbqVc3L5KM+mnNVVPxCDoLwOXd1SAT D2N5k8yo5R4ppvRmdnkutTIMub3Hk7vll7Kl1Uqb79fSCsE/x1sWbjJ26V7BO8ZmDFZZKHqCv6O v8clIkmfSbYy27HtjLeSK3ZxQAF3wFFoeUQdaAf2rS3QsnKCIroVr0f1zXLzg+USLJJ6lLiCvpT 3ULjlu0Niv7+mOB9fBG4Pu7cDB+O27gDfY1IL19Zfip8CboCxDmog303cQGMtuA7aWaca4YcMsR VvXng7dhnl+tGOiurnwq40F+JGrrFDiA13LuGuzvTcn857IkVKXVUZEs7xtvEXBA7Pt2kn+7QZJ wEOsWcCp668xrDQXhbQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-20_02,2026-08-20_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 clxscore=1015 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608200162 Add a descriptor-free counterpart to iommufd_sw_msi(). The existing function is tied to a struct msi_desc and stores the result in the descriptor. This variant returns the IOVA directly so callers can pre-map MSI targets before any descriptor has been allocated. Signed-off-by: Andrew Jones --- drivers/iommu/iommu-priv.h | 11 +++++++ drivers/iommu/iommufd/driver.c | 60 +++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h index aaffad5854fc..f60373cd2f70 100644 --- a/drivers/iommu/iommu-priv.h +++ b/drivers/iommu/iommu-priv.h @@ -55,12 +55,23 @@ int iommu_replace_group_handle(struct iommu_group *group, #if IS_ENABLED(CONFIG_IOMMUFD_DRIVER_CORE) && IS_ENABLED(CONFIG_IRQ_MSI_IOMMU) int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, phys_addr_t msi_addr); +int iommufd_sw_map_msi(struct iommu_domain *domain, struct device *dev, + phys_addr_t msi_addr, size_t required_size, + dma_addr_t *msi_iova, unsigned int *msi_shift); #else /* !CONFIG_IOMMUFD_DRIVER_CORE || !CONFIG_IRQ_MSI_IOMMU */ static inline int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, phys_addr_t msi_addr) { return -EOPNOTSUPP; } + +static inline int iommufd_sw_map_msi(struct iommu_domain *domain, + struct device *dev, phys_addr_t msi_addr, + size_t required_size, dma_addr_t *msi_iova, + unsigned int *msi_shift) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_IOMMUFD_DRIVER_CORE && CONFIG_IRQ_MSI_IOMMU */ int iommu_replace_device_pasid(struct iommu_domain *domain, diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index 9b9316ae4266..69b3dbcbee3b 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -249,15 +249,23 @@ int iommufd_sw_msi_install(struct iommufd_ctx *ictx, EXPORT_SYMBOL_NS_GPL(iommufd_sw_msi_install, "IOMMUFD_INTERNAL"); /* - * Called by the irq code if the platform translates the MSI address through the - * IOMMU. msi_addr is the physical address of the MSI page. iommufd will - * allocate a fd global iova for the physical page that is the same on all - * domains and devices. + * Descriptor-free counterpart to iommufd_sw_msi(). Maps an MSI physical page + * into the domain and returns the IOVA. Used for pre-mapping MSI targets before + * any MSI descriptor has been set (e.g. IMSIC doorbell pages). The IOVA is + * global to the iommufd file descriptor: every domain and device using the + * same MSI parameters gets the same IOVA. + * + * msi_addr is the exact byte offset of the MSI doorbell; the caller must have + * verified it is contained within an MMIO region safe to map at PAGE_SIZE. If + * required_size is non-zero it must equal PAGE_SIZE. @msi_iova and @msi_shift + * must be non-NULL. + * + * The caller must hold @dev's iommu group mutex. */ -int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, - phys_addr_t msi_addr) +int iommufd_sw_map_msi(struct iommu_domain *domain, struct device *dev, + phys_addr_t msi_addr, size_t required_size, + dma_addr_t *msi_iova, unsigned int *msi_shift) { - struct device *dev = msi_desc_to_dev(desc); struct iommufd_hwpt_paging *hwpt_paging; struct iommu_attach_handle *raw_handle; struct iommufd_attach_handle *handle; @@ -266,6 +274,12 @@ int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, unsigned long iova; int rc; + *msi_iova = 0; + *msi_shift = 0; + + if (required_size && required_size != PAGE_SIZE) + return -EOPNOTSUPP; + /* * It is safe to call iommu_attach_handle_get() here because the iommu * core code invokes this under the group mutex which also prevents any @@ -286,13 +300,7 @@ int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, ictx = handle->idev->ictx; guard(mutex)(&ictx->sw_msi_lock); - /* - * The input msi_addr is the exact byte offset of the MSI doorbell, we - * assume the caller has checked that it is contained with a MMIO region - * that is secure to map at PAGE_SIZE. - */ - msi_map = iommufd_sw_msi_get_map(handle->idev->ictx, - msi_addr & PAGE_MASK, + msi_map = iommufd_sw_msi_get_map(ictx, msi_addr & PAGE_MASK, handle->idev->igroup->sw_msi_start); if (IS_ERR(msi_map)) return PTR_ERR(msi_map); @@ -308,7 +316,29 @@ int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, __set_bit(msi_map->id, handle->idev->igroup->required_sw_msi.bitmap); iova = msi_map->sw_msi_start + msi_map->pgoff * PAGE_SIZE; - msi_desc_set_iommu_msi_iova(desc, iova, PAGE_SHIFT); + *msi_iova = iova; + *msi_shift = PAGE_SHIFT; + return 0; +} +EXPORT_SYMBOL_NS_GPL(iommufd_sw_map_msi, "IOMMUFD"); + +/* + * Called by the irq layer when the platform translates MSI addresses through + * the IOMMU. Wraps iommufd_sw_map_msi() and stores the result in the descriptor. + */ +int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, + phys_addr_t msi_addr) +{ + dma_addr_t msi_iova; + unsigned int msi_shift; + int rc; + + rc = iommufd_sw_map_msi(domain, msi_desc_to_dev(desc), msi_addr, + 0, &msi_iova, &msi_shift); + if (rc) + return rc; + + msi_desc_set_iommu_msi_iova(desc, msi_iova, msi_shift); return 0; } EXPORT_SYMBOL_NS_GPL(iommufd_sw_msi, "IOMMUFD"); -- 2.43.0