@@ -524,6 +524,8 @@ struct kvm_x86_ops {
int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
int (*get_tdp_level)(void);
int (*get_mt_mask_shift)(void);
+
+ bool (*gb_page_enable)(void);
};
extern struct kvm_x86_ops *kvm_x86_ops;
@@ -2622,6 +2622,11 @@ static int svm_get_mt_mask_shift(void)
return 0;
}
+static bool svm_gb_page_enable(void)
+{
+ return npt_enabled;
+}
+
static struct kvm_x86_ops svm_x86_ops = {
.cpu_has_kvm_support = has_svm,
.disabled_by_bios = is_disabled,
@@ -2679,6 +2684,8 @@ static struct kvm_x86_ops svm_x86_ops = {
.set_tss_addr = svm_set_tss_addr,
.get_tdp_level = get_npt_level,
.get_mt_mask_shift = svm_get_mt_mask_shift,
+
+ .gb_page_enable = svm_gb_page_enable,
};
static int __init svm_init(void)
@@ -3683,6 +3683,11 @@ static int vmx_get_mt_mask_shift(void)
return VMX_EPT_MT_EPTE_SHIFT;
}
+static bool vmx_gb_page_enable(void)
+{
+ return false;
+}
+
static struct kvm_x86_ops vmx_x86_ops = {
.cpu_has_kvm_support = cpu_has_kvm_support,
.disabled_by_bios = vmx_disabled_by_bios,
@@ -3738,6 +3743,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
.set_tss_addr = vmx_set_tss_addr,
.get_tdp_level = get_ept_level,
.get_mt_mask_shift = vmx_get_mt_mask_shift,
+
+ .gb_page_enable = vmx_gb_page_enable,
};
static int __init vmx_init(void)
@@ -1011,7 +1011,7 @@ out:
int kvm_dev_ioctl_check_extension(long ext)
{
- int r;
+ int r = 0;
switch (ext) {
case KVM_CAP_IRQCHIP:
@@ -1029,6 +1029,10 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_ASSIGN_DEV_IRQ:
r = 1;
break;
+ case KVM_CAP_1GB_PAGES:
+ if (kvm_x86_ops->gb_page_enable())
+ r = 1;
+ break;
case KVM_CAP_COALESCED_MMIO:
r = KVM_COALESCED_MMIO_PAGE_OFFSET;
break;
@@ -415,6 +415,7 @@ struct kvm_trace_rec {
#define KVM_CAP_ASSIGN_DEV_IRQ 29
/* Another bug in KVM_SET_USER_MEMORY_REGION fixed: */
#define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30
+#define KVM_CAP_1GB_PAGES 31
#ifdef KVM_CAP_IRQ_ROUTING
If userspace knows that the kernel part supports 1GB pages it can enable the corresponding cpuid bit so that guests actually use GB pages. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/svm.c | 7 +++++++ arch/x86/kvm/vmx.c | 7 +++++++ arch/x86/kvm/x86.c | 6 +++++- include/linux/kvm.h | 1 + 5 files changed, 22 insertions(+), 1 deletions(-)