From patchwork Thu Jan 25 12:08:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivaprasad G Bhat X-Patchwork-Id: 192045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1590603dyi; Thu, 25 Jan 2024 04:09:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEV1qglgrpmZJBO/9djMXvoYMCckfBCj+2aw2CTpVniFFieldQoPOIxS3yG5i17ao64ZZYL X-Received: by 2002:a05:622a:1008:b0:42a:5654:bbc5 with SMTP id d8-20020a05622a100800b0042a5654bbc5mr769689qte.132.1706184579403; Thu, 25 Jan 2024 04:09:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706184579; cv=pass; d=google.com; s=arc-20160816; b=iZmZn8GgFmWPQmk/Dz/THiQRf5R9BHhf6aupSE0OiHa7eCeUt69K1UbxZPfNZYDLdb Pr3CP0wFhh2EgiC9vMDOwwFlDFjkKK4VlyJtvXPRYoQHjDAH0PleGbEgAdi6nSbM+SXK inCJpN526sStoqmpJGCbt6pP339ztCmcfRRospNMgGX3cjftC/0Q+GHim0pHDslOo9WQ +nzhLiXYJPXOkfPjpps6v4NFvfMTn8lP9NgKjOPRsenw77tlzEGlrplLRGe8KWNhtt9n iC15fdOSr7C8YhOqJa5zQmS/b0ePxNeBZYO+ZV+BhE51kDXyogzUfUEVAY9pxPzluROi ZYIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=xq3woupK/AJHaIAxlnBBcKbFimpB/Ytqlol8MeYqF4s=; fh=bB2t8pimPSEnAwbiWcrAz14Rc33OdfzuWusVbzVIAgA=; b=j66B6iTsu7A1NULOlsO73/VrpdKgA5B0fW3VwfnK67+BmERTsLhpuqB9oLfKhXq0lL J/tIfEBOTVqBTZvoS1kX3U8zzoVP99euxIuzCtv05v03plXfXvv5lwtpLIgxJHShcZ1U ZDX7dGNScFlDQv53LQ1bMmYK2zd09nFenGry6MnMlDKXuqXpUiP6KtdU4XrUIjfuFxb5 4xJrdvBcoCZoWfztlEXXc9E5Xhm/f4hvfBYNHYK9OBuRb37cMkSQWRZNCPPPeDIH9E17 5AbPKvUZJazIvb6M90iNex4DBg38u92VEbM21K7v1nc3MyAQBiU3i6DZ2GWaCu9qC3Br hRHg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Vp4NhwYO; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-38565-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38565-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t7-20020ac85887000000b0042a70dcb6fcsi139195qta.98.2024.01.25.04.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 04:09:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38565-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Vp4NhwYO; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-38565-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38565-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1627B1C20A60 for ; Thu, 25 Jan 2024 12:09:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C76D345BF4; Thu, 25 Jan 2024 12:09:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Vp4NhwYO" 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 2F7B5374F5 for ; Thu, 25 Jan 2024 12:09:05 +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=1706184547; cv=none; b=H8ZYi4weXOp5/w8eH/t8EIs/+ExW9plIQ21LXFobZiNkXKobSTEuW5ItthCfgXhXTFbuwEBEJrrHpKUBgKpYibBO3PpqrqtZyAoDPpDb7lhIWPa3VD1KZVv45sX+oIucAY9+yNB+EOFhkH+Ydltjh9WQKPGf6ymlMJNK0xAG89g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706184547; c=relaxed/simple; bh=QNEuaPSeTMUedywIkeADQtjhcNqBXuYTWNaZCOucOjE=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=APfjy96r7ilgL3xx/yBw+rxHs6isU8dQ5XA0OEvEaanS7eyVvrTTYimu/LDK6MQN+plRXJXN9eMMXi8WwLX/5owl76PGc6uNaO6BRKgv9NpJClxZxAatLuTQrdvwYLeUVuEH//JwQqqYyjtAhAMKVGe/zRHWdzRHFVr9k5rKtB8= 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=Vp4NhwYO; 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 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40PBxrBO017909; Thu, 25 Jan 2024 12:08:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=xq3woupK/AJHaIAxlnBBcKbFimpB/Ytqlol8MeYqF4s=; b=Vp4NhwYOtwjJvvJ96RQy2MACM1JRMn5rUQJKciWmaaQ8T4wKPPvQdSM+NN2gdF22wHhj fSVJQdMYU261vUYmaFVGjiWbkEQRY/dgucdXVkGWFyrck5hFS+yfNAh7Cm4p6Al3v/6e B4GXoNy4YisIIxwOEg+kO2OlOsmL7YRGgmbDFheASuvHpZ6q/dIY9guR3UH/n3LWEVkm Zi6E8eR2xIYoUu4ZYgopNti0jlC07zh9Bd/yaoyCk79M40zANXimIG8rfyokeYAk+Cwu dCToqVP96fyW49lXEi+GGb7c7/jDyqJH7H166sMr3MxoMPuqYo2fBgv5pD/N87hkRssJ /A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vupgph8m5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 12:08:46 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40PBlBjp013231; Thu, 25 Jan 2024 12:08:46 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vupgph8kq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 12:08:46 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40PAOPrk025268; Thu, 25 Jan 2024 12:08:45 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vrtqkkvtx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 12:08:45 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40PC8gWh000548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Jan 2024 12:08:42 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B08420040; Thu, 25 Jan 2024 12:08:42 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D4E7A20063; Thu, 25 Jan 2024 12:08:39 +0000 (GMT) Received: from ltcd48-lp2.aus.stglab.ibm.com (unknown [9.3.101.175]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 25 Jan 2024 12:08:39 +0000 (GMT) Subject: [PATCH 1/2] powerpc: iommu: Bring back table group release_ownership() call From: Shivaprasad G Bhat To: iommu@lists.linux.dev, linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, jgg@ziepe.ca, jroedel@suse.de, tpearson@raptorengineering.com, aik@amd.com, bgray@linux.ibm.com, gregkh@linuxfoundation.org, sbhat@linux.ibm.com, gbatra@linux.vnet.ibm.com, vaibhav@linux.ibm.com Date: Thu, 25 Jan 2024 06:08:39 -0600 Message-ID: <170618451433.3805.9015493852395837391.stgit@ltcd48-lp2.aus.stglab.ibm.com> In-Reply-To: <170618450592.3805.8216395093813382208.stgit@ltcd48-lp2.aus.stglab.ibm.com> References: <170618450592.3805.8216395093813382208.stgit@ltcd48-lp2.aus.stglab.ibm.com> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 8Oc4vB_K5IVqloohLoC5iKjgxeZvViyP X-Proofpoint-ORIG-GUID: E1GfupPUpyw-wyPiEx2bqwEdZom0-0IP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_06,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 spamscore=0 priorityscore=1501 mlxlogscore=997 mlxscore=0 malwarescore=0 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401250084 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789064201405154262 X-GMAIL-MSGID: 1789064201405154262 The commit 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops") refactored the code removing the set_platform_dma_ops(). It missed out the table group release_ownership() call which would have got called otherwise during the guest shutdown via vfio_group_detach_container(). On PPC64, this particular call actually sets up the 32-bit TCE table, and enables the 64-bit DMA bypass etc. Now after guest shutdown, the subsequent host driver (e.g megaraid-sas) probe post unbind from vfio-pci fails like, megaraid_sas 0031:01:00.0: Warning: IOMMU dma not supported: mask 0x7fffffffffffffff, table unavailable megaraid_sas 0031:01:00.0: Warning: IOMMU dma not supported: mask 0xffffffff, table unavailable megaraid_sas 0031:01:00.0: Failed to set DMA mask megaraid_sas 0031:01:00.0: Failed from megasas_init_fw 6539 The patch brings back the call to table_group release_ownership() call when switching back to PLATFORM domain. Fixes: 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops") Signed-off-by: Shivaprasad G Bhat --- arch/powerpc/kernel/iommu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ebe259bdd462..ac7df43fa7ef 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1296,9 +1296,19 @@ spapr_tce_platform_iommu_attach_dev(struct iommu_domain *platform_domain, if (!grp) return -ENODEV; - table_group = iommu_group_get_iommudata(grp); - ret = table_group->ops->take_ownership(table_group); - iommu_group_put(grp); + if (platform_domain->type == IOMMU_DOMAIN_PLATFORM) { + ret = 0; + table_group = iommu_group_get_iommudata(grp); + /* + * The domain being set to PLATFORM from earlier + * BLOCKED. The table_group ownership has to be released. + */ + table_group->ops->release_ownership(table_group); + } else if (platform_domain->type == IOMMU_DOMAIN_BLOCKED) { + table_group = iommu_group_get_iommudata(grp); + ret = table_group->ops->take_ownership(table_group); + iommu_group_put(grp); + } return ret; } From patchwork Thu Jan 25 12:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivaprasad G Bhat X-Patchwork-Id: 192046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1590738dyi; Thu, 25 Jan 2024 04:09:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFa/K41wpPpQDgIBETI8kCqihG6v0NIWrEww0LpCqox1Rkhgx+nOI1sP9RBrV88h8OpPBSi X-Received: by 2002:a05:6808:ece:b0:3bd:a8b3:f5f5 with SMTP id q14-20020a0568080ece00b003bda8b3f5f5mr792812oiv.75.1706184593622; Thu, 25 Jan 2024 04:09:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706184593; cv=pass; d=google.com; s=arc-20160816; b=f5kouwqp6U9h4pAw2U8XACtK7zyZ1ZkZJzJJCjl8gn34xWO77PlzEneTjOMdXVceuO XvMUmZOs7d3C82qAIL7pWoKmHpjBFxluTMrixBwtxkCb+bSqFcOiiQ+nlecKi2JiAvsV gYFEl2V4Tsbv3m2yrHjCQ+rfhrKYHIu/opHTeA/KRcPHYqDMNSOY9IcukjvoaHFDtKYe 1S7sq7xVu0CR1Xm05nnn93yo6fcMIX/PcmkTX7AGG/rIXmcuIBY8RE8ShXRQ8sLz2yXG sBDXSIf2DgJJvIYS9Nttg3oOOyyG7c6VQEu2suf1KwZ30RGVrXGNFA45J+gCzehqo+Ub s+vQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=gG7MWoLavXnDvTTl0ZNI4e07YAFVw1dRRN0uz35CGH8=; fh=bB2t8pimPSEnAwbiWcrAz14Rc33OdfzuWusVbzVIAgA=; b=xFwjc0o1rTvFkk4Ub3wjHLJRj/9l1J13WWBh0V2FnaWTLe6nkNdjnqGVn4K5/ZvTPs h57l/r3I9URS1ILbQCfJkvfZAsLVky8lCAUUi5d1K1yhBABk68SwdrB/DDttCGfc9cZX HBm09oGbbGLjmLsd6EkMFO/kF8ypc7nSuodqUW1Kw6Vth2eK0zm4EkufPF3Bn9X+A0V9 fn7o4asBMnwHiAtkCDUeVtWb1GT5ORKaou7dK+eiASU/KjsqqsTjjHidon7Tox3oe2Ep UXNY9l4316KCpmA/EtSyp655yH5lUvVjvgL9W8ZVNVTpG925GJn0NFS3WPUiP0UMLggG LHWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NRloBHEG; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-38566-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38566-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w35-20020a05622a192300b00429f1b15880si12616675qtc.142.2024.01.25.04.09.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 04:09:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38566-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NRloBHEG; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-38566-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38566-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2B5971C21159 for ; Thu, 25 Jan 2024 12:09:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C13B41742; Thu, 25 Jan 2024 12:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="NRloBHEG" 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 C9E0D35EF1 for ; Thu, 25 Jan 2024 12:09:16 +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=1706184558; cv=none; b=I7PzF+mC6OjfgK5J14QIA8D31maE3Fk7PkIXusuq1+n+LFzd/kIxo1ky9DHzZKMHX7Mz1pAg5D85twUPSMObilhLnqhtjJ+gXowZZ7xwCXTnlof4q7aSxkrlR3TgKLXrRpQfIYFe2HPQkZq12MPRU7woM9C4C70HqpHfHa0Heig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706184558; c=relaxed/simple; bh=X6KtrTWcCvaIY23io48qzhxPzmn2ctueQC3YSuzO8zI=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dypOnup9hZdN5mV/0Oash6Y3zUwsG2eWWk+mCqZbGJZ3qBNt5tGvPtmvhZZWB9B2NpvqeTHB2+laQaSEZ9ug8CPKpUtYzhUE/flCIR47mkQWtK+ZoicZJ6gYMG7B3ff3/TXGxJEfR3Xm2uLdfdCyxmjcMAvuycu11s1lSgWCHXs= 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=NRloBHEG; 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 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40PBkxof011424; Thu, 25 Jan 2024 12:09:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=gG7MWoLavXnDvTTl0ZNI4e07YAFVw1dRRN0uz35CGH8=; b=NRloBHEGgwxRhiG9kPGGlqR3Pj4sYFg2s50WNbCZf2HyYHqkTBuxA1/cpO38w7aqpKxX 9v7WMUYSPMU8V4Q4HLIfQ/tlmeKSL+HBtVcNulZCkJCBvTQri/6d7dJ6WM8jpicmBPCW urvy4vuTGSwbgV0H4W1o8VCxBTXwBUcsGQ88+sfjZlvmSM5Gcn5kdjMjvPKeqK6/Qv3K ZV6H6xgThKfjkHypE7VxHNKL72w267EkB42bj0Ku0L7mOKaSlbSq64D3HMZaTB0pOR52 jBAVcqVzysznwaHoOIohfWcRMiQEC1IMA/v7XsVlXudsZFv9xVJORhcyKuUxBcfNzdGc Ew== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vupgph8ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 12:09:00 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40PBm9Xt019389; Thu, 25 Jan 2024 12:08:59 GMT 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 3vupgph8tu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 12:08:59 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40P9eDin022510; Thu, 25 Jan 2024 12:08:58 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vrt0mc2h0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 12:08:58 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40PC8tr624969908 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Jan 2024 12:08:55 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46F5720040; Thu, 25 Jan 2024 12:08:55 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6FCB20043; Thu, 25 Jan 2024 12:08:52 +0000 (GMT) Received: from ltcd48-lp2.aus.stglab.ibm.com (unknown [9.3.101.175]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 25 Jan 2024 12:08:52 +0000 (GMT) Subject: [PATCH 2/2] iommu: Fix the domain type checks when default_domain is set From: Shivaprasad G Bhat To: iommu@lists.linux.dev, linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, jgg@ziepe.ca, jroedel@suse.de, tpearson@raptorengineering.com, aik@amd.com, bgray@linux.ibm.com, gregkh@linuxfoundation.org, sbhat@linux.ibm.com, gbatra@linux.vnet.ibm.com, vaibhav@linux.ibm.com Date: Thu, 25 Jan 2024 06:08:52 -0600 Message-ID: <170618452753.3805.4425669653666211728.stgit@ltcd48-lp2.aus.stglab.ibm.com> In-Reply-To: <170618450592.3805.8216395093813382208.stgit@ltcd48-lp2.aus.stglab.ibm.com> References: <170618450592.3805.8216395093813382208.stgit@ltcd48-lp2.aus.stglab.ibm.com> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 9xLRX-Ci5ldGH1TbQ5_NxrdYVilzJJRA X-Proofpoint-ORIG-GUID: tjZYyV_h8WBjmfJrXQ754fuCM9NqkNdA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_06,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 spamscore=0 priorityscore=1501 mlxlogscore=989 mlxscore=0 malwarescore=0 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401250084 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789064216315097209 X-GMAIL-MSGID: 1789064216315097209 On PPC64, the iommu_ops.def_domain_type() is not defined and CONFIG_IOMMU_DMA not enabled. With commit 0f6a90436a57 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled"), the iommu_get_default_domain_type() return IOMMU_DOMAIN_IDENTITY. With commit 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops"), the defaule_domain is set wih the type being PLATFORM. With these two changes, iommu_group_alloc_default_domain() ends up returning the NULL(with recent changes, ERR_PTR(-EINVAL)) leading to iommu_probe_device() failure and the device has no iommu_group set in effect. Subsequently, the bind to vfio(VFIO_IOMMU) fail as the iommu_group is not set for the device. Make the iommu_get_default_domain_type() to take default_domain->type into consideration along with default_domain_type() and fix iommu_group_alloc_default_domain() to not error out if the requested type is same as default domain type. Fixes: 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops") Fixes: 0f6a90436a57 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled") Signed-off-by: Shivaprasad G Bhat --- drivers/iommu/iommu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 68e648b55767..04083a1d9f7e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -135,6 +135,8 @@ static struct group_device *iommu_group_alloc_device(struct iommu_group *group, struct device *dev); static void __iommu_group_free_device(struct iommu_group *group, struct group_device *grp_dev); +static int iommu_get_def_domain_type(struct iommu_group *group, + struct device *dev, int cur_type); #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ @@ -1788,7 +1790,8 @@ __iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) static struct iommu_domain * iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) { - const struct iommu_ops *ops = dev_iommu_ops(iommu_group_first_dev(group)); + struct device *dev = iommu_group_first_dev(group); + const struct iommu_ops *ops = dev_iommu_ops(dev); struct iommu_domain *dom; lockdep_assert_held(&group->mutex); @@ -1799,7 +1802,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) * domain. Do not use in new drivers. */ if (ops->default_domain) { - if (req_type) + if (iommu_get_def_domain_type(group, dev, req_type) != req_type) return ERR_PTR(-EINVAL); return ops->default_domain; } @@ -1871,10 +1874,13 @@ static int iommu_get_def_domain_type(struct iommu_group *group, const struct iommu_ops *ops = dev_iommu_ops(dev); int type; - if (!ops->def_domain_type) + if (ops->def_domain_type) + type = ops->def_domain_type(dev); + else if (group->default_domain) + type = group->default_domain->type; + else return cur_type; - type = ops->def_domain_type(dev); if (!type || cur_type == type) return cur_type; if (!cur_type)