linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Morel <pmorel@linux.ibm.com>
To: alex.williamson@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	walling@linux.ibm.com, cohuck@redhat.com, david@redhat.com,
	pasic@linux.ibm.com, thuth@redhat.com
Subject: [PATCH v1 2/2] vfio:iommu: Get DMA information from real IOMMU
Date: Wed,  9 Jan 2019 13:41:54 +0100	[thread overview]
Message-ID: <1547037714-21592-3-git-send-email-pmorel@linux.ibm.com> (raw)
In-Reply-To: <1547037714-21592-1-git-send-email-pmorel@linux.ibm.com>

We report the real IOMMU geometry through the VFIO_IOMMU_GET_INFO
ioctl call when the vfio_iommu_type1_info support capabilities.

Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
 drivers/vfio/vfio_iommu_type1.c | 43 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index d9fd318..0a7746c 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1673,6 +1673,23 @@ static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu)
 	return ret;
 }
 
+static int vfio_iommu_type1_caps(struct vfio_iommu *iommu,
+				 struct vfio_info_cap *caps)
+{
+	struct vfio_domain *d;
+	struct vfio_iommu_cap_dma info = { .header.id = VFIO_IOMMU_INFO_CAP_DMA,
+					   .header.version = 1 };
+	int ret;
+
+	d = list_first_entry(&iommu->domain_list, struct vfio_domain, next);
+	if (!d || !d->domain)
+		return -ENODEV;
+	info.dma_start = d->domain->geometry.aperture_start;
+	info.dma_end = d->domain->geometry.aperture_end;
+	ret = vfio_info_add_capability(caps, &info.header, sizeof(info));
+	return ret;
+}
+
 static long vfio_iommu_type1_ioctl(void *iommu_data,
 				   unsigned int cmd, unsigned long arg)
 {
@@ -1694,6 +1711,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
 		}
 	} else if (cmd == VFIO_IOMMU_GET_INFO) {
 		struct vfio_iommu_type1_info info;
+		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
+		int ret;
 
 		minsz = offsetofend(struct vfio_iommu_type1_info, iova_pgsizes);
 
@@ -1703,7 +1722,29 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
 		if (info.argsz < minsz)
 			return -EINVAL;
 
-		info.flags = VFIO_IOMMU_INFO_PGSIZES;
+		if (info.flags & VFIO_IOMMU_INFO_CAPABILITIES) {
+			ret = vfio_iommu_type1_caps(iommu, &caps);
+			if (ret)
+				return ret;
+		}
+		if (caps.size) {
+			if (info.argsz < sizeof(info) + caps.size) {
+				info.argsz = sizeof(info) + caps.size;
+				info.cap_offset = 0;
+			} else {
+				vfio_info_cap_shift(&caps, sizeof(info));
+				if (copy_to_user((void __user *)arg +
+					sizeof(info), caps.buf,
+					caps.size)) {
+					kfree(caps.buf);
+					return -EFAULT;
+				}
+				info.cap_offset = sizeof(info);
+			}
+			kfree(caps.buf);
+		}
+
+		info.flags |= VFIO_IOMMU_INFO_PGSIZES;
 
 		info.iova_pgsizes = vfio_pgsize_bitmap(iommu);
 
-- 
2.7.4


      parent reply	other threads:[~2019-01-09 12:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-09 12:41 [PATCH v1 0/2] Get DMA information from real IOMMU Pierre Morel
2019-01-09 12:41 ` [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations Pierre Morel
2019-01-09 15:37   ` Alex Williamson
2019-01-09 17:07     ` Pierre Morel
2019-01-09 19:43       ` Alex Williamson
2019-01-10 12:47         ` Pierre Morel
2019-01-09 17:08     ` Shameerali Kolothum Thodi
2019-01-10  0:55       ` Tian, Kevin
2019-01-09 12:41 ` Pierre Morel [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=1547037714-21592-3-git-send-email-pmorel@linux.ibm.com \
    --to=pmorel@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pasic@linux.ibm.com \
    --cc=thuth@redhat.com \
    --cc=walling@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).