Skip to content

Commit 279dcf6

Browse files
Shuo Liugregkh
authored andcommitted
virt: acrn: Introduce an interface for Service VM to control vCPU
ACRN supports partition mode to achieve real-time requirements. In partition mode, a CPU core can be dedicated to a vCPU of User VM. The local APIC of the dedicated CPU core can be passthrough to the User VM. The Service VM controls the assignment of the CPU cores. Introduce an interface for the Service VM to remove the control of CPU core from hypervisor perspective so that the CPU core can be a dedicated CPU core of User VM. 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: Zhi Wang <zhi.a.wang@intel.com> 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-18-shuo.a.liu@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aa3b483 commit 279dcf6

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎drivers/virt/acrn/hsm.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Yakui Zhao <yakui.zhao@intel.com>
1010
*/
1111

12+
#include <linux/cpu.h>
1213
#include <linux/io.h>
1314
#include <linux/mm.h>
1415
#include <linux/module.h>
@@ -371,6 +372,52 @@ static int acrn_dev_release(struct inode *inode, struct file *filp)
371372
return 0;
372373
}
373374

375+
static ssize_t remove_cpu_store(struct device *dev,
376+
struct device_attribute *attr,
377+
const char *buf, size_t count)
378+
{
379+
u64 cpu, lapicid;
380+
int ret;
381+
382+
if (kstrtoull(buf, 0, &cpu) < 0)
383+
return -EINVAL;
384+
385+
if (cpu >= num_possible_cpus() || cpu == 0 || !cpu_is_hotpluggable(cpu))
386+
return -EINVAL;
387+
388+
if (cpu_online(cpu))
389+
remove_cpu(cpu);
390+
391+
lapicid = cpu_data(cpu).apicid;
392+
dev_dbg(dev, "Try to remove cpu %lld with lapicid %lld\n", cpu, lapicid);
393+
ret = hcall_sos_remove_cpu(lapicid);
394+
if (ret < 0) {
395+
dev_err(dev, "Failed to remove cpu %lld!\n", cpu);
396+
goto fail_remove;
397+
}
398+
399+
return count;
400+
401+
fail_remove:
402+
add_cpu(cpu);
403+
return ret;
404+
}
405+
static DEVICE_ATTR_WO(remove_cpu);
406+
407+
static struct attribute *acrn_attrs[] = {
408+
&dev_attr_remove_cpu.attr,
409+
NULL
410+
};
411+
412+
static struct attribute_group acrn_attr_group = {
413+
.attrs = acrn_attrs,
414+
};
415+
416+
static const struct attribute_group *acrn_attr_groups[] = {
417+
&acrn_attr_group,
418+
NULL
419+
};
420+
374421
static const struct file_operations acrn_fops = {
375422
.owner = THIS_MODULE,
376423
.open = acrn_dev_open,
@@ -382,6 +429,7 @@ struct miscdevice acrn_dev = {
382429
.minor = MISC_DYNAMIC_MINOR,
383430
.name = "acrn_hsm",
384431
.fops = &acrn_fops,
432+
.groups = acrn_attr_groups,
385433
};
386434

387435
static int __init hsm_init(void)

‎drivers/virt/acrn/hypercall.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#define HC_ID 0x80UL
1515

16+
#define HC_ID_GEN_BASE 0x0UL
17+
#define HC_SOS_REMOVE_CPU _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01)
18+
1619
#define HC_ID_VM_BASE 0x10UL
1720
#define HC_CREATE_VM _HC_ID(HC_ID, HC_ID_VM_BASE + 0x00)
1821
#define HC_DESTROY_VM _HC_ID(HC_ID, HC_ID_VM_BASE + 0x01)
@@ -42,6 +45,17 @@
4245
#define HC_ID_PM_BASE 0x80UL
4346
#define HC_PM_GET_CPU_STATE _HC_ID(HC_ID, HC_ID_PM_BASE + 0x00)
4447

48+
/**
49+
* hcall_sos_remove_cpu() - Remove a vCPU of Service VM
50+
* @cpu: The vCPU to be removed
51+
*
52+
* Return: 0 on success, <0 on failure
53+
*/
54+
static inline long hcall_sos_remove_cpu(u64 cpu)
55+
{
56+
return acrn_hypercall1(HC_SOS_REMOVE_CPU, cpu);
57+
}
58+
4559
/**
4660
* hcall_create_vm() - Create a User VM
4761
* @vminfo: Service VM GPA of info of User VM creation

0 commit comments

Comments
 (0)