Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virt: acrn: Introduce ACRN HSM basic driver

ACRN Hypervisor Service Module (HSM) is a kernel module in Service VM
which communicates with ACRN userspace through ioctls and talks to ACRN
Hypervisor through hypercalls.

Add a basic HSM driver which allows Service VM userspace to communicate
with ACRN. The following patches will add more ioctls, guest VM memory
mapping caching, I/O request processing, ioeventfd and irqfd into this
module. HSM exports a char device interface (/dev/acrn_hsm) to userspace.

Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Yu Wang <yu1.wang@intel.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuo Liu <shuo.a.liu@intel.com>
Link: https://lore.kernel.org/r/20210207031040.49576-6-shuo.a.liu@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Shuo Liu and committed by
Greg Kroah-Hartman
666834c4 8a0a8719

+126
+1
MAINTAINERS
··· 442 442 S: Supported 443 443 W: https://projectacrn.org 444 444 F: Documentation/virt/acrn/ 445 + F: drivers/virt/acrn/ 445 446 446 447 AD1889 ALSA SOUND DRIVER 447 448 L: linux-parisc@vger.kernel.org
+2
drivers/virt/Kconfig
··· 34 34 source "drivers/virt/vboxguest/Kconfig" 35 35 36 36 source "drivers/virt/nitro_enclaves/Kconfig" 37 + 38 + source "drivers/virt/acrn/Kconfig" 37 39 endif
+1
drivers/virt/Makefile
··· 7 7 obj-y += vboxguest/ 8 8 9 9 obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ 10 + obj-$(CONFIG_ACRN_HSM) += acrn/
+14
drivers/virt/acrn/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + config ACRN_HSM 3 + tristate "ACRN Hypervisor Service Module" 4 + depends on ACRN_GUEST 5 + help 6 + ACRN Hypervisor Service Module (HSM) is a kernel module which 7 + communicates with ACRN userspace through ioctls and talks to 8 + the ACRN Hypervisor through hypercalls. HSM will only run in 9 + a privileged management VM, called Service VM, to manage User 10 + VMs and do I/O emulation. Not required for simply running 11 + under ACRN as a User VM. 12 + 13 + To compile as a module, choose M, the module will be called 14 + acrn. If unsure, say N.
+3
drivers/virt/acrn/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-$(CONFIG_ACRN_HSM) := acrn.o 3 + acrn-y := hsm.o
+18
drivers/virt/acrn/acrn_drv.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ACRN_HSM_DRV_H 4 + #define __ACRN_HSM_DRV_H 5 + 6 + #include <linux/types.h> 7 + 8 + #define ACRN_INVALID_VMID (0xffffU) 9 + 10 + /** 11 + * struct acrn_vm - Properties of ACRN User VM. 12 + * @vmid: User VM ID 13 + */ 14 + struct acrn_vm { 15 + u16 vmid; 16 + }; 17 + 18 + #endif /* __ACRN_HSM_DRV_H */
+87
drivers/virt/acrn/hsm.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * ACRN Hypervisor Service Module (HSM) 4 + * 5 + * Copyright (C) 2020 Intel Corporation. All rights reserved. 6 + * 7 + * Authors: 8 + * Fengwei Yin <fengwei.yin@intel.com> 9 + * Yakui Zhao <yakui.zhao@intel.com> 10 + */ 11 + 12 + #include <linux/miscdevice.h> 13 + #include <linux/mm.h> 14 + #include <linux/module.h> 15 + #include <linux/slab.h> 16 + 17 + #include <asm/acrn.h> 18 + #include <asm/hypervisor.h> 19 + 20 + #include "acrn_drv.h" 21 + 22 + /* 23 + * When /dev/acrn_hsm is opened, a 'struct acrn_vm' object is created to 24 + * represent a VM instance and continues to be associated with the opened file 25 + * descriptor. All ioctl operations on this file descriptor will be targeted to 26 + * the VM instance. Release of this file descriptor will destroy the object. 27 + */ 28 + static int acrn_dev_open(struct inode *inode, struct file *filp) 29 + { 30 + struct acrn_vm *vm; 31 + 32 + vm = kzalloc(sizeof(*vm), GFP_KERNEL); 33 + if (!vm) 34 + return -ENOMEM; 35 + 36 + vm->vmid = ACRN_INVALID_VMID; 37 + filp->private_data = vm; 38 + return 0; 39 + } 40 + 41 + static int acrn_dev_release(struct inode *inode, struct file *filp) 42 + { 43 + struct acrn_vm *vm = filp->private_data; 44 + 45 + kfree(vm); 46 + return 0; 47 + } 48 + 49 + static const struct file_operations acrn_fops = { 50 + .owner = THIS_MODULE, 51 + .open = acrn_dev_open, 52 + .release = acrn_dev_release, 53 + }; 54 + 55 + static struct miscdevice acrn_dev = { 56 + .minor = MISC_DYNAMIC_MINOR, 57 + .name = "acrn_hsm", 58 + .fops = &acrn_fops, 59 + }; 60 + 61 + static int __init hsm_init(void) 62 + { 63 + int ret; 64 + 65 + if (x86_hyper_type != X86_HYPER_ACRN) 66 + return -ENODEV; 67 + 68 + if (!(cpuid_eax(ACRN_CPUID_FEATURES) & ACRN_FEATURE_PRIVILEGED_VM)) 69 + return -EPERM; 70 + 71 + ret = misc_register(&acrn_dev); 72 + if (ret) 73 + pr_err("Create misc dev failed!\n"); 74 + 75 + return ret; 76 + } 77 + 78 + static void __exit hsm_exit(void) 79 + { 80 + misc_deregister(&acrn_dev); 81 + } 82 + module_init(hsm_init); 83 + module_exit(hsm_exit); 84 + 85 + MODULE_AUTHOR("Intel Corporation"); 86 + MODULE_LICENSE("GPL"); 87 + MODULE_DESCRIPTION("ACRN Hypervisor Service Module (HSM)");