From: Lan Tianyu <tianyu.lan@intel.com>
To: kvm@vger.kernel.org
Cc: Lan Tianyu <tianyu.lan@intel.com>,
kevin.tian@intel.com, mst@redhat.com, jan.kiszka@siemens.com,
jasowang@redhat.com, peterx@redhat.com,
david@gibson.dropbear.id.au, alex.williamson@redhat.com,
yi.l.liu@intel.com
Subject: [RFC PATCH 1/3] VFIO: Add new cmd to receive eventfd from userspace to notify IOMMU fault event
Date: Sun, 19 Feb 2017 22:47:07 +0800 [thread overview]
Message-ID: <1487515629-13815-2-git-send-email-tianyu.lan@intel.com> (raw)
In-Reply-To: <1487515629-13815-1-git-send-email-tianyu.lan@intel.com>
This patch is to receive IOMMU fault eventfd and IOMMU fault event flag
from userspace. VFIO should register IOMMU fault event handler according
fault event flag which designates what kind of fault events need to be
reported. When VFIO get IOMMU fault event from IOMMU driver, it should
notify userspace via received fd.
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
drivers/vfio/vfio_iommu_type1.c | 45 +++++++++++++++++++++++++++++++++++++++++
include/uapi/linux/vfio.h | 15 ++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index b3cc33f..46674ea 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -38,6 +38,7 @@
#include <linux/workqueue.h>
#include <linux/mdev.h>
#include <linux/notifier.h>
+#include <linux/eventfd.h>
#define DRIVER_VERSION "0.2"
#define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>"
@@ -61,6 +62,8 @@ struct vfio_iommu {
struct mutex lock;
struct rb_root dma_list;
struct blocking_notifier_head notifier;
+ struct eventfd_ctx *iommu_fault_fd;
+ struct mutex fault_lock;
bool v2;
bool nesting;
};
@@ -1452,6 +1455,7 @@ static void *vfio_iommu_type1_open(unsigned long arg)
INIT_LIST_HEAD(&iommu->domain_list);
iommu->dma_list = RB_ROOT;
mutex_init(&iommu->lock);
+ mutex_init(&iommu->fault_lock);
BLOCKING_INIT_NOTIFIER_HEAD(&iommu->notifier);
return iommu;
@@ -1582,6 +1586,47 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
return copy_to_user((void __user *)arg, &unmap, minsz) ?
-EFAULT : 0;
+ } else if (cmd == VFIO_IOMMU_SET_FAULT_EVENTFD) {
+ struct vfio_iommu_type1_set_fault_eventfd eventfd;
+ int fd;
+ int ret;
+
+ minsz = offsetofend(struct vfio_iommu_type1_set_fault_eventfd,
+ fd);
+
+ if (copy_from_user(&eventfd, (void __user *)arg, minsz))
+ return -EFAULT;
+
+ if (eventfd.argsz < minsz)
+ return -EINVAL;
+
+
+ mutex_lock(&iommu->fault_lock);
+
+ fd = eventfd.fd;
+ if (fd == -1) {
+ if (iommu->iommu_fault_fd)
+ eventfd_ctx_put(iommu->iommu_fault_fd);
+ iommu->iommu_fault_fd = NULL;
+ ret = 0;
+ } else if (fd >= 0) {
+ struct eventfd_ctx *ctx;
+
+ ctx = eventfd_ctx_fdget(fd);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ if (ctx)
+ eventfd_ctx_put(ctx);
+
+ iommu->iommu_fault_fd = ctx;
+ ret = 0;
+ } else
+ ret = -EINVAL;
+
+ mutex_unlock(&iommu->fault_lock);
+
+ return ret;
}
return -ENOTTY;
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index 519eff3..8616334 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -547,6 +547,21 @@ struct vfio_iommu_type1_dma_unmap {
#define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15)
#define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16)
+/*
+ * VFIO_IOMMU_SET_FAULT_EVENT_FD _IO(VFIO_TYPE, VFIO_BASE + 17)
+ *
+ * Receive eventfd from userspace to notify fault event from IOMMU.
+ */
+struct vfio_iommu_type1_set_fault_eventfd {
+ __u32 argsz;
+ __u32 flags;
+/* What IOMMU Fault events should be reported. */
+#define VFIO_IOMMU_UR_FAULT_WITHOUT_PASID (1 << 0)
+ __s32 fd; /* Eventfd from user space */
+};
+
+#define VFIO_IOMMU_SET_FAULT_EVENTFD _IO(VFIO_TYPE, VFIO_BASE + 17)
+
/* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */
/*
--
1.8.3.1
next prev parent reply other threads:[~2017-02-19 14:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-19 14:47 [RFC PATCH 0/3] VFIO: Report IOMMU fault event to userspace Lan Tianyu
2017-02-19 14:47 ` Lan Tianyu [this message]
2017-02-20 20:53 ` [RFC PATCH 1/3] VFIO: Add new cmd to receive eventfd from userspace to notify IOMMU fault event Alex Williamson
2017-02-21 5:29 ` Lan Tianyu
2017-02-21 5:48 ` Michael S. Tsirkin
2017-02-21 6:05 ` Alex Williamson
2017-02-21 6:11 ` Liu, Yi L
2017-02-19 14:47 ` [RFC PATCH 2/3] VFIO: Add IOMMU fault notifier callback Lan Tianyu
2017-02-20 2:58 ` Liu, Yi L
2017-02-20 20:53 ` Alex Williamson
2017-02-21 6:05 ` Lan Tianyu
2017-02-21 5:55 ` Michael S. Tsirkin
2017-02-21 6:13 ` Lan Tianyu
2017-02-19 14:47 ` [RFC PATCH 3/3] VFIO: Add new cmd for user space to get IOMMU fault info Lan Tianyu
2017-02-20 20:53 ` Alex Williamson
2017-02-20 20:53 ` [RFC PATCH 0/3] VFIO: Report IOMMU fault event to userspace Alex Williamson
2017-02-21 4:49 ` Lan Tianyu
2017-02-21 5:29 ` Alex Williamson
2017-02-21 15:18 ` Lan Tianyu
2017-02-21 15:21 ` Lan, Tianyu
2017-02-28 15:58 ` Lan, Tianyu
2017-03-15 6:17 ` Liu, Yi L
2017-03-15 19:52 ` Alex Williamson
2017-03-16 1:42 ` Lan Tianyu
2017-03-16 3:32 ` Jason Wang
2017-03-16 5:22 ` Lan Tianyu
2017-03-21 23:57 ` Liu, Yi L
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=1487515629-13815-2-git-send-email-tianyu.lan@intel.com \
--to=tianyu.lan@intel.com \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=jan.kiszka@siemens.com \
--cc=jasowang@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--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