Skip to content

Commit 666834c

Browse files
Shuo Liugregkh
authored andcommitted
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 <[email protected]> Cc: Zhi Wang <[email protected]> Cc: Zhenyu Wang <[email protected]> Cc: Yu Wang <[email protected]> Cc: Reinette Chatre <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuo Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8a0a871 commit 666834c

File tree

7 files changed

+126
-0
lines changed

7 files changed

+126
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ L: [email protected]
442442
S: Supported
443443
W: https://projectacrn.org
444444
F: Documentation/virt/acrn/
445+
F: drivers/virt/acrn/
445446

446447
AD1889 ALSA SOUND DRIVER
447448

drivers/virt/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ config FSL_HV_MANAGER
3434
source "drivers/virt/vboxguest/Kconfig"
3535

3636
source "drivers/virt/nitro_enclaves/Kconfig"
37+
38+
source "drivers/virt/acrn/Kconfig"
3739
endif

drivers/virt/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ obj-$(CONFIG_FSL_HV_MANAGER) += fsl_hypervisor.o
77
obj-y += vboxguest/
88

99
obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/
10+
obj-$(CONFIG_ACRN_HSM) += acrn/

drivers/virt/acrn/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.

drivers/virt/acrn/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_ACRN_HSM) := acrn.o
3+
acrn-y := hsm.o

drivers/virt/acrn/acrn_drv.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 */

drivers/virt/acrn/hsm.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 <[email protected]>
9+
* Yakui Zhao <[email protected]>
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)");

0 commit comments

Comments
 (0)