From nobody Fri Dec 27 11:31:48 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 0635A1991D8; Mon, 9 Dec 2024 19:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772366; cv=none; b=QaZ+2x8144Um29Uo0wxs8xNLjwnZqe8muuAJXABwiRRoFnvb9s+/KBmiQgmmI9kUEvFdawCdKugVE1txObHuSta3I+86SeQbW2NahUSbIuJxY916C/tlXy0hsvH5VpRYtXOiHawUuxFupe9VN0vPGQEmZZNa8DPoEMsuzWYhdK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772366; c=relaxed/simple; bh=wxZWM9Xs9hzLVx4T4oIxM0wQO9HXSPjKPMqyzhTXIgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZmijFBXzVhjwcpIYZux8fwQDDnD772EWusOmF3z594aRhk1g948/E0l+NHjMC6CV6Ia+gEBh2buAof+xvJhSuodu83VBjKfaXz8lOzYFHIcmUcqVs1Mt04H4odsOBs6umv0HVE+SDwNhWLkWBnJlbu4RuVT4gnPiBe6UPbXkkKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=aIv065iS; arc=none smtp.client-ip=148.163.158.5 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.b="aIv065iS" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9E4dEJ032428; Mon, 9 Dec 2024 19:25:54 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=D2f2503/0UUWMj4Q2 QM5cTBMIYS1TJwXDMjg3PiH/oA=; b=aIv065iSv7nO+KhmlvUqogMKb0Am0YpGF HE/q4ezQmvPgfqaVaFyu24+jN8JiFbmvqHLWERxr48wQkKnwAA53EQAwxW9wRdDu +RpXC1FF6XHwfTPHo4wTS+rdszfbU2yEtt/23Rkph8YyH4hNK+EjlhKcfYjMbpme BaJmhNIqEPd8vrGlacUcMjt6ImXyUzvAQKChCd6Q5SvDo5gB9XeLgSXw1g1Eny6U Jkl1oG6F85FF4MdFd6cWP4H3UZFqFTSMvEEnUm+4SV7i8CDatOPbHzu0WHW+TBeF 9mq3m1zigEKivguqIdjxhcciTWwbA5hxZJsmncKFM4RahEgf1ytUg== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43cbsq2hu9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:54 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9FtZPR017364; Mon, 9 Dec 2024 19:25:53 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 43d3d1fqwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:53 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPqeD21234216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:25:52 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D46458055; Mon, 9 Dec 2024 19:25:52 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A49358043; Mon, 9 Dec 2024 19:25:51 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:51 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 1/7] iommu/s390: add initial fields to track table size Date: Mon, 9 Dec 2024 14:25:43 -0500 Message-ID: <20241209192549.107226-2-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: xjECl8VcHEBY91AEimNOqJLLhPfnrsFC X-Proofpoint-GUID: xjECl8VcHEBY91AEimNOqJLLhPfnrsFC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 suspectscore=0 spamscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090147 Content-Type: text/plain; charset="utf-8" In preparation for allowing for additional table levels, add the necessary information to the zdev and s390 domain to track table type. For now, these values will always be set to signify a region third table which is what s390-iommu always uses today. Signed-off-by: Matthew Rosato --- arch/s390/include/asm/pci.h | 2 ++ drivers/iommu/s390-iommu.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h index 474e1f8d1d3c..8f8ebaeec60a 100644 --- a/arch/s390/include/asm/pci.h +++ b/arch/s390/include/asm/pci.h @@ -189,6 +189,8 @@ struct zpci_dev { struct kvm_zdev *kzdev; struct mutex kzdev_lock; spinlock_t dom_lock; /* protect s390_domain change */ + u64 max_table_size; + u8 origin_type; }; =20 static inline bool zdev_enabled(struct zpci_dev *zdev) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index fbdeded3d48b..f6c27b6ab4c6 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -31,6 +31,7 @@ struct s390_domain { unsigned long *dma_table; spinlock_t list_lock; struct rcu_head rcu; + u8 origin_type; }; =20 static struct iommu_domain blocking_domain; @@ -331,6 +332,7 @@ static bool s390_iommu_capable(struct device *dev, enum= iommu_cap cap) =20 static struct iommu_domain *s390_domain_alloc_paging(struct device *dev) { + struct zpci_dev *zdev =3D to_zpci_dev(dev); struct s390_domain *s390_domain; =20 s390_domain =3D kzalloc(sizeof(*s390_domain), GFP_KERNEL); @@ -344,7 +346,8 @@ static struct iommu_domain *s390_domain_alloc_paging(st= ruct device *dev) } s390_domain->domain.geometry.force_aperture =3D true; s390_domain->domain.geometry.aperture_start =3D 0; - s390_domain->domain.geometry.aperture_end =3D ZPCI_TABLE_SIZE_RT - 1; + s390_domain->domain.geometry.aperture_end =3D zdev->max_table_size; + s390_domain->origin_type =3D zdev->origin_type; =20 spin_lock_init(&s390_domain->list_lock); INIT_LIST_HEAD_RCU(&s390_domain->devices); @@ -450,9 +453,9 @@ static void s390_iommu_get_resv_regions(struct device *= dev, list_add_tail(®ion->list, list); } =20 - if (zdev->end_dma < ZPCI_TABLE_SIZE_RT - 1) { + if (zdev->end_dma < zdev->max_table_size) { region =3D iommu_alloc_resv_region(zdev->end_dma + 1, - ZPCI_TABLE_SIZE_RT - zdev->end_dma - 1, + zdev->max_table_size - zdev->end_dma, 0, IOMMU_RESV_RESERVED, GFP_KERNEL); if (!region) return; @@ -470,11 +473,11 @@ static struct iommu_device *s390_iommu_probe_device(s= truct device *dev) zdev =3D to_zpci_dev(dev); =20 if (zdev->start_dma > zdev->end_dma || - zdev->start_dma > ZPCI_TABLE_SIZE_RT - 1) + zdev->start_dma > zdev->max_table_size) return ERR_PTR(-EINVAL); =20 - if (zdev->end_dma > ZPCI_TABLE_SIZE_RT - 1) - zdev->end_dma =3D ZPCI_TABLE_SIZE_RT - 1; + if (zdev->end_dma > zdev->max_table_size) + zdev->end_dma =3D zdev->max_table_size; =20 if (zdev->tlb_refresh) dev->iommu->shadow_on_flush =3D 1; @@ -732,6 +735,8 @@ int zpci_init_iommu(struct zpci_dev *zdev) ZPCI_TABLE_SIZE_RT - zdev->start_dma, zdev->end_dma - zdev->start_dma + 1); zdev->end_dma =3D zdev->start_dma + aperture_size - 1; + zdev->origin_type =3D ZPCI_TABLE_TYPE_RTX; + zdev->max_table_size =3D ZPCI_TABLE_SIZE_RT - 1; =20 return 0; =20 --=20 2.47.0 From nobody Fri Dec 27 11:31:48 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 9F05E1991BB; Mon, 9 Dec 2024 19:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772366; cv=none; b=AKwQcWJeu9fz+Uhe7L9QYjvdZwlMpP5qhFqXAwe3ziCyrqQPNeiIoTjOLVJ938f/Y4Gv/Hn9ZgqVN+35Q0TlNGG1j/iVLyHhEY7xfBQ1OrkNJHLqnB48+M5RnJSt3vD+SdNPet9SO3IqG78qk7v0JxJkGRUeg4UzMjJgyoOUM9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772366; c=relaxed/simple; bh=MOxUnTPqC4lNkYcr6hcNIssZn/uxBRlqjsb8SWYozhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzHn2lzjduUe99aM9Zt2mpRCjaj3Q6xFZpJwHrLEQKNgLrS+nlBNFJ1uH2XZHnvzE+c4KZpfTU4zYpws5n9u9A169uDf8XTXY1ORiPngdjfR9fRHkka53ZMmkVi02LcqI0etgWXTNr+s2HWN50+f0ubgD5451CGE8NjuQYD+m/0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=KtdiSQrn; arc=none smtp.client-ip=148.163.158.5 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.b="KtdiSQrn" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9BQYSn018470; Mon, 9 Dec 2024 19:25:55 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=BlZLtE/1kHwAY0hj6 Hv/ahaeet1ErQycBmfqpNmPhL8=; b=KtdiSQrnQ+Aj4Jjy0qk8Zf5R55NPz9K78 zFup0VM8v8eQR+jC7HTmff2AHz/N+27dWf4sIYeQA9tklaZ96irWUxXXpp7tiCkM xxcp+uRGQ52svDGghRb8Z33ktR3l1PjmYfEQAecUn/fnmenTPBMB5qL04INu0MDz oEmZ4bB4Mym/Em0DfSwm+b4x49jdOGAAxfFWBbIZBLQITmkmlh0dMejB85P80h/+ S6B++bs7gF7KHcQ9g/r8Xgjhdk5a2LNAzkTZEl3FYg9e7/AGPC+9uax7+mUxSD7i YxF8YrxWitn/jTfRohaYofk+lJntPX7g0uEBcla1PJ+a5CUN6dNbA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43cbsq2hud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:55 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9J7RYi000582; Mon, 9 Dec 2024 19:25:54 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43d1pn02k5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:54 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPrEp31457822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:25:53 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B13A75805D; Mon, 9 Dec 2024 19:25:53 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9BC6A58043; Mon, 9 Dec 2024 19:25:52 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:52 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 2/7] s390/pci: set appropriate IOTA region type Date: Mon, 9 Dec 2024 14:25:44 -0500 Message-ID: <20241209192549.107226-3-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: b7G-fD-krmbx2VkrGPRfUlyLwzfkVK4I X-Proofpoint-GUID: b7G-fD-krmbx2VkrGPRfUlyLwzfkVK4I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=881 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 suspectscore=0 spamscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090147 Content-Type: text/plain; charset="utf-8" When registering the I/O Translation Anchor, use the current table type stored in the zdev to set the apporpriate region type indication. Signed-off-by: Matthew Rosato --- arch/s390/pci/pci.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 88f72745fa59..9f7adf913729 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -116,6 +116,21 @@ int pci_proc_domain(struct pci_bus *bus) } EXPORT_SYMBOL_GPL(pci_proc_domain); =20 +static u64 zpci_get_iota_region_flag(struct zpci_dev *zdev) +{ + switch (zdev->origin_type) { + case ZPCI_TABLE_TYPE_RTX: + return ZPCI_IOTA_RTTO_FLAG; + case ZPCI_TABLE_TYPE_RSX: + return ZPCI_IOTA_RSTO_FLAG; + case ZPCI_TABLE_TYPE_RFX: + return ZPCI_IOTA_RFTO_FLAG; + default: + WARN_ONCE(1, "Invalid IOMMU table (%x)\n", zdev->origin_type); + return 0; + } +} + /* Modify PCI: Register I/O address translation parameters */ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas, u64 base, u64 limit, u64 iota, u8 *status) @@ -131,7 +146,7 @@ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas, fib.pal =3D limit + (1 << 12); else fib.pal =3D limit; - fib.iota =3D iota | ZPCI_IOTA_RTTO_FLAG; + fib.iota =3D iota | zpci_get_iota_region_flag(zdev); fib.gd =3D zdev->gisa; cc =3D zpci_mod_fc(req, &fib, status); if (cc) --=20 2.47.0 From nobody Fri Dec 27 11:31:48 2024 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 42C441A0734; Mon, 9 Dec 2024 19:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772369; cv=none; b=IES7fuOK2gCJhvEiep733J1fXNzUjCf5Rg7bRaoJG3rlq2p2wYsnfA0oMyR592BevgK8wCTow6KY4DBr90v7nyO3qXsTF2NQKla56xal+uEGYUnWZocomQzzZljG+HID0TBJ4rq+0a8vI5708rmiuA8dUF5J9NjUjdTgR6ATbag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772369; c=relaxed/simple; bh=rbhZbY3Dd+rBvt4S/xtnNlWvk1H17uwGeAcBkneHPPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b8sd8BoF2sLNtP7sr9gIcQwEFhAUPtxY/2lTdPmANuLE6tmSXljzIcaQFX5Z58ZMjPtdonyOh6sOsX1rI0XEsVw6jkL2gns+GmdSlhwG1b5WTjI554Fn5hFag7PE8MEFrIhdsNzoga0wSKqfw5sU3sOoluID6cMiZk1XYIE5L/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=aEYBo5km; arc=none smtp.client-ip=148.163.156.1 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.b="aEYBo5km" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9AAF5g019995; Mon, 9 Dec 2024 19:25:58 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=0JLfkf9VdKGccRSC0 m8J4tuXh7p7tr7AFE7LLyjKoNI=; b=aEYBo5kmI1cnyAupxck+nvqNGJGONRkeN v6xMK3OlCi91/LJqCU7q+ZApUJjq6gFyyrY4eDJTGVY7CaWkBUw+EiLD58IJwzeI bdF5l8ATMX6/jqF4hZ92l4u6tomDJOrBKIgTDwlE8Fj41dlB2kZJ2rhe4aPDSx+8 4K91PSd1qW3dc2yjB22mJambEC/b02U9UDrYfyjGWxNSL/v+OurITgHZG26TDAdK 0BpyUE5Q4Yp8vJHahKu+uPD+UsVizelBCZEgHhWWP5RjJI8acjFpF70Ux/WiGW6s /IwtvVPa4wpbsNhhXfNvLLls9OskWxLCZJ55Pq7uwjsl67MKB16cw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43ce38k5tw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:57 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9IWKb2032575; Mon, 9 Dec 2024 19:25:56 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43d1pn02k8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:56 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPtCm11469370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:25:55 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F24CA58055; Mon, 9 Dec 2024 19:25:54 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D163558043; Mon, 9 Dec 2024 19:25:53 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:53 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 3/7] iommu/s390: add basic routines for region 1st and 2nd tables Date: Mon, 9 Dec 2024 14:25:45 -0500 Message-ID: <20241209192549.107226-4-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4su4skLim7CwGtxiLS4zlBSghCNm6QLq X-Proofpoint-ORIG-GUID: 4su4skLim7CwGtxiLS4zlBSghCNm6QLq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 spamscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 impostorscore=0 bulkscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090147 Content-Type: text/plain; charset="utf-8" Add common routines for region first and region second tables, similar to what already exists for region third tables. Routines added are for determining an index value based on address, getting and setting origin flags, and validating entries. These routines are not yet used, but will be in subsequent commits. Signed-off-by: Matthew Rosato --- arch/s390/include/asm/pci_dma.h | 2 ++ drivers/iommu/s390-iommu.c | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/arch/s390/include/asm/pci_dma.h b/arch/s390/include/asm/pci_dm= a.h index 42d7cc4262ca..8d8962e4fd58 100644 --- a/arch/s390/include/asm/pci_dma.h +++ b/arch/s390/include/asm/pci_dma.h @@ -55,6 +55,8 @@ enum zpci_ioat_dtype { #define ZPCI_PT_BITS 8 #define ZPCI_ST_SHIFT (ZPCI_PT_BITS + PAGE_SHIFT) #define ZPCI_RT_SHIFT (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS) +#define ZPCI_RS_SHIFT (ZPCI_RT_SHIFT + ZPCI_TABLE_BITS) +#define ZPCI_RF_SHIFT (ZPCI_RS_SHIFT + ZPCI_TABLE_BITS) =20 #define ZPCI_RTE_FLAG_MASK 0x3fffUL #define ZPCI_RTE_ADDR_MASK (~ZPCI_RTE_FLAG_MASK) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index f6c27b6ab4c6..fcebc7415fb3 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -36,6 +36,16 @@ struct s390_domain { =20 static struct iommu_domain blocking_domain; =20 +static inline unsigned int calc_rfx(dma_addr_t ptr) +{ + return ((unsigned long)ptr >> ZPCI_RF_SHIFT) & ZPCI_INDEX_MASK; +} + +static inline unsigned int calc_rsx(dma_addr_t ptr) +{ + return ((unsigned long)ptr >> ZPCI_RS_SHIFT) & ZPCI_INDEX_MASK; +} + static inline unsigned int calc_rtx(dma_addr_t ptr) { return ((unsigned long)ptr >> ZPCI_RT_SHIFT) & ZPCI_INDEX_MASK; @@ -57,6 +67,20 @@ static inline void set_pt_pfaa(unsigned long *entry, phy= s_addr_t pfaa) *entry |=3D (pfaa & ZPCI_PTE_ADDR_MASK); } =20 +static inline void set_rf_rso(unsigned long *entry, phys_addr_t rso) +{ + *entry &=3D ZPCI_RTE_FLAG_MASK; + *entry |=3D (rso & ZPCI_RTE_ADDR_MASK); + *entry |=3D ZPCI_TABLE_TYPE_RFX; +} + +static inline void set_rs_rto(unsigned long *entry, phys_addr_t rto) +{ + *entry &=3D ZPCI_RTE_FLAG_MASK; + *entry |=3D (rto & ZPCI_RTE_ADDR_MASK); + *entry |=3D ZPCI_TABLE_TYPE_RSX; +} + static inline void set_rt_sto(unsigned long *entry, phys_addr_t sto) { *entry &=3D ZPCI_RTE_FLAG_MASK; @@ -71,6 +95,22 @@ static inline void set_st_pto(unsigned long *entry, phys= _addr_t pto) *entry |=3D ZPCI_TABLE_TYPE_SX; } =20 +static inline void validate_rf_entry(unsigned long *entry) +{ + *entry &=3D ~ZPCI_TABLE_VALID_MASK; + *entry &=3D ~ZPCI_TABLE_OFFSET_MASK; + *entry |=3D ZPCI_TABLE_VALID; + *entry |=3D ZPCI_TABLE_LEN_RFX; +} + +static inline void validate_rs_entry(unsigned long *entry) +{ + *entry &=3D ~ZPCI_TABLE_VALID_MASK; + *entry &=3D ~ZPCI_TABLE_OFFSET_MASK; + *entry |=3D ZPCI_TABLE_VALID; + *entry |=3D ZPCI_TABLE_LEN_RSX; +} + static inline void validate_rt_entry(unsigned long *entry) { *entry &=3D ~ZPCI_TABLE_VALID_MASK; @@ -121,6 +161,22 @@ static inline int pt_entry_isvalid(unsigned long entry) return (entry & ZPCI_PTE_VALID_MASK) =3D=3D ZPCI_PTE_VALID; } =20 +static inline unsigned long *get_rf_rso(unsigned long entry) +{ + if ((entry & ZPCI_TABLE_TYPE_MASK) =3D=3D ZPCI_TABLE_TYPE_RFX) + return phys_to_virt(entry & ZPCI_RTE_ADDR_MASK); + else + return NULL; +} + +static inline unsigned long *get_rs_rto(unsigned long entry) +{ + if ((entry & ZPCI_TABLE_TYPE_MASK) =3D=3D ZPCI_TABLE_TYPE_RSX) + return phys_to_virt(entry & ZPCI_RTE_ADDR_MASK); + else + return NULL; +} + static inline unsigned long *get_rt_sto(unsigned long entry) { if ((entry & ZPCI_TABLE_TYPE_MASK) =3D=3D ZPCI_TABLE_TYPE_RTX) --=20 2.47.0 From nobody Fri Dec 27 11:31:48 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 E822A1A08B8; Mon, 9 Dec 2024 19:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772370; cv=none; b=maq2j6jFcJkzq077aAUHEquJ2dm4brnRfKVjY0dMUP1AAB3onHixW6viy8T5Y7mxADZzLriVLmGgCJKR3oBxLbGtXaUbsnrK47jeQmbf7Wer5KDJ2KkKwPuJ7lqoegISs5bUDVHGaT2prdXygQkH1HT9eqmBIlHs6PLYgdqUN0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772370; c=relaxed/simple; bh=Xsl7jgulT0Qc/ccSP55Jhb1h2cHHRcXWbVUjesDs0A8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5SyEcmx7kQofTEiysQ/g2j1ManjuhY3nDHRmh6ORjhwmQPdYtccU32KpPWjucqbkQq+aK3v9/MpLTM+aTMzREwv5ei4e14it3yX/L1+vBdxcTI9JdJ3m3viL8KSppDq017j97nAXzQw2qufFrCb8wVgO7Na50DA0BqjQP1drMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=RiJ55d90; arc=none smtp.client-ip=148.163.158.5 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.b="RiJ55d90" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9Cc4V2028746; Mon, 9 Dec 2024 19:25:59 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=rq7OInXWI/6WeBhhk RkFfWl6kqqoaATPpRAXFBbuZL4=; b=RiJ55d90NJVGkvtD/5gx72MxKQKNDJsv8 neYpPzZYhBusejIvzeMONhGqCOEqwUECnVNJXDGE7ECEb/ttZfxJ2ARwqFoU78EB yZmPFS5q4xQzNTMdMkia+qatsgNLoNlcTY4UzCGZn21Ej89p5kH/YieMBnkJlO5d tOl3D5KjLlqVN0fBLJjY2G5ZI6o9Hq/j0lBVFQ2ywthJWyG4nmjKQIeHQTqDP8jU OLW6lMwpQOgdDaKnJ2rwMW2zR5Dk6J8ITr3Ic0Os+auUjuEMc6XSSLR1zSwVBdWh zjVYfnUrCTwIT/LONG+cmXyVkMhcZWWwHMwX5HHDhPPn+gLueb8ew== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43ccsjab5n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:58 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9GIuud017397; Mon, 9 Dec 2024 19:25:58 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 43d3d1fqwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:58 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPufE29557452 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:25:56 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3131658055; Mon, 9 Dec 2024 19:25:56 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D40158043; Mon, 9 Dec 2024 19:25:55 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:55 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 4/7] iommu/s390: support cleanup of additional table regions Date: Mon, 9 Dec 2024 14:25:46 -0500 Message-ID: <20241209192549.107226-5-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SgIUkq00ML8tXOVDSKuXO5W8JLKyUqD1 X-Proofpoint-ORIG-GUID: SgIUkq00ML8tXOVDSKuXO5W8JLKyUqD1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090147 Content-Type: text/plain; charset="utf-8" Extend the existing dma_cleanup_tables to also handle region second and region first tables. Signed-off-by: Matthew Rosato --- drivers/iommu/s390-iommu.c | 55 +++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index fcebc7415fb3..5782f329cae9 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -248,18 +248,59 @@ static void dma_free_seg_table(unsigned long entry) dma_free_cpu_table(sto); } =20 -static void dma_cleanup_tables(unsigned long *table) +static void dma_free_rt_table(unsigned long entry) { + unsigned long *rto =3D get_rs_rto(entry); int rtx; =20 - if (!table) + for (rtx =3D 0; rtx < ZPCI_TABLE_ENTRIES; rtx++) + if (reg_entry_isvalid(rto[rtx])) + dma_free_seg_table(rto[rtx]); + + dma_free_cpu_table(rto); +} + +static void dma_free_rs_table(unsigned long entry) +{ + unsigned long *rso =3D get_rf_rso(entry); + int rsx; + + for (rsx =3D 0; rsx < ZPCI_TABLE_ENTRIES; rsx++) + if (reg_entry_isvalid(rso[rsx])) + dma_free_rt_table(rso[rsx]); + + dma_free_cpu_table(rso); +} + +static void dma_cleanup_tables(struct s390_domain *domain) +{ + int rtx, rsx, rfx; + + if (!domain->dma_table) return; =20 - for (rtx =3D 0; rtx < ZPCI_TABLE_ENTRIES; rtx++) - if (reg_entry_isvalid(table[rtx])) - dma_free_seg_table(table[rtx]); + switch (domain->origin_type) { + case ZPCI_TABLE_TYPE_RFX: + for (rfx =3D 0; rfx < ZPCI_TABLE_ENTRIES; rfx++) + if (reg_entry_isvalid(domain->dma_table[rfx])) + dma_free_rs_table(domain->dma_table[rfx]); + break; + case ZPCI_TABLE_TYPE_RSX: + for (rsx =3D 0; rsx < ZPCI_TABLE_ENTRIES; rsx++) + if (reg_entry_isvalid(domain->dma_table[rsx])) + dma_free_rt_table(domain->dma_table[rsx]); + break; + case ZPCI_TABLE_TYPE_RTX: + for (rtx =3D 0; rtx < ZPCI_TABLE_ENTRIES; rtx++) + if (reg_entry_isvalid(domain->dma_table[rtx])) + dma_free_seg_table(domain->dma_table[rtx]); + break; + default: + WARN_ONCE(1, "Invalid IOMMU table (%x)\n", domain->origin_type); + return; + } =20 - dma_free_cpu_table(table); + dma_free_cpu_table(domain->dma_table); } =20 static unsigned long *dma_alloc_page_table(gfp_t gfp) @@ -415,7 +456,7 @@ static void s390_iommu_rcu_free_domain(struct rcu_head = *head) { struct s390_domain *s390_domain =3D container_of(head, struct s390_domain= , rcu); =20 - dma_cleanup_tables(s390_domain->dma_table); + dma_cleanup_tables(s390_domain); kfree(s390_domain); } =20 --=20 2.47.0 From nobody Fri Dec 27 11:31:48 2024 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 AE3101A0BC0; Mon, 9 Dec 2024 19:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772372; cv=none; b=ZnoMwa82GQ+CfdJxLkyI0W3VOsMIq01xmH+NqoWxMd1zhznBcZIRr10VdmcrWLM3GfjT5muwS3HHFIw6QzGUXNqiqj0f38E6zbCjlMnQszLI6itCVODXCcFfJL+BEDVnFb0MBFTm0DThbw1kGi3BBAy9OfNssmavk87teRSztkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772372; c=relaxed/simple; bh=Ctkvp9MYU5c6ZxozXGYpe/mnjejPZAZzg2dizRoLEYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tiQ2Ii1/eGIeXpZ1epi5KB1UrgcX+vzFvLFoJiaCUt6jdK4Gq+/ICMFhhrCJF96zMTcZQN0VOGITZcN+0V7Uzvjn3qhpvi06mWx6WR05E8M31w85oo/f9DwVP7328JM0Zuk4YkcA94BTdsrOBKkRn2EuRPUswkWJ2jTD9zyOc9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=OdRt1gT+; arc=none smtp.client-ip=148.163.156.1 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.b="OdRt1gT+" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9AD9qX019481; Mon, 9 Dec 2024 19:26:00 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=lD+okMqmTBth5ZV/u A89GNS+iS4rJ2NggJAIkLOozw0=; b=OdRt1gT+aH6G81lA210FGLd3aV28SLCmH Cu+57u9GraGNQ/AQ17skgZVeL/2lKNfo6IzF+jFKcBlZPuWpDzAXPyvyDYKMHDTc RmzTArnJAbsjaN9/Nyp/8FMSBjPI7M1L71pQMT6OzMEYjWCOlGrUpUoJYYys4r3g +UpNXrjukCFnlm52+KQkfAGajmR96Je8Zp5n4ZG4HPqCTIcOz53U2i4XsYD8x0x6 /BfsRvTtZmrHKoDQLIrSf7Dq6R33zvHmiG2g5hc4YqMVedTdDsZ1Df3kamlfxJcY wyXX1MlC9fRphyf6f/RQKU3+zWUPOjoOSz+heRyRFm+CmZRgAKBhA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43cdv8k7ne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:59 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9Ix6jv018636; Mon, 9 Dec 2024 19:25:58 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43d26k80hk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:58 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPvXS24772966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:25:57 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 627A758059; Mon, 9 Dec 2024 19:25:57 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EE4758043; Mon, 9 Dec 2024 19:25:56 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:56 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 5/7] iommu/s390: support iova_to_phys for additional table regions Date: Mon, 9 Dec 2024 14:25:47 -0500 Message-ID: <20241209192549.107226-6-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xS6pYYbtkqR_yZuNEQe-__wljMJsgX6g X-Proofpoint-ORIG-GUID: xS6pYYbtkqR_yZuNEQe-__wljMJsgX6g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 mlxlogscore=969 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090143 Content-Type: text/plain; charset="utf-8" The origin_type of the dma_table is used to determine how many table levels must be traversed for the translation. Signed-off-by: Matthew Rosato --- drivers/iommu/s390-iommu.c | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index 5782f329cae9..cea528bf61db 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -744,6 +744,43 @@ static int s390_iommu_map_pages(struct iommu_domain *d= omain, return rc; } =20 +static unsigned long *get_rto_from_iova(struct s390_domain *domain, + dma_addr_t iova) +{ + unsigned long *rfo, *rso, *rto; + unsigned long rfe, rse; + unsigned int rfx, rsx; + + switch (domain->origin_type) { + case ZPCI_TABLE_TYPE_RFX: + rfo =3D domain->dma_table; + goto itp_rf; + case ZPCI_TABLE_TYPE_RSX: + rso =3D domain->dma_table; + goto itp_rs; + case ZPCI_TABLE_TYPE_RTX: + return domain->dma_table; + default: + return NULL; + } + +itp_rf: + rfx =3D calc_rfx(iova); + rfe =3D READ_ONCE(rfo[rfx]); + if (!reg_entry_isvalid(rfe)) + return NULL; + rso =3D get_rf_rso(rfe); + +itp_rs: + rsx =3D calc_rsx(iova); + rse =3D READ_ONCE(rso[rsx]); + if (!reg_entry_isvalid(rse)) + return NULL; + rto =3D get_rs_rto(rse); + + return rto; +} + static phys_addr_t s390_iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { @@ -757,10 +794,13 @@ static phys_addr_t s390_iommu_iova_to_phys(struct iom= mu_domain *domain, iova > domain->geometry.aperture_end) return 0; =20 + rto =3D get_rto_from_iova(s390_domain, iova); + if (!rto) + return 0; + rtx =3D calc_rtx(iova); sx =3D calc_sx(iova); px =3D calc_px(iova); - rto =3D s390_domain->dma_table; =20 rte =3D READ_ONCE(rto[rtx]); if (reg_entry_isvalid(rte)) { --=20 2.47.0 From nobody Fri Dec 27 11:31:48 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 90A431A08CC; Mon, 9 Dec 2024 19:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772371; cv=none; b=TtkuPngfWCAqK9E+gryVDAAzg6yOQC+3aI2lENpj3Mi83gZJMVmRr2dqXwWYRCZDKlxVfWavTWFp+Bt7bFFjyJMyy+bFoMXUwRC4oMTBxhSb+X8ByFB4GbqbwYYtfHSwH2QbUMVS+6+p6AJK4U7sUWZbwpr3rwGoIL8mayMx5hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772371; c=relaxed/simple; bh=WIi9XoA9A2uc6JbaovPL4q1ymijAA7WpAaKJ8FZuIpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f1VUqf14bCZh1HvbdbEUr/mRHseI7D7IOc70nU/HzMj2/OLxi3mlRuipmy1F2D642lVM6Q7+3uC0v8+jV3yK8m5TIoQegdomrJNl695VvMITYN+7TIzkChPAOgdlWqcqfFSrr9vrZnuZZPBrdvVhBOi1SO0nAsaJTnZHTsiTXDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=Qjw34iwM; arc=none smtp.client-ip=148.163.158.5 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.b="Qjw34iwM" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9B4xUG032677; Mon, 9 Dec 2024 19:26:00 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=nSZPheZvpKDOK9A3V LIi74XqV9783u/Q0buFMWqezos=; b=Qjw34iwMaWT6hkQhZaYPsSCSnE033wwbw fymslt49kYNjw+3HPCl970Gfd0LA8R8oE/hkXD/g6RAO+oF6gypaOPOPDvYQRbHy WlVmFLp0ihfmnSkstkVFUc/zj0rDyyZ/jqkN4A1MSnt09Xvf46sYrzIZ7eCb3Ulo vDJp8mlbw3ovQHDoXbaMIjNtQpq2ffFhloUfnm7YRPc+scDwVcmJ4gcbGkg3kdBy IkeAkgsCX8Je0w1ftNHJSuBlGaTYv2yhGJw9h6jeSawKxSvRwChCzImpf9fGGUdu +Vtgy/4m1yyaZuXU8G+xTX9UqdltHl6rsN0x/cTn42Hi/bAAEmWbA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43cbsq2hur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:26:00 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9J74W5018605; Mon, 9 Dec 2024 19:25:59 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43d26k80hn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:25:59 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPwXO15532584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:25:58 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A64858055; Mon, 9 Dec 2024 19:25:58 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82A8C58043; Mon, 9 Dec 2024 19:25:57 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:57 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 6/7] iommu/s390: support map/unmap for additional table regions Date: Mon, 9 Dec 2024 14:25:48 -0500 Message-ID: <20241209192549.107226-7-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: BCmp2h_SP5dqWOkrgzTFC7HPTzhRqxmR X-Proofpoint-GUID: BCmp2h_SP5dqWOkrgzTFC7HPTzhRqxmR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 suspectscore=0 spamscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090147 Content-Type: text/plain; charset="utf-8" Map and unmap ops use the shared dma_walk_cpu_trans routine, update this using the origin_type of the dma_table to determine how many table levels must be walked. Signed-off-by: Matthew Rosato --- drivers/iommu/s390-iommu.c | 101 ++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index cea528bf61db..4924fe9faccb 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -316,6 +316,60 @@ static unsigned long *dma_alloc_page_table(gfp_t gfp) return table; } =20 +static unsigned long *dma_get_rs_table_origin(unsigned long *rfep, gfp_t g= fp) +{ + unsigned long old_rfe, rfe; + unsigned long *rso; + + rfe =3D READ_ONCE(*rfep); + if (reg_entry_isvalid(rfe)) { + rso =3D get_rf_rso(rfe); + } else { + rso =3D dma_alloc_cpu_table(gfp); + if (!rso) + return NULL; + + set_rf_rso(&rfe, virt_to_phys(rso)); + validate_rf_entry(&rfe); + entry_clr_protected(&rfe); + + old_rfe =3D cmpxchg(rfep, ZPCI_TABLE_INVALID, rfe); + if (old_rfe !=3D ZPCI_TABLE_INVALID) { + /* Somone else was faster, use theirs */ + dma_free_cpu_table(rso); + rso =3D get_rf_rso(old_rfe); + } + } + return rso; +} + +static unsigned long *dma_get_rt_table_origin(unsigned long *rsep, gfp_t g= fp) +{ + unsigned long old_rse, rse; + unsigned long *rto; + + rse =3D READ_ONCE(*rsep); + if (reg_entry_isvalid(rse)) { + rto =3D get_rs_rto(rse); + } else { + rto =3D dma_alloc_cpu_table(gfp); + if (!rto) + return NULL; + + set_rs_rto(&rse, virt_to_phys(rto)); + validate_rs_entry(&rse); + entry_clr_protected(&rse); + + old_rse =3D cmpxchg(rsep, ZPCI_TABLE_INVALID, rse); + if (old_rse !=3D ZPCI_TABLE_INVALID) { + /* Somone else was faster, use theirs */ + dma_free_cpu_table(rto); + rto =3D get_rs_rto(old_rse); + } + } + return rto; +} + static unsigned long *dma_get_seg_table_origin(unsigned long *rtep, gfp_t = gfp) { unsigned long old_rte, rte; @@ -369,11 +423,45 @@ static unsigned long *dma_get_page_table_origin(unsig= ned long *step, gfp_t gfp) return pto; } =20 -static unsigned long *dma_walk_cpu_trans(unsigned long *rto, dma_addr_t dm= a_addr, gfp_t gfp) +static unsigned long *dma_walk_region_tables(struct s390_domain *domain, + dma_addr_t dma_addr, gfp_t gfp) +{ + unsigned long *rfo, *rso; + unsigned int rfx, rsx; + + switch (domain->origin_type) { + case ZPCI_TABLE_TYPE_RFX: + rfo =3D domain->dma_table; + goto walk_rf; + case ZPCI_TABLE_TYPE_RSX: + rso =3D domain->dma_table; + goto walk_rs; + case ZPCI_TABLE_TYPE_RTX: + return domain->dma_table; + default: + return NULL; + } + +walk_rf: + rfx =3D calc_rfx(dma_addr); + rso =3D dma_get_rs_table_origin(&rfo[rfx], gfp); + if (!rso) + return NULL; +walk_rs: + rsx =3D calc_rsx(dma_addr); + return dma_get_rt_table_origin(&rso[rsx], gfp); +} + +static unsigned long *dma_walk_cpu_trans(struct s390_domain *domain, + dma_addr_t dma_addr, gfp_t gfp) { - unsigned long *sto, *pto; + unsigned long *rto, *sto, *pto; unsigned int rtx, sx, px; =20 + rto =3D dma_walk_region_tables(domain, dma_addr, gfp); + if (!rto) + return NULL; + rtx =3D calc_rtx(dma_addr); sto =3D dma_get_seg_table_origin(&rto[rtx], gfp); if (!sto) @@ -665,8 +753,7 @@ static int s390_iommu_validate_trans(struct s390_domain= *s390_domain, int rc; =20 for (i =3D 0; i < nr_pages; i++) { - entry =3D dma_walk_cpu_trans(s390_domain->dma_table, dma_addr, - gfp); + entry =3D dma_walk_cpu_trans(s390_domain, dma_addr, gfp); if (unlikely(!entry)) { rc =3D -ENOMEM; goto undo_cpu_trans; @@ -681,8 +768,7 @@ static int s390_iommu_validate_trans(struct s390_domain= *s390_domain, undo_cpu_trans: while (i-- > 0) { dma_addr -=3D PAGE_SIZE; - entry =3D dma_walk_cpu_trans(s390_domain->dma_table, - dma_addr, gfp); + entry =3D dma_walk_cpu_trans(s390_domain, dma_addr, gfp); if (!entry) break; dma_update_cpu_trans(entry, 0, ZPCI_PTE_INVALID); @@ -699,8 +785,7 @@ static int s390_iommu_invalidate_trans(struct s390_doma= in *s390_domain, int rc =3D 0; =20 for (i =3D 0; i < nr_pages; i++) { - entry =3D dma_walk_cpu_trans(s390_domain->dma_table, dma_addr, - GFP_ATOMIC); + entry =3D dma_walk_cpu_trans(s390_domain, dma_addr, GFP_ATOMIC); if (unlikely(!entry)) { rc =3D -EINVAL; break; --=20 2.47.0 From nobody Fri Dec 27 11:31:48 2024 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 98C951A0BE3; Mon, 9 Dec 2024 19:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772373; cv=none; b=jmt3qL7lTYTUiDaNpkA6R8gklf2Z9ALOukowtZFZoXOTZxTvUrN8DCtLSc2xhubvoDBZZnG7lJPb6vUDZjUXdsY2z6yr9ETZEtIywbDYc0YDLSIC6aIw3DRliTVEjm4zT+Xved/gpvKcb1VHnN0Cfpg1ve3FjEtDnjNRwPtvN6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733772373; c=relaxed/simple; bh=LPNkuOmebHNuBo/pC6lnaWGMiAhUES4i8Dyjjjq50mk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L2JNJlSy5JYu3QP96xSWOQG7NxLp8TZQrCKKanCOrWF9Osuy+ZgQS+O7RplWUf2o+B2ovzRK1LZF9DAHcNhfYCFkx56J0xWWSVmpUGWtb1HCs0RfalIhaoIcAzYJpW7qR4ygMcUXDG6VJPBGHQslKQeVRK4MTUwSDI+Jt1V9HV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=K9S/Trdl; arc=none smtp.client-ip=148.163.156.1 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.b="K9S/Trdl" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9JBHF1024001; Mon, 9 Dec 2024 19:26:02 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=FunvrjiwafodM2rLJ eOmhzOHrDQ5GsZcH0APQLk7yY8=; b=K9S/Trdl3Is20Lc7P73REHlus4ftIj1Am ULl4sH8MpE3ok19WtPrzH0iDl4oH5eeHiq/rgj3Ig7gllAfhjyGLb/u1u0wdvhK9 xpxSAjWdIdQdFn+kzgYojRQUjp7aN9zDqD4bENK27mKXDb/Gn8fCNQdxpJnvFUt5 f6uTDdsG995SCwLKRKhp2liDgkOgZ0g2PqnarVa8wdg2ow2KEBkrVCbpKJG0sOnC J97PKMU7VeDZQaitLRMMkNnfVA6kWsozSUM0Uk7MaYYRGN151n42T1wVefI8eDVN pQfPtktg6NSjVxHPukuKN2bRg46EjF5WB9umuxyheZ1PZ6asxB3pA== 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 43cdv8k7nr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:26:01 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B9HRcQc032727; Mon, 9 Dec 2024 19:26:00 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 43d0ps89x0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:26:00 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B9JPxHg25428568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Dec 2024 19:26:00 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3F8B58055; Mon, 9 Dec 2024 19:25:59 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB3A458043; Mon, 9 Dec 2024 19:25:58 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Dec 2024 19:25:58 +0000 (GMT) From: Matthew Rosato To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com Cc: hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, borntraeger@linux.ibm.com, clegoate@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 7/7] iommu/s390: allow larger region tables Date: Mon, 9 Dec 2024 14:25:49 -0500 Message-ID: <20241209192549.107226-8-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209192549.107226-1-mjrosato@linux.ibm.com> References: <20241209192549.107226-1-mjrosato@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: uCaPcHQf14DWuo35zKYXSM53Mm4iXKLh X-Proofpoint-ORIG-GUID: uCaPcHQf14DWuo35zKYXSM53Mm4iXKLh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 mlxlogscore=903 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412090143 Content-Type: text/plain; charset="utf-8" Extend the aperture calculation to consider sizes beyond the maximum size of a region third table. Attempt to always use the smallest table size possible to avoid unnecessary extra steps during translation. Signed-off-by: Matthew Rosato --- arch/s390/include/asm/pci_dma.h | 1 + drivers/iommu/s390-iommu.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/s390/include/asm/pci_dma.h b/arch/s390/include/asm/pci_dm= a.h index 8d8962e4fd58..d12e17201661 100644 --- a/arch/s390/include/asm/pci_dma.h +++ b/arch/s390/include/asm/pci_dma.h @@ -25,6 +25,7 @@ enum zpci_ioat_dtype { #define ZPCI_KEY (PAGE_DEFAULT_KEY << 5) =20 #define ZPCI_TABLE_SIZE_RT (1UL << 42) +#define ZPCI_TABLE_SIZE_RS (1UL << 53) =20 #define ZPCI_IOTA_STO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_D= T_ST) #define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_= DT_RT) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index 4924fe9faccb..c6b2bca881c3 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -953,12 +953,24 @@ int zpci_init_iommu(struct zpci_dev *zdev) goto out_sysfs; =20 zdev->start_dma =3D PAGE_ALIGN(zdev->start_dma); - aperture_size =3D min3(s390_iommu_aperture, - ZPCI_TABLE_SIZE_RT - zdev->start_dma, - zdev->end_dma - zdev->start_dma + 1); + aperture_size =3D min(s390_iommu_aperture, + zdev->end_dma - zdev->start_dma + 1); + if (aperture_size <=3D (ZPCI_TABLE_SIZE_RT - zdev->start_dma)) { + zdev->origin_type =3D ZPCI_TABLE_TYPE_RTX; + zdev->max_table_size =3D ZPCI_TABLE_SIZE_RT - 1; + } else if (aperture_size <=3D (ZPCI_TABLE_SIZE_RS - zdev->start_dma) && + (zdev->dtsm & ZPCI_IOTA_DT_RS)) { + zdev->origin_type =3D ZPCI_TABLE_TYPE_RSX; + zdev->max_table_size =3D ZPCI_TABLE_SIZE_RS - 1; + } else if (zdev->dtsm & ZPCI_IOTA_DT_RF) { + zdev->origin_type =3D ZPCI_TABLE_TYPE_RFX; + zdev->max_table_size =3D U64_MAX; + } else { + /* Assume RTX available */ + zdev->origin_type =3D ZPCI_TABLE_TYPE_RTX; + zdev->max_table_size =3D ZPCI_TABLE_SIZE_RT - 1; + } zdev->end_dma =3D zdev->start_dma + aperture_size - 1; - zdev->origin_type =3D ZPCI_TABLE_TYPE_RTX; - zdev->max_table_size =3D ZPCI_TABLE_SIZE_RT - 1; =20 return 0; =20 --=20 2.47.0