From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796395646; b=MQVKZKo0US4hziubC8Phi4a0/TO6pmMXgKUugKFY86xJ6yvdjiwuDHNLfn2XJRMGsqL6 ZaNT58D+5RjNNL/iAjAuTvDFgj47gA1vw4hw7ZvqOsWla6GpplrQtnkD8cxev2bQl8mVj fu/dKIckcIIHjkTiEXVTaCFpUDxPdrht5w/cc/XrbQ100yz2sdosfSV7AJjx91coV2pIG x7ABqWpUB/b4llXCKriFLar1D67uaPBjS+amV11Fqh9uZ1nNiY/bzuy/RIEgy+KyscWJH P8Q3pdn0drtBfuedvxCHyj7bREHkOvPnJc1ucXn2j9HVBxQ69SfRyA9ZN/+UibYf3yA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796395646; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Authority-Analysis: X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=VP4CV3pdG810IjNQbVnnFeNEBo+L1RQmCfnpP2GBDEA=; b=028Q6D7ckzn4PsR1L9t0pIaGfO2OGGgA+wbYd02B59Y0OwLoMWihvrzvGWPbYJhh7qyC c/Lwgnej11fnsFrzjtQSEmS85mNPGWrNxr6dRVdb1jRn5nd1lcxes0KDGUtBOQ8raIUmZ 6bdiiDj3hjZwZpstJjDuBd2gGkeLfkQwdsYmyq+HSNmYK6oFCSmep14Wqm+jn4IlKmMoN SI2xJLlHY/71MhzyoUQ3dK4bEadCiiXfy2VWuE8vxT11Za440jIcLQ7Lpb43Im3S8c7vr Md7dsuRkYdsyTa5tNUpji2tuqkC9FFP5AB6E5kghEJnjyTkTCAdHStr6zrfUVJiaRmg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b="LUU/VF5y"; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 AC055606A338; Fri, 4 Dec 2026 14:47:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC055606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LUU/VF5y Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B4EYbV51102489; Fri, 4 Dec 2026 14:47:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=VP4CV3pdG810IjNQb VnnFeNEBo+L1RQmCfnpP2GBDEA=; b=LUU/VF5yX9XsfCQXh3lWMpmzw0GiamZVU kGvbMk+g29UMDBVmGUJWZbwaPdtr8fI/bEKfiCjns6CG8P+XSFatirT1903W1Opa MV0UdDBbFP+R+Ndwy7UwBAg9+Nz3kGa/pu1IIWfBAUNFfTy1DGo1z6jRqp7DoXwC CMNHuyH8K6nhk2QOjJQfuFTOS8jp/tz19LpazLm8f4T3Bop6yAnECCYOVkspMX33 aizV/o3Ze3prU7EB06Z6x8tKTbAqWPd1mRl6OLJvre8ymRVY76A9Ql6HIiU5F8NF A/jnJLizo3Zg1Pw2d4sYScSLCbO2E0ENryciB4r4D0DNxBQjKOUfQ== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4jbqght7rn-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 14:47:06 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B4EYQpG2168987; Fri, 4 Dec 2026 14:47:06 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([172.16.1.6]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4jb5a1p0ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 14:47:06 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B4El5dJ21627462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Dec 2026 14:47:05 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 264575805C; Fri, 4 Dec 2026 14:47:05 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CDD2F5805F; Fri, 4 Dec 2026 14:47:04 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTPS; Fri, 4 Dec 2026 14:47:04 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55390) id 989AF1610DF; Fri, 04 Dec 2026 15:47:03 +0100 (CET) From: Sven Schnelle To: Marc Zyngier , Mark Rutland , "Joerg Roedel (AMD)" , Will Deacon Cc: Robin Murphy , Catalin Marinas , Sudeep Holla , Ard Biesheuvel , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Christian Borntraeger , Hendrik Brueckner , Ulrich Weigand , Arnd Bergmann , linux-s390@vger.kernel.org Subject: [PATCH 1/3] iommu: sva: allow SVA without PASID Date: Fri, 4 Dec 2026 15:45:27 +0100 Message-ID: <20261204144529.960326-2-svens@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204144529.960326-1-svens@linux.ibm.com> References: <20261204144529.960326-1-svens@linux.ibm.com> X-Mailing-List: linux-s390@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 X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=eYyo7LEH c=1 sm=1 tr=0 ts=6b12d26a cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=KLbBlA4IYUuR1QsM6LUA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDA1OCBTYWx0ZWRfXzit4pqvo9HP6 uhYKmStlsxEcZyDcqNEVsKor0jon4Fg4dw7KUqggSOJWb69/FHlrRBfQVF7J8linmY8iiPtWewF zSEXwQzhQ06CX1haJNEs/Jr2XCeHQqo= X-Proofpoint-ORIG-GUID: dkXI7Je-9Ur-CNIsXEwvIgXSNg74hQat X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDA1OCBTYWx0ZWRfX62hbNiycwQQK tqdxUDmeZdLpgjuDtp2DPMsdcruj+WGVan+ON7JyeYup8sU/trzQMom7bjuzzKpy2PN4vUgX52B oSznOJvbdbhIotKRCRsCWU6gWY1q+stpRPoA5jik3gYTDTWiv4ffmjVgguja6FjEwNRJpu0iIJs CSlh1ItYGsR3lUFma4zt/NYxXG8S7LPS5rWZdP4069q7SK1d63k10GkxvCwKInrUXw2w85Y8wFO HrGYaH8ESToj+OoTpqhSG/QAYLjaF8pcKj3rJdV9rCbXiZPSzA7PHTAbGV7zVP11hWzarhsXMiP Oi1kNfeHzOiDm3sqM4vjUbisX4Zx0SW5kVjsFJ2yz3Xu42+3wNYOxKxj1uop15f1saRoK3oZrTz EtPXN1RdVkHbFuxQ+2o9OJq80eTbb9R5E9RQ93l/D8HxNsyuPJDeu61WhqeWlpn2BRVmZUNewlJ 5czbxa2kmYbCnRhaNZQ== X-Proofpoint-GUID: dkXI7Je-9Ur-CNIsXEwvIgXSNg74hQat X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-04_03,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 spamscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0 priorityscore=1501 phishscore=0 clxscore=1011 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040058 From: Arnd Bergmann On devices that are tightly integrated with the CPU and use the regular page tables for synchronous commands, the PASID is ignored and the actual ASID is used in its place, on Arm CPUs this is in TTBR0_EL1. Create a new iommu_sva_bind_device_no_iommu() interface that lets device drivers install an iommu_mm object in an mm for such devices. As before, multiple SVA devices can be used by the same process as long as all of them are able to use the same PASID. When a device without an IOMMU enables SVA, the process will still allocate a PASID that can be used for any other devices accessed by the same process after a successful call to iommu_sva_bind_device(). Signed-off-by: Arnd Bergmann Signed-off-by: Sven Schnelle --- drivers/iommu/iommu-sva.c | 31 ++++++++++++++++++++++++++++++- drivers/iommu/iommu.c | 21 ++++++++++++++------- include/linux/iommu.h | 8 ++++++++ 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 9827cb804363..b444f3483f6d 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -29,7 +29,7 @@ static struct iommu_mm_data *iommu_alloc_mm_data(struct mm_struct *mm, struct de iommu_mm = mm->iommu_mm; /* Is a PASID already associated with this mm? */ if (iommu_mm) { - if (iommu_mm->pasid >= dev->iommu->max_pasids) + if (dev->iommu && iommu_mm->pasid >= dev->iommu->max_pasids) return ERR_PTR(-EOVERFLOW); return iommu_mm; } @@ -156,6 +156,35 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm } EXPORT_SYMBOL_GPL(iommu_sva_bind_device); +/** + * iommu_sva_bind_device_no_iommu() - Bind a process address space to a device without iommu + * @dev: the device + * @mm: the mm to bind, caller must hold a reference to mm_users + * + * Allow the use of shared virtual addressing on devices that transparently + * use the CPU's page table instead of an IOMMU. A global PASID is allocated + * in case the same process uses another device with an IOMMU later. + * + * The reference is held until the mm_struct is destroyed. + * + * On error, returns a negative error number, or zero on success. + */ +int iommu_sva_bind_device_no_iommu(struct device *dev, struct mm_struct *mm) +{ + struct iommu_mm_data *iommu_mm; + + if (dev->iommu_group) + return -EINVAL; + + mutex_lock(&iommu_sva_lock); + /* Allocate mm->pasid if necessary. */ + iommu_mm = iommu_alloc_mm_data(mm, dev); + mutex_unlock(&iommu_sva_lock); + + return PTR_ERR_OR_ZERO(iommu_mm); +} +EXPORT_SYMBOL_GPL(iommu_sva_bind_device_no_iommu); + /** * iommu_sva_unbind_device() - Remove a bond created with iommu_sva_bind_device * @handle: the handle returned by iommu_sva_bind_device() diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b486b8bbd1fc..1470bb9c1ca8 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3827,17 +3827,24 @@ EXPORT_SYMBOL_GPL(iommu_detach_device_pasid); ioasid_t iommu_alloc_global_pasid(struct device *dev) { int ret; + unsigned int max_pasid; - /* max_pasids == 0 means that the device does not support PASID */ - if (!dev->iommu->max_pasids) + if (!dev->iommu) { + /* no IOMMU but capable of enqcmd/st64bv0: pick any PASID */ + max_pasid = IOMMU_PASID_INVALID - 1; + } else if (dev->iommu->max_pasids) { + /* + * max_pasids is set up by vendor driver based on number of + * PASID bits supported but the IDA allocation is inclusive. + */ + max_pasid = dev->iommu->max_pasids - 1; + } else { + /* max_pasids == 0 means that the device does not support PASID */ return IOMMU_PASID_INVALID; + } - /* - * max_pasids is set up by vendor driver based on number of PASID bits - * supported but the IDA allocation is inclusive. - */ ret = ida_alloc_range(&iommu_global_pasid_ida, IOMMU_FIRST_GLOBAL_PASID, - dev->iommu->max_pasids - 1, GFP_KERNEL); + max_pasid, GFP_KERNEL); return ret < 0 ? IOMMU_PASID_INVALID : ret; } EXPORT_SYMBOL_GPL(iommu_alloc_global_pasid); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ef5043752a36..131595da295f 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1663,6 +1663,8 @@ static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm) void mm_pasid_drop(struct mm_struct *mm); struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm); +int iommu_sva_bind_device_no_iommu(struct device *dev, + struct mm_struct *mm); void iommu_sva_unbind_device(struct iommu_sva *handle); u32 iommu_sva_get_pasid(struct iommu_sva *handle); void iommu_sva_invalidate_kva_range(unsigned long start, unsigned long end); @@ -1673,6 +1675,12 @@ iommu_sva_bind_device(struct device *dev, struct mm_struct *mm) return ERR_PTR(-ENODEV); } +static inline int iommu_sva_bind_device_no_iommu(struct device *dev, + struct mm_struct *mm) +{ + return -ENODEV; +} + static inline void iommu_sva_unbind_device(struct iommu_sva *handle) { } -- 2.56.1