From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (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 2EDF340802B for ; Tue, 15 Sep 2026 03:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789442933; cv=none; b=WNXwvKLx5CDW+4UpQ4IR82RahSGAIoTarXnvp+iIiDii6U1XM4sbmKQwEQahfa74OrSG7aEYw9iaG1nNx0uJoHurT0SwDlOvZUI+gnN1QuR78n0G101keMvA9I5+49WY5GvuaziHn0gH+Sd/Lz8CpKTWZh7wrvd6jzNI0aUDtYk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789442933; c=relaxed/simple; bh=QZd5LcQmi31RYjqourm2Kwb48o8RZpwnEXupXFssEVQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FCcVf8B5NiGKjiUwxB5FKOHCdBndW6BdbZIetyG8w7e8S1/7HKBjnnnBZ8MEzZ7fn5vDmfDMalUUxNGSkVovEVmX6avbgNhqQk4SOAOV9z1DIHjMU+qxiuBE/w3KOKYrpUv4J+E6vN0jGWybUQQmgbC782zPzcNeGb0AXlH6hDY= 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=oFmyrw+x; arc=none smtp.client-ip=115.124.30.118 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="oFmyrw+x" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789442930; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=fN2a+F9K2N+9UIHzo/fPW1ZnfAPXmKisjaWnaBsgmck=; b=oFmyrw+xru3Ytegh4oOZY8kK60XKmLC9iMDoSNssl4CtSDl1dE4STe2rNJ1g0K5Z+WQdnlN2DdrjD3L5FGzcIt5clHBlDx+IK6/CrtFoUUE+mF1OyR73NLvuDuunyLBnoda6VdacPmNC6ZDHFOYMBk1BM+jJMU2YPpskAzlJPDg= 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-contentspam033045133197;MF=fangyu.yu@linux.alibaba.com;NM=1;PH=DS;RN=26;SR=0;TI=SMTPD_---0XB.uvSP_1789442926; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0XB.uvSP_1789442926 cluster:ay36) by smtp.aliyun-inc.com; Tue, 15 Sep 2026 11:28:48 +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, joerg.roedel@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, kvm-riscv@lists.infradead.org Subject: [RFC PATCH v4 08/10] iommu/riscv: Pre-enable GADE for second-stage domains Date: Tue, 15 Sep 2026 11:28:27 +0800 Message-Id: <20260915032828.11250-9-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260915032828.11250-1-fangyu.yu@linux.alibaba.com> References: <20260915032828.11250-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