vm.c 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2019 Western Digital Corporation or its affiliates.
 *
 * Authors:
 *     Anup Patel <anup.patel@wdc.com>
 */

#include <linux/errno.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/kvm_host.h>

const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
	KVM_GENERIC_VM_STATS()
};
static_assert(ARRAY_SIZE(kvm_vm_stats_desc) ==
		sizeof(struct kvm_vm_stat) / sizeof(u64));

const struct kvm_stats_header kvm_vm_stats_header = {
	.name_size = KVM_STATS_NAME_SIZE,
	.num_desc = ARRAY_SIZE(kvm_vm_stats_desc),
	.id_offset =  sizeof(struct kvm_stats_header),
	.desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE,
	.data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE +
		       sizeof(kvm_vm_stats_desc),
};

int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
{
	int r;

34
	r = kvm_riscv_gstage_alloc_pgd(kvm);
35 36 37
	if (r)
		return r;

38
	r = kvm_riscv_gstage_vmid_init(kvm);
A
Anup Patel 已提交
39
	if (r) {
40
		kvm_riscv_gstage_free_pgd(kvm);
A
Anup Patel 已提交
41 42 43
		return r;
	}

A
Atish Patra 已提交
44
	return kvm_riscv_guest_timer_init(kvm);
45 46 47 48
}

void kvm_arch_destroy_vm(struct kvm *kvm)
{
49
	kvm_destroy_vcpus(kvm);
50 51 52 53 54 55 56
}

int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
{
	int r;

	switch (ext) {
57
	case KVM_CAP_IOEVENTFD:
58 59
	case KVM_CAP_DEVICE_CTRL:
	case KVM_CAP_USER_MEMORY:
A
Anup Patel 已提交
60
	case KVM_CAP_SYNC_MMU:
61 62 63 64 65 66 67 68
	case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
	case KVM_CAP_ONE_REG:
	case KVM_CAP_READONLY_MEM:
	case KVM_CAP_MP_STATE:
	case KVM_CAP_IMMEDIATE_EXIT:
		r = 1;
		break;
	case KVM_CAP_NR_VCPUS:
69
		r = min_t(unsigned int, num_online_cpus(), KVM_MAX_VCPUS);
70 71 72 73 74 75 76
		break;
	case KVM_CAP_MAX_VCPUS:
		r = KVM_MAX_VCPUS;
		break;
	case KVM_CAP_NR_MEMSLOTS:
		r = KVM_USER_MEM_SLOTS;
		break;
77
	case KVM_CAP_VM_GPA_BITS:
78
		r = kvm_riscv_gstage_gpa_bits();
79
		break;
80 81 82 83 84 85 86 87 88 89 90 91 92
	default:
		r = 0;
		break;
	}

	return r;
}

long kvm_arch_vm_ioctl(struct file *filp,
		       unsigned int ioctl, unsigned long arg)
{
	return -EINVAL;
}