Skip to content

Commit e946554

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "ARM64: - Fix a regression with pKVM when kmemleak is enabled - Add Oliver Upton as an official KVM/arm64 reviewer selftests: - deal with compiler optimizations around hypervisor exits x86: - MAINTAINERS reorganization - Two SEV fixes" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: SEV: Init target VMCBs in sev_migrate_from KVM: x86/svm: add __GFP_ACCOUNT to __sev_dbg_{en,de}crypt_user() MAINTAINERS: Reorganize KVM/x86 maintainership selftests: KVM: Handle compiler optimizations in ucall KVM: arm64: Add Oliver as a reviewer KVM: arm64: Prevent kmemleak from accessing pKVM memory tools/kvm_stat: fix display of error when multiple processes are found
2 parents 38bc4ac + 6defa24 commit e946554

File tree

7 files changed

+92
-53
lines changed

7 files changed

+92
-53
lines changed

MAINTAINERS

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10846,6 +10846,7 @@ M: Marc Zyngier <[email protected]>
1084610846
R: James Morse <[email protected]>
1084710847
R: Alexandru Elisei <[email protected]>
1084810848
R: Suzuki K Poulose <[email protected]>
10849+
R: Oliver Upton <[email protected]>
1084910850
L: [email protected] (moderated for non-subscribers)
1085010851
L: [email protected] (moderated for non-subscribers)
1085110852
S: Maintained
@@ -10912,28 +10913,51 @@ F: tools/testing/selftests/kvm/*/s390x/
1091210913
F: tools/testing/selftests/kvm/s390x/
1091310914

1091410915
KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86)
10916+
M: Sean Christopherson <[email protected]>
1091510917
M: Paolo Bonzini <[email protected]>
10916-
R: Sean Christopherson <[email protected]>
10917-
R: Vitaly Kuznetsov <[email protected]>
10918-
R: Wanpeng Li <[email protected]>
10919-
R: Jim Mattson <[email protected]>
10920-
R: Joerg Roedel <[email protected]>
1092110918
1092210919
S: Supported
10923-
W: http://www.linux-kvm.org
1092410920
T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git
1092510921
F: arch/x86/include/asm/kvm*
10926-
F: arch/x86/include/asm/pvclock-abi.h
1092710922
F: arch/x86/include/asm/svm.h
1092810923
F: arch/x86/include/asm/vmx*.h
1092910924
F: arch/x86/include/uapi/asm/kvm*
1093010925
F: arch/x86/include/uapi/asm/svm.h
1093110926
F: arch/x86/include/uapi/asm/vmx.h
10932-
F: arch/x86/kernel/kvm.c
10933-
F: arch/x86/kernel/kvmclock.c
1093410927
F: arch/x86/kvm/
1093510928
F: arch/x86/kvm/*/
1093610929

10930+
KVM PARAVIRT (KVM/paravirt)
10931+
M: Paolo Bonzini <[email protected]>
10932+
R: Wanpeng Li <[email protected]>
10933+
R: Vitaly Kuznetsov <[email protected]>
10934+
10935+
S: Supported
10936+
T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git
10937+
F: arch/x86/kernel/kvm.c
10938+
F: arch/x86/kernel/kvmclock.c
10939+
F: arch/x86/include/asm/pvclock-abi.h
10940+
F: include/linux/kvm_para.h
10941+
F: include/uapi/linux/kvm_para.h
10942+
F: include/uapi/asm-generic/kvm_para.h
10943+
F: include/asm-generic/kvm_para.h
10944+
F: arch/um/include/asm/kvm_para.h
10945+
F: arch/x86/include/asm/kvm_para.h
10946+
F: arch/x86/include/uapi/asm/kvm_para.h
10947+
10948+
KVM X86 HYPER-V (KVM/hyper-v)
10949+
M: Vitaly Kuznetsov <[email protected]>
10950+
M: Sean Christopherson <[email protected]>
10951+
M: Paolo Bonzini <[email protected]>
10952+
10953+
S: Supported
10954+
T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git
10955+
F: arch/x86/kvm/hyperv.*
10956+
F: arch/x86/kvm/kvm_onhyperv.*
10957+
F: arch/x86/kvm/svm/hyperv.*
10958+
F: arch/x86/kvm/svm/svm_onhyperv.*
10959+
F: arch/x86/kvm/vmx/evmcs.*
10960+
1093710961
KERNFS
1093810962
M: Greg Kroah-Hartman <[email protected]>
1093910963
M: Tejun Heo <[email protected]>

arch/arm64/kvm/arm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,11 +2112,11 @@ static int finalize_hyp_mode(void)
21122112
return 0;
21132113

21142114
/*
2115-
* Exclude HYP BSS from kmemleak so that it doesn't get peeked
2116-
* at, which would end badly once the section is inaccessible.
2117-
* None of other sections should ever be introspected.
2115+
* Exclude HYP sections from kmemleak so that they don't get peeked
2116+
* at, which would end badly once inaccessible.
21182117
*/
21192118
kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start);
2119+
kmemleak_free_part(__va(hyp_mem_base), hyp_mem_size);
21202120
return pkvm_drop_host_privileges();
21212121
}
21222122

arch/x86/kvm/svm/sev.c

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ static int __sev_dbg_encrypt_user(struct kvm *kvm, unsigned long paddr,
844844

845845
/* If source buffer is not aligned then use an intermediate buffer */
846846
if (!IS_ALIGNED((unsigned long)vaddr, 16)) {
847-
src_tpage = alloc_page(GFP_KERNEL);
847+
src_tpage = alloc_page(GFP_KERNEL_ACCOUNT);
848848
if (!src_tpage)
849849
return -ENOMEM;
850850

@@ -865,7 +865,7 @@ static int __sev_dbg_encrypt_user(struct kvm *kvm, unsigned long paddr,
865865
if (!IS_ALIGNED((unsigned long)dst_vaddr, 16) || !IS_ALIGNED(size, 16)) {
866866
int dst_offset;
867867

868-
dst_tpage = alloc_page(GFP_KERNEL);
868+
dst_tpage = alloc_page(GFP_KERNEL_ACCOUNT);
869869
if (!dst_tpage) {
870870
ret = -ENOMEM;
871871
goto e_free;
@@ -1665,19 +1665,24 @@ static void sev_migrate_from(struct kvm *dst_kvm, struct kvm *src_kvm)
16651665
{
16661666
struct kvm_sev_info *dst = &to_kvm_svm(dst_kvm)->sev_info;
16671667
struct kvm_sev_info *src = &to_kvm_svm(src_kvm)->sev_info;
1668+
struct kvm_vcpu *dst_vcpu, *src_vcpu;
1669+
struct vcpu_svm *dst_svm, *src_svm;
16681670
struct kvm_sev_info *mirror;
1671+
unsigned long i;
16691672

16701673
dst->active = true;
16711674
dst->asid = src->asid;
16721675
dst->handle = src->handle;
16731676
dst->pages_locked = src->pages_locked;
16741677
dst->enc_context_owner = src->enc_context_owner;
1678+
dst->es_active = src->es_active;
16751679

16761680
src->asid = 0;
16771681
src->active = false;
16781682
src->handle = 0;
16791683
src->pages_locked = 0;
16801684
src->enc_context_owner = NULL;
1685+
src->es_active = false;
16811686

16821687
list_cut_before(&dst->regions_list, &src->regions_list, &src->regions_list);
16831688

@@ -1704,26 +1709,21 @@ static void sev_migrate_from(struct kvm *dst_kvm, struct kvm *src_kvm)
17041709
list_del(&src->mirror_entry);
17051710
list_add_tail(&dst->mirror_entry, &owner_sev_info->mirror_vms);
17061711
}
1707-
}
17081712

1709-
static int sev_es_migrate_from(struct kvm *dst, struct kvm *src)
1710-
{
1711-
unsigned long i;
1712-
struct kvm_vcpu *dst_vcpu, *src_vcpu;
1713-
struct vcpu_svm *dst_svm, *src_svm;
1713+
kvm_for_each_vcpu(i, dst_vcpu, dst_kvm) {
1714+
dst_svm = to_svm(dst_vcpu);
17141715

1715-
if (atomic_read(&src->online_vcpus) != atomic_read(&dst->online_vcpus))
1716-
return -EINVAL;
1716+
sev_init_vmcb(dst_svm);
17171717

1718-
kvm_for_each_vcpu(i, src_vcpu, src) {
1719-
if (!src_vcpu->arch.guest_state_protected)
1720-
return -EINVAL;
1721-
}
1718+
if (!dst->es_active)
1719+
continue;
17221720

1723-
kvm_for_each_vcpu(i, src_vcpu, src) {
1721+
/*
1722+
* Note, the source is not required to have the same number of
1723+
* vCPUs as the destination when migrating a vanilla SEV VM.
1724+
*/
1725+
src_vcpu = kvm_get_vcpu(dst_kvm, i);
17241726
src_svm = to_svm(src_vcpu);
1725-
dst_vcpu = kvm_get_vcpu(dst, i);
1726-
dst_svm = to_svm(dst_vcpu);
17271727

17281728
/*
17291729
* Transfer VMSA and GHCB state to the destination. Nullify and
@@ -1740,8 +1740,23 @@ static int sev_es_migrate_from(struct kvm *dst, struct kvm *src)
17401740
src_svm->vmcb->control.vmsa_pa = INVALID_PAGE;
17411741
src_vcpu->arch.guest_state_protected = false;
17421742
}
1743-
to_kvm_svm(src)->sev_info.es_active = false;
1744-
to_kvm_svm(dst)->sev_info.es_active = true;
1743+
}
1744+
1745+
static int sev_check_source_vcpus(struct kvm *dst, struct kvm *src)
1746+
{
1747+
struct kvm_vcpu *src_vcpu;
1748+
unsigned long i;
1749+
1750+
if (!sev_es_guest(src))
1751+
return 0;
1752+
1753+
if (atomic_read(&src->online_vcpus) != atomic_read(&dst->online_vcpus))
1754+
return -EINVAL;
1755+
1756+
kvm_for_each_vcpu(i, src_vcpu, src) {
1757+
if (!src_vcpu->arch.guest_state_protected)
1758+
return -EINVAL;
1759+
}
17451760

17461761
return 0;
17471762
}
@@ -1789,11 +1804,9 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
17891804
if (ret)
17901805
goto out_dst_vcpu;
17911806

1792-
if (sev_es_guest(source_kvm)) {
1793-
ret = sev_es_migrate_from(kvm, source_kvm);
1794-
if (ret)
1795-
goto out_source_vcpu;
1796-
}
1807+
ret = sev_check_source_vcpus(kvm, source_kvm);
1808+
if (ret)
1809+
goto out_source_vcpu;
17971810

17981811
sev_migrate_from(kvm, source_kvm);
17991812
kvm_vm_dead(source_kvm);
@@ -2914,7 +2927,7 @@ int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in)
29142927
count, in);
29152928
}
29162929

2917-
void sev_es_init_vmcb(struct vcpu_svm *svm)
2930+
static void sev_es_init_vmcb(struct vcpu_svm *svm)
29182931
{
29192932
struct kvm_vcpu *vcpu = &svm->vcpu;
29202933

@@ -2967,6 +2980,15 @@ void sev_es_init_vmcb(struct vcpu_svm *svm)
29672980
}
29682981
}
29692982

2983+
void sev_init_vmcb(struct vcpu_svm *svm)
2984+
{
2985+
svm->vmcb->control.nested_ctl |= SVM_NESTED_CTL_SEV_ENABLE;
2986+
clr_exception_intercept(svm, UD_VECTOR);
2987+
2988+
if (sev_es_guest(svm->vcpu.kvm))
2989+
sev_es_init_vmcb(svm);
2990+
}
2991+
29702992
void sev_es_vcpu_reset(struct vcpu_svm *svm)
29712993
{
29722994
/*

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,8 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
12121212
svm->vmcb->control.int_ctl |= V_GIF_ENABLE_MASK;
12131213
}
12141214

1215-
if (sev_guest(vcpu->kvm)) {
1216-
svm->vmcb->control.nested_ctl |= SVM_NESTED_CTL_SEV_ENABLE;
1217-
clr_exception_intercept(svm, UD_VECTOR);
1218-
1219-
if (sev_es_guest(vcpu->kvm)) {
1220-
/* Perform SEV-ES specific VMCB updates */
1221-
sev_es_init_vmcb(svm);
1222-
}
1223-
}
1215+
if (sev_guest(vcpu->kvm))
1216+
sev_init_vmcb(svm);
12241217

12251218
svm_hv_init_vmcb(vmcb);
12261219
init_vmcb_after_set_cpuid(vcpu);

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,10 @@ void __init sev_set_cpu_caps(void);
649649
void __init sev_hardware_setup(void);
650650
void sev_hardware_unsetup(void);
651651
int sev_cpu_init(struct svm_cpu_data *sd);
652+
void sev_init_vmcb(struct vcpu_svm *svm);
652653
void sev_free_vcpu(struct kvm_vcpu *vcpu);
653654
int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
654655
int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in);
655-
void sev_es_init_vmcb(struct vcpu_svm *svm);
656656
void sev_es_vcpu_reset(struct vcpu_svm *svm);
657657
void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
658658
void sev_es_prepare_switch_to_guest(struct sev_es_save_area *hostsa);

tools/kvm/kvm_stat/kvm_stat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,8 @@ Press any other key to refresh statistics immediately.
16461646
.format(values))
16471647
if len(pids) > 1:
16481648
sys.exit('Error: Multiple processes found (pids: {}). Use "-p"'
1649-
' to specify the desired pid'.format(" ".join(pids)))
1649+
' to specify the desired pid'
1650+
.format(" ".join(map(str, pids))))
16501651
namespace.pid = pids[0]
16511652

16521653
argparser = argparse.ArgumentParser(description=description_text,

tools/testing/selftests/kvm/lib/aarch64/ucall.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,19 @@ void ucall_uninit(struct kvm_vm *vm)
7373

7474
void ucall(uint64_t cmd, int nargs, ...)
7575
{
76-
struct ucall uc = {
77-
.cmd = cmd,
78-
};
76+
struct ucall uc = {};
7977
va_list va;
8078
int i;
8179

80+
WRITE_ONCE(uc.cmd, cmd);
8281
nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS;
8382

8483
va_start(va, nargs);
8584
for (i = 0; i < nargs; ++i)
86-
uc.args[i] = va_arg(va, uint64_t);
85+
WRITE_ONCE(uc.args[i], va_arg(va, uint64_t));
8786
va_end(va);
8887

89-
*ucall_exit_mmio_addr = (vm_vaddr_t)&uc;
88+
WRITE_ONCE(*ucall_exit_mmio_addr, (vm_vaddr_t)&uc);
9089
}
9190

9291
uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)

0 commit comments

Comments
 (0)