Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp74100lqm; Tue, 30 Apr 2024 13:13:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXg+SAcoo8jxL3Ma5lIfgqEQGsG9q4/VdcKHtkd785kL4iToeiIGM6/HHC5S7DVnFDp1TvMP8klPNBHCNujO1gc0bdvnqIapUFLQBlVKQ== X-Google-Smtp-Source: AGHT+IEFA1WwUkfmrOk6hkaxbCAhfjWOsbSMWCPLUcCYBE00n7M0BzEWMOnhVpTbL8j2qkTBd3Ld X-Received: by 2002:a9d:6f95:0:b0:6eb:79fe:893 with SMTP id h21-20020a9d6f95000000b006eb79fe0893mr644308otq.2.1714507981544; Tue, 30 Apr 2024 13:13:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714507981; cv=pass; d=google.com; s=arc-20160816; b=Ue+97mIwVTyetzADhzPIeq0PaVsahczqAW+albrIgwNcqdvtbhuDOcq0+bj248+I/K 5RnjMAaWxntcBtL5qliDoYkZ+rn5p4jpUr0O8kP0TCjvmuFKOwa/lr2kwWcEKPs5oL9p MYq7ujEt12KrwpUmkRBhbGN+AS5HfYHe3f/fQtfDfQBuXnk5JSWO350KQFqfnoCwVQMl tvlfceHntFJalv3dx8lhzXf0waX6zM4hdWloLI06VbVnvE4AmERsvVx/5H2KFiBoS1qC h19mjY4wZfyGYnpzoNuZcM+hgnhM9pgU27hjO4FlYWkbieJ2hBBN1a3nU/wTBnC+M8sJ 1H2g== 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=yBhQkttHnEyL5cv2acTqp19DVPXSx5tGvkMc8RzjqEA=; fh=UX7B+URBof1iyOuI0D2KMTQveDR665+eqMJizA4SjEw=; b=ZSErBL1/xovHWWbSppNn6F0A/FQWQXBfSZIAk0O4+dv25D7LTKZ6DmqHDJEyoa6CYH /xziHz4bT8g6t5azL8fp4f/qMDv2PxMGuPyVyhEwq8UenpSO3Oh9/XI6gBI2+UauSauV 3dnX7dtxRjzyWC1SAI9s5uwzP04c1zLS0jQIMu2ajjl6vJHr3uNuH43JKkgS3tDBtSf6 XcfBfulbUqk5yylGLZ6ICyKEyENFv6nfI+MFeSNdQ5gNPRu/ZKgcggHM4GcnHEasdcvk qrA1ZDrhEFaCl6QUO+7ZRORP3gbVvYL31mDaUZSXxFP+t2mGvCx7FkX/CRVEJp7PNmGK UlUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=LxBjMBR1; 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-164699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164699-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ql4-20020a05620a890400b00790fc53b3f6si4556959qkn.615.2024.04.30.13.13.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 13:13:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164699-linux.lists.archive=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=LxBjMBR1; 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-164699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164699-linux.lists.archive=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 4298D1C22AA1 for ; Tue, 30 Apr 2024 20:12:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12FEB19DF48; Tue, 30 Apr 2024 20:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="LxBjMBR1" 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 C1755199E9B; Tue, 30 Apr 2024 20:11:58 +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=1714507920; cv=none; b=mb5ZnCr8rBqZOI1RL7cUTERU+r4KBO+g1ek4bJZg+RVbNzJvEjI+FlWvS4K9o3c8DyaPtXD+tt0NWy7R7o7SB81gu+9hI8oGSXcgkIVu0G7SSofPfajY0C0oQJN2rCSRuPgUlvNC2nGzq3E/oLuBvNKJYmXFz4y7ibxH7moTohQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714507920; c=relaxed/simple; bh=US6PgPuYBkBHBzzJOfK04Hwg/abY8CZ7Jk3Z2bpKCqs=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HXbtt5H8oeU09DNTnTnPVUYIAGaJLeDST03LgvTXaDpL+wcYp05BdiLQaVgOj6MMH2PQzckZZtUt0CTbqqTiX/PBlwBUR9lSlJq06YaN639Z10e0Z3hLr0thiZZI8pwf0WB9ul2+Bqm9MT/JIiKdKs1PNqUKYsatog0zJmThQEI= 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=LxBjMBR1; 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 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43UK2Xpa007507; Tue, 30 Apr 2024 20:11:42 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=yBhQkttHnEyL5cv2acTqp19DVPXSx5tGvkMc8RzjqEA=; b=LxBjMBR1WhMCimHmYhDo6ZYa3DBTOr6EYmh2Ts3p1cRnWXa/gzQHIjwqhI5xl4kqglJj C89i8ff/eBHBPmN5vkvdxElIPUoZOMAJRbyV6kYg3ioFyCVpT9eLQG7mvDoMn7DRh8JS GdCg3SQVCwEFTknfRUjxTh3ag0vtz+y8eHQepodRCtcZQmSTeA8kWIMQ/LDjeRF2NX2a X6KZSuad6UQXgmGsc1QoNWvPW+ldr4ZcwQAw8GnzcKnTL2eSqSU/Rxl7vVNDB7tC7/M3 djj2l0Rgctu2yo1OTnWdSUY9wp/iem6rN2hPoiADs72TZM5HISTDqlXGnY0xxCHlm7l2 LQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xu7aw80ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Apr 2024 20:11:41 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43UKBfVm020065; Tue, 30 Apr 2024 20:11:41 GMT 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 3xu7aw80ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Apr 2024 20:11:41 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43UGtH7m003210; Tue, 30 Apr 2024 20:06:39 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xscppey66-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Apr 2024 20:06:39 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43UK6XCw50659668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2024 20:06:35 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C204B20043; Tue, 30 Apr 2024 20:06:33 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B80D20040; Tue, 30 Apr 2024 20:06:30 +0000 (GMT) Received: from ltcd48-lp2.aus.stglabs.ibm.com (unknown [9.3.101.175]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 30 Apr 2024 20:06:30 +0000 (GMT) Subject: [RFC PATCH v2 4/6] vfio/spapr: Always clear TCEs before unsetting the window From: Shivaprasad G Bhat To: mpe@ellerman.id.au, tpearson@raptorengineering.com, alex.williamson@redhat.com, linuxppc-dev@lists.ozlabs.org, aik@amd.com Cc: npiggin@gmail.com, christophe.leroy@csgroup.eu, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, gbatra@linux.vnet.ibm.com, brking@linux.vnet.ibm.com, sbhat@linux.ibm.com, aik@ozlabs.ru, jgg@ziepe.ca, ruscur@russell.cc, robh@kernel.org, linux-kernel@vger.kernel.org, joel@jms.id.au, kvm@vger.kernel.org, msuchanek@suse.de, oohall@gmail.com, mahesh@linux.ibm.com, jroedel@suse.de, vaibhav@linux.ibm.com, svaidy@linux.ibm.com Date: Tue, 30 Apr 2024 15:06:29 -0500 Message-ID: <171450758612.10851.13609092281484392070.stgit@linux.ibm.com> In-Reply-To: <171450753489.10851.3056035705169121613.stgit@linux.ibm.com> References: <171450753489.10851.3056035705169121613.stgit@linux.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: v2Ee3IWtSfGXxFnGrk9v1eDWCkNWoWr8 X-Proofpoint-GUID: w1ScwEyd33lLBSZOVCzp4v6AovvoB6ET X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-30_12,2024-04-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=862 suspectscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404300145 The PAPR expects the TCE table to have no entries at the time of unset window(i.e. remove-pe). The TCE clear right now is done before freeing the iommu table. On pSeries, the unset window makes those entries inaccessible to the OS and the H_PUT/GET calls fail on them with H_CONSTRAINED. On PowerNV, this has no side effect as the TCE clear can be done before the DMA window removal as well. Signed-off-by: Shivaprasad G Bhat --- drivers/vfio/vfio_iommu_spapr_tce.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c index a94ec6225d31..5f9e7e477078 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -364,7 +364,6 @@ static void tce_iommu_release(void *iommu_data) if (!tbl) continue; - tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size); tce_iommu_free_table(container, tbl); } @@ -720,6 +719,8 @@ static long tce_iommu_remove_window(struct tce_container *container, BUG_ON(!tbl->it_size); + tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size); + /* Detach groups from IOMMUs */ list_for_each_entry(tcegrp, &container->group_list, next) { table_group = iommu_group_get_iommudata(tcegrp->grp); @@ -738,7 +739,6 @@ static long tce_iommu_remove_window(struct tce_container *container, } /* Free table */ - tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size); tce_iommu_free_table(container, tbl); container->tables[num] = NULL; @@ -1197,9 +1197,14 @@ static void tce_iommu_release_ownership(struct tce_container *container, return; } - for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) - if (container->tables[i]) + for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) { + if (container->tables[i]) { + tce_iommu_clear(container, container->tables[i], + container->tables[i]->it_offset, + container->tables[i]->it_size); table_group->ops->unset_window(table_group, i); + } + } } static long tce_iommu_take_ownership(struct tce_container *container,