From nobody Mon Jun 15 15:07:16 2026 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 298CC1DA628 for ; Sat, 11 Apr 2026 02:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775874154; cv=none; b=CewTtQE39Hq1JbAi2KS5WaLh5DwY3d51xsi8SbIzGn8uMswyJASX2SC6GZCy/8QCywtJ1P4xHtXL5OGBIaBekdUZzCkMQoLD6DxvGeZDlf64+dXaYpchg8gGne7KEPiPO5psngUZimwvlMCp3tg4Kw2eGcNjPyVb2akcIVTBcJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775874154; c=relaxed/simple; bh=58v0fU3YrjbI+y/Hs5MKqEjkWZ+H5LPkDA7DPOBHNJc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P6tnMYFOsKfSEFTvT0MKwykWkR/u7d4ISNDltSXtEkrQ66JfwvrFOn/XlsAdQfShSbVaAndeJz8gTni3a35np2jSXPu+/9rp6AVPKCIMyYxGPExs5fB7Z26jDerPSWRfvd+UdT1AbPaMFCDkU8UYLQzORmPfb/Rbvfct+5IutWg= 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=s0iAoLjS; arc=none smtp.client-ip=115.124.30.99 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="s0iAoLjS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775874150; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=lRfbN+qFsMwF7HYtaTY+0ggUK9iXGO0XzHEDssk5rVo=; b=s0iAoLjS9NWy4Odjs1u5iUrUnklaxuoH7nQDPzJ80fOjkfYZP2UqDEVqNEpAf3rAOePPV80iiLPpRRnIm5XUN9sJCPcT3WfCvGHN1u+tFuVEdUOzSetR56y7FZs9HNTGwmCmow3AbSRWA5m5VR25MN/A6IiwadkHDOKrzT0D6Yw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;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=18;SR=0;TI=SMTPD_---0X0miYRm_1775874148; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0X0miYRm_1775874148 cluster:ay36) by smtp.aliyun-inc.com; Sat, 11 Apr 2026 10:22:29 +0800 From: fangyu.yu@linux.alibaba.com To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, tjeznach@rivosinc.com, jgg@ziepe.ca, kevin.tian@intel.com, baolu.lu@linux.intel.com, vasant.hegde@amd.com Cc: guoren@kernel.org, iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Fangyu Yu Subject: [PATCH 1/2] iommu/riscv: Advertise Svpbmt support to generic page table Date: Sat, 11 Apr 2026 10:22:22 +0800 Message-Id: <20260411022223.91029-2-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260411022223.91029-1-fangyu.yu@linux.alibaba.com> References: <20260411022223.91029-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fangyu Yu The RISC-V IOMMU can optionally support Svpbmt page-based memory types in its page table format. When present,the generic page table code can use this capability to encode memory attributes (e.g. MMIO vs normal memory) in PTEs. Signed-off-by: Fangyu Yu Reviewed-by: Anup Patel Reviewed-by: Guo Ren Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/riscv/iommu.c | 2 ++ include/linux/generic_pt/common.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index c7d0342aa747..e53883935563 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1194,6 +1194,8 @@ static struct iommu_domain *riscv_iommu_alloc_paging_= domain(struct device *dev) cfg.common.features =3D BIT(PT_FEAT_SIGN_EXTEND) | BIT(PT_FEAT_FLUSH_RANGE) | BIT(PT_FEAT_RISCV_SVNAPOT_64K); + if (iommu->caps & RISCV_IOMMU_CAPABILITIES_SVPBMT) + cfg.common.features |=3D BIT(PT_FEAT_RISCV_SVPBMT); domain->riscvpt.iommu.nid =3D dev_to_node(iommu->dev); domain->domain.ops =3D &riscv_iommu_paging_domain_ops; =20 diff --git a/include/linux/generic_pt/common.h b/include/linux/generic_pt/c= ommon.h index fc5d0b5edadc..dfadf8a5752a 100644 --- a/include/linux/generic_pt/common.h +++ b/include/linux/generic_pt/common.h @@ -188,6 +188,7 @@ enum { * Support the 64k contiguous page size following the Svnapot extension. */ PT_FEAT_RISCV_SVNAPOT_64K =3D PT_FEAT_FMT_START, + PT_FEAT_RISCV_SVPBMT, =20 }; =20 --=20 2.50.1 From nobody Mon Jun 15 15:07:16 2026 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 CF6DC21E091 for ; Sat, 11 Apr 2026 02:22:39 +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=1775874161; cv=none; b=T2BI65044Ih+Eg4XSCATENTsn+YnW52Uw7I+2Qf13Q9hjDgYfwCcrgJ3Xoe3dNXgWOXgUrfE5VBK8w2JlMRlU3iXiKA5Ozi76N7GBk6zVynenw01ASky76egA+Tla8viIcELobUB8KpqcVcY8QqPjSMzw/bMZ6PlPALRxcH2wQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775874161; c=relaxed/simple; bh=uDmgou8cV9j995XJJlidkFrJvFWu5yVrSrmrGZy80Ds=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SYq679XCY6jXOlEM7CgPGyrqUwK8nEykN79i/uWy16+bD5VOfnpiFJjfemqM2+BONrN0dDNz1jrQpv/iMNzc7gd4B98+8xMDE1C+qxq3KXcocI+1HvaQzlYs8lTchxcCusetDh0UlhwVqn+HSyEHTe25bij22NNRV7NNKZnjHn4= 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=XYXgnG31; 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="XYXgnG31" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775874152; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=OH5/TUCPHpy8sy8haBbJAQ5yBUA8WaHxyR6Sehfd16w=; b=XYXgnG31M5b0ZtkLYJdAVRc1DGhMC+UqYJWrNpk+m+P9pDrf5rhPja7wMyrajSDCC2okrukL3e97M3K7f13S8jGpjR2IlFEoKMXQxJ6LYTy5ZkRLqhAvNtrVm2VNIdD/naVn+j3tMhbgNmiLiSY9q67SXF8yZCb9OqrtJBeowb0= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;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=18;SR=0;TI=SMTPD_---0X0miYSJ_1775874149; Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0X0miYSJ_1775874149 cluster:ay36) by smtp.aliyun-inc.com; Sat, 11 Apr 2026 10:22:30 +0800 From: fangyu.yu@linux.alibaba.com To: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, tjeznach@rivosinc.com, jgg@ziepe.ca, kevin.tian@intel.com, baolu.lu@linux.intel.com, vasant.hegde@amd.com Cc: guoren@kernel.org, iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Fangyu Yu Subject: [PATCH 2/2] iommupt: Encode IOMMU_MMIO/IOMMU_CACHE via RISC-V Svpbmt bits Date: Sat, 11 Apr 2026 10:22:23 +0800 Message-Id: <20260411022223.91029-3-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260411022223.91029-1-fangyu.yu@linux.alibaba.com> References: <20260411022223.91029-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fangyu Yu When the RISC-V IOMMU page table format support Svpbmt, PBMT provides a way to tag mappings with page-based memory types. Encode memory type via PBMT in RISC-V IOMMU PTEs: - IOMMU_MMIO -> PBMT=3DIO - !IOMMU_CACHE -> PBMT=3DNC - otherwise -> PBMT=3DNormal (PBMT=3D0) Clear the PBMT field before applying the selected encoding, and only touch PBMT when PT_FEAT_RISCV_SVPBMT is advertised. Signed-off-by: Fangyu Yu Reviewed-by: Anup Patel Reviewed-by: Guo Ren Reviewed-by: Jason Gunthorpe --- drivers/iommu/generic_pt/fmt/riscv.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iommu/generic_pt/fmt/riscv.h b/drivers/iommu/generic_p= t/fmt/riscv.h index a7fef6266a36..02051bb3c6e5 100644 --- a/drivers/iommu/generic_pt/fmt/riscv.h +++ b/drivers/iommu/generic_pt/fmt/riscv.h @@ -58,6 +58,8 @@ enum { RISCVPT_G =3D BIT(5), RISCVPT_A =3D BIT(6), RISCVPT_D =3D BIT(7), + RISCVPT_NC =3D BIT(61), + RISCVPT_IO =3D BIT(62), RISCVPT_RSW =3D GENMASK(9, 8), RISCVPT_PPN32 =3D GENMASK(31, 10), =20 @@ -237,6 +239,13 @@ static inline int riscvpt_iommu_set_prot(struct pt_com= mon *common, pte |=3D RISCVPT_R; if (!(iommu_prot & IOMMU_NOEXEC)) pte |=3D RISCVPT_X; + if (common->features & BIT(PT_FEAT_RISCV_SVPBMT)) { + pte &=3D ~RISCVPT_PBMT; + if (iommu_prot & IOMMU_MMIO) + pte |=3D RISCVPT_IO; + else if (!(iommu_prot & IOMMU_CACHE)) + pte |=3D RISCVPT_NC; + } =20 /* Caller must specify a supported combination of flags */ if (unlikely((pte & (RISCVPT_X | RISCVPT_W | RISCVPT_R)) =3D=3D 0)) --=20 2.50.1