From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
kvm-ppc@vger.kernel.org
Cc: aik@ozlabs.ru, alex.williamson@redhat.com,
qiudayu@linux.vnet.ibm.com,
Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH 08/22] kvm: Address mapping for VFIO device
Date: Mon, 5 May 2014 11:27:57 +1000 [thread overview]
Message-ID: <1399253291-3975-9-git-send-email-gwshan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1399253291-3975-1-git-send-email-gwshan@linux.vnet.ibm.com>
The address (domain/bus/slot/function) looks different from the
perspective of host and guest. We have to setup the mapping for
EEH and tear it down accordingly. The patch introduces additional
attributes to KVM VFIO device for address mapping or unmapping.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
arch/powerpc/kvm/Kconfig | 1 +
arch/powerpc/kvm/Makefile | 3 +++
include/uapi/linux/kvm.h | 10 ++++++++
virt/kvm/vfio.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 743d2d9..6764fc5 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -64,6 +64,7 @@ config KVM_BOOK3S_64
select KVM_BOOK3S_64_HANDLER
select KVM
select KVM_BOOK3S_PR_POSSIBLE if !KVM_BOOK3S_HV_POSSIBLE
+ select KVM_VFIO if VFIO
---help---
Support running unmodified book3s_64 and book3s_32 guest kernels
in virtual machines on book3s_64 host processors.
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index ce569b6..673038d 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -97,6 +97,9 @@ endif
kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \
book3s_xics.o
+kvm-book3s_64-objs-$(CONFIG_KVM_VFIO) += \
+ $(addprefix ../../../virt/kvm/, vfio.o)
+
kvm-book3s_64-module-objs += \
$(KVM)/kvm_main.o \
$(KVM)/eventfd.o \
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index a8f4ee5..97b4d1e 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -932,9 +932,19 @@ struct kvm_device_attr {
#define KVM_DEV_VFIO_GROUP 1
#define KVM_DEV_VFIO_GROUP_ADD 1
#define KVM_DEV_VFIO_GROUP_DEL 2
+#define KVM_DEV_VFIO_DEV 2
+#define KVM_DEV_VFIO_DEV_EEH_MAP 1
+#define KVM_DEV_VFIO_DEV_EEH_UNMAP 2
#define KVM_DEV_TYPE_ARM_VGIC_V2 5
#define KVM_DEV_TYPE_FLIC 6
+struct kvm_vfio_pci_addr {
+ __u32 domain; /* Host PHB domain */
+ __u32 bdn; /* Host bus/dev/func */
+ __u64 gbuid; /* Guet PHB BUID */
+ __u32 gbdn; /* Guest bus/dev/func */
+};
+
/*
* ioctls for VM fds
*/
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index ba1a93f..778015d 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -28,6 +28,10 @@ struct kvm_vfio {
struct list_head group_list;
struct mutex lock;
bool noncoherent;
+#ifdef CONFIG_KVM_EEH
+ kvm_vfio_dev_eeh_map eeh_map;
+ kvm_vfio_dev_eeh_unmap eeh_unmap;
+#endif
};
static struct vfio_group *kvm_vfio_group_get_external_user(struct file *filep)
@@ -201,12 +205,53 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
return -ENXIO;
}
+static int kvm_vfio_set_dev(struct kvm_device *dev, long attr, u64 arg)
+{
+ struct kvm_vfio *kv = dev->private;
+ struct kvm_vfio_pci_addr addr;
+ int ret = -ENXIO;
+
+ switch (attr) {
+#ifdef CONFIG_KVM_EEH
+ case KVM_DEV_VFIO_DEV_EEH_MAP:
+ if (copy_from_user(&addr, (void __user *)arg, sizeof(addr))) {
+ ret = -EFAULT;
+ break;
+ }
+
+ if (kv->eeh_map)
+ ret = kv->eeh_map(dev->kvm, addr.domain,
+ addr.bdn, addr.gbuid, addr.gbdn);
+ else
+ ret = 0;
+
+ break;
+ case KVM_DEV_VFIO_DEV_EEH_UNMAP:
+ if (copy_from_user(&addr, (void __user *)arg, sizeof(addr))) {
+ ret = -EFAULT;
+ break;
+ }
+
+ if (kv->eeh_unmap)
+ ret = kv->eeh_unmap(dev->kvm, addr.domain, addr.bdn);
+ else
+ ret = 0;
+
+ break;
+#endif
+ }
+
+ return ret;
+}
+
static int kvm_vfio_set_attr(struct kvm_device *dev,
struct kvm_device_attr *attr)
{
switch (attr->group) {
case KVM_DEV_VFIO_GROUP:
return kvm_vfio_set_group(dev, attr->attr, attr->addr);
+ case KVM_DEV_VFIO_DEV:
+ return kvm_vfio_set_dev(dev, attr->attr, attr->addr);
}
return -ENXIO;
@@ -224,6 +269,16 @@ static int kvm_vfio_has_attr(struct kvm_device *dev,
}
break;
+ case KVM_DEV_VFIO_DEV:
+ switch (attr->attr) {
+#ifdef CONFIG_KVM_EEH
+ case KVM_DEV_VFIO_DEV_EEH_MAP:
+ case KVM_DEV_VFIO_DEV_EEH_UNMAP:
+ return 0;
+#endif
+ }
+
+ break;
}
return -ENXIO;
@@ -262,7 +317,10 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)
INIT_LIST_HEAD(&kv->group_list);
mutex_init(&kv->lock);
-
+#ifdef CONFIG_KVM_EEH
+ kv->eeh_map = kvm_vfio_eeh_dev_map;
+ kv->eeh_unmap = kvm_vfio_eeh_dev_unmap;
+#endif
dev->private = kv;
return 0;
--
1.8.3.2
next prev parent reply other threads:[~2014-05-05 1:27 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-05 1:27 [PATCH RFC 00/22] EEH Support for VFIO PCI devices on PowerKVM guest Gavin Shan
2014-05-05 1:27 ` [PATCH 01/22] powerpc: Introduce CONFIG_KVM_EEH Gavin Shan
2014-05-05 1:27 ` [PATCH 02/22] powerpc/eeh: Info to trace passed devices Gavin Shan
2014-05-05 1:27 ` [PATCH 03/22] powerpc/eeh: Search EEH device by guest address Gavin Shan
2014-05-05 1:27 ` [PATCH 04/22] powerpc/eeh: Search EEH PE " Gavin Shan
2014-05-05 1:27 ` [PATCH 05/22] powerpc/eeh: Release VFIO dev on VM destruction Gavin Shan
2014-05-05 1:27 ` [PATCH 06/22] powerpc/eeh: Function for address mapping Gavin Shan
2014-05-05 1:27 ` [PATCH 07/22] powerpc/eeh: Function to tear down " Gavin Shan
2014-05-05 1:27 ` Gavin Shan [this message]
2014-05-05 1:27 ` [PATCH 09/22] powerpc/powernv: EEH RTAS emulation backend Gavin Shan
2014-05-05 1:27 ` [PATCH 10/22] powerpc/eeh: Introduce kvmppc_eeh_format_addr() Gavin Shan
2014-05-05 1:28 ` [PATCH 11/22] powerpc/eeh: Emulate RTAS call ibm,set-eeh-option Gavin Shan
2014-05-05 1:28 ` [PATCH 12/22] powerpc/eeh: Emulate RTAS call ibm,set-slot-reset Gavin Shan
2014-05-05 1:28 ` [PATCH 13/22] powerpc/eeh: Emulate RTAS call ibm, read-slot-reset-state2 Gavin Shan
2014-05-05 1:28 ` [PATCH 14/22] powerpc/eeh: Emulate RTAS call ibm, get-config-addr-info2 Gavin Shan
2014-05-05 1:28 ` [PATCH 15/22] powerpc/eeh: Emulate RTAS call ibm,slot-error-detail Gavin Shan
2014-05-05 1:28 ` [PATCH 16/22] powerpc/eeh: Emulate RTAS call ibm,configure-pe Gavin Shan
2014-05-05 1:28 ` [PATCH 17/22] powerpc/kvm: Connect EEH RTAS emulation backend Gavin Shan
2014-05-05 1:28 ` [PATCH 18/22] powerpc/eeh: Avoid event on passed PE Gavin Shan
2014-05-05 1:28 ` [PATCH 19/22] powerpc: Introduce CONFIG_KVM_ERRINJCT Gavin Shan
2014-05-05 1:28 ` [PATCH 20/22] powerpc/kvm: Infrastructure for error injection Gavin Shan
2014-05-05 1:28 ` [PATCH 21/22] powerpc/powernv: Sync OPAL header file with firmware Gavin Shan
2014-05-05 1:28 ` [PATCH 22/22] powerpc/powernv: Support PCI error injection Gavin Shan
2014-05-05 11:56 ` [PATCH RFC 00/22] EEH Support for VFIO PCI devices on PowerKVM guest Alexander Graf
2014-05-05 14:00 ` Alex Williamson
2014-05-06 4:26 ` Gavin Shan
2014-05-06 6:56 ` Alexander Graf
2014-05-06 7:14 ` Benjamin Herrenschmidt
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=1399253291-3975-9-git-send-email-gwshan@linux.vnet.ibm.com \
--to=gwshan@linux.vnet.ibm.com \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=qiudayu@linux.vnet.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).