From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.110 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793707405; b=uQ6j39/6z3ndP1/va9Ykkp5Y2BzxN8CkYrzFZQoEh/w0oEIEuaZlKjGSa/Jn2O3spX4x 6SnPQtXlDZfl55gpaVyc0o1fuPFSg3Tu5iU9+7SZa2HYciygwF0fMbj/9MFGkwEz2DWdY ti+nXRX6G+9BM7UOKe28p6YEngynxnY6vun65hTjUuYOh3+CvvjSDSTvovYV/yajXeGIt m2xYMvXfT5ZrTsNTrvXmndj3k30frmAsfqD4dTqDgwrOchb5x5CGHCVOTrMkVkmyOda7l Y4Fb6/toAeTPJprRi/do22nDtAuHbQX+dojprBYDtq7CYshgpQLXeclo/ZBJYd/aW9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793707405; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=NOxToOaRCWHOshJgMcU31n+bkp0++VjZYWL+rK/hMio=; b=Cj765+WAkbTKRqjY5ZlwJaIaJEq9uaJ2b4ArdOJESghGWNMlYyrS2+ZOOVTWxj4prWoc X5IkjDa7HIvRyUPK16q4zm1DvRGFrSeJ5XEWPKvJLeUu3g4sVrNABDMbZPkJrG9tnuPrm eJoz7Uk91XXmerPmgE5U+/1Xhjm/mMBv750SIlNWGQp0jff8orCy/CbvLy3/N8hc2emEJ UCdtML0ihsnAknokEAwHc1qYZz3yvkWyrnTR5cNZU9tBwoc9eTA/CKmEtbgZS2LVwKgva j7AGHzJEXr4G74XNL9tGKriHootjQlwv5nPuBM+BlCeHcx/rWCQ0QYvzDoVwdjDN3DQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=fJI6lh9X; arc=none smtp.remote-ip=115.124.30.110 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45B73606EEB6 for ; Tue, 3 Nov 2026 12:03:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 45B73606EEB6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=fJI6lh9X DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1793707402; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=NOxToOaRCWHOshJgMcU31n+bkp0++VjZYWL+rK/hMio=; b=fJI6lh9XqwYh55gqI66CNat1yOkXh1eWBVpYhsrIqqioZ8JbaLBIyu4AoUkqayLg9HBVJq7mUlIX/ARXtj977C4j1kx3MXP3ZxbWG+7c9I5TxS0CbhOzxoddnflN+ubJDGrqZoy6JCRGBk8EL6AEhdZFSD/MN1d6nIxyJsSmxFo= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R861e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=fangyu.yu@linux.alibaba.com;NM=1;PH=DS;RN=29;SR=0;TI=SMTPD_---0XE2qH0l_1793707398; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0XE2qH0l_1793707398 cluster:ay36) by smtp.aliyun-inc.com; Tue, 03 Nov 2026 20:03:19 +0800 From: fangyu.yu@linux.alibaba.com To: tomasz.jeznach@linux.dev, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, baolu.lu@linux.intel.com, jroedel@suse.de, zong.li@sifive.com, andrew.jones@linux.dev, anup@brainfault.org, jgg@nvidia.com, jgg@ziepe.ca, kevin.tian@intel.com, atish.patra@linux.dev, skhawaja@google.com, vasant.hegde@amd.com, joerg.roedel@amd.com, tanchi25@mails.ucas.ac.cn, gong.shuai@sanechips.com.cn Cc: fangyu.yu@linux.alibaba.com, guoren@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Nutty Liu Subject: [PATCH v7 10/10] iommu/riscv: Add IOTINVAL.GVMA invalidations Date: Tue, 3 Nov 2026 20:02:36 +0800 Message-Id: <20261103120236.53474-11-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20261103120236.53474-1-fangyu.yu@linux.alibaba.com> References: <20261103120236.53474-1-fangyu.yu@linux.alibaba.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Fangyu Yu Previously, only IOTINVAL.VMA was issued, which is insufficient for second-stage address translation consistency. Signed-off-by: Fangyu Yu Reviewed-by: Nutty Liu --- drivers/iommu/riscv/iommu.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index ff1043afe973..8c15710d60b6 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -831,6 +831,15 @@ static int riscv_iommu_iodir_set_mode(struct riscv_iommu_device *iommu, riscv_iommu_cmd_inval_vma(&cmd); riscv_iommu_cmd_send(iommu, &cmd); + /* + * Per the RISC-V IOMMU spec (sec. 5.5), the IOMMU may retain + * cached translations across mode switches. IOTINVAL.VMA only + * covers first-stage leaf PTEs, so use a global IOTINVAL.GVMA + * to flush stale second-stage translations. + */ + riscv_iommu_cmd_inval_gvma(&cmd); + riscv_iommu_cmd_send(iommu, &cmd); + /* IOFENCE.C */ riscv_iommu_cmd_sync(iommu, RISCV_IOMMU_IOTINVAL_TIMEOUT); @@ -1176,12 +1185,15 @@ static void riscv_iommu_iodir_iotinval(struct riscv_iommu_device *iommu, /* * else: IOTINVAL.VMA with GV=1,AV=PSCV=0,and * GSCID=DC.iohgatp.GSCID - * + */ + riscv_iommu_cmd_send(iommu, &cmd); + /* * IOTINVAL.GVMA with GV=1,AV=0,and * GSCID=DC.iohgatp.GSCID - * TODO: For now, the Second-Stage feature have not yet been merged, - * also issue IOTINVAL.GVMA once second-stage support is merged. */ + riscv_iommu_cmd_inval_gvma(&cmd); + riscv_iommu_cmd_inval_set_gscid(&cmd, + FIELD_GET(RISCV_IOMMU_DC_IOHGATP_GSCID, iohgatp)); } riscv_iommu_cmd_send(iommu, &cmd); } -- 2.50.1