From: yakui.zhao@intel.com (Zhao Yakui)
Subject: [RFC PATCH 10/15] drivers/acrn: add interrupt injection support
Date: Fri, 16 Aug 2019 10:25:51 +0800 [thread overview]
Message-ID: <1565922356-4488-11-git-send-email-yakui.zhao@intel.com> (raw)
In-Reply-To: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com>
After ACRN devicemodel finishes the emulation of trapped MMIO/IO/PCICFG
access, it needs to inject one interrupt to notify that the guest can be
resumed.
IC_SET_IRQLINE: This is used to inject virtual IOAPIC gsi interrupt
IC_INJECT_MSI: Inject virtual MSI interrupt to guest OS
IC_VM_INTR_MONITOR: monitor the interrupt info for one guest OS
Co-developed-by: Jason Chen CJ <jason.cj.chen at intel.com>
Signed-off-by: Jason Chen CJ <jason.cj.chen at intel.com>
Co-developed-by: Mingqiang Chi <mingqiang.chi at intel.com>
Signed-off-by: Mingqiang Chi <mingqiang.chi at intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao at intel.com>
---
drivers/staging/acrn/acrn_dev.c | 48 +++++++++++++++++++++++++++++++
drivers/staging/acrn/acrn_vm_mngt.c | 28 ++++++++++++++++++
include/linux/acrn/acrn_drv.h | 12 ++++++++
include/uapi/linux/acrn/acrn_ioctl_defs.h | 18 ++++++++++++
4 files changed, 106 insertions(+)
diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 28bbd78..1476817 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -19,6 +19,7 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/io.h>
+#include <linux/mm.h>
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
@@ -316,6 +317,53 @@ long acrn_dev_ioctl(struct file *filep,
break;
}
+ case IC_SET_IRQLINE: {
+ ret = hcall_set_irqline(vm->vmid, ioctl_param);
+ if (ret < 0) {
+ pr_err("acrn: failed to set irqline!\n");
+ return -EFAULT;
+ }
+ break;
+ }
+
+ case IC_INJECT_MSI: {
+ struct acrn_msi_entry *msi;
+
+ msi = kmalloc(sizeof(*msi), GFP_KERNEL);
+ if (!msi)
+ return -ENOMEM;
+
+ if (copy_from_user(msi, (void *)ioctl_param, sizeof(*msi))) {
+ kfree(msi);
+ return -EFAULT;
+ }
+
+ ret = hcall_inject_msi(vm->vmid, virt_to_phys(msi));
+ kfree(msi);
+ if (ret < 0) {
+ pr_err("acrn: failed to inject!\n");
+ return -EFAULT;
+ }
+ break;
+ }
+
+ case IC_VM_INTR_MONITOR: {
+ struct page *page;
+
+ ret = get_user_pages_fast(ioctl_param, 1, 1, &page);
+ if (unlikely(ret != 1) || !page) {
+ pr_err("acrn-dev: failed to pin intr hdr buffer!\n");
+ return -ENOMEM;
+ }
+
+ ret = hcall_vm_intr_monitor(vm->vmid, page_to_phys(page));
+ if (ret < 0) {
+ pr_err("acrn-dev: monitor intr data err=%ld\n", ret);
+ return -EFAULT;
+ }
+ break;
+ }
+
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
ret = -EFAULT;
diff --git a/drivers/staging/acrn/acrn_vm_mngt.c b/drivers/staging/acrn/acrn_vm_mngt.c
index 9c6dd6d..4287595 100644
--- a/drivers/staging/acrn/acrn_vm_mngt.c
+++ b/drivers/staging/acrn/acrn_vm_mngt.c
@@ -11,8 +11,10 @@
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/init.h>
+#include <linux/io.h>
#include <linux/rwlock_types.h>
#include <linux/acrn/acrn_ioctl_defs.h>
+#include <linux/acrn/acrn_drv.h>
#include "acrn_hypercall.h"
#include "acrn_drv_internal.h"
@@ -72,3 +74,29 @@ int acrn_vm_destroy(struct acrn_vm *vm)
vm->vmid = ACRN_INVALID_VMID;
return 0;
}
+
+int acrn_inject_msi(unsigned short vmid, unsigned long msi_addr,
+ unsigned long msi_data)
+{
+ struct acrn_msi_entry *msi;
+ int ret;
+
+ msi = kzalloc(sizeof(*msi), GFP_KERNEL);
+
+ if (!msi)
+ return -ENOMEM;
+
+ /* msi_addr: addr[19:12] with dest vcpu id */
+ /* msi_data: data[7:0] with vector */
+ msi->msi_addr = msi_addr;
+ msi->msi_data = msi_data;
+ ret = hcall_inject_msi(vmid, virt_to_phys(msi));
+ kfree(msi);
+ if (ret < 0) {
+ pr_err("acrn: failed to inject MSI for vmid %d, msi_addr %lx msi_data%lx!\n",
+ vmid, msi_addr, msi_data);
+ return -EFAULT;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(acrn_inject_msi);
diff --git a/include/linux/acrn/acrn_drv.h b/include/linux/acrn/acrn_drv.h
index 62b03f0..bcdfcaf 100644
--- a/include/linux/acrn/acrn_drv.h
+++ b/include/linux/acrn/acrn_drv.h
@@ -83,4 +83,16 @@ extern int acrn_del_memory_region(unsigned short vmid, unsigned long gpa,
extern int acrn_write_protect_page(unsigned short vmid, unsigned long gpa,
unsigned char set);
+/**
+ * acrn_inject_msi() - inject MSI interrupt to guest
+ *
+ * @vmid: guest vmid
+ * @msi_addr: MSI addr matches MSI spec
+ * @msi_data: MSI data matches MSI spec
+ *
+ * Return: 0 on success, <0 on error
+ */
+extern int acrn_inject_msi(unsigned short vmid, unsigned long msi_addr,
+ unsigned long msi_data);
+
#endif
diff --git a/include/uapi/linux/acrn/acrn_ioctl_defs.h b/include/uapi/linux/acrn/acrn_ioctl_defs.h
index ee259c2..371904c 100644
--- a/include/uapi/linux/acrn/acrn_ioctl_defs.h
+++ b/include/uapi/linux/acrn/acrn_ioctl_defs.h
@@ -210,6 +210,19 @@ struct vm_memmap {
uint32_t prot; /* RWX */
};
+/**
+ * @brief Info to inject a MSI interrupt to VM
+ *
+ * the parameter for HC_INJECT_MSI hypercall
+ */
+struct acrn_msi_entry {
+ /** MSI addr[19:12] with dest VCPU ID */
+ uint64_t msi_addr;
+
+ /** MSI data[7:0] with vector */
+ uint64_t msi_data;
+};
+
/*
* Common IOCTL ID definition for DM
*/
@@ -230,6 +243,11 @@ struct vm_memmap {
#define IC_RESET_VM _IC_ID(IC_ID, IC_ID_VM_BASE + 0x05)
#define IC_SET_VCPU_REGS _IC_ID(IC_ID, IC_ID_VM_BASE + 0x06)
+/* IRQ and Interrupts */
+#define IC_ID_IRQ_BASE 0x20UL
+#define IC_INJECT_MSI _IC_ID(IC_ID, IC_ID_IRQ_BASE + 0x03)
+#define IC_VM_INTR_MONITOR _IC_ID(IC_ID, IC_ID_IRQ_BASE + 0x04)
+#define IC_SET_IRQLINE _IC_ID(IC_ID, IC_ID_IRQ_BASE + 0x05)
/* Guest memory management */
#define IC_ID_MEM_BASE 0x40UL
--
2.7.4
next prev parent reply other threads:[~2019-08-16 2:25 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-16 2:25 [RFC PATCH 00/15] acrn: add the ACRN driver module Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 01/15] x86/acrn: Report X2APIC for ACRN guest Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 02/15] x86/acrn: Add two APIs to add/remove driver-specific upcall ISR handler Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 03/15] x86/acrn: Add hypercall for ACRN guest Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 04/15] drivers/acrn: add the basic framework of acrn char device driver Zhao Yakui
2019-08-16 7:05 ` Greg KH
2019-08-19 4:02 ` Zhao, Yakui
2019-08-19 5:26 ` Greg KH
2019-08-16 11:28 ` Dan Carpenter
2019-08-16 2:25 ` [RFC PATCH 05/15] drivers/acrn: add driver-specific hypercall for ACRN_HSM Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 06/15] drivers/acrn: add the support of querying ACRN api version Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 07/15] drivers/acrn: add acrn vm/vcpu management for ACRN_HSM char device Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 08/15] drivers/acrn: add VM memory management for ACRN " Zhao Yakui
2019-08-16 12:58 ` Dan Carpenter
2019-08-19 5:32 ` Zhao, Yakui
2019-08-19 7:39 ` Dan Carpenter
2019-08-19 7:46 ` Borislav Petkov
2019-08-20 2:25 ` Zhao, Yakui
2019-08-16 2:25 ` [RFC PATCH 09/15] drivers/acrn: add passthrough device support Zhao Yakui
2019-08-16 13:05 ` Dan Carpenter
2019-09-02 0:18 ` Zhao, Yakui
2019-08-16 2:25 ` Zhao Yakui [this message]
2019-08-16 13:12 ` [RFC PATCH 10/15] drivers/acrn: add interrupt injection support Dan Carpenter
2019-08-19 4:59 ` Zhao, Yakui
2019-08-16 2:25 ` [RFC PATCH 11/15] drivers/acrn: add the support of handling emulated ioreq Zhao Yakui
2019-08-16 13:39 ` Dan Carpenter
2019-08-19 4:54 ` Zhao, Yakui
2019-08-16 2:25 ` [RFC PATCH 12/15] drivers/acrn: add driver-specific IRQ handle to dispatch IO_REQ request Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 13/15] drivers/acrn: add service to obtain Power data transition Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 14/15] drivers/acrn: add the support of irqfd and eventfd Zhao Yakui
2019-08-16 2:25 ` [RFC PATCH 15/15] drivers/acrn: add the support of offline SOS cpu Zhao Yakui
2019-08-19 10:34 ` Dan Carpenter
2019-08-20 2:23 ` Zhao, Yakui
2019-08-16 6:39 ` [RFC PATCH 00/15] acrn: add the ACRN driver module Borislav Petkov
2019-08-16 7:03 ` Greg KH
2019-08-19 2:39 ` Zhao, Yakui
2019-08-19 5:25 ` Greg KH
2019-08-19 1:44 ` Zhao, Yakui
2019-08-19 5:25 ` Greg KH
2019-08-19 5:39 ` Zhao, Yakui
2019-08-19 6:18 ` Borislav Petkov
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=1565922356-4488-11-git-send-email-yakui.zhao@intel.com \
--to=yakui.zhao@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).