Message ID | 170618451433.3805.9015493852395837391.stgit@ltcd48-lp2.aus.stglab.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-38565-ouuuleilei=gmail.com@vger.kernel.org> 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 <ouuuleilei@gmail.com> (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 <ouuuleilei@gmail.com>; 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 <linux-kernel@vger.kernel.org>; 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 <sbhat@linux.ibm.com> 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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 |
Series |
powerpc: iommu: Fix the vfio-pci bind and unbind issues
|
|
Commit Message
Shivaprasad G Bhat
Jan. 25, 2024, 12:08 p.m. UTC
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 <sbhat@linux.ibm.com>
---
arch/powerpc/kernel/iommu.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
Comments
On Thu, Jan 25, 2024 at 06:08:39AM -0600, Shivaprasad G Bhat wrote: > 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 <sbhat@linux.ibm.com> > --- > 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); > + } Sure, but please split the function, don't test on the platform->domain_type. Also, is there any chance someone can work on actually fixing this to be a proper iommu driver? I think that will become important for power to use the common dma_iommu code in the next year... Sort of like this: diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ebe259bdd46298..0d6a7fea2bd9a5 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1287,20 +1287,20 @@ spapr_tce_platform_iommu_attach_dev(struct iommu_domain *platform_domain, struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct iommu_group *grp = iommu_group_get(dev); struct iommu_table_group *table_group; - int ret = -EINVAL; /* At first attach the ownership is already set */ if (!domain) return 0; - if (!grp) - return -ENODEV; - table_group = iommu_group_get_iommudata(grp); - ret = table_group->ops->take_ownership(table_group); + /* + * The domain being set to PLATFORM from earlier + * BLOCKED. The table_group ownership has to be released. + */ + table_group->ops->release_ownership(table_group); iommu_group_put(grp); - return ret; + return 0 } static const struct iommu_domain_ops spapr_tce_platform_domain_ops = { @@ -1312,13 +1312,33 @@ static struct iommu_domain spapr_tce_platform_domain = { .ops = &spapr_tce_platform_domain_ops, }; -static struct iommu_domain spapr_tce_blocked_domain = { - .type = IOMMU_DOMAIN_BLOCKED, +static int +spapr_tce_platform_iommu_blocked_dev(struct iommu_domain *platform_domain, + struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct iommu_group *grp = iommu_group_get(dev); + struct iommu_table_group *table_group; + int ret = -EINVAL; + /* * FIXME: SPAPR mixes blocked and platform behaviors, the blocked domain * also sets the dma_api ops */ - .ops = &spapr_tce_platform_domain_ops, + table_group = iommu_group_get_iommudata(grp); + ret = table_group->ops->take_ownership(table_group); + iommu_group_put(grp); + + return ret; +} + +static const struct iommu_domain_ops spapr_tce_blocked_domain_ops = { + .attach_dev = spapr_tce_blocked_iommu_attach_dev, +}; + +static struct iommu_domain spapr_tce_blocked_domain = { + .type = IOMMU_DOMAIN_BLOCKED, + .ops = &spapr_tce_blocked_domain_ops, }; static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap)
On 1/25/24 21:20, Jason Gunthorpe wrote: > On Thu, Jan 25, 2024 at 06:08:39AM -0600, Shivaprasad G Bhat wrote: >> The commit 2ad56efa80db ("powerpc/iommu: Setup a default domain and [snip] >> + /* >> + * 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); >> + } > Sure, but please split the function, don't test on the > platform->domain_type. Sure. > Also, is there any chance someone can work on actually fixing this to > be a proper iommu driver? I think that will become important for power > to use the common dma_iommu code in the next year... We are looking into it. > Sort of like this: > > diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c > index ebe259bdd46298..0d6a7fea2bd9a5 100644 > --- a/arch/powerpc/kernel/iommu.c > +++ b/arch/powerpc/kernel/iommu.c > @@ -1287,20 +1287,20 @@ spapr_tce_platform_iommu_attach_dev(struct iommu_domain *platform_domain, > struct iommu_domain *domain = iommu_get_domain_for_dev(dev); > struct iommu_group *grp = iommu_group_get(dev); [snip] > +static const struct iommu_domain_ops spapr_tce_blocked_domain_ops = { > + .attach_dev = spapr_tce_blocked_iommu_attach_dev, > +}; > + > +static struct iommu_domain spapr_tce_blocked_domain = { > + .type = IOMMU_DOMAIN_BLOCKED, > + .ops = &spapr_tce_blocked_domain_ops, > }; > > static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap) I have posted the next version as suggested. Thanks for the quick review! Regards, Shivaprasad
On Fri, Jan 26, 2024 at 08:43:12PM +0530, Shivaprasad G Bhat wrote: > > Also, is there any chance someone can work on actually fixing this to > > be a proper iommu driver? I think that will become important for power > > to use the common dma_iommu code in the next year... > We are looking into it. Okay, let me know, I can possibly help make parts of this happen power is the last still-current architecture to be outside the modern IOMMU and DMA API design and I'm going to start proposing things that will not be efficient on power because of this. I think a basic iommu driver using the dma API would not be so hard. I don't know what to do about the SPAPR VFIO mess though. :( Jason
----- Original Message ----- > From: "Jason Gunthorpe" <jgg@ziepe.ca> > To: "Shivaprasad G Bhat" <sbhat@linux.ibm.com> > Cc: iommu@lists.linux.dev, "linuxppc-dev" <linuxppc-dev@lists.ozlabs.org>, "linux-kernel" > <linux-kernel@vger.kernel.org>, "Michael Ellerman" <mpe@ellerman.id.au>, "npiggin" <npiggin@gmail.com>, "christophe > leroy" <christophe.leroy@csgroup.eu>, "aneesh kumar" <aneesh.kumar@kernel.org>, "naveen n rao" > <naveen.n.rao@linux.ibm.com>, jroedel@suse.de, "Timothy Pearson" <tpearson@raptorengineering.com>, aik@amd.com, > bgray@linux.ibm.com, "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>, gbatra@linux.vnet.ibm.com, > vaibhav@linux.ibm.com > Sent: Friday, January 26, 2024 9:17:01 AM > Subject: Re: [PATCH 1/2] powerpc: iommu: Bring back table group release_ownership() call > On Fri, Jan 26, 2024 at 08:43:12PM +0530, Shivaprasad G Bhat wrote: >> > Also, is there any chance someone can work on actually fixing this to >> > be a proper iommu driver? I think that will become important for power >> > to use the common dma_iommu code in the next year... >> We are looking into it. > > Okay, let me know, I can possibly help make parts of this happen > > power is the last still-current architecture to be outside the modern > IOMMU and DMA API design and I'm going to start proposing things that > will not be efficient on power because of this. I can get development resources on this fairly rapidly, including testing. We should figure out the best way forward and how to deal with the VFIO side of things, even if that's a rewrite at the end of the day the machine-specific codebase isn't *that* large for our two target flavors (64-bit PowerNV and 64-bit pSeries). > I think a basic iommu driver using the dma API would not be so hard. > > I don't know what to do about the SPAPR VFIO mess though. :( > > Jason
On Fri, Jan 26, 2024 at 09:29:55AM -0600, Timothy Pearson wrote: > > On Fri, Jan 26, 2024 at 08:43:12PM +0530, Shivaprasad G Bhat wrote: > >> > Also, is there any chance someone can work on actually fixing this to > >> > be a proper iommu driver? I think that will become important for power > >> > to use the common dma_iommu code in the next year... > >> We are looking into it. > > > > Okay, let me know, I can possibly help make parts of this happen > > > > power is the last still-current architecture to be outside the modern > > IOMMU and DMA API design and I'm going to start proposing things that > > will not be efficient on power because of this. > > I can get development resources on this fairly rapidly, including > testing. We should figure out the best way forward and how to deal > with the VFIO side of things, even if that's a rewrite at the end of > the day the machine-specific codebase isn't *that* large for our two > target flavors (64-bit PowerNV and 64-bit pSeries). I have a feeling the way forward is to just start a power driver under drivers/iommu/ and use kconfig to make the user exclusively select either the legacy arch or the modern iommu. Get that working to a level where dma_iommu is happy. Get iommufd support in the new driver good enough to run your application. Just forget about the weird KVM and SPAPR stuff, leave it under the kconfig of the old code and nobody will run it. Almost nobody already runs it, apparently. Remove it in a few years From what I remember the code under the arch directory is already very nearly almost an iommu driver. I think someone could fairly quickly get to something working and using dma_iommu.c. If s390 is any experience there is some benchmarking and tweaking to get performance equal to the arch's tweaked dma_iommu copy. Jason
----- Original Message ----- > From: "Jason Gunthorpe" <jgg@ziepe.ca> > To: "Timothy Pearson" <tpearson@raptorengineering.com> > Cc: "Shivaprasad G Bhat" <sbhat@linux.ibm.com>, "iommu" <iommu@lists.linux.dev>, "linuxppc-dev" > <linuxppc-dev@lists.ozlabs.org>, "linux-kernel" <linux-kernel@vger.kernel.org>, "Michael Ellerman" > <mpe@ellerman.id.au>, "npiggin" <npiggin@gmail.com>, "christophe leroy" <christophe.leroy@csgroup.eu>, "aneesh kumar" > <aneesh.kumar@kernel.org>, "naveen n rao" <naveen.n.rao@linux.ibm.com>, "jroedel" <jroedel@suse.de>, "aik" > <aik@amd.com>, "bgray" <bgray@linux.ibm.com>, "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>, "gbatra" > <gbatra@linux.vnet.ibm.com>, "vaibhav" <vaibhav@linux.ibm.com> > Sent: Friday, January 26, 2024 9:38:06 AM > Subject: Re: [PATCH 1/2] powerpc: iommu: Bring back table group release_ownership() call > On Fri, Jan 26, 2024 at 09:29:55AM -0600, Timothy Pearson wrote: >> > On Fri, Jan 26, 2024 at 08:43:12PM +0530, Shivaprasad G Bhat wrote: >> >> > Also, is there any chance someone can work on actually fixing this to >> >> > be a proper iommu driver? I think that will become important for power >> >> > to use the common dma_iommu code in the next year... >> >> We are looking into it. >> > >> > Okay, let me know, I can possibly help make parts of this happen >> > >> > power is the last still-current architecture to be outside the modern >> > IOMMU and DMA API design and I'm going to start proposing things that >> > will not be efficient on power because of this. >> >> I can get development resources on this fairly rapidly, including >> testing. We should figure out the best way forward and how to deal >> with the VFIO side of things, even if that's a rewrite at the end of >> the day the machine-specific codebase isn't *that* large for our two >> target flavors (64-bit PowerNV and 64-bit pSeries). > > I have a feeling the way forward is to just start a power driver under > drivers/iommu/ and use kconfig to make the user exclusively select > either the legacy arch or the modern iommu. > > Get that working to a level where dma_iommu is happy. > > Get iommufd support in the new driver good enough to run your > application. > > Just forget about the weird KVM and SPAPR stuff, leave it under the > kconfig of the old code and nobody will run it. Almost nobody already > runs it, apparently. We actually use QEMU/KVM/VFIO extensively at Raptor, so need the support and need it to be performant... > Remove it in a few years > > From what I remember the code under the arch directory is already very > nearly almost an iommu driver. I think someone could fairly quickly > get to something working and using dma_iommu.c. If s390 is any > experience there is some benchmarking and tweaking to get performance > equal to the arch's tweaked dma_iommu copy. > > Jason
----- Original Message ----- > From: "Timothy Pearson" <tpearson@raptorengineering.com> > To: "Jason Gunthorpe" <jgg@ziepe.ca> > Cc: "Timothy Pearson" <tpearson@raptorengineering.com>, "Shivaprasad G Bhat" <sbhat@linux.ibm.com>, "iommu" > <iommu@lists.linux.dev>, "linuxppc-dev" <linuxppc-dev@lists.ozlabs.org>, "linux-kernel" <linux-kernel@vger.kernel.org>, > "Michael Ellerman" <mpe@ellerman.id.au>, "npiggin" <npiggin@gmail.com>, "christophe leroy" > <christophe.leroy@csgroup.eu>, "aneesh kumar" <aneesh.kumar@kernel.org>, "naveen n rao" <naveen.n.rao@linux.ibm.com>, > "jroedel" <jroedel@suse.de>, "aik" <aik@amd.com>, "bgray" <bgray@linux.ibm.com>, "Greg Kroah-Hartman" > <gregkh@linuxfoundation.org>, "gbatra" <gbatra@linux.vnet.ibm.com>, "vaibhav" <vaibhav@linux.ibm.com> > Sent: Friday, January 26, 2024 9:39:56 AM > Subject: Re: [PATCH 1/2] powerpc: iommu: Bring back table group release_ownership() call > ----- Original Message ----- >> From: "Jason Gunthorpe" <jgg@ziepe.ca> >> To: "Timothy Pearson" <tpearson@raptorengineering.com> >> Cc: "Shivaprasad G Bhat" <sbhat@linux.ibm.com>, "iommu" <iommu@lists.linux.dev>, >> "linuxppc-dev" >> <linuxppc-dev@lists.ozlabs.org>, "linux-kernel" <linux-kernel@vger.kernel.org>, >> "Michael Ellerman" >> <mpe@ellerman.id.au>, "npiggin" <npiggin@gmail.com>, "christophe leroy" >> <christophe.leroy@csgroup.eu>, "aneesh kumar" >> <aneesh.kumar@kernel.org>, "naveen n rao" <naveen.n.rao@linux.ibm.com>, >> "jroedel" <jroedel@suse.de>, "aik" >> <aik@amd.com>, "bgray" <bgray@linux.ibm.com>, "Greg Kroah-Hartman" >> <gregkh@linuxfoundation.org>, "gbatra" >> <gbatra@linux.vnet.ibm.com>, "vaibhav" <vaibhav@linux.ibm.com> >> Sent: Friday, January 26, 2024 9:38:06 AM >> Subject: Re: [PATCH 1/2] powerpc: iommu: Bring back table group >> release_ownership() call > >> On Fri, Jan 26, 2024 at 09:29:55AM -0600, Timothy Pearson wrote: >>> > On Fri, Jan 26, 2024 at 08:43:12PM +0530, Shivaprasad G Bhat wrote: >>> >> > Also, is there any chance someone can work on actually fixing this to >>> >> > be a proper iommu driver? I think that will become important for power >>> >> > to use the common dma_iommu code in the next year... >>> >> We are looking into it. >>> > >>> > Okay, let me know, I can possibly help make parts of this happen >>> > >>> > power is the last still-current architecture to be outside the modern >>> > IOMMU and DMA API design and I'm going to start proposing things that >>> > will not be efficient on power because of this. >>> >>> I can get development resources on this fairly rapidly, including >>> testing. We should figure out the best way forward and how to deal >>> with the VFIO side of things, even if that's a rewrite at the end of >>> the day the machine-specific codebase isn't *that* large for our two >>> target flavors (64-bit PowerNV and 64-bit pSeries). >> >> I have a feeling the way forward is to just start a power driver under >> drivers/iommu/ and use kconfig to make the user exclusively select >> either the legacy arch or the modern iommu. >> >> Get that working to a level where dma_iommu is happy. >> >> Get iommufd support in the new driver good enough to run your >> application. >> >> Just forget about the weird KVM and SPAPR stuff, leave it under the >> kconfig of the old code and nobody will run it. Almost nobody already >> runs it, apparently. > > We actually use QEMU/KVM/VFIO extensively at Raptor, so need the support and > need it to be performant... Never mind, I can't read this morning. :) You did say iommufd support, which gives the VFIO passthrough functionality. I think this is a reasonable approach, and will discuss further internally this afternoon.
On Fri, Jan 26, 2024 at 09:39:56AM -0600, Timothy Pearson wrote: > > Just forget about the weird KVM and SPAPR stuff, leave it under the > > kconfig of the old code and nobody will run it. Almost nobody already > > runs it, apparently. > > We actually use QEMU/KVM/VFIO extensively at Raptor, so need the > support and need it to be performant... I wonder if you alone are the "almost" :) The KVM entanglement was hairy and scary. I never did figure out what was really going on there. Maybe you don't need all of it and can be successful with a more typical iommu working model? Suggest to tackle it after getting the first parts done. Jason
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; }