From: Alex Williamson <alex.williamson@redhat.com>
To: Lan Tianyu <tianyu.lan@intel.com>
Cc: qemu-devel@nongnu.org, kevin.tian@intel.com, mst@redhat.com,
jan.kiszka@siemens.com, jasowang@redhat.com, peterx@redhat.com,
david@gibson.dropbear.id.au, yi.l.liu@intel.com
Subject: Re: [Qemu-devel] [Resend RFC PATCH 1/4] VFIO: Set eventfd for IOMMU fault event via new vfio cmd
Date: Mon, 20 Feb 2017 14:08:33 -0700 [thread overview]
Message-ID: <20170220140833.7221fcd5@t450s.home> (raw)
In-Reply-To: <1487554087-15347-2-git-send-email-tianyu.lan@intel.com>
On Mon, 20 Feb 2017 09:28:04 +0800
Lan Tianyu <tianyu.lan@intel.com> wrote:
> This patch is to assign an event fd to VFIO IOMMU type1 driver
> in order to get notification when IOMMU driver reports fault event.
>
> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
> ---
> hw/vfio/common.c | 37 +++++++++++++++++++++++++++++++++++++
> include/hw/vfio/vfio-common.h | 3 +++
> linux-headers/linux/vfio.h | 13 +++++++++++++
> 3 files changed, 53 insertions(+)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 6b33b9f..628b424 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -33,6 +33,7 @@
> #include "qemu/error-report.h"
> #include "qemu/range.h"
> #include "sysemu/kvm.h"
> +#include "sysemu/sysemu.h"
> #include "trace.h"
> #include "qapi/error.h"
>
> @@ -294,6 +295,34 @@ static bool vfio_listener_skipped_section(MemoryRegionSection *section)
> section->offset_within_address_space & (1ULL << 63);
> }
>
> +static void vfio_iommu_fault(void *opaque)
> +{
> +}
> +
> +static int vfio_set_iommu_fault_notifier(struct VFIOContainer *container)
> +{
> + struct vfio_iommu_type1_set_fault_eventfd eventfd;
> + int ret;
> +
> + ret = event_notifier_init(&container->fault_notifier, 0);
> + if (ret < 0) {
> + error_report("vfio: Failed to init notifier for IOMMU fault event");
> + return ret;
> + }
> +
> + eventfd.fd = event_notifier_get_fd(&container->fault_notifier);
> + eventfd.argsz = sizeof(eventfd);
> +
> + ret = ioctl(container->fd, VFIO_IOMMU_SET_FAULT_EVENTFD, &eventfd);
> + if (ret < 0) {
> + error_report("vfio: Failed to set notifier for IOMMU fault event");
> + return ret;
> + }
> +
> + qemu_set_fd_handler(eventfd.fd, vfio_iommu_fault, NULL, container);
> + return 0;
> +}
> +
> /* Called with rcu_read_lock held. */
> static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr,
> bool *read_only)
> @@ -1103,6 +1132,14 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
> goto listener_release_exit;
> }
>
> + if (memory_region_is_iommu(container->space->as->root)) {
> + if (vfio_set_iommu_fault_notifier(container)) {
> + error_setg_errno(errp, -ret,
> + "Fail to set IOMMU fault notifier");
> + goto listener_release_exit;
> + }
> + }
Backwards compatibility needs to be supported, we can't invent a
feature and impose it on all users. We can either opportunistically
enable it and be silent about it when it's not there, or we can add a
feature flag and complain and fail if the user requests the feature and
it's not available or errors.
> +
> container->initialized = true;
>
> QLIST_INIT(&container->group_list);
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index c582de1..1b594c6 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -26,6 +26,7 @@
> #include "exec/memory.h"
> #include "qemu/queue.h"
> #include "qemu/notify.h"
> +#include "qemu/event_notifier.h"
> #ifdef CONFIG_LINUX
> #include <linux/vfio.h>
> #endif
> @@ -81,6 +82,8 @@ typedef struct VFIOContainer {
> unsigned iommu_type;
> int error;
> bool initialized;
> + EventNotifier fault_notifier;
> +
> /*
> * This assumes the host IOMMU can support only a single
> * contiguous IOVA window. We may need to generalize that in
> diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
> index 759b850..ca890ee 100644
> --- a/linux-headers/linux/vfio.h
> +++ b/linux-headers/linux/vfio.h
> @@ -537,6 +537,19 @@ 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;
> + __u32 fd;
> +};
> +
> +#define VFIO_IOMMU_SET_FAULT_EVENTFD _IO(VFIO_TYPE, VFIO_BASE + 17)
> +
> /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */
>
> /*
next prev parent reply other threads:[~2017-02-20 21:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-20 1:28 [Qemu-devel] [Resend RFC PATCH 0/4] VT-d: Inject fault event from IOMMU hardware Lan Tianyu
2017-02-20 1:28 ` [Qemu-devel] [Resend RFC PATCH 1/4] VFIO: Set eventfd for IOMMU fault event via new vfio cmd Lan Tianyu
2017-02-20 21:08 ` Alex Williamson [this message]
2017-02-20 1:28 ` [Qemu-devel] [Resend RFC PATCH 3/4] Intel iommu: Add Intel IOMMU fault event callback Lan Tianyu
2017-02-20 21:08 ` Alex Williamson
2017-02-20 1:28 ` [Qemu-devel] [Resend RFC PATCH 4/4] VFIO: Read IOMMU fault info from kernel space when get fault event Lan Tianyu
2017-02-20 21:09 ` Alex Williamson
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=20170220140833.7221fcd5@t450s.home \
--to=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=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tianyu.lan@intel.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;
as well as URLs for NNTP newsgroup(s).