From nobody Wed Dec 17 14:20:38 2025 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 81A97202C5B; Wed, 12 Feb 2025 21:34:35 +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=1739396077; cv=none; b=pRvamaVO5Q5MIGIMDiXoSZ0usy5lmbxkWAMzSiWA8iCk8xTgAzV2Gb9iwsOFHHRO6Kem0p/KAz4gsWyuVP5GP6xgkUwcIypxAaSJDwI5RcJ7tAX0Ylxbfe6vTgGrJTRf8tO4qgU7QU7c2ErqRFrMSlkX81XQmEa890mxhr3OfXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739396077; c=relaxed/simple; bh=wI1MHowA80iIxAECLLCmspP1IM6adPGDHCugie5UhD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RjRMT8jtirC4Pc4DBHSUIQAoeThXLzjqUWwd0Y9oAIzErdjI0l8BdhPg7cqJlsFwg+qvIBXE5iLg/H9Y+hheUUrIUV5ddLRA3rmMg3/SUWCAnu8q4kqoH2YqpPxJax7nJACKnsnr5g9Kqpawqmk7WJrMFByuvt5DMm+xjV/1hZw= 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=IbrvaJQy; 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="IbrvaJQy" 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 51CKG9ei015177; Wed, 12 Feb 2025 21:34:23 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=qQXDr9ee4DxcBjU9H P0m1OF3o9C1GlZT/POYV4GYW5w=; b=IbrvaJQyTBkRf4U3zkA212wtjuEsFXXvh fYjlHltvF/jt23bXbFZBwN3QGyenkFb+VgKANMyjE2WxELtzr9jHYe687euED7fP NI6TGw3FH4yOuzgtm1HMVGhW6uUzWi2fvbk2Btee7PpdnUmVCvUYeU26+YmqhnZf 1pl1qdXyaqQROHaERHA6NUje5moahIWJ1mJeNZle/DjuKOL/zfFxAr81vpVDUMlf 9lT43MDKWcfRO2woOz+65F6s7u6DHl9NZgBPQn7sIURZ7VM+hnnrrTF/nT0tAAzL E9zA9JBIK/lJX+MPWcYhbOPpdJk3zIRHKo+zK8BjS10JR9VQ62I7A== 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 44rxfu1qfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:23 +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 51CJFBXI016679; Wed, 12 Feb 2025 21:34:22 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 44pk3kay23-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:22 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51CLYLfZ32178730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Feb 2025 21:34:21 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A07FE5805A; Wed, 12 Feb 2025 21:34:21 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8895A58056; Wed, 12 Feb 2025 21:34:20 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.186.234]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 12 Feb 2025 21:34:20 +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, farman@linux.ibm.com, clegoate@redhat.com, jgg@nvidia.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v5 1/4] s390/pci: check for relaxed translation capability Date: Wed, 12 Feb 2025 16:34:15 -0500 Message-ID: <20250212213418.182902-2-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250212213418.182902-1-mjrosato@linux.ibm.com> References: <20250212213418.182902-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: -HN6U-kw9B1jPD0k7y_YccgCHhHmiLJG X-Proofpoint-GUID: -HN6U-kw9B1jPD0k7y_YccgCHhHmiLJG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-12_06,2025-02-11_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 mlxlogscore=785 phishscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502120152 Content-Type: text/plain; charset="utf-8" For each zdev, record whether or not CLP indicates relaxed translation capability for the associated device group. Reviewed-by: Niklas Schnelle Tested-by: Niklas Schnelle Signed-off-by: Matthew Rosato --- arch/s390/include/asm/pci.h | 2 +- arch/s390/include/asm/pci_clp.h | 4 +++- arch/s390/pci/pci_clp.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h index 474e1f8d1d3c..8fe4c7a72c0b 100644 --- a/arch/s390/include/asm/pci.h +++ b/arch/s390/include/asm/pci.h @@ -144,7 +144,7 @@ struct zpci_dev { u8 util_str_avail : 1; u8 irqs_registered : 1; u8 tid_avail : 1; - u8 reserved : 1; + u8 rtr_avail : 1; /* Relaxed translation allowed */ unsigned int devfn; /* DEVFN part of the RID*/ =20 u8 pfip[CLP_PFIP_NR_SEGMENTS]; /* pci function internal path */ diff --git a/arch/s390/include/asm/pci_clp.h b/arch/s390/include/asm/pci_cl= p.h index 3fff2f7095c8..7ebff39c84b3 100644 --- a/arch/s390/include/asm/pci_clp.h +++ b/arch/s390/include/asm/pci_clp.h @@ -156,7 +156,9 @@ struct clp_rsp_query_pci_grp { u16 : 4; u16 noi : 12; /* number of interrupts */ u8 version; - u8 : 6; + u8 : 2; + u8 rtr : 1; /* Relaxed translation requirement */ + u8 : 3; u8 frame : 1; u8 refresh : 1; /* TLB refresh mode */ u16 : 3; diff --git a/arch/s390/pci/pci_clp.c b/arch/s390/pci/pci_clp.c index 14bf7e8d06b7..27248686e588 100644 --- a/arch/s390/pci/pci_clp.c +++ b/arch/s390/pci/pci_clp.c @@ -112,6 +112,7 @@ static void clp_store_query_pci_fngrp(struct zpci_dev *= zdev, zdev->version =3D response->version; zdev->maxstbl =3D response->maxstbl; zdev->dtsm =3D response->dtsm; + zdev->rtr_avail =3D response->rtr; =20 switch (response->version) { case 1: --=20 2.48.1 From nobody Wed Dec 17 14:20:38 2025 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 59B6C2036EB; Wed, 12 Feb 2025 21:34:38 +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=1739396079; cv=none; b=sFZZMvZ4XmByw25EvsJB+XGVlJDWgLWNpusqmZezLJoVgKGLfexS6F2ontioBbkHl7oWqnFrLJDSqsudfA3SDLw49mx49QrwLuRAWvxaQOMTf/1Kivrq0gKprECNTZmSrYnoI7bK8Ia9jxPHjnaee3Ot8X9OhPe7PDltjc6uhFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739396079; c=relaxed/simple; bh=Pz27KBxivFB/1h86mWXpvQYtsw4RQhgfR+83qzBhmnQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mte2UtarhR5SgxTi11si7CrRX2aOQtxvD94Dma2z1N6NoNNH19a17M+kuVsdMQ9gd2HHCP3OMlCgVcfUAvPJdOvWSkUL5sdDvPFRJoDzPYaUdGnd4cKVzfa4ASm+LneLG7C/QW/0iynuHsIO3acbT4lneHoMut3s8u5bM9AjUdc= 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=dnhDHfq6; 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="dnhDHfq6" 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 51CKGA1j011934; Wed, 12 Feb 2025 21:34:25 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=VOi5YzOhZwWrlCPfS pxx7Q8bocn48/ZD9KlSCzhf0Hs=; b=dnhDHfq69hFnnYhqxTIqdmxriNRrNeIwK Uq2aBGOp14hKmlqOytFDoXXhTDplHzMNodkxZgrxDaDzoajrvTnpCkfIm1W+ZKEy 57G+PDC2cqGFRaFY3MGp2pl2Mg6aedRE9xVDGWkIFt3+NWgFqAVIuUmymg8lMR7D lYEJmNZ+5garKJv97VGwmNYdFPfVH4DgiTzIO0ULSHr+fI5cTjMDjGDMPTgay0OK 19YaKdzPAEZOCfnMDzpJZkCof/VkCyDmgG54B3sF1VBMpp/mvOCU8VTWJUc0e2oe NrR71nnqgSAu1mIBFSQKxpwz1Ec+6tLJt8TnCq9ae57L0IOIg9yqA== 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 44rfpa67dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:25 +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 51CIMhuY021875; Wed, 12 Feb 2025 21:34:24 GMT Received: from smtprelay01.wdc07v.mail.ibm.com ([172.16.1.68]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 44phksu5ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:24 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay01.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51CLYMEX25625242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Feb 2025 21:34:23 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C90F35803F; Wed, 12 Feb 2025 21:34:22 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB67458056; Wed, 12 Feb 2025 21:34:21 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.186.234]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 12 Feb 2025 21:34:21 +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, farman@linux.ibm.com, clegoate@redhat.com, jgg@nvidia.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v5 2/4] s390/pci: store DMA offset in bus_dma_region Date: Wed, 12 Feb 2025 16:34:16 -0500 Message-ID: <20250212213418.182902-3-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250212213418.182902-1-mjrosato@linux.ibm.com> References: <20250212213418.182902-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: K5T5_4uNLo_nPJYvu_eeRl2jxD43pfgS X-Proofpoint-ORIG-GUID: K5T5_4uNLo_nPJYvu_eeRl2jxD43pfgS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-12_06,2025-02-11_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=768 clxscore=1015 phishscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502120152 Content-Type: text/plain; charset="utf-8" PCI devices on s390 have a DMA offset that is reported via CLP. In preparation for allowing identity domains, setup the bus_dma_region for all PCI devices using the reported CLP value. Signed-off-by: Matthew Rosato Reviewed-by: Niklas Schnelle Tested-by: Niklas Schnelle --- arch/s390/pci/pci_bus.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c index 857afbc4828f..3fa113c4ad8f 100644 --- a/arch/s390/pci/pci_bus.c +++ b/arch/s390/pci/pci_bus.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -283,10 +284,34 @@ static struct zpci_bus *zpci_bus_alloc(int topo, bool= topo_is_tid) return zbus; } =20 +static void pci_dma_range_setup(struct pci_dev *pdev) +{ + struct zpci_dev *zdev =3D to_zpci(pdev); + struct bus_dma_region *map; + u64 aligned_end; + + map =3D kzalloc(sizeof(*map), GFP_KERNEL); + if (!map) + return; + + map->cpu_start =3D 0; + map->dma_start =3D PAGE_ALIGN(zdev->start_dma); + aligned_end =3D PAGE_ALIGN_DOWN(zdev->end_dma + 1); + if (aligned_end >=3D map->dma_start) + map->size =3D aligned_end - map->dma_start; + else + map->size =3D 0; + WARN_ON_ONCE(map->size =3D=3D 0); + + pdev->dev.dma_range_map =3D map; +} + void pcibios_bus_add_device(struct pci_dev *pdev) { struct zpci_dev *zdev =3D to_zpci(pdev); =20 + pci_dma_range_setup(pdev); + /* * With pdev->no_vf_scan the common PCI probing code does not * perform PF/VF linking. --=20 2.48.1 From nobody Wed Dec 17 14:20:38 2025 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 4DB1A20370D; Wed, 12 Feb 2025 21:34:38 +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=1739396081; cv=none; b=dNuIrxukDtpAktr7EAM6HcU1viT3oKDcWlpR4n0QgoFVsWJXP2SgYp5DTdfyfFRUBcesvKugW2shrKUlAbdneuXf0ZURWEXwJ4jwdDtvzs2V6ZnC6hWOsPRySO0+52q1lX6I1j8VQUNpJj9uiFOkhnLvfHweNV9eQpiTUyIuU2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739396081; c=relaxed/simple; bh=pPA/FPCALLtCi1P09AFQdrA3b92adSUYx4G0GA5Nh5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aAJszZChe1m08taZ3hfbWHkIPSttyCFlwc81f0MAmc4I4erIW811ZJLqio/WKa/Vt1wjt2l0p0TsH96f/mSB/6p58I5ZKnCMsPELacjGIeQ2iAH0JD/9LVaRguvbexpAB4oy2p2H7s+7ynFnkX1UUM5I9p5PN3MMioJ+8cWxy/g= 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=lLkCW9/P; 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="lLkCW9/P" 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 51CKGA03015253; Wed, 12 Feb 2025 21:34:27 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=1o0mWr+AP905Ri1hg xKnneXc4cju+1S36WBaT8aqkn0=; b=lLkCW9/PB9g12Qh+AreOuglRFPJZMmLeY PQOHw51v1DA+KNqaBH7f4d9qPVQnFjh4Ts5W1tFRzrSHIuaITzRy+9ztI/NNPPSM lrANS3UOJreOctv+c59I8aJANEKqyBr9EkjpdRv52cddYZxR+WN6SpXDrgCQscWE sMT+huAmu4fduhdNBwNvwe4ArQzb4ovFnKi7oTlTncH7Ld48t1jE5vWLbGXw+QMh VOQrZL08ppxTeGptSItT8PoMnD5wy5maLfQ3RvV2UmzkixS4eY5EvgrDZ7uTuLcv lNlcT7goKpaPHmCvQAhHzpNzi6kNRi6lF7b4e9xS0dvszUgrgctkw== 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 44rxfu1qg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:26 +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 51CIEXA3021665; Wed, 12 Feb 2025 21:34:26 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 44phksu5tu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:26 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51CLYNfp57606482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Feb 2025 21:34:23 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 20DC658060; Wed, 12 Feb 2025 21:34:24 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F21BC58068; Wed, 12 Feb 2025 21:34:22 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.186.234]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 12 Feb 2025 21:34:22 +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, farman@linux.ibm.com, clegoate@redhat.com, jgg@nvidia.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v5 3/4] iommu/s390: handle IOAT registration based on domain Date: Wed, 12 Feb 2025 16:34:17 -0500 Message-ID: <20250212213418.182902-4-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250212213418.182902-1-mjrosato@linux.ibm.com> References: <20250212213418.182902-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: uTe1SCDQ96HjuHZSpAlr_Wn87CvPZHVu X-Proofpoint-GUID: uTe1SCDQ96HjuHZSpAlr_Wn87CvPZHVu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-12_06,2025-02-11_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 mlxlogscore=922 phishscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502120152 Content-Type: text/plain; charset="utf-8" At this point, the dma_table is really a property of the s390-iommu domain. Rather than checking its contents elsewhere in the codebase, move the code that registers the table with firmware into s390-iommu and make a decision what to register with firmware based upon the type of domain in use for the device in question. Tested-by: Niklas Schnelle Reviewed-by: Niklas Schnelle Signed-off-by: Matthew Rosato --- arch/s390/include/asm/pci.h | 2 ++ arch/s390/kvm/pci.c | 17 ++------------- arch/s390/pci/pci.c | 35 +++++++++++++++++------------- arch/s390/pci/pci_sysfs.c | 11 +--------- drivers/iommu/s390-iommu.c | 43 +++++++++++++++++++++++++++++++++++-- 5 files changed, 66 insertions(+), 42 deletions(-) diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h index 8fe4c7a72c0b..7cc6a7cc66e7 100644 --- a/arch/s390/include/asm/pci.h +++ b/arch/s390/include/asm/pci.h @@ -217,6 +217,7 @@ extern struct airq_iv *zpci_aif_sbv; struct zpci_dev *zpci_create_device(u32 fid, u32 fh, enum zpci_state state= ); int zpci_add_device(struct zpci_dev *zdev); int zpci_enable_device(struct zpci_dev *); +int zpci_reenable_device(struct zpci_dev *zdev); int zpci_disable_device(struct zpci_dev *); int zpci_scan_configured_device(struct zpci_dev *zdev, u32 fh); int zpci_deconfigure_device(struct zpci_dev *zdev); @@ -245,6 +246,7 @@ void update_uid_checking(bool new); /* IOMMU Interface */ int zpci_init_iommu(struct zpci_dev *zdev); void zpci_destroy_iommu(struct zpci_dev *zdev); +int zpci_iommu_register_ioat(struct zpci_dev *zdev, u8 *status); =20 #ifdef CONFIG_PCI static inline bool zpci_use_mio(struct zpci_dev *zdev) diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c index 9b9e7fdd5380..8c40154ff50f 100644 --- a/arch/s390/kvm/pci.c +++ b/arch/s390/kvm/pci.c @@ -433,7 +433,6 @@ static void kvm_s390_pci_dev_release(struct zpci_dev *z= dev) static int kvm_s390_pci_register_kvm(void *opaque, struct kvm *kvm) { struct zpci_dev *zdev =3D opaque; - u8 status; int rc; =20 if (!zdev) @@ -480,13 +479,7 @@ static int kvm_s390_pci_register_kvm(void *opaque, str= uct kvm *kvm) */ zdev->gisa =3D (u32)virt_to_phys(&kvm->arch.sie_page2->gisa); =20 - rc =3D zpci_enable_device(zdev); - if (rc) - goto clear_gisa; - - /* Re-register the IOMMU that was already created */ - rc =3D zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, - virt_to_phys(zdev->dma_table), &status); + rc =3D zpci_reenable_device(zdev); if (rc) goto clear_gisa; =20 @@ -516,7 +509,6 @@ static void kvm_s390_pci_unregister_kvm(void *opaque) { struct zpci_dev *zdev =3D opaque; struct kvm *kvm; - u8 status; =20 if (!zdev) return; @@ -550,12 +542,7 @@ static void kvm_s390_pci_unregister_kvm(void *opaque) goto out; } =20 - if (zpci_enable_device(zdev)) - goto out; - - /* Re-register the IOMMU that was already created */ - zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, - virt_to_phys(zdev->dma_table), &status); + zpci_reenable_device(zdev); =20 out: spin_lock(&kvm->arch.kzdev_list_lock); diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 88f72745fa59..fa879351efb5 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -124,14 +124,13 @@ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaa= s, struct zpci_fib fib =3D {0}; u8 cc; =20 - WARN_ON_ONCE(iota & 0x3fff); fib.pba =3D base; /* Work around off by one in ISM virt device */ if (zdev->pft =3D=3D PCI_FUNC_TYPE_ISM && limit > base) fib.pal =3D limit + (1 << 12); else fib.pal =3D limit; - fib.iota =3D iota | ZPCI_IOTA_RTTO_FLAG; + fib.iota =3D iota; fib.gd =3D zdev->gisa; cc =3D zpci_mod_fc(req, &fib, status); if (cc) @@ -690,6 +689,23 @@ int zpci_enable_device(struct zpci_dev *zdev) } EXPORT_SYMBOL_GPL(zpci_enable_device); =20 +int zpci_reenable_device(struct zpci_dev *zdev) +{ + u8 status; + int rc; + + rc =3D zpci_enable_device(zdev); + if (rc) + return rc; + + rc =3D zpci_iommu_register_ioat(zdev, &status); + if (rc) + zpci_disable_device(zdev); + + return rc; +} +EXPORT_SYMBOL_GPL(zpci_reenable_device); + int zpci_disable_device(struct zpci_dev *zdev) { u32 fh =3D zdev->fh; @@ -739,7 +755,6 @@ EXPORT_SYMBOL_GPL(zpci_disable_device); */ int zpci_hot_reset_device(struct zpci_dev *zdev) { - u8 status; int rc; =20 lockdep_assert_held(&zdev->state_lock); @@ -758,19 +773,9 @@ int zpci_hot_reset_device(struct zpci_dev *zdev) return rc; } =20 - rc =3D zpci_enable_device(zdev); - if (rc) - return rc; - - if (zdev->dma_table) - rc =3D zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, - virt_to_phys(zdev->dma_table), &status); - if (rc) { - zpci_disable_device(zdev); - return rc; - } + rc =3D zpci_reenable_device(zdev); =20 - return 0; + return rc; } =20 /** diff --git a/arch/s390/pci/pci_sysfs.c b/arch/s390/pci/pci_sysfs.c index 2de1ea6c3a8c..0ecad08e1b1e 100644 --- a/arch/s390/pci/pci_sysfs.c +++ b/arch/s390/pci/pci_sysfs.c @@ -52,7 +52,6 @@ static DEVICE_ATTR_RO(mio_enabled); =20 static int _do_recover(struct pci_dev *pdev, struct zpci_dev *zdev) { - u8 status; int ret; =20 pci_stop_and_remove_bus_device(pdev); @@ -70,16 +69,8 @@ static int _do_recover(struct pci_dev *pdev, struct zpci= _dev *zdev) return ret; } =20 - ret =3D zpci_enable_device(zdev); - if (ret) - return ret; + ret =3D zpci_reenable_device(zdev); =20 - if (zdev->dma_table) { - ret =3D zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, - virt_to_phys(zdev->dma_table), &status); - if (ret) - zpci_disable_device(zdev); - } return ret; } =20 diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index fbdeded3d48b..007ccfdad495 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -381,6 +381,46 @@ static void zdev_s390_domain_update(struct zpci_dev *z= dev, spin_unlock_irqrestore(&zdev->dom_lock, flags); } =20 +static int s390_iommu_domain_reg_ioat(struct zpci_dev *zdev, + struct iommu_domain *domain, u8 *status) +{ + struct s390_domain *s390_domain; + int rc =3D 0; + u64 iota; + + switch (domain->type) { + case IOMMU_DOMAIN_IDENTITY: + rc =3D zpci_register_ioat(zdev, 0, zdev->start_dma, + zdev->end_dma, 0, status); + break; + case IOMMU_DOMAIN_BLOCKED: + /* Nothing to do in this case */ + break; + default: + s390_domain =3D to_s390_domain(domain); + iota =3D virt_to_phys(s390_domain->dma_table) | + ZPCI_IOTA_RTTO_FLAG; + rc =3D zpci_register_ioat(zdev, 0, zdev->start_dma, + zdev->end_dma, iota, status); + } + + return rc; +} + +int zpci_iommu_register_ioat(struct zpci_dev *zdev, u8 *status) +{ + unsigned long flags; + int rc; + + spin_lock_irqsave(&zdev->dom_lock, flags); + + rc =3D s390_iommu_domain_reg_ioat(zdev, zdev->s390_domain, status); + + spin_unlock_irqrestore(&zdev->dom_lock, flags); + + return rc; +} + static int blocking_domain_attach_device(struct iommu_domain *domain, struct device *dev) { @@ -422,8 +462,7 @@ static int s390_iommu_attach_device(struct iommu_domain= *domain, blocking_domain_attach_device(&blocking_domain, dev); =20 /* If we fail now DMA remains blocked via blocking domain */ - cc =3D zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, - virt_to_phys(s390_domain->dma_table), &status); + cc =3D s390_iommu_domain_reg_ioat(zdev, domain, &status); if (cc && status !=3D ZPCI_PCI_ST_FUNC_NOT_AVAIL) return -EIO; zdev->dma_table =3D s390_domain->dma_table; --=20 2.48.1 From nobody Wed Dec 17 14:20:38 2025 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 C625220371D; Wed, 12 Feb 2025 21:34:39 +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=1739396081; cv=none; b=T6qyVjgfYi3enL2Mt9qqBODPSuTUSdQJXVcxpGP8tT9pB6dOQoLzb72a7iwZRzVA/dMDka1YYRe0gEAjIkQYx5m5Jeccf3a22cl7x5SOccVj00zEIh2rs0i/6MozrfyIBAXfZNjb+iPkQpP9Suvu4fXPwBeYXokvA06MW81DDM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739396081; c=relaxed/simple; bh=lVLVvKssvh23Wa1P5dfJrqLc+D1LxadSc52EeR3Ak7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nqUzSP1FTgn/9kcmzISo9UUQCScfo/Pnvl/xRXVCVJ4KUCqtYWpYnCxULp0SM9slsH59ihV1Fc60VUTo3OpPcLXbBL66SI0IqDwrOzEEq/w5UkisVijG4QBl5NKWPXu4sdUpH4LyNPqyLOX8vZx7NWsjpIms42uA/GTFC/0t9wk= 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=nnUHyp3d; 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="nnUHyp3d" 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 51CKGFap011996; Wed, 12 Feb 2025 21:34:28 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=jr1qt4yvIuAZDAiDh a5koiFFri8NBXeUCFli7Bilgdw=; b=nnUHyp3da/+sGZLGOzqkRMxQVH0Om3Lzl sCCLjpe8629vIGk6rGvNcrVAPUCfr5jRAWy93Xiiaqij0C8r8mYZhFy02S19WuSe 8zAF1s9ZEZ/nod4cXfuYm5o9lagcdKzn5DjsRAsC9/+el1iQv0P0VvkJm8biwMjR GBn+RClZ9cXQkcLldirRVpEccVEbr4zIhs7j4k9+vOJKxsmG/NCRXnF3wOBcveuP Jhge3QYEKj8A2qsGraVZ6h1fHkV5Bx1honrhkWZfrme+UqM7Pzxp8N9B8DAG/0ZB Dksnoda9qz2978oiR/homNMLjF7P9axrDgzyUotHEpnp9PZsY2zmg== 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 44rfpa67dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:28 +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 51CKsVIb029203; Wed, 12 Feb 2025 21:34:27 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 44pma1tm0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 21:34:27 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51CLYP4235455560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Feb 2025 21:34:25 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5377758060; Wed, 12 Feb 2025 21:34:25 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3ADDC58056; Wed, 12 Feb 2025 21:34:24 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.186.234]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 12 Feb 2025 21:34:24 +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, farman@linux.ibm.com, clegoate@redhat.com, jgg@nvidia.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v5 4/4] iommu/s390: implement iommu passthrough via identity domain Date: Wed, 12 Feb 2025 16:34:18 -0500 Message-ID: <20250212213418.182902-5-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250212213418.182902-1-mjrosato@linux.ibm.com> References: <20250212213418.182902-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: QZcHwOmbSWqWWFvDk7uWCZ4JBjAcDChX X-Proofpoint-ORIG-GUID: QZcHwOmbSWqWWFvDk7uWCZ4JBjAcDChX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-12_06,2025-02-11_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 phishscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502120152 Content-Type: text/plain; charset="utf-8" Enabled via the kernel command-line 'iommu.passthrough=3D1' option. Introduce the concept of identity domains to s390-iommu, which relies on the bus_dma_region to offset identity mappings to the start of the DMA aperture advertized by CLP. Tested-by: Niklas Schnelle Reviewed-by: Niklas Schnelle Signed-off-by: Matthew Rosato --- drivers/iommu/s390-iommu.c | 95 +++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index 007ccfdad495..e1c76e0f9c2b 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -16,7 +16,7 @@ =20 #include "dma-iommu.h" =20 -static const struct iommu_ops s390_iommu_ops; +static const struct iommu_ops s390_iommu_ops, s390_iommu_rtr_ops; =20 static struct kmem_cache *dma_region_table_cache; static struct kmem_cache *dma_page_table_cache; @@ -432,9 +432,11 @@ static int blocking_domain_attach_device(struct iommu_= domain *domain, return 0; =20 s390_domain =3D to_s390_domain(zdev->s390_domain); - spin_lock_irqsave(&s390_domain->list_lock, flags); - list_del_rcu(&zdev->iommu_list); - spin_unlock_irqrestore(&s390_domain->list_lock, flags); + if (zdev->dma_table) { + spin_lock_irqsave(&s390_domain->list_lock, flags); + list_del_rcu(&zdev->iommu_list); + spin_unlock_irqrestore(&s390_domain->list_lock, flags); + } =20 zpci_unregister_ioat(zdev, 0); zdev->dma_table =3D NULL; @@ -762,7 +764,13 @@ int zpci_init_iommu(struct zpci_dev *zdev) if (rc) goto out_err; =20 - rc =3D iommu_device_register(&zdev->iommu_dev, &s390_iommu_ops, NULL); + if (zdev->rtr_avail) { + rc =3D iommu_device_register(&zdev->iommu_dev, + &s390_iommu_rtr_ops, NULL); + } else { + rc =3D iommu_device_register(&zdev->iommu_dev, &s390_iommu_ops, + NULL); + } if (rc) goto out_sysfs; =20 @@ -826,6 +834,39 @@ static int __init s390_iommu_init(void) } subsys_initcall(s390_iommu_init); =20 +static int s390_attach_dev_identity(struct iommu_domain *domain, + struct device *dev) +{ + struct zpci_dev *zdev =3D to_zpci_dev(dev); + u8 status; + int cc; + + blocking_domain_attach_device(&blocking_domain, dev); + + /* If we fail now DMA remains blocked via blocking domain */ + cc =3D s390_iommu_domain_reg_ioat(zdev, domain, &status); + + /* + * If the device is undergoing error recovery the reset code + * will re-establish the new domain. + */ + if (cc && status !=3D ZPCI_PCI_ST_FUNC_NOT_AVAIL) + return -EIO; + + zdev_s390_domain_update(zdev, domain); + + return 0; +} + +static const struct iommu_domain_ops s390_identity_ops =3D { + .attach_dev =3D s390_attach_dev_identity, +}; + +static struct iommu_domain s390_identity_domain =3D { + .type =3D IOMMU_DOMAIN_IDENTITY, + .ops =3D &s390_identity_ops, +}; + static struct iommu_domain blocking_domain =3D { .type =3D IOMMU_DOMAIN_BLOCKED, .ops =3D &(const struct iommu_domain_ops) { @@ -833,23 +874,31 @@ static struct iommu_domain blocking_domain =3D { } }; =20 -static const struct iommu_ops s390_iommu_ops =3D { - .blocked_domain =3D &blocking_domain, - .release_domain =3D &blocking_domain, - .capable =3D s390_iommu_capable, - .domain_alloc_paging =3D s390_domain_alloc_paging, - .probe_device =3D s390_iommu_probe_device, - .device_group =3D generic_device_group, - .pgsize_bitmap =3D SZ_4K, - .get_resv_regions =3D s390_iommu_get_resv_regions, - .default_domain_ops =3D &(const struct iommu_domain_ops) { - .attach_dev =3D s390_iommu_attach_device, - .map_pages =3D s390_iommu_map_pages, - .unmap_pages =3D s390_iommu_unmap_pages, - .flush_iotlb_all =3D s390_iommu_flush_iotlb_all, - .iotlb_sync =3D s390_iommu_iotlb_sync, - .iotlb_sync_map =3D s390_iommu_iotlb_sync_map, - .iova_to_phys =3D s390_iommu_iova_to_phys, - .free =3D s390_domain_free, +#define S390_IOMMU_COMMON_OPS() \ + .blocked_domain =3D &blocking_domain, \ + .release_domain =3D &blocking_domain, \ + .capable =3D s390_iommu_capable, \ + .domain_alloc_paging =3D s390_domain_alloc_paging, \ + .probe_device =3D s390_iommu_probe_device, \ + .device_group =3D generic_device_group, \ + .pgsize_bitmap =3D SZ_4K, \ + .get_resv_regions =3D s390_iommu_get_resv_regions, \ + .default_domain_ops =3D &(const struct iommu_domain_ops) { \ + .attach_dev =3D s390_iommu_attach_device, \ + .map_pages =3D s390_iommu_map_pages, \ + .unmap_pages =3D s390_iommu_unmap_pages, \ + .flush_iotlb_all =3D s390_iommu_flush_iotlb_all, \ + .iotlb_sync =3D s390_iommu_iotlb_sync, \ + .iotlb_sync_map =3D s390_iommu_iotlb_sync_map, \ + .iova_to_phys =3D s390_iommu_iova_to_phys, \ + .free =3D s390_domain_free, \ } + +static const struct iommu_ops s390_iommu_ops =3D { + S390_IOMMU_COMMON_OPS() +}; + +static const struct iommu_ops s390_iommu_rtr_ops =3D { + .identity_domain =3D &s390_identity_domain, + S390_IOMMU_COMMON_OPS() }; --=20 2.48.1