From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793435439; b=v0Caup1Dv2lVDvcaurGV9Iqfbg1ZVC9lwP0faB+Y/D2uo6qL9kdxZC5o76+Gwo1G+Fgm feI4RW6KtvfJ3fbz9oSK1sEpF3GEBFfSug1beptgjsHmgq1nY5JCe94UP0GbNySf1HRwo evyEIGzwGqPuju94TeDT78dtSsbkBwtJZZWacXZJSs3ajtXPTDow+x9EA6t/qzvacJvwL bZsURVQWN6ZHjx2zTv8mxHemfaZCPXOM5YphZ5I+6/DeAhMPP2TbVLZA56nEi8hGEQwcx ovm9prYz+Y4IQnWwi2HIotyMIHj5l2XtiZm0CBo7P+d4Gk+4L0ZcWgd+a4mDHTu5ZiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793435439; 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=11EZsZQc/6GCS8JBX6hOIFtCcJazynSKhMoTlW4DEkk=; b=3ACJaiMD1vuoGjpFOgmVPNww0zzcYX9ul3YXFW5a0lUlrxr3yZleUNJhymrSXEy2QhJ1 GwJodFdyUSFC8FtStiR0vXhWEyjtCH317Onw1wbqkPyf5jFGgjL/9TnObCPVFO8JTnUzM dPD3Pcay6nNL1uD2ZrQ/KF5pMuZtvI9TQtNGTo7ON0enZPheS5BHOnnthbYkIkR3TJIjD 2MzWeIaCsPfmWXK29fMgc8+ClawsTFgcDh7mXFdIma0Ooo2u7htn45SHA01dEkGKuyhPr VFR3Hqrxg7oRcQae7i6y2Md3n49HZ+1udAXLaic+oS1WfWwGg9oNvjAG+xNgyFqJElw== 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=Fgf1Ut1M; arc=none smtp.remote-ip=115.124.30.100 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 EA4D860A2603 for ; Sat, 31 Oct 2026 08:30:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EA4D860A2603 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=Fgf1Ut1M DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1793435437; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=11EZsZQc/6GCS8JBX6hOIFtCcJazynSKhMoTlW4DEkk=; b=Fgf1Ut1M55KuTVDf6TpnEqUbAfHX+vA9opzTWJBniyV7KFaraMzpObO6BoKNKmvVn1ZZQna6Sql1HySydL9w4eploM4+3VQyNSega74z8GxOYuEDTIWn4P+Kxjztreyn0lW7b5SMAzXyIJWhuhcS2Xi+CaQqbVdXAtPAOBwpR28= 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-contentspam033045133197;MF=fangyu.yu@linux.alibaba.com;NM=1;PH=DS;RN=29;SR=0;TI=SMTPD_---0XDo-2nW_1793435433; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0XDo-2nW_1793435433 cluster:ay36) by smtp.aliyun-inc.com; Sat, 31 Oct 2026 16:30:34 +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 08/10] iommu/riscv: Pre-enable GADE for second-stage domains Date: Sat, 31 Oct 2026 16:30:12 +0800 Message-Id: <20261031083014.15040-9-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: 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 Pre-enable RISCV_IOMMU_DC_TC_GADE in the device context when attaching a second-stage domain, if the IOMMU supports AMO_HWAD. Software pre-populates second-stage page tables with D set, so enabling GADE by default does not change normal behavior. When dirty tracking is enabled, iommufd clears the pre-set D bits and GADE becomes necessary for hardware to update the dirty bit on write access. This avoids toggling GADE dynamically and keeps device context setup consistent with second-stage domain attachment. Signed-off-by: Fangyu Yu Reviewed-by: Nutty Liu --- drivers/iommu/riscv/iommu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 082f55c44d20..fc7a80393833 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1237,6 +1237,8 @@ static void riscv_iommu_iodir_update(struct riscv_iommu_device *iommu, for (i = 0; i < fwspec->num_ids; i++) { dc = riscv_iommu_get_dc(iommu, fwspec->ids[i]); tc = READ_ONCE(dc->tc); + tc &= ~RISCV_IOMMU_DC_TC_GADE; + tc |= new_dc->tc & RISCV_IOMMU_DC_TC_GADE; tc |= new_dc->ta & RISCV_IOMMU_DC_TC_V; WRITE_ONCE(dc->fsc, new_dc->fsc); @@ -1353,6 +1355,8 @@ static int riscv_iommu_attach_paging_domain(struct iommu_domain *iommu_domain, FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_MODE, pt_info.iohgatp_mode) | FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_GSCID, domain->gscid) | FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_PPN, pt_info.ppn); + if (iommu->caps & RISCV_IOMMU_CAPABILITIES_AMO_HWAD) + dc.tc |= RISCV_IOMMU_DC_TC_GADE; } else { if (!riscv_iommu_fsc_supported(iommu, pt_info.fsc_iosatp_mode)) return -ENODEV; -- 2.50.1