From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 6E14447252B for ; Fri, 21 Aug 2026 13:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787318903; cv=none; b=Wd22ZkFn31AkWSIY39OTj4ZSJ2WIz+d0SKjzOEq3JibMwip6mgTIjdrgUdiu2XjQTfaWtjDBrsYKYLTgYK+dDHcM1vxi1l5Jjwpyb0UOBZR07GtPjZBhBi008vgv1dZZibsMs4GxNF3My+MWbJh7E03iMKthcDFEj+4aJewOFX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787318903; c=relaxed/simple; bh=QZd5LcQmi31RYjqourm2Kwb48o8RZpwnEXupXFssEVQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JC4puZ8L9U4zq04+kgO+fls0t6jF2wtjoIIpkCIqIICDLqNxSNnFnJeFUElDdPvxOP8Cf0g/QJiG35OrMUD6by3Xwxu/BMl4xwXwbmtySq4KlZl4A7DdL3E1ZZu4MCRJUQVR0jMOLno77Y22Kgf4DdIU+X482esRJERqr0aE/sU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=HJILMs9x; arc=none smtp.client-ip=115.124.30.130 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) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="HJILMs9x" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1787318893; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=fN2a+F9K2N+9UIHzo/fPW1ZnfAPXmKisjaWnaBsgmck=; b=HJILMs9xSE5iB8wgRpkCOvAzEcsKskPJcXHwiYkoG48gTDKelhh5XlVcKb+NzCv4QuwOW5v4kXWx5JepYjpw1jIuBbuTn7GGgPD6nBcezU+LV8TUDkhGOtxC4wClLq9Bbz28TjO2JBSLSbp4Zzxj2fg3Mn8ROhx8l0EFVfZi5G8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=fangyu.yu@linux.alibaba.com;NM=1;PH=DS;RN=24;SR=0;TI=SMTPD_---0X9MSFIP_1787318888; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0X9MSFIP_1787318888 cluster:ay36) by smtp.aliyun-inc.com; Fri, 21 Aug 2026 21:28:10 +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@oss.qualcomm.com, anup@brainfault.org, jgg@nvidia.com, jgg@ziepe.ca, kevin.tian@intel.com, atish.patra@linux.dev, skhawaja@google.com, vasant.hegde@amd.com Cc: fangyu.yu@linux.alibaba.com, guoren@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [RFC PATCH v3 08/10] iommu/riscv: Pre-enable GADE for second-stage domains Date: Fri, 21 Aug 2026 21:27:48 +0800 Message-Id: <20260821132749.82070-9-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260821132749.82070-1-fangyu.yu@linux.alibaba.com> References: <20260821132749.82070-1-fangyu.yu@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 --- drivers/iommu/riscv/iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 16779877351b..f01fd4e2f840 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1330,6 +1330,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