From nobody Sun Feb 8 04:00:45 2026 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 731701946AA; Fri, 13 Dec 2024 22:49:59 +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=1734130200; cv=none; b=K0mBj95UBIos+GnMaggjfOmksxWJX2TQyDynFQsvvrAm0ivw7LEROc1SCCTGMei9uq1Dz/hcPBz39Z1Kd4vFoLBvgidMx3CjJT4K0rYQlLxJscTP0Ujf063yIXJtNZ9Z54f6EZiJPyoYMDzVgDBOClLOPENElEUr4zAQaWHue9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734130200; c=relaxed/simple; bh=ZbKiRTrrdkm1V2O7xQ8FaIJbHWH0EDzhFY+/0iLsyTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CVrFV4J0xF//yfr5Xey6PwJzihQX6QL/3CmUmgtr6NaebxfuCztHZQCExlX00PWcRIP+rg0Xn3DUhvnBe3zB0Ot8hN/XXZn6JdAPS17tTP+kuN3LNzGSxG3F4UmwI+e4dXv/b3/RJGS+Fwa1XsOSUvW1pEprnaVS2A7oCJ9cwLU= 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=KAjpf6mV; 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="KAjpf6mV" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BDGfW9i026836; Fri, 13 Dec 2024 22:49:48 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=AZ72KimlqaUWy6p7F bz2xaxxOBZNuveFrquwyCc7Cxk=; b=KAjpf6mV+Uj2EY3SlCqNem6Wel7wPTk26 /iPSzbhrY50rFS0Ijhmicq67d/eEYasNQiKKSxzlz5IdUes7KP0FNE0uOyfdnw5/ DD/U1XR4os957B015PnWn5tBh1+K8MVKnliCzx1xugjq62REfkhOIPC/aujZxQQx F3ocovaVGKxs1UcZ2MIUE3dpDJCb6/YaXF/2+xEmtiH3cpI18cXbi1feZzZU/ksn /ycedq7GOQQd1Z2Piwj+4n48+NFfode3baEb41WPAxNpn7aLEo3fqb+N0pppSFW7 xu806qfqqXfL3PWcM7IezKOXCt+mxMdDvOWBflu+wITDcsHAXqsCw== 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 43g9yhnqwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Dec 2024 22:49:48 +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 4BDIrw4S007796; Fri, 13 Dec 2024 22:49:47 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43ft121hs1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Dec 2024 22:49:47 +0000 Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4BDMnktc35455716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Dec 2024 22:49:46 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D3F15805A; Fri, 13 Dec 2024 22:49:46 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6573958054; Fri, 13 Dec 2024 22:49:44 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 13 Dec 2024 22:49:44 +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, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v2 1/3] s390/pci: check for relaxed translation capability Date: Fri, 13 Dec 2024 17:49:39 -0500 Message-ID: <20241213224941.571060-2-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241213224941.571060-1-mjrosato@linux.ibm.com> References: <20241213224941.571060-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: bXuQhXRvw4sO4i9r7kOaMO24ZkeZr5hs X-Proofpoint-ORIG-GUID: bXuQhXRvw4sO4i9r7kOaMO24ZkeZr5hs 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 phishscore=0 clxscore=1015 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 impostorscore=0 mlxscore=0 bulkscore=0 mlxlogscore=811 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412130159 Content-Type: text/plain; charset="utf-8" For each zdev, record whether or not CLP indicates relaxed translation capability for the associated device group. 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.47.1 From nobody Sun Feb 8 04:00:45 2026 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 D974019992C; Fri, 13 Dec 2024 22:50:00 +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=1734130202; cv=none; b=Mh5VGhqp4KxOfsl7ZgRx0na5D/ha3VFFm5i3JDD+aJi1rnkt3AlTAJwHML/MZ9JjFNR+kcqEvxDEvUnLAzZeRlOLdYQj1zcEHWzbnzn+6vA6STANE2BfebwVoraB+ZMSS/oTdhDkF625+armMPy/UXNuwDibsWFJP0FtSzwlu8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734130202; c=relaxed/simple; bh=NV8s4CDPlzXfozxFeCXvR/Xud5ZSw+WUm6fxmIWPfEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QvmGEJhZWXGR3rgZqZAoHGKLHuJnu7ACUgbcT1CO0m6Jrz2GEDNn6cMGzXnhleUm2r6b7phY4vOAdyY1zSrWoI5SWFxgzCjo68mStVhGzQ0d6MP6NWxinJKp0jJyqxiH3eUQoSTExcdubI9XEayhNIkd6EWD1N8sSYR7gAkoS+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=XOEMgqSa; 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="XOEMgqSa" 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 4BDGfF49020128; Fri, 13 Dec 2024 22:49:51 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=U6IvUlDr62v5uqIXD HVMMi+43c+GZHQaTwOfqWN7TzE=; b=XOEMgqSaaoXyQR2NngIFt4h6vUJPUk+R1 C2wk1JXIZyyxQzg/mhWKMYPZTt0QYfsBMsHkLtYiTXkll3Y+88nnIZBDwrFTIuva Jg4xbluXq9VnXCIghXwIOd4oZR/a9IfxWzn7v/dQvLa7lIQMdWMAhFsBS3UzRJmc 8zpHQkM9wQ/zKqf1Ad7o5YuGSiOfLb1jjoEHZ2YnO8BN9AZR/WH81uc3LKMHMVRK lTbpsT0ngus+JtzSM2nNSvALlEeSU+PKqgWnMYJhaudRLb6H6M36pQjEdrL7G/cf IBwFB3paLzo8yDoKbJ86xnnaddZwJV7uWpRfuHlLyDiFcRSiKQnNQ== 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 43gddbw0su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Dec 2024 22:49:50 +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 4BDIcBC0029231; Fri, 13 Dec 2024 22:49:49 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 43gcprv9vs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Dec 2024 22:49:49 +0000 Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4BDMnmmS7209616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Dec 2024 22:49:48 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DE635805C; Fri, 13 Dec 2024 22:49:48 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B3AA58054; Fri, 13 Dec 2024 22:49:46 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 13 Dec 2024 22:49:46 +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, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v2 2/3] s390/pci: store DMA offset in bus_dma_region Date: Fri, 13 Dec 2024 17:49:40 -0500 Message-ID: <20241213224941.571060-3-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241213224941.571060-1-mjrosato@linux.ibm.com> References: <20241213224941.571060-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: 1kJc52XyvCxOVmHk5Bdc4F01FsGhN9qO X-Proofpoint-GUID: 1kJc52XyvCxOVmHk5Bdc4F01FsGhN9qO 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 phishscore=0 bulkscore=0 clxscore=1015 suspectscore=0 mlxlogscore=800 adultscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412130159 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 --- arch/s390/pci/pci_bus.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c index d5ace00d10f0..14527687d0f2 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 @@ -284,10 +285,27 @@ 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; + + map =3D kzalloc(sizeof(*map), GFP_KERNEL); + if (!map) + return; + + map->cpu_start =3D 0; + map->dma_start =3D PAGE_ALIGN(zdev->start_dma); + map->size =3D (u64)virt_to_phys(high_memory); + 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.47.1 From nobody Sun Feb 8 04:00:45 2026 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 79D8F1974EA; Fri, 13 Dec 2024 22:50:03 +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=1734130205; cv=none; b=n+EfHrVzmn4pWoFYa2zu5JuWGv1UoA5EyWvLj2xW8WHmZA/FzPa/usyZwkUAGpn9xkTfcGk8GIn/mqlGD0WD0uwxaiwGkfW7MBgcQuQO172Vve2qe0zPMHANsGIjJ9QjMDjRG/qRGqgTIhoBcK3e9uSc0AHIQ0yFOkkfPEfcYDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734130205; c=relaxed/simple; bh=0QrxwDumdv9ylh/ETp9pcFH7MM4XVeh5MXPIRYyG6vo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vo7ipE3PGcJT3+PTcSRGtiYoVS/eOpQWETTwHzOMTxAcsuurnXfhj2BiI39JtvrjdSY9WQakp06YOu07j7gBLMa42Q/6idxjAIR0P+62GRP9+hd1kG3gn7EWg49DZHFsV9nFaL2WFSIVW7Lo/s61K/xZsLuTy2C35i6JJH/9D+M= 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=UAw76aLS; 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="UAw76aLS" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BDGfGaM026699; Fri, 13 Dec 2024 22:49:52 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=XlZ7QWe3g498nZiSw gZp6D/1c5C+8eNDxfmcCpETGq0=; b=UAw76aLSePYWOlnh7yozAwkxQUCLqBZbN hukhww4S7xxM7X+dvvgQKjIb1eRybVA4P9MKN3KjH3Cr+rAzklLUUo7t7U2tHXJp oiaXuYgZw7bSyXDT0lssSuXciAjKBfsA421LrszGmMqlu4tXuNXzdexdFWnBhrWu su/1kOLUSnzyLvgfTzg4VVwAPYoQwuRCEh/E0MnpMXwTGr7G7KEnrkOArNdDfL3D kUacNDwAxu9GiV4l6AEAWat2i1xXywdFByOuB7YKi1mNTFdhjBoaj5aVmMxFWZW6 pV6jBKAO6vaxgOyNQ+1Rb2N3HQgwCMTVwVqbquZpPs12z+PCI5qNA== 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 43g9yhnqwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Dec 2024 22:49:52 +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 4BDIjudC029309; Fri, 13 Dec 2024 22:49:51 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 43gcprv9vw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Dec 2024 22:49:51 +0000 Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4BDMno9c26149410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Dec 2024 22:49:50 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 03EC85805A; Fri, 13 Dec 2024 22:49:50 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C25A58054; Fri, 13 Dec 2024 22:49:48 +0000 (GMT) Received: from li-2311da4c-2e09-11b2-a85c-c003041e9174.ibm.com.com (unknown [9.61.107.222]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 13 Dec 2024 22:49:48 +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, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v2 3/3] iommu/s390: implement iommu passthrough via identity domain Date: Fri, 13 Dec 2024 17:49:41 -0500 Message-ID: <20241213224941.571060-4-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241213224941.571060-1-mjrosato@linux.ibm.com> References: <20241213224941.571060-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: xEitcT7Om9Vv-MH5wyhxCzaQDno0AFNw X-Proofpoint-ORIG-GUID: xEitcT7Om9Vv-MH5wyhxCzaQDno0AFNw 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 phishscore=0 clxscore=1015 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 impostorscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412130159 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. Signed-off-by: Matthew Rosato --- arch/s390/pci/pci.c | 6 ++- drivers/iommu/s390-iommu.c | 95 +++++++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 88f72745fa59..758b23331754 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -124,14 +124,16 @@ 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; + if (iota =3D=3D 0) + fib.iota =3D iota; + else + fib.iota =3D iota | ZPCI_IOTA_RTTO_FLAG; fib.gd =3D zdev->gisa; cc =3D zpci_mod_fc(req, &fib, status); if (cc) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index fbdeded3d48b..3d93a9644fca 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; @@ -392,9 +392,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; @@ -723,7 +725,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 @@ -787,6 +795,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 zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, + 0, &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) { @@ -794,23 +835,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.47.1