Skip to content

Commit 3e10585

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM updates from Paolo Bonzini: "x86: - Support for userspace to emulate Xen hypercalls - Raise the maximum number of user memslots - Scalability improvements for the new MMU. Instead of the complex "fast page fault" logic that is used in mmu.c, tdp_mmu.c uses an rwlock so that page faults are concurrent, but the code that can run against page faults is limited. Right now only page faults take the lock for reading; in the future this will be extended to some cases of page table destruction. I hope to switch the default MMU around 5.12-rc3 (some testing was delayed due to Chinese New Year). - Cleanups for MAXPHYADDR checks - Use static calls for vendor-specific callbacks - On AMD, use VMLOAD/VMSAVE to save and restore host state - Stop using deprecated jump label APIs - Workaround for AMD erratum that made nested virtualization unreliable - Support for LBR emulation in the guest - Support for communicating bus lock vmexits to userspace - Add support for SEV attestation command - Miscellaneous cleanups PPC: - Support for second data watchpoint on POWER10 - Remove some complex workarounds for buggy early versions of POWER9 - Guest entry/exit fixes ARM64: - Make the nVHE EL2 object relocatable - Cleanups for concurrent translation faults hitting the same page - Support for the standard TRNG hypervisor call - A bunch of small PMU/Debug fixes - Simplification of the early init hypercall handling Non-KVM changes (with acks): - Detection of contended rwlocks (implemented only for qrwlocks, because KVM only needs it for x86) - Allow __DISABLE_EXPORTS from assembly code - Provide a saner follow_pfn replacements for modules" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (192 commits) KVM: x86/xen: Explicitly pad struct compat_vcpu_info to 64 bytes KVM: selftests: Don't bother mapping GVA for Xen shinfo test KVM: selftests: Fix hex vs. decimal snafu in Xen test KVM: selftests: Fix size of memslots created by Xen tests KVM: selftests: Ignore recently added Xen tests' build output KVM: selftests: Add missing header file needed by xAPIC IPI tests KVM: selftests: Add operand to vmsave/vmload/vmrun in svm.c KVM: SVM: Make symbol 'svm_gp_erratum_intercept' static locking/arch: Move qrwlock.h include after qspinlock.h KVM: PPC: Book3S HV: Fix host radix SLB optimisation with hash guests KVM: PPC: Book3S HV: Ensure radix guest has no SLB entries KVM: PPC: Don't always report hash MMU capability for P9 < DD2.2 KVM: PPC: Book3S HV: Save and restore FSCR in the P9 path KVM: PPC: remove unneeded semicolon KVM: PPC: Book3S HV: Use POWER9 SLBIA IH=6 variant to clear SLB KVM: PPC: Book3S HV: No need to clear radix host SLB before loading HPT guest KVM: PPC: Book3S HV: Fix radix guest SLB side channel KVM: PPC: Book3S HV: Remove support for running HPT guest on RPT host without mixed mode support KVM: PPC: Book3S HV: Introduce new capability for 2nd DAWR KVM: PPC: Book3S HV: Add infrastructure to support 2nd DAWR ...
2 parents 9c5b80b + 8c6e67b commit 3e10585

150 files changed

Lines changed: 6655 additions & 2060 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/virt/kvm/amd-memory-encryption.rst‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,27 @@ Returns: 0 on success, -negative on error
263263
__u32 trans_len;
264264
};
265265

266+
10. KVM_SEV_GET_ATTESTATION_REPORT
267+
----------------------------------
268+
269+
The KVM_SEV_GET_ATTESTATION_REPORT command can be used by the hypervisor to query the attestation
270+
report containing the SHA-256 digest of the guest memory and VMSA passed through the KVM_SEV_LAUNCH
271+
commands and signed with the PEK. The digest returned by the command should match the digest
272+
used by the guest owner with the KVM_SEV_LAUNCH_MEASURE.
273+
274+
Parameters (in): struct kvm_sev_attestation
275+
276+
Returns: 0 on success, -negative on error
277+
278+
::
279+
280+
struct kvm_sev_attestation_report {
281+
__u8 mnonce[16]; /* A random mnonce that will be placed in the report */
282+
283+
__u64 uaddr; /* userspace address where the report should be copied */
284+
__u32 len;
285+
};
286+
266287
References
267288
==========
268289

‎Documentation/virt/kvm/api.rst‎

Lines changed: 220 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,14 @@ memory.
960960
__u8 pad2[30];
961961
};
962962

963+
If the KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag is returned from the
964+
KVM_CAP_XEN_HVM check, it may be set in the flags field of this ioctl.
965+
This requests KVM to generate the contents of the hypercall page
966+
automatically; hypercalls will be intercepted and passed to userspace
967+
through KVM_EXIT_XEN. In this case, all of the blob size and address
968+
fields must be zero.
969+
970+
No other flags are currently valid in the struct kvm_xen_hvm_config.
963971

964972
4.29 KVM_GET_CLOCK
965973
------------------
@@ -2268,6 +2276,8 @@ registers, find a list below:
22682276
PPC KVM_REG_PPC_PSSCR 64
22692277
PPC KVM_REG_PPC_DEC_EXPIRY 64
22702278
PPC KVM_REG_PPC_PTCR 64
2279+
PPC KVM_REG_PPC_DAWR1 64
2280+
PPC KVM_REG_PPC_DAWRX1 64
22712281
PPC KVM_REG_PPC_TM_GPR0 64
22722282
...
22732283
PPC KVM_REG_PPC_TM_GPR31 64
@@ -4831,6 +4841,101 @@ into user space.
48314841
If a vCPU is in running state while this ioctl is invoked, the vCPU may
48324842
experience inconsistent filtering behavior on MSR accesses.
48334843

4844+
4.127 KVM_XEN_HVM_SET_ATTR
4845+
--------------------------
4846+
4847+
:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4848+
:Architectures: x86
4849+
:Type: vm ioctl
4850+
:Parameters: struct kvm_xen_hvm_attr
4851+
:Returns: 0 on success, < 0 on error
4852+
4853+
::
4854+
4855+
struct kvm_xen_hvm_attr {
4856+
__u16 type;
4857+
__u16 pad[3];
4858+
union {
4859+
__u8 long_mode;
4860+
__u8 vector;
4861+
struct {
4862+
__u64 gfn;
4863+
} shared_info;
4864+
__u64 pad[4];
4865+
} u;
4866+
};
4867+
4868+
type values:
4869+
4870+
KVM_XEN_ATTR_TYPE_LONG_MODE
4871+
Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This
4872+
determines the layout of the shared info pages exposed to the VM.
4873+
4874+
KVM_XEN_ATTR_TYPE_SHARED_INFO
4875+
Sets the guest physical frame number at which the Xen "shared info"
4876+
page resides. Note that although Xen places vcpu_info for the first
4877+
32 vCPUs in the shared_info page, KVM does not automatically do so
4878+
and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
4879+
explicitly even when the vcpu_info for a given vCPU resides at the
4880+
"default" location in the shared_info page. This is because KVM is
4881+
not aware of the Xen CPU id which is used as the index into the
4882+
vcpu_info[] array, so cannot know the correct default location.
4883+
4884+
KVM_XEN_ATTR_TYPE_UPCALL_VECTOR
4885+
Sets the exception vector used to deliver Xen event channel upcalls.
4886+
4887+
4.128 KVM_XEN_HVM_GET_ATTR
4888+
--------------------------
4889+
4890+
:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4891+
:Architectures: x86
4892+
:Type: vm ioctl
4893+
:Parameters: struct kvm_xen_hvm_attr
4894+
:Returns: 0 on success, < 0 on error
4895+
4896+
Allows Xen VM attributes to be read. For the structure and types,
4897+
see KVM_XEN_HVM_SET_ATTR above.
4898+
4899+
4.129 KVM_XEN_VCPU_SET_ATTR
4900+
---------------------------
4901+
4902+
:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4903+
:Architectures: x86
4904+
:Type: vcpu ioctl
4905+
:Parameters: struct kvm_xen_vcpu_attr
4906+
:Returns: 0 on success, < 0 on error
4907+
4908+
::
4909+
4910+
struct kvm_xen_vcpu_attr {
4911+
__u16 type;
4912+
__u16 pad[3];
4913+
union {
4914+
__u64 gpa;
4915+
__u64 pad[4];
4916+
} u;
4917+
};
4918+
4919+
type values:
4920+
4921+
KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
4922+
Sets the guest physical address of the vcpu_info for a given vCPU.
4923+
4924+
KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
4925+
Sets the guest physical address of an additional pvclock structure
4926+
for a given vCPU. This is typically used for guest vsyscall support.
4927+
4928+
4.130 KVM_XEN_VCPU_GET_ATTR
4929+
---------------------------
4930+
4931+
:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4932+
:Architectures: x86
4933+
:Type: vcpu ioctl
4934+
:Parameters: struct kvm_xen_vcpu_attr
4935+
:Returns: 0 on success, < 0 on error
4936+
4937+
Allows Xen vCPU attributes to be read. For the structure and types,
4938+
see KVM_XEN_VCPU_SET_ATTR above.
48344939

48354940
5. The kvm_run structure
48364941
========================
@@ -4893,9 +4998,11 @@ local APIC is not used.
48934998
__u16 flags;
48944999

48955000
More architecture-specific flags detailing state of the VCPU that may
4896-
affect the device's behavior. The only currently defined flag is
4897-
KVM_RUN_X86_SMM, which is valid on x86 machines and is set if the
4898-
VCPU is in system management mode.
5001+
affect the device's behavior. Current defined flags:
5002+
/* x86, set if the VCPU is in system management mode */
5003+
#define KVM_RUN_X86_SMM (1 << 0)
5004+
/* x86, set if bus lock detected in VM */
5005+
#define KVM_RUN_BUS_LOCK (1 << 1)
48995006
49005007
::
49015008

@@ -4996,13 +5103,18 @@ to the byte array.
49965103

49975104
.. note::
49985105

4999-
For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR,
5106+
For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN,
50005107
KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding
50015108
operations are complete (and guest state is consistent) only after userspace
50025109
has re-entered the kernel with KVM_RUN. The kernel side will first finish
5003-
incomplete operations and then check for pending signals. Userspace
5004-
can re-enter the guest with an unmasked signal pending to complete
5005-
pending operations.
5110+
incomplete operations and then check for pending signals.
5111+
5112+
The pending state of the operation is not preserved in state which is
5113+
visible to userspace, thus userspace should ensure that the operation is
5114+
completed before performing a live migration. Userspace can re-enter the
5115+
guest with an unmasked signal pending or with the immediate_exit field set
5116+
to complete pending operations without allowing any further instructions
5117+
to be executed.
50065118

50075119
::
50085120

@@ -5327,6 +5439,34 @@ wants to write. Once finished processing the event, user space must continue
53275439
vCPU execution. If the MSR write was unsuccessful, user space also sets the
53285440
"error" field to "1".
53295441

5442+
::
5443+
5444+
5445+
struct kvm_xen_exit {
5446+
#define KVM_EXIT_XEN_HCALL 1
5447+
__u32 type;
5448+
union {
5449+
struct {
5450+
__u32 longmode;
5451+
__u32 cpl;
5452+
__u64 input;
5453+
__u64 result;
5454+
__u64 params[6];
5455+
} hcall;
5456+
} u;
5457+
};
5458+
/* KVM_EXIT_XEN */
5459+
struct kvm_hyperv_exit xen;
5460+
5461+
Indicates that the VCPU exits into userspace to process some tasks
5462+
related to Xen emulation.
5463+
5464+
Valid values for 'type' are:
5465+
5466+
- KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall.
5467+
Userspace is expected to place the hypercall result into the appropriate
5468+
field before invoking KVM_RUN again.
5469+
53305470
::
53315471

53325472
/* Fix the size of the union. */
@@ -6038,6 +6178,53 @@ KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications which user space
60386178
can then handle to implement model specific MSR handling and/or user notifications
60396179
to inform a user that an MSR was not handled.
60406180

6181+
7.22 KVM_CAP_X86_BUS_LOCK_EXIT
6182+
-------------------------------
6183+
6184+
:Architectures: x86
6185+
:Target: VM
6186+
:Parameters: args[0] defines the policy used when bus locks detected in guest
6187+
:Returns: 0 on success, -EINVAL when args[0] contains invalid bits
6188+
6189+
Valid bits in args[0] are::
6190+
6191+
#define KVM_BUS_LOCK_DETECTION_OFF (1 << 0)
6192+
#define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1)
6193+
6194+
Enabling this capability on a VM provides userspace with a way to select
6195+
a policy to handle the bus locks detected in guest. Userspace can obtain
6196+
the supported modes from the result of KVM_CHECK_EXTENSION and define it
6197+
through the KVM_ENABLE_CAP.
6198+
6199+
KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
6200+
currently and mutually exclusive with each other. More bits can be added in
6201+
the future.
6202+
6203+
With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
6204+
so that no additional actions are needed. This is the default mode.
6205+
6206+
With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
6207+
in VM. KVM just exits to userspace when handling them. Userspace can enforce
6208+
its own throttling or other policy based mitigations.
6209+
6210+
This capability is aimed to address the thread that VM can exploit bus locks to
6211+
degree the performance of the whole system. Once the userspace enable this
6212+
capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
6213+
KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
6214+
the bus lock vm exit can be preempted by a higher priority VM exit, the exit
6215+
notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
6216+
KVM_RUN_BUS_LOCK flag is used to distinguish between them.
6217+
6218+
7.22 KVM_CAP_PPC_DAWR1
6219+
----------------------
6220+
6221+
:Architectures: ppc
6222+
:Parameters: none
6223+
:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
6224+
6225+
This capability can be used to check / enable 2nd DAWR feature provided
6226+
by POWER10 processor.
6227+
60416228
8. Other capabilities.
60426229
======================
60436230

@@ -6415,7 +6602,6 @@ guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
64156602
(0x40000001). Otherwise, a guest may use the paravirtual features
64166603
regardless of what has actually been exposed through the CPUID leaf.
64176604

6418-
64196605
8.29 KVM_CAP_DIRTY_LOG_RING
64206606
---------------------------
64216607

@@ -6502,3 +6688,29 @@ KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG. After enabling
65026688
KVM_CAP_DIRTY_LOG_RING with an acceptable dirty ring size, the virtual
65036689
machine will switch to ring-buffer dirty page tracking and further
65046690
KVM_GET_DIRTY_LOG or KVM_CLEAR_DIRTY_LOG ioctls will fail.
6691+
6692+
8.30 KVM_CAP_XEN_HVM
6693+
--------------------
6694+
6695+
:Architectures: x86
6696+
6697+
This capability indicates the features that Xen supports for hosting Xen
6698+
PVHVM guests. Valid flags are::
6699+
6700+
#define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR (1 << 0)
6701+
#define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL (1 << 1)
6702+
#define KVM_XEN_HVM_CONFIG_SHARED_INFO (1 << 2)
6703+
6704+
The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
6705+
ioctl is available, for the guest to set its hypercall page.
6706+
6707+
If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be
6708+
provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page
6709+
contents, to request that KVM generate hypercall page content automatically
6710+
and also enable interception of guest hypercalls with KVM_EXIT_XEN.
6711+
6712+
The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the
6713+
KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and
6714+
KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors
6715+
for event channel upcalls when the evtchn_upcall_pending field of a vcpu's
6716+
vcpu_info is set.

‎Documentation/virt/kvm/locking.rst‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ The acquisition orders for mutexes are as follows:
1616
- kvm->slots_lock is taken outside kvm->irq_lock, though acquiring
1717
them together is quite rare.
1818

19-
On x86, vcpu->mutex is taken outside kvm->arch.hyperv.hv_lock.
19+
On x86:
20+
21+
- vcpu->mutex is taken outside kvm->arch.hyperv.hv_lock
22+
23+
- kvm->arch.mmu_lock is an rwlock. kvm->arch.tdp_mmu_pages_lock is
24+
taken inside kvm->arch.mmu_lock, and cannot be taken without already
25+
holding kvm->arch.mmu_lock (typically with ``read_lock``, otherwise
26+
there's no need to take kvm->arch.tdp_mmu_pages_lock at all).
2027

2128
Everything else is a leaf: no other lock is taken inside the critical
2229
sections.

‎arch/arm64/include/asm/hyp_image.h‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef __ARM64_HYP_IMAGE_H__
88
#define __ARM64_HYP_IMAGE_H__
99

10+
#define __HYP_CONCAT(a, b) a ## b
11+
#define HYP_CONCAT(a, b) __HYP_CONCAT(a, b)
12+
1013
/*
1114
* KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_,
1215
* to separate it from the kernel proper.
@@ -21,9 +24,31 @@
2124
*/
2225
#define HYP_SECTION_NAME(NAME) .hyp##NAME
2326

27+
/* Symbol defined at the beginning of each hyp section. */
28+
#define HYP_SECTION_SYMBOL_NAME(NAME) \
29+
HYP_CONCAT(__hyp_section_, HYP_SECTION_NAME(NAME))
30+
31+
/*
32+
* Helper to generate linker script statements starting a hyp section.
33+
*
34+
* A symbol with a well-known name is defined at the first byte. This
35+
* is used as a base for hyp relocations (see gen-hyprel.c). It must
36+
* be defined inside the section so the linker of `vmlinux` cannot
37+
* separate it from the section data.
38+
*/
39+
#define BEGIN_HYP_SECTION(NAME) \
40+
HYP_SECTION_NAME(NAME) : { \
41+
HYP_SECTION_SYMBOL_NAME(NAME) = .;
42+
43+
/* Helper to generate linker script statements ending a hyp section. */
44+
#define END_HYP_SECTION \
45+
}
46+
2447
/* Defines an ELF hyp section from input section @NAME and its subsections. */
25-
#define HYP_SECTION(NAME) \
26-
HYP_SECTION_NAME(NAME) : { *(NAME NAME##.*) }
48+
#define HYP_SECTION(NAME) \
49+
BEGIN_HYP_SECTION(NAME) \
50+
*(NAME NAME##.*) \
51+
END_HYP_SECTION
2752

2853
/*
2954
* Defines a linker script alias of a kernel-proper symbol referenced by

0 commit comments

Comments
 (0)