iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Antonios Motakis <a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
To: kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org,
	alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Cc: linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	agraf-l3A5Bk7waGM@public.gmane.org,
	B08248-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Antonios Motakis
	<a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>,
	tech-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org
Subject: [PATCH 4/7] VFIO: DT: Support MMAP of MMIO regions
Date: Mon, 30 Sep 2013 17:28:40 +0200	[thread overview]
Message-ID: <1380554923-17818-5-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1380554923-17818-1-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>

Signed-off-by: Antonios Motakis <a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
---
 drivers/vfio/vfio_platform.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/vfio/vfio_platform.c b/drivers/vfio/vfio_platform.c
index a0abcfa..6364316 100644
--- a/drivers/vfio/vfio_platform.c
+++ b/drivers/vfio/vfio_platform.c
@@ -103,6 +103,10 @@ static long vfio_platform_ioctl(void *device_data,
 		info.offset = res.start;	/* map phys addr with offset */
 		info.size = resource_size(&res);
 		info.flags = 0;
+		/* Only regions addressed with PAGE granularity can be MMAPed
+		 * securely. */
+		if (!(info.offset & ~PAGE_MASK) && !(info.size & ~PAGE_MASK))
+			info.flags |= VFIO_REGION_INFO_FLAG_MMAP;
 
 		return copy_to_user((void __user *)arg, &info, minsz);
 
@@ -134,6 +138,18 @@ static long vfio_platform_ioctl(void *device_data,
 	return -ENOTTY;
 }
 
+static bool is_in_resource(struct resource res, u64 addr, u64 size)
+{
+	if (addr < res.start)
+		return false;
+	if (addr > res.end)
+		return false;
+	if (addr + size - 1 > res.end)
+		return false;
+
+	return true;
+}
+
 static ssize_t vfio_platform_read(void *device_data, char __user *buf,
 			     size_t count, loff_t *ppos)
 {
@@ -148,6 +164,34 @@ static ssize_t vfio_platform_write(void *device_data, const char __user *buf,
 
 static int vfio_platform_mmap(void *device_data, struct vm_area_struct *vma)
 {
+	struct vfio_platform_device *vdev = device_data;
+	struct device_node *of_node = vdev->pdev->dev.of_node;
+	u64 req_len = vma->vm_end - vma->vm_start;
+	u64 addr = vma->vm_pgoff << PAGE_SHIFT;
+	struct resource res;
+	int i;
+
+	if (vma->vm_end < vma->vm_start)
+		return -EINVAL;
+	if (vma->vm_start & ~PAGE_MASK)
+		return -EINVAL;
+	if (vma->vm_end & ~PAGE_MASK)
+		return -EINVAL;
+	if ((vma->vm_flags & VM_SHARED) == 0)
+		return -EINVAL;
+
+	for (i = 0; !of_address_to_resource(of_node, i, &res); i++) {
+		if (!is_in_resource(res, addr, req_len))
+			continue;
+
+		vma->vm_private_data = vdev;
+		vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
+		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+		return remap_pfn_range(vma, vma->vm_start, addr,
+				       req_len, vma->vm_page_prot);
+	}
+
 	return -EINVAL;
 }
 
-- 
1.8.1.2

  parent reply	other threads:[~2013-09-30 15:28 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-30 15:28 [RFC PATCH v2 0/7] VFIO for device tree based platform devices (work in progress) Antonios Motakis
     [not found] ` <1380554923-17818-1-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2013-09-30 15:28   ` [PATCH 1/7] VFIO_IOMMU_TYPE1 workaround to build for platform devices Antonios Motakis
     [not found]     ` <1380554923-17818-2-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2013-09-30 17:39       ` Alex Williamson
     [not found]         ` <1380562782.2674.178.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2013-10-01  9:36           ` Antonios Motakis
2013-10-01 19:21         ` Yoder Stuart-B08248
     [not found]           ` <9F6FE96B71CF29479FF1CDC8046E15036D37D9-TcFNo7jSaXOLgTCmFNXF2K4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org>
2013-10-02 11:13             ` Antonios Motakis
2013-10-02 12:55               ` Yoder Stuart-B08248
2013-10-29 15:57               ` Yoder Stuart-B08248
2013-10-02 12:14           ` Alexander Graf
     [not found]             ` <170DCB6D-6185-4C8A-977A-4DADF82DB274-l3A5Bk7waGM@public.gmane.org>
2013-10-29  1:17               ` Don Dutile
2013-09-30 15:28   ` [PATCH 2/7] Initial skeleton of VFIO support for Device Tree based devices Antonios Motakis
2013-09-30 15:37     ` Bhushan Bharat-R65777
     [not found]       ` <6A3DF150A5B70D4F9B66A25E3F7C888D0718A4AC-RL0Hj/+nBVCMXPU/2EZmt64g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org>
2013-10-29  1:29         ` Don Dutile
     [not found]           ` <526F0F7F.1040509-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-10-29 11:47             ` Alex Williamson
     [not found]               ` <1383047233.4097.124.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2013-10-29 13:37                 ` Bhushan Bharat-R65777
2013-10-29 17:13                 ` Don Dutile
2013-10-29 21:58                   ` Yoder Stuart-B08248
2013-10-29 13:07           ` Yoder Stuart-B08248
     [not found]     ` <1380554923-17818-3-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2013-09-30 19:41       ` Alex Williamson
     [not found]         ` <1380570100.2674.207.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2013-10-01  9:36           ` Antonios Motakis
2013-09-30 15:28   ` [PATCH 3/7] Return info for device and its memory regions and interrupts Antonios Motakis
     [not found]     ` <1380554923-17818-4-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2013-09-30 15:49       ` Bhushan Bharat-R65777
     [not found]         ` <6A3DF150A5B70D4F9B66A25E3F7C888D0718A526-RL0Hj/+nBVCMXPU/2EZmt64g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org>
2013-10-01  9:35           ` Antonios Motakis
2013-09-30 17:39       ` Alex Williamson
     [not found]         ` <1380562776.2674.177.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2013-10-01  9:35           ` Antonios Motakis
2013-10-01 19:32             ` Yoder Stuart-B08248
     [not found]               ` <9F6FE96B71CF29479FF1CDC8046E15036D3803-TcFNo7jSaXOLgTCmFNXF2K4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org>
2013-10-01 19:41                 ` Alex Williamson
2013-10-02 11:21                 ` Antonios Motakis
2013-10-02 12:12                   ` Alexander Graf
2013-10-02 13:03                   ` Yoder Stuart-B08248
2013-10-02 13:14                     ` Antonios Motakis
2013-11-07 20:38                       ` Stuart Yoder
2013-09-30 15:28   ` Antonios Motakis [this message]
2013-09-30 15:28   ` [PATCH 5/7] VFIO: DT: Read and write support for the device fd Antonios Motakis
2013-09-30 15:28   ` [PATCH 6/7] VFIO: Update documentation for VFIO_IOMMU_TYPE1 driver Antonios Motakis
     [not found]     ` <1380554923-17818-7-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2013-09-30 17:39       ` Alex Williamson
     [not found]         ` <1380562766.2674.176.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2013-10-01  9:35           ` Antonios Motakis
2013-09-30 15:28   ` [PATCH 7/7] VFIO: VFIO_PLATFORM: Update documentation for platform specific devices Antonios Motakis
2013-09-30 17:42   ` [RFC PATCH v2 0/7] VFIO for device tree based platform devices (work in progress) Alex Williamson
2013-10-01 15:47 ` Christoffer Dall
2013-10-01 17:13   ` Antonios Motakis
2013-12-01 12:09 ` Kim Phillips
     [not found]   ` <20131201120954.1d6cec431a99a7ad5f34da18-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2013-12-02 13:55     ` Antonios Motakis
2013-12-02 13:56     ` Antonios Motakis
2013-12-02 16:08       ` Kim Phillips
     [not found]         ` <20131202160832.8f5ee84355086cdb14d6a431-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2013-12-02 16:30           ` Antonios Motakis
2013-12-02 18:08             ` Kim Phillips

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=1380554923-17818-5-git-send-email-a.motakis@virtualopensystems.com \
    --to=a.motakis-lrhrjnjw1ufhk3s98ze1ajgjjy/sre9j@public.gmane.org \
    --cc=B08248-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=agraf-l3A5Bk7waGM@public.gmane.org \
    --cc=alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org \
    --cc=linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tech-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org \
    /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).