Skip to content

Commit

Permalink
KVM: x86: Enabled protected memory extension
Browse files Browse the repository at this point in the history
Wire up hypercalls for the feature and define VM_KVM_PROTECTED.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
  • Loading branch information
kiryl authored and intel-lab-lkp committed Oct 20, 2020
1 parent 63d2c45 commit 7f6be13
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ config KVM_GUEST
select X86_HV_CALLBACK_VECTOR
select X86_MEM_ENCRYPT_COMMON
select SWIOTLB
select ARCH_USES_HIGH_VMA_FLAGS
default y
help
This option enables various optimizations for running under the KVM
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ config KVM
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_VFIO
select SRCU
select HAVE_KVM_PROTECTED_MEMORY
help
Support hosting fully virtualized guest machines using hardware
virtualization extensions. You will need a fairly recent
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kvm/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
(1 << KVM_FEATURE_PV_SEND_IPI) |
(1 << KVM_FEATURE_POLL_CONTROL) |
(1 << KVM_FEATURE_PV_SCHED_YIELD) |
(1 << KVM_FEATURE_ASYNC_PF_INT);
(1 << KVM_FEATURE_ASYNC_PF_INT) |
(1 << KVM_FEATURE_MEM_PROTECTED);

if (sched_info_on())
entry->eax |= (1 << KVM_FEATURE_STEAL_TIME);
Expand Down
9 changes: 9 additions & 0 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -7752,6 +7752,15 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
kvm_sched_yield(vcpu->kvm, a0);
ret = 0;
break;
case KVM_HC_ENABLE_MEM_PROTECTED:
ret = kvm_protect_all_memory(vcpu->kvm);
break;
case KVM_HC_MEM_SHARE:
ret = kvm_protect_memory(vcpu->kvm, a0, a1, false);
break;
case KVM_HC_MEM_UNSHARE:
ret = kvm_protect_memory(vcpu->kvm, a0, a1, true);
break;
default:
ret = -KVM_ENOSYS;
break;
Expand Down
6 changes: 6 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ extern unsigned int kobjsize(const void *objp);
#define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)
#define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)
#define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)
#define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3)
#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5)
#endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */

#ifdef CONFIG_ARCH_HAS_PKEYS
Expand Down Expand Up @@ -342,7 +344,11 @@ extern unsigned int kobjsize(const void *objp);
# define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */
#endif

#if defined(CONFIG_X86_64) && defined(CONFIG_KVM)
#define VM_KVM_PROTECTED VM_HIGH_ARCH_5
#else
#define VM_KVM_PROTECTED 0
#endif

#ifndef VM_GROWSUP
# define VM_GROWSUP VM_NONE
Expand Down

0 comments on commit 7f6be13

Please sign in to comment.