Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.119 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793435444; b=3cUc2bH+NcD/7edzUHqqft/beoOLVa7oE2P90VNAwW0cLuQgCqH+gg/TI85V0oUdW2a3 bKa9zltfJhL01cTOGLGT+20Tm8/Kdvi8hPJ8LfT2HDexObtwmbCwB3/e8727a6i7XzKC+ IhoXZDTdCW2OEmna9M/zRykFgwo6s39pORlNZMoktEmNZdPpevwvx/xSj7+83F6/qfYF4 nAps9AisEbmBgubg7ab5XRpNaaUJRcMdov2kMLlJ79MsnJFSqwPdEah0m7UIWCW0dhfNk C2ByxMLpIcupPNhyBIIZ9PpxmxTSWUwLhyjfWgT4jJrRksm+IXGVlPQRAgqRVGwo+IA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793435444; 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=57eOqBZzxslFG3511fl8N/Q8eICKpPDwxcb18ps4Eg4=; b=n/JRpz2tcFE5LzCyacFdPqknTsKjhRozYLY0RdEBRKBZE71B7qtQZrBpyu9QtZyYvamO kl1dX+IUvlmNYxAEUVNWWoHqkbxkOOdjPrCwoJjvKN9kBNc7VvcCOcMJi4zEWCtwYYQRZ f+CEptZ+odaaAR3uzJiFQFCj+MwUMLvl2xcqTFtGKqkQIn+7uBy1yPOzM9jTkMRlveYLy 4SO2NUWp+IJUaSyZmhisUlt6eywF6DR82/fQ9Xk9Anuyo7ggd0QBEExt8VkF7sSJzNYUx kYmK/xncqHME1oFbQTEYLF3Yo8IQoCzhp69Un5czmVXxAVZ+iI2GqXgf4eH0Pvi3Hsw== 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=gWW3N1vC; arc=none smtp.remote-ip=115.124.30.119 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (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 8A3B7606A322 for ; Sat, 31 Oct 2026 08:30:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8A3B7606A322 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=gWW3N1vC DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1793435440; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=57eOqBZzxslFG3511fl8N/Q8eICKpPDwxcb18ps4Eg4=; b=gWW3N1vC71ipjdFiwRxYAVMZiEKqA3LMcw6d3GiXzBLWqLYLBYg410QI1mVrOeW0G8JXD0AePTBqfn7supuTCdSN5cRc5xdOG+haDUMTwvoCODy55HD0s1pr1hFw9u1xGCKjXgQ94Vi0cLyr1Q7g1m377CwVTLaCvImV8qboag8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=fangyu.yu@linux.alibaba.com;NM=1;PH=DS;RN=29;SR=0;TI=SMTPD_---0XDo-2pB_1793435436; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0XDo-2pB_1793435436 cluster:ay36) by smtp.aliyun-inc.com; Sat, 31 Oct 2026 16:30:38 +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 v6 10/10] iommu/riscv: Add IOTINVAL.GVMA invalidations Date: Sat, 31 Oct 2026 16:30:14 +0800 Message-Id: <20261031083014.15040-11-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20261031083014.15040-1-fangyu.yu@linux.alibaba.com> References: <20261031083014.15040-1-fangyu.yu@linux.alibaba.com> X-Mailing-List: iommu@lists.linux.dev 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 9f572baeca74..899b9872ca56 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