Linux IOMMU Development
 help / color / mirror / Atom feed
From: Tina Zhang <tina.zhang@intel.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>,
	Kevin Tian <kevin.tian@intel.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	joro@8bytes.org, will@kernel.org, Yi Liu <yi.l.liu@intel.com>
Cc: virtualization@lists.linux-foundation.org, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org, Tina Zhang <tina.zhang@intel.com>
Subject: [RFC PATCH 5/5] iommu/virtio-iommu: Support attaching VT-d IO pgtable
Date: Mon,  6 Nov 2023 02:12:26 -0500	[thread overview]
Message-ID: <20231106071226.9656-6-tina.zhang@intel.com> (raw)
In-Reply-To: <20231106071226.9656-1-tina.zhang@intel.com>

Add VT-d IO page table support to ATTACH_TABLE request.

Signed-off-by: Tina Zhang <tina.zhang@intel.com>
---
 drivers/iommu/virtio-iommu.c      | 23 +++++++++++++++++++++++
 include/uapi/linux/virtio_iommu.h | 26 ++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index b1ceaac974e2..b02eeb1d27a4 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -991,12 +991,25 @@ static int viommu_attach_pgtable(struct viommu_domain *vdomain,
 	};
 
 	/* TODO: bypass flag? */
+	if (vdomain->bypass == true)
+		return 0;
 
 	switch (fmt) {
 	case VIRT_IO_PGTABLE:
 		req.format = cpu_to_le16(VIRTIO_IOMMU_FORMAT_PGTF_VIRT);
 		req.pgd = cpu_to_le64((u64)cfg->virt.pgd);
 		break;
+	case INTEL_IOMMU: {
+		struct virtio_iommu_req_attach_pgt_vtd *vtd_req =
+			(struct virtio_iommu_req_attach_pgt_vtd *)&req;
+
+		vtd_req->format = cpu_to_le16(VIRTIO_IOMMU_FORMAT_PGTF_VTD);
+		vtd_req->pgd = cpu_to_le64((u64)cfg->virt.pgd);
+		vtd_req->addr_width = cpu_to_le32(cfg->oas);
+		vtd_req->pasid = IOMMU_NO_PASID;
+		break;
+	}
+
 	default:
 		return -EINVAL;
 	};
@@ -1034,6 +1047,16 @@ static int viommu_setup_pgtable(struct viommu_domain *vdomain,
 	case VIRTIO_IOMMU_FORMAT_PGTF_VIRT:
 		fmt = VIRT_IO_PGTABLE;
 		break;
+	case VIRTIO_IOMMU_FORMAT_PGTF_VTD:
+	{
+		struct virtio_iommu_probe_pgt_vtd *vtd_desc =
+			(struct virtio_iommu_probe_pgt_vtd *)desc;
+
+		cfg.vtd_cfg.cap_reg = le64_to_cpu(vtd_desc->cap_reg);
+		cfg.vtd_cfg.ecap_reg = le64_to_cpu(vtd_desc->ecap_reg);
+		fmt = INTEL_IOMMU;
+		break;
+	}
 	default:
 		dev_warn(vdev->dev, "unsupported page table format 0x%x\n",
 			 le16_to_cpu(desc->format));
diff --git a/include/uapi/linux/virtio_iommu.h b/include/uapi/linux/virtio_iommu.h
index 656be1f3d926..17e0d5fcdd54 100644
--- a/include/uapi/linux/virtio_iommu.h
+++ b/include/uapi/linux/virtio_iommu.h
@@ -139,6 +139,22 @@ struct virtio_iommu_req_attach_pgt_virt {
 	struct virtio_iommu_req_tail		tail;
 };
 
+/* Vt-d I/O Page Table Descriptor */
+struct virtio_iommu_req_attach_pgt_vtd {
+	struct virtio_iommu_req_head		head;
+	__le32					domain;
+	__le32					endpoint;
+	__le32					flags;
+	__le16					format;
+	__u8					reserved[2];
+	__le32					pasid;
+	__le64					pgd;
+	__le64                                  fl_flags;
+	__le32                                  addr_width;
+	__u8					reserved2[36];
+	struct virtio_iommu_req_tail		tail;
+};
+
 #define VIRTIO_IOMMU_MAP_F_READ			(1 << 0)
 #define VIRTIO_IOMMU_MAP_F_WRITE		(1 << 1)
 #define VIRTIO_IOMMU_MAP_F_MMIO			(1 << 2)
@@ -224,6 +240,8 @@ struct virtio_iommu_probe_pasid_size {
 #define VIRTIO_IOMMU_FORMAT_PSTF_ARM_SMMU_V3	2
 /* Virt I/O page table format */
 #define VIRTIO_IOMMU_FORMAT_PGTF_VIRT		3
+/* VT-d I/O page table format */
+#define VIRTIO_IOMMU_FORMAT_PGTF_VTD		4
 
 struct virtio_iommu_probe_table_format {
 	struct virtio_iommu_probe_property	head;
@@ -231,6 +249,14 @@ struct virtio_iommu_probe_table_format {
 	__u8					reserved[2];
 };
 
+struct virtio_iommu_probe_pgt_vtd {
+	struct virtio_iommu_probe_property	head;
+	__le16					format;
+	__u8					reserved[2];
+	__le64					cap_reg;
+	__le64					ecap_reg;
+};
+
 struct virtio_iommu_req_probe {
 	struct virtio_iommu_req_head		head;
 	__le32					endpoint;
-- 
2.39.3


      parent reply	other threads:[~2023-11-06  7:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06  7:12 [RFC PATCH 0/5] virtio-iommu: Add VT-d IO page table Tina Zhang
2023-11-06  7:12 ` [RFC PATCH 1/5] iommu/virtio-iommu: Correct the values of granule and nr_pages Tina Zhang
2023-11-06  7:12 ` [RFC PATCH 2/5] iommu/vt-d: Add generic IO page table support Tina Zhang
2023-11-06 19:32   ` Jason Gunthorpe
2023-11-09  0:10     ` Zhang, Tina
2023-11-09  0:33       ` Jason Gunthorpe
2023-11-06  7:12 ` [RFC PATCH 3/5] iommu/io-pgtable: Introduce struct vtd_cfg Tina Zhang
2023-11-06  7:12 ` [RFC PATCH 4/5] iommu/vt-d: Adapt alloc_pgtable interface to be used by others Tina Zhang
2023-11-06  7:12 ` Tina Zhang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231106071226.9656-6-tina.zhang@intel.com \
    --to=tina.zhang@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jean-philippe@linaro.org \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=will@kernel.org \
    --cc=yi.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox