mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM updates from Paolo Bonzini:
"Loongarch:
- Add more CPUCFG mask bits
- Improve feature detection
- Add lazy load support for FPU and binary translation (LBT) register
state
- Fix return value for memory reads from and writes to in-kernel
devices
- Add support for detecting preemption from within a guest
- Add KVM steal time test case to tools/selftests
ARM:
- Add support for FEAT_IDST, allowing ID registers that are not
implemented to be reported as a normal trap rather than as an UNDEF
exception
- Add sanitisation of the VTCR_EL2 register, fixing a number of
UXN/PXN/XN bugs in the process
- Full handling of RESx bits, instead of only RES0, and resulting in
SCTLR_EL2 being added to the list of sanitised registers
- More pKVM fixes for features that are not supposed to be exposed to
guests
- Make sure that MTE being disabled on the pKVM host doesn't give it
the ability to attack the hypervisor
- Allow pKVM's host stage-2 mappings to use the Force Write Back
version of the memory attributes by using the "pass-through'
encoding
- Fix trapping of ICC_DIR_EL1 on GICv5 hosts emulating GICv3 for the
guest
- Preliminary work for guest GICv5 support
- A bunch of debugfs fixes, removing pointless custom iterators
stored in guest data structures
- A small set of FPSIMD cleanups
- Selftest fixes addressing the incorrect alignment of page
allocation
- Other assorted low-impact fixes and spelling fixes
RISC-V:
- Fixes for issues discoverd by KVM API fuzzing in
kvm_riscv_aia_imsic_has_attr(), kvm_riscv_aia_imsic_rw_attr(), and
kvm_riscv_vcpu_aia_imsic_update()
- Allow Zalasr, Zilsd and Zclsd extensions for Guest/VM
- Transparent huge page support for hypervisor page tables
- Adjust the number of available guest irq files based on MMIO
register sizes found in the device tree or the ACPI tables
- Add RISC-V specific paging modes to KVM selftests
- Detect paging mode at runtime for selftests
s390:
- Performance improvement for vSIE (aka nested virtualization)
- Completely new memory management. s390 was a special snowflake that
enlisted help from the architecture's page table management to
build hypervisor page tables, in particular enabling sharing the
last level of page tables. This however was a lot of code (~3K
lines) in order to support KVM, and also blocked several features.
The biggest advantages is that the page size of userspace is
completely independent of the page size used by the guest:
userspace can mix normal pages, THPs and hugetlbfs as it sees fit,
and in fact transparent hugepages were not possible before. It's
also now possible to have nested guests and guests with huge pages
running on the same host
- Maintainership change for s390 vfio-pci
- Small quality of life improvement for protected guests
x86:
- Add support for giving the guest full ownership of PMU hardware
(contexted switched around the fastpath run loop) and allowing
direct access to data MSRs and PMCs (restricted by the vPMU model).
KVM still intercepts access to control registers, e.g. to enforce
event filtering and to prevent the guest from profiling sensitive
host state. This is more accurate, since it has no risk of
contention and thus dropped events, and also has significantly less
overhead.
For more information, see the commit message for merge commit
bf2c3138ae ("Merge tag 'kvm-x86-pmu-6.20' ...")
- Disallow changing the virtual CPU model if L2 is active, for all
the same reasons KVM disallows change the model after the first
KVM_RUN
- Fix a bug where KVM would incorrectly reject host accesses to PV
MSRs when running with KVM_CAP_ENFORCE_PV_FEATURE_CPUID enabled,
even if those were advertised as supported to userspace,
- Fix a bug with protected guest state (SEV-ES/SNP and TDX) VMs,
where KVM would attempt to read CR3 configuring an async #PF entry
- Fail the build if EXPORT_SYMBOL_GPL or EXPORT_SYMBOL is used in KVM
(for x86 only) to enforce usage of EXPORT_SYMBOL_FOR_KVM_INTERNAL.
Only a few exports that are intended for external usage, and those
are allowed explicitly
- When checking nested events after a vCPU is unblocked, ignore
-EBUSY instead of WARNing. Userspace can sometimes put the vCPU
into what should be an impossible state, and spurious exit to
userspace on -EBUSY does not really do anything to solve the issue
- Also throw in the towel and drop the WARN on INIT/SIPI being
blocked when vCPU is in Wait-For-SIPI, which also resulted in
playing whack-a-mole with syzkaller stuffing architecturally
impossible states into KVM
- Add support for new Intel instructions that don't require anything
beyond enumerating feature flags to userspace
- Grab SRCU when reading PDPTRs in KVM_GET_SREGS2
- Add WARNs to guard against modifying KVM's CPU caps outside of the
intended setup flow, as nested VMX in particular is sensitive to
unexpected changes in KVM's golden configuration
- Add a quirk to allow userspace to opt-in to actually suppress EOI
broadcasts when the suppression feature is enabled by the guest
(currently limited to split IRQCHIP, i.e. userspace I/O APIC).
Sadly, simply fixing KVM to honor Suppress EOI Broadcasts isn't an
option as some userspaces have come to rely on KVM's buggy behavior
(KVM advertises Supress EOI Broadcast irrespective of whether or
not userspace I/O APIC supports Directed EOIs)
- Clean up KVM's handling of marking mapped vCPU pages dirty
- Drop a pile of *ancient* sanity checks hidden behind in KVM's
unused ASSERT() macro, most of which could be trivially triggered
by the guest and/or user, and all of which were useless
- Fold "struct dest_map" into its sole user, "struct rtc_status", to
make it more obvious what the weird parameter is used for, and to
allow fropping these RTC shenanigans if CONFIG_KVM_IOAPIC=n
- Bury all of ioapic.h, i8254.h and related ioctls (including
KVM_CREATE_IRQCHIP) behind CONFIG_KVM_IOAPIC=y
- Add a regression test for recent APICv update fixes
- Handle "hardware APIC ISR", a.k.a. SVI, updates in
kvm_apic_update_apicv() to consolidate the updates, and to
co-locate SVI updates with the updates for KVM's own cache of ISR
information
- Drop a dead function declaration
- Minor cleanups
x86 (Intel):
- Rework KVM's handling of VMCS updates while L2 is active to
temporarily switch to vmcs01 instead of deferring the update until
the next nested VM-Exit.
The deferred updates approach directly contributed to several bugs,
was proving to be a maintenance burden due to the difficulty in
auditing the correctness of deferred updates, and was polluting
"struct nested_vmx" with a growing pile of booleans
- Fix an SGX bug where KVM would incorrectly try to handle EPCM page
faults, and instead always reflect them into the guest. Since KVM
doesn't shadow EPCM entries, EPCM violations cannot be due to KVM
interference and can't be resolved by KVM
- Fix a bug where KVM would register its posted interrupt wakeup
handler even if loading kvm-intel.ko ultimately failed
- Disallow access to vmcb12 fields that aren't fully supported,
mostly to avoid weirdness and complexity for FRED and other
features, where KVM wants enable VMCS shadowing for fields that
conditionally exist
- Print out the "bad" offsets and values if kvm-intel.ko refuses to
load (or refuses to online a CPU) due to a VMCS config mismatch
x86 (AMD):
- Drop a user-triggerable WARN on nested_svm_load_cr3() failure
- Add support for virtualizing ERAPS. Note, correct virtualization of
ERAPS relies on an upcoming, publicly announced change in the APM
to reduce the set of conditions where hardware (i.e. KVM) *must*
flush the RAP
- Ignore nSVM intercepts for instructions that are not supported
according to L1's virtual CPU model
- Add support for expedited writes to the fast MMIO bus, a la VMX's
fastpath for EPT Misconfig
- Don't set GIF when clearing EFER.SVME, as GIF exists independently
of SVM, and allow userspace to restore nested state with GIF=0
- Treat exit_code as an unsigned 64-bit value through all of KVM
- Add support for fetching SNP certificates from userspace
- Fix a bug where KVM would use vmcb02 instead of vmcb01 when
emulating VMLOAD or VMSAVE on behalf of L2
- Misc fixes and cleanups
x86 selftests:
- Add a regression test for TPR<=>CR8 synchronization and IRQ masking
- Overhaul selftest's MMU infrastructure to genericize stage-2 MMU
support, and extend x86's infrastructure to support EPT and NPT
(for L2 guests)
- Extend several nested VMX tests to also cover nested SVM
- Add a selftest for nested VMLOAD/VMSAVE
- Rework the nested dirty log test, originally added as a regression
test for PML where KVM logged L2 GPAs instead of L1 GPAs, to
improve test coverage and to hopefully make the test easier to
understand and maintain
guest_memfd:
- Remove kvm_gmem_populate()'s preparation tracking and half-baked
hugepage handling. SEV/SNP was the only user of the tracking and it
can do it via the RMP
- Retroactively document and enforce (for SNP) that
KVM_SEV_SNP_LAUNCH_UPDATE and KVM_TDX_INIT_MEM_REGION require the
source page to be 4KiB aligned, to avoid non-trivial complexity for
something that no known VMM seems to be doing and to avoid an API
special case for in-place conversion, which simply can't support
unaligned sources
- When populating guest_memfd memory, GUP the source page in common
code and pass the refcounted page to the vendor callback, instead
of letting vendor code do the heavy lifting. Doing so avoids a
looming deadlock bug with in-place due an AB-BA conflict betwee
mmap_lock and guest_memfd's filemap invalidate lock
Generic:
- Fix a bug where KVM would ignore the vCPU's selected address space
when creating a vCPU-specific mapping of guest memory. Actually
this bug could not be hit even on x86, the only architecture with
multiple address spaces, but it's a bug nevertheless"
* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (267 commits)
KVM: s390: Increase permitted SE header size to 1 MiB
MAINTAINERS: Replace backup for s390 vfio-pci
KVM: s390: vsie: Fix race in acquire_gmap_shadow()
KVM: s390: vsie: Fix race in walk_guest_tables()
KVM: s390: Use guest address to mark guest page dirty
irqchip/riscv-imsic: Adjust the number of available guest irq files
RISC-V: KVM: Transparent huge page support
RISC-V: KVM: selftests: Add Zalasr extensions to get-reg-list test
RISC-V: KVM: Allow Zalasr extensions for Guest/VM
KVM: riscv: selftests: Add riscv vm satp modes
KVM: riscv: selftests: add Zilsd and Zclsd extension to get-reg-list test
riscv: KVM: allow Zilsd and Zclsd extensions for Guest/VM
RISC-V: KVM: Skip IMSIC update if vCPU IMSIC state is not initialized
RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_has_attr()
RISC-V: KVM: Remove unnecessary 'ret' assignment
KVM: s390: Add explicit padding to struct kvm_s390_keyop
KVM: LoongArch: selftests: Add steal time test case
LoongArch: KVM: Add paravirt vcpu_is_preempted() support in guest side
LoongArch: KVM: Add paravirt preempt feature in hypervisor side
...
This commit is contained in:
@@ -3100,6 +3100,26 @@ Kernel parameters
|
||||
|
||||
Default is Y (on).
|
||||
|
||||
kvm.enable_pmu=[KVM,X86]
|
||||
If enabled, KVM will virtualize PMU functionality based
|
||||
on the virtual CPU model defined by userspace. This
|
||||
can be overridden on a per-VM basis via
|
||||
KVM_CAP_PMU_CAPABILITY.
|
||||
|
||||
If disabled, KVM will not virtualize PMU functionality,
|
||||
e.g. MSRs, PMCs, PMIs, etc., even if userspace defines
|
||||
a virtual CPU model that contains PMU assets.
|
||||
|
||||
Note, KVM's vPMU support implicitly requires running
|
||||
with an in-kernel local APIC, e.g. to deliver PMIs to
|
||||
the guest. Running without an in-kernel local APIC is
|
||||
not supported, though KVM will allow such a combination
|
||||
(with severely degraded functionality).
|
||||
|
||||
See also enable_mediated_pmu.
|
||||
|
||||
Default is Y (on).
|
||||
|
||||
kvm.enable_virt_at_load=[KVM,ARM64,LOONGARCH,MIPS,RISCV,X86]
|
||||
If enabled, KVM will enable virtualization in hardware
|
||||
when KVM is loaded, and disable virtualization when KVM
|
||||
@@ -3146,6 +3166,35 @@ Kernel parameters
|
||||
If the value is 0 (the default), KVM will pick a period based
|
||||
on the ratio, such that a page is zapped after 1 hour on average.
|
||||
|
||||
kvm-{amd,intel}.enable_mediated_pmu=[KVM,AMD,INTEL]
|
||||
If enabled, KVM will provide a mediated virtual PMU,
|
||||
instead of the default perf-based virtual PMU (if
|
||||
kvm.enable_pmu is true and PMU is enumerated via the
|
||||
virtual CPU model).
|
||||
|
||||
With a perf-based vPMU, KVM operates as a user of perf,
|
||||
i.e. emulates guest PMU counters using perf events.
|
||||
KVM-created perf events are managed by perf as regular
|
||||
(guest-only) events, e.g. are scheduled in/out, contend
|
||||
for hardware resources, etc. Using a perf-based vPMU
|
||||
allows guest and host usage of the PMU to co-exist, but
|
||||
incurs non-trivial overhead and can result in silently
|
||||
dropped guest events (due to resource contention).
|
||||
|
||||
With a mediated vPMU, hardware PMU state is context
|
||||
switched around the world switch to/from the guest.
|
||||
KVM mediates which events the guest can utilize, but
|
||||
gives the guest direct access to all other PMU assets
|
||||
when possible (KVM may intercept some accesses if the
|
||||
virtual CPU model provides a subset of hardware PMU
|
||||
functionality). Using a mediated vPMU significantly
|
||||
reduces PMU virtualization overhead and eliminates lost
|
||||
guest events, but is mutually exclusive with using perf
|
||||
to profile KVM guests and adds latency to most VM-Exits
|
||||
(to context switch PMU state).
|
||||
|
||||
Default is N (off).
|
||||
|
||||
kvm-amd.nested= [KVM,AMD] Control nested virtualization feature in
|
||||
KVM/SVM. Default is 1 (enabled).
|
||||
|
||||
|
||||
@@ -6518,6 +6518,40 @@ the capability to be present.
|
||||
|
||||
`flags` must currently be zero.
|
||||
|
||||
4.144 KVM_S390_KEYOP
|
||||
--------------------
|
||||
|
||||
:Capability: KVM_CAP_S390_KEYOP
|
||||
:Architectures: s390
|
||||
:Type: vm ioctl
|
||||
:Parameters: struct kvm_s390_keyop (in/out)
|
||||
:Returns: 0 in case of success, < 0 on error
|
||||
|
||||
The specified key operation is performed on the given guest address. The
|
||||
previous storage key (or the relevant part thereof) will be returned in
|
||||
`key`.
|
||||
|
||||
::
|
||||
|
||||
struct kvm_s390_keyop {
|
||||
__u64 guest_addr;
|
||||
__u8 key;
|
||||
__u8 operation;
|
||||
};
|
||||
|
||||
Currently supported values for ``operation``:
|
||||
|
||||
KVM_S390_KEYOP_ISKE
|
||||
Returns the storage key for the guest address ``guest_addr`` in ``key``.
|
||||
|
||||
KVM_S390_KEYOP_RRBE
|
||||
Resets the reference bit for the guest address ``guest_addr``, returning the
|
||||
R and C bits of the old storage key in ``key``; the remaining fields of
|
||||
the storage key will be set to 0.
|
||||
|
||||
KVM_S390_KEYOP_SSKE
|
||||
Sets the storage key for the guest address ``guest_addr`` to the key
|
||||
specified in ``key``, returning the previous value in ``key``.
|
||||
|
||||
.. _kvm_run:
|
||||
|
||||
@@ -7382,6 +7416,50 @@ Please note that the kernel is allowed to use the kvm_run structure as the
|
||||
primary storage for certain register types. Therefore, the kernel may use the
|
||||
values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
|
||||
|
||||
::
|
||||
|
||||
/* KVM_EXIT_SNP_REQ_CERTS */
|
||||
struct kvm_exit_snp_req_certs {
|
||||
__u64 gpa;
|
||||
__u64 npages;
|
||||
__u64 ret;
|
||||
};
|
||||
|
||||
KVM_EXIT_SNP_REQ_CERTS indicates an SEV-SNP guest with certificate-fetching
|
||||
enabled (see KVM_SEV_SNP_ENABLE_REQ_CERTS) has generated an Extended Guest
|
||||
Request NAE #VMGEXIT (SNP_GUEST_REQUEST) with message type MSG_REPORT_REQ,
|
||||
i.e. has requested an attestation report from firmware, and would like the
|
||||
certificate data corresponding to the attestation report signature to be
|
||||
provided by the hypervisor as part of the request.
|
||||
|
||||
To allow for userspace to provide the certificate, the 'gpa' and 'npages'
|
||||
are forwarded verbatim from the guest request (the RAX and RBX GHCB fields
|
||||
respectively). 'ret' is not an "output" from KVM, and is always '0' on
|
||||
exit. KVM verifies the 'gpa' is 4KiB aligned prior to exiting to userspace,
|
||||
but otherwise the information from the guest isn't validated.
|
||||
|
||||
Upon the next KVM_RUN, e.g. after userspace has serviced the request (or not),
|
||||
KVM will complete the #VMGEXIT, using the 'ret' field to determine whether to
|
||||
signal success or failure to the guest, and on failure, what reason code will
|
||||
be communicated via SW_EXITINFO2. If 'ret' is set to an unsupported value (see
|
||||
the table below), KVM_RUN will fail with -EINVAL. For a 'ret' of 'ENOSPC', KVM
|
||||
also consumes the 'npages' field, i.e. userspace can use the field to inform
|
||||
the guest of the number of pages needed to hold all the certificate data.
|
||||
|
||||
The supported 'ret' values and their respective SW_EXITINFO2 encodings:
|
||||
|
||||
====== =============================================================
|
||||
0 0x0, i.e. success. KVM will emit an SNP_GUEST_REQUEST command
|
||||
to SNP firmware.
|
||||
ENOSPC 0x0000000100000000, i.e. not enough guest pages to hold the
|
||||
certificate table and certificate data. KVM will also set the
|
||||
RBX field in the GHBC to 'npages'.
|
||||
EAGAIN 0x0000000200000000, i.e. the host is busy and the guest should
|
||||
retry the request.
|
||||
EIO 0xffffffff00000000, for all other errors (this return code is
|
||||
a KVM-defined hypervisor value, as allowed by the GHCB)
|
||||
====== =============================================================
|
||||
|
||||
|
||||
.. _cap_enable:
|
||||
|
||||
@@ -7864,8 +7942,10 @@ Will return -EBUSY if a VCPU has already been created.
|
||||
|
||||
Valid feature flags in args[0] are::
|
||||
|
||||
#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
|
||||
#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
|
||||
#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
|
||||
#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
|
||||
#define KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST (1ULL << 2)
|
||||
#define KVM_X2APIC_DISABLE_SUPPRESS_EOI_BROADCAST (1ULL << 3)
|
||||
|
||||
Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
|
||||
KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
|
||||
@@ -7878,6 +7958,28 @@ as a broadcast even in x2APIC mode in order to support physical x2APIC
|
||||
without interrupt remapping. This is undesirable in logical mode,
|
||||
where 0xff represents CPUs 0-7 in cluster 0.
|
||||
|
||||
Setting KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST instructs KVM to enable
|
||||
Suppress EOI Broadcasts. KVM will advertise support for Suppress EOI
|
||||
Broadcast to the guest and suppress LAPIC EOI broadcasts when the guest
|
||||
sets the Suppress EOI Broadcast bit in the SPIV register. This flag is
|
||||
supported only when using a split IRQCHIP.
|
||||
|
||||
Setting KVM_X2APIC_DISABLE_SUPPRESS_EOI_BROADCAST disables support for
|
||||
Suppress EOI Broadcasts entirely, i.e. instructs KVM to NOT advertise
|
||||
support to the guest.
|
||||
|
||||
Modern VMMs should either enable KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST
|
||||
or KVM_X2APIC_DISABLE_SUPPRESS_EOI_BROADCAST. If not, legacy quirky
|
||||
behavior will be used by KVM: in split IRQCHIP mode, KVM will advertise
|
||||
support for Suppress EOI Broadcasts but not actually suppress EOI
|
||||
broadcasts; for in-kernel IRQCHIP mode, KVM will not advertise support for
|
||||
Suppress EOI Broadcasts.
|
||||
|
||||
Setting both KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST and
|
||||
KVM_X2APIC_DISABLE_SUPPRESS_EOI_BROADCAST will fail with an EINVAL error,
|
||||
as will setting KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST without a split
|
||||
IRCHIP.
|
||||
|
||||
7.8 KVM_CAP_S390_USER_INSTR0
|
||||
----------------------------
|
||||
|
||||
@@ -9316,6 +9418,14 @@ The presence of this capability indicates that KVM_RUN will update the
|
||||
KVM_RUN_X86_GUEST_MODE bit in kvm_run.flags to indicate whether the
|
||||
vCPU was executing nested guest code when it exited.
|
||||
|
||||
8.46 KVM_CAP_S390_KEYOP
|
||||
-----------------------
|
||||
|
||||
:Architectures: s390
|
||||
|
||||
The presence of this capability indicates that the KVM_S390_KEYOP ioctl is
|
||||
available.
|
||||
|
||||
KVM exits with the register state of either the L1 or L2 guest
|
||||
depending on which executed at the time of an exit. Userspace must
|
||||
take care to differentiate between these cases.
|
||||
|
||||
@@ -523,7 +523,7 @@ Returns: 0 on success, < 0 on error, -EAGAIN if caller should retry
|
||||
|
||||
struct kvm_sev_snp_launch_update {
|
||||
__u64 gfn_start; /* Guest page number to load/encrypt data into. */
|
||||
__u64 uaddr; /* Userspace address of data to be loaded/encrypted. */
|
||||
__u64 uaddr; /* 4k-aligned address of data to be loaded/encrypted. */
|
||||
__u64 len; /* 4k-aligned length in bytes to copy into guest memory.*/
|
||||
__u8 type; /* The type of the guest pages being initialized. */
|
||||
__u8 pad0;
|
||||
@@ -572,6 +572,52 @@ Returns: 0 on success, -negative on error
|
||||
See SNP_LAUNCH_FINISH in the SEV-SNP specification [snp-fw-abi]_ for further
|
||||
details on the input parameters in ``struct kvm_sev_snp_launch_finish``.
|
||||
|
||||
21. KVM_SEV_SNP_ENABLE_REQ_CERTS
|
||||
--------------------------------
|
||||
|
||||
The KVM_SEV_SNP_ENABLE_REQ_CERTS command will configure KVM to exit to
|
||||
userspace with a ``KVM_EXIT_SNP_REQ_CERTS`` exit type as part of handling
|
||||
a guest attestation report, which will to allow userspace to provide a
|
||||
certificate corresponding to the endorsement key used by firmware to sign
|
||||
that attestation report.
|
||||
|
||||
Returns: 0 on success, -negative on error
|
||||
|
||||
NOTE: The endorsement key used by firmware may change as a result of
|
||||
management activities like updating SEV-SNP firmware or loading new
|
||||
endorsement keys, so some care should be taken to keep the returned
|
||||
certificate data in sync with the actual endorsement key in use by
|
||||
firmware at the time the attestation request is sent to SNP firmware. The
|
||||
recommended scheme to do this is to use file locking (e.g. via fcntl()'s
|
||||
F_OFD_SETLK) in the following manner:
|
||||
|
||||
- Prior to obtaining/providing certificate data as part of servicing an
|
||||
exit type of ``KVM_EXIT_SNP_REQ_CERTS``, the VMM should obtain a
|
||||
shared/read or exclusive/write lock on the certificate blob file before
|
||||
reading it and returning it to KVM, and continue to hold the lock until
|
||||
the attestation request is actually sent to firmware. To facilitate
|
||||
this, the VMM can set the ``immediate_exit`` flag of kvm_run just after
|
||||
supplying the certificate data, and just before resuming the vCPU.
|
||||
This will ensure the vCPU will exit again to userspace with ``-EINTR``
|
||||
after it finishes fetching the attestation request from firmware, at
|
||||
which point the VMM can safely drop the file lock.
|
||||
|
||||
- Tools/libraries that perform updates to SNP firmware TCB values or
|
||||
endorsement keys (e.g. via /dev/sev interfaces such as ``SNP_COMMIT``,
|
||||
``SNP_SET_CONFIG``, or ``SNP_VLEK_LOAD``, see
|
||||
Documentation/virt/coco/sev-guest.rst for more details) in such a way
|
||||
that the certificate blob needs to be updated, should similarly take an
|
||||
exclusive lock on the certificate blob for the duration of any updates
|
||||
to endorsement keys or the certificate blob contents to ensure that
|
||||
VMMs using the above scheme will not return certificate blob data that
|
||||
is out of sync with the endorsement key used by firmware at the time
|
||||
the attestation request is actually issued.
|
||||
|
||||
This scheme is recommended so that tools can use a fairly generic/natural
|
||||
approach to synchronizing firmware/certificate updates via file-locking,
|
||||
which should make it easier to maintain interoperability across
|
||||
tools/VMMs/vendors.
|
||||
|
||||
Device attribute API
|
||||
====================
|
||||
|
||||
@@ -579,11 +625,15 @@ Attributes of the SEV implementation can be retrieved through the
|
||||
``KVM_HAS_DEVICE_ATTR`` and ``KVM_GET_DEVICE_ATTR`` ioctls on the ``/dev/kvm``
|
||||
device node, using group ``KVM_X86_GRP_SEV``.
|
||||
|
||||
Currently only one attribute is implemented:
|
||||
The following attributes are currently implemented:
|
||||
|
||||
* ``KVM_X86_SEV_VMSA_FEATURES``: return the set of all bits that
|
||||
are accepted in the ``vmsa_features`` of ``KVM_SEV_INIT2``.
|
||||
|
||||
* ``KVM_X86_SEV_SNP_REQ_CERTS``: return a value of 1 if the kernel supports the
|
||||
``KVM_EXIT_SNP_REQ_CERTS`` exit, which allows for fetching endorsement key
|
||||
certificates from userspace for each SNP attestation request the guest issues.
|
||||
|
||||
Firmware Management
|
||||
===================
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ KVM_TDX_INIT_MEM_REGION
|
||||
:Returns: 0 on success, <0 on error
|
||||
|
||||
Initialize @nr_pages TDX guest private memory starting from @gpa with userspace
|
||||
provided data from @source_addr.
|
||||
provided data from @source_addr. @source_addr must be PAGE_SIZE-aligned.
|
||||
|
||||
Note, before calling this sub command, memory attribute of the range
|
||||
[gpa, gpa + nr_pages] needs to be private. Userspace can use
|
||||
|
||||
+2
-3
@@ -14012,14 +14012,12 @@ L: kvm@vger.kernel.org
|
||||
S: Supported
|
||||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git
|
||||
F: Documentation/virt/kvm/s390*
|
||||
F: arch/s390/include/asm/gmap.h
|
||||
F: arch/s390/include/asm/gmap_helpers.h
|
||||
F: arch/s390/include/asm/kvm*
|
||||
F: arch/s390/include/uapi/asm/kvm*
|
||||
F: arch/s390/include/uapi/asm/uvdevice.h
|
||||
F: arch/s390/kernel/uv.c
|
||||
F: arch/s390/kvm/
|
||||
F: arch/s390/mm/gmap.c
|
||||
F: arch/s390/mm/gmap_helpers.c
|
||||
F: drivers/s390/char/uvdevice.c
|
||||
F: tools/testing/selftests/drivers/s390x/uvdevice/
|
||||
@@ -23300,7 +23298,8 @@ F: include/uapi/linux/vfio_ccw.h
|
||||
|
||||
S390 VFIO-PCI DRIVER
|
||||
M: Matthew Rosato <mjrosato@linux.ibm.com>
|
||||
M: Eric Farman <farman@linux.ibm.com>
|
||||
M: Farhan Ali <alifm@linux.ibm.com>
|
||||
R: Eric Farman <farman@linux.ibm.com>
|
||||
L: linux-s390@vger.kernel.org
|
||||
L: kvm@vger.kernel.org
|
||||
S: Supported
|
||||
|
||||
@@ -235,7 +235,6 @@
|
||||
ICH_HFGRTR_EL2_ICC_ICSR_EL1 | \
|
||||
ICH_HFGRTR_EL2_ICC_PCR_EL1 | \
|
||||
ICH_HFGRTR_EL2_ICC_HPPIR_EL1 | \
|
||||
ICH_HFGRTR_EL2_ICC_HAPR_EL1 | \
|
||||
ICH_HFGRTR_EL2_ICC_CR0_EL1 | \
|
||||
ICH_HFGRTR_EL2_ICC_IDRn_EL1 | \
|
||||
ICH_HFGRTR_EL2_ICC_APR_EL1)
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
HCR_BSU_IS | HCR_FB | HCR_TACR | \
|
||||
HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
|
||||
HCR_FMO | HCR_IMO | HCR_PTW | HCR_TID3 | HCR_TID1)
|
||||
#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA)
|
||||
#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK)
|
||||
#define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
|
||||
#define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H | HCR_AMO | HCR_IMO | HCR_FMO)
|
||||
|
||||
@@ -124,37 +124,7 @@
|
||||
#define TCR_EL2_MASK (TCR_EL2_TG0_MASK | TCR_EL2_SH0_MASK | \
|
||||
TCR_EL2_ORGN0_MASK | TCR_EL2_IRGN0_MASK)
|
||||
|
||||
/* VTCR_EL2 Registers bits */
|
||||
#define VTCR_EL2_DS TCR_EL2_DS
|
||||
#define VTCR_EL2_RES1 (1U << 31)
|
||||
#define VTCR_EL2_HD (1 << 22)
|
||||
#define VTCR_EL2_HA (1 << 21)
|
||||
#define VTCR_EL2_PS_SHIFT TCR_EL2_PS_SHIFT
|
||||
#define VTCR_EL2_PS_MASK TCR_EL2_PS_MASK
|
||||
#define VTCR_EL2_TG0_MASK TCR_TG0_MASK
|
||||
#define VTCR_EL2_TG0_4K TCR_TG0_4K
|
||||
#define VTCR_EL2_TG0_16K TCR_TG0_16K
|
||||
#define VTCR_EL2_TG0_64K TCR_TG0_64K
|
||||
#define VTCR_EL2_SH0_MASK TCR_SH0_MASK
|
||||
#define VTCR_EL2_SH0_INNER TCR_SH0_INNER
|
||||
#define VTCR_EL2_ORGN0_MASK TCR_ORGN0_MASK
|
||||
#define VTCR_EL2_ORGN0_WBWA TCR_ORGN0_WBWA
|
||||
#define VTCR_EL2_IRGN0_MASK TCR_IRGN0_MASK
|
||||
#define VTCR_EL2_IRGN0_WBWA TCR_IRGN0_WBWA
|
||||
#define VTCR_EL2_SL0_SHIFT 6
|
||||
#define VTCR_EL2_SL0_MASK (3 << VTCR_EL2_SL0_SHIFT)
|
||||
#define VTCR_EL2_T0SZ_MASK 0x3f
|
||||
#define VTCR_EL2_VS_SHIFT 19
|
||||
#define VTCR_EL2_VS_8BIT (0 << VTCR_EL2_VS_SHIFT)
|
||||
#define VTCR_EL2_VS_16BIT (1 << VTCR_EL2_VS_SHIFT)
|
||||
|
||||
#define VTCR_EL2_T0SZ(x) TCR_T0SZ(x)
|
||||
|
||||
/*
|
||||
* We configure the Stage-2 page tables to always restrict the IPA space to be
|
||||
* 40 bits wide (T0SZ = 24). Systems with a PARange smaller than 40 bits are
|
||||
* not known to exist and will break with this configuration.
|
||||
*
|
||||
* The VTCR_EL2 is configured per VM and is initialised in kvm_init_stage2_mmu.
|
||||
*
|
||||
* Note that when using 4K pages, we concatenate two first level page tables
|
||||
@@ -162,9 +132,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define VTCR_EL2_COMMON_BITS (VTCR_EL2_SH0_INNER | VTCR_EL2_ORGN0_WBWA | \
|
||||
VTCR_EL2_IRGN0_WBWA | VTCR_EL2_RES1)
|
||||
|
||||
/*
|
||||
* VTCR_EL2:SL0 indicates the entry level for Stage2 translation.
|
||||
* Interestingly, it depends on the page size.
|
||||
@@ -196,30 +163,35 @@
|
||||
*/
|
||||
#ifdef CONFIG_ARM64_64K_PAGES
|
||||
|
||||
#define VTCR_EL2_TGRAN VTCR_EL2_TG0_64K
|
||||
#define VTCR_EL2_TGRAN 64K
|
||||
#define VTCR_EL2_TGRAN_SL0_BASE 3UL
|
||||
|
||||
#elif defined(CONFIG_ARM64_16K_PAGES)
|
||||
|
||||
#define VTCR_EL2_TGRAN VTCR_EL2_TG0_16K
|
||||
#define VTCR_EL2_TGRAN 16K
|
||||
#define VTCR_EL2_TGRAN_SL0_BASE 3UL
|
||||
|
||||
#else /* 4K */
|
||||
|
||||
#define VTCR_EL2_TGRAN VTCR_EL2_TG0_4K
|
||||
#define VTCR_EL2_TGRAN 4K
|
||||
#define VTCR_EL2_TGRAN_SL0_BASE 2UL
|
||||
|
||||
#endif
|
||||
|
||||
#define VTCR_EL2_LVLS_TO_SL0(levels) \
|
||||
((VTCR_EL2_TGRAN_SL0_BASE - (4 - (levels))) << VTCR_EL2_SL0_SHIFT)
|
||||
FIELD_PREP(VTCR_EL2_SL0, (VTCR_EL2_TGRAN_SL0_BASE - (4 - (levels))))
|
||||
#define VTCR_EL2_SL0_TO_LVLS(sl0) \
|
||||
((sl0) + 4 - VTCR_EL2_TGRAN_SL0_BASE)
|
||||
#define VTCR_EL2_LVLS(vtcr) \
|
||||
VTCR_EL2_SL0_TO_LVLS(((vtcr) & VTCR_EL2_SL0_MASK) >> VTCR_EL2_SL0_SHIFT)
|
||||
VTCR_EL2_SL0_TO_LVLS(FIELD_GET(VTCR_EL2_SL0, (vtcr)))
|
||||
|
||||
#define VTCR_EL2_FLAGS (VTCR_EL2_COMMON_BITS | VTCR_EL2_TGRAN)
|
||||
#define VTCR_EL2_IPA(vtcr) (64 - ((vtcr) & VTCR_EL2_T0SZ_MASK))
|
||||
#define VTCR_EL2_FLAGS (SYS_FIELD_PREP_ENUM(VTCR_EL2, SH0, INNER) | \
|
||||
SYS_FIELD_PREP_ENUM(VTCR_EL2, ORGN0, WBWA) | \
|
||||
SYS_FIELD_PREP_ENUM(VTCR_EL2, IRGN0, WBWA) | \
|
||||
SYS_FIELD_PREP_ENUM(VTCR_EL2, TG0, VTCR_EL2_TGRAN) | \
|
||||
VTCR_EL2_RES1)
|
||||
|
||||
#define VTCR_EL2_IPA(vtcr) (64 - FIELD_GET(VTCR_EL2_T0SZ, (vtcr)))
|
||||
|
||||
/*
|
||||
* ARM VMSAv8-64 defines an algorithm for finding the translation table
|
||||
@@ -344,6 +316,8 @@
|
||||
#define PAR_TO_HPFAR(par) \
|
||||
(((par) & GENMASK_ULL(52 - 1, 12)) >> 8)
|
||||
|
||||
#define FAR_TO_FIPA_OFFSET(far) ((far) & GENMASK_ULL(11, 0))
|
||||
|
||||
#define ECN(x) { ESR_ELx_EC_##x, #x }
|
||||
|
||||
#define kvm_arm_exception_class \
|
||||
|
||||
@@ -300,8 +300,6 @@ void kvm_get_kimage_voffset(struct alt_instr *alt,
|
||||
__le32 *origptr, __le32 *updptr, int nr_inst);
|
||||
void kvm_compute_final_ctr_el0(struct alt_instr *alt,
|
||||
__le32 *origptr, __le32 *updptr, int nr_inst);
|
||||
void kvm_pan_patch_el2_entry(struct alt_instr *alt,
|
||||
__le32 *origptr, __le32 *updptr, int nr_inst);
|
||||
void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, u64 elr_virt,
|
||||
u64 elr_phys, u64 par, uintptr_t vcpu, u64 far, u64 hpfar);
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
|
||||
void kvm_skip_instr32(struct kvm_vcpu *vcpu);
|
||||
|
||||
void kvm_inject_undefined(struct kvm_vcpu *vcpu);
|
||||
void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
|
||||
int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
|
||||
int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
|
||||
int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
|
||||
|
||||
@@ -201,7 +201,7 @@ struct kvm_s2_mmu {
|
||||
* host to parse the guest S2.
|
||||
* This either contains:
|
||||
* - the virtual VTTBR programmed by the guest hypervisor with
|
||||
* CnP cleared
|
||||
* CnP cleared
|
||||
* - The value 1 (VMID=0, BADDR=0, CnP=1) if invalid
|
||||
*
|
||||
* We also cache the full VTCR which gets used for TLB invalidation,
|
||||
@@ -373,9 +373,6 @@ struct kvm_arch {
|
||||
/* Maximum number of counters for the guest */
|
||||
u8 nr_pmu_counters;
|
||||
|
||||
/* Iterator for idreg debugfs */
|
||||
u8 idreg_debugfs_iter;
|
||||
|
||||
/* Hypercall features firmware registers' descriptor */
|
||||
struct kvm_smccc_features smccc_feat;
|
||||
struct maple_tree smccc_filter;
|
||||
@@ -495,7 +492,6 @@ enum vcpu_sysreg {
|
||||
DBGVCR32_EL2, /* Debug Vector Catch Register */
|
||||
|
||||
/* EL2 registers */
|
||||
SCTLR_EL2, /* System Control Register (EL2) */
|
||||
ACTLR_EL2, /* Auxiliary Control Register (EL2) */
|
||||
CPTR_EL2, /* Architectural Feature Trap Register (EL2) */
|
||||
HACR_EL2, /* Hypervisor Auxiliary Control Register */
|
||||
@@ -526,6 +522,7 @@ enum vcpu_sysreg {
|
||||
|
||||
/* Anything from this can be RES0/RES1 sanitised */
|
||||
MARKER(__SANITISED_REG_START__),
|
||||
SCTLR_EL2, /* System Control Register (EL2) */
|
||||
TCR2_EL2, /* Extended Translation Control Register (EL2) */
|
||||
SCTLR2_EL2, /* System Control Register 2 (EL2) */
|
||||
MDCR_EL2, /* Monitor Debug Configuration Register (EL2) */
|
||||
@@ -626,18 +623,45 @@ enum vcpu_sysreg {
|
||||
NR_SYS_REGS /* Nothing after this line! */
|
||||
};
|
||||
|
||||
struct kvm_sysreg_masks {
|
||||
struct {
|
||||
u64 res0;
|
||||
u64 res1;
|
||||
} mask[NR_SYS_REGS - __SANITISED_REG_START__];
|
||||
struct resx {
|
||||
u64 res0;
|
||||
u64 res1;
|
||||
};
|
||||
|
||||
struct kvm_sysreg_masks {
|
||||
struct resx mask[NR_SYS_REGS - __SANITISED_REG_START__];
|
||||
};
|
||||
|
||||
static inline struct resx __kvm_get_sysreg_resx(struct kvm_arch *arch,
|
||||
enum vcpu_sysreg sr)
|
||||
{
|
||||
struct kvm_sysreg_masks *masks;
|
||||
|
||||
masks = arch->sysreg_masks;
|
||||
if (likely(masks &&
|
||||
sr >= __SANITISED_REG_START__ && sr < NR_SYS_REGS))
|
||||
return masks->mask[sr - __SANITISED_REG_START__];
|
||||
|
||||
return (struct resx){};
|
||||
}
|
||||
|
||||
#define kvm_get_sysreg_resx(k, sr) __kvm_get_sysreg_resx(&(k)->arch, (sr))
|
||||
|
||||
static inline void __kvm_set_sysreg_resx(struct kvm_arch *arch,
|
||||
enum vcpu_sysreg sr, struct resx resx)
|
||||
{
|
||||
arch->sysreg_masks->mask[sr - __SANITISED_REG_START__] = resx;
|
||||
}
|
||||
|
||||
#define kvm_set_sysreg_resx(k, sr, resx) \
|
||||
__kvm_set_sysreg_resx(&(k)->arch, (sr), (resx))
|
||||
|
||||
struct fgt_masks {
|
||||
const char *str;
|
||||
u64 mask;
|
||||
u64 nmask;
|
||||
u64 res0;
|
||||
u64 res1;
|
||||
};
|
||||
|
||||
extern struct fgt_masks hfgrtr_masks;
|
||||
@@ -710,11 +734,11 @@ struct cpu_sve_state {
|
||||
struct kvm_host_data {
|
||||
#define KVM_HOST_DATA_FLAG_HAS_SPE 0
|
||||
#define KVM_HOST_DATA_FLAG_HAS_TRBE 1
|
||||
#define KVM_HOST_DATA_FLAG_TRBE_ENABLED 4
|
||||
#define KVM_HOST_DATA_FLAG_EL1_TRACING_CONFIGURED 5
|
||||
#define KVM_HOST_DATA_FLAG_VCPU_IN_HYP_CONTEXT 6
|
||||
#define KVM_HOST_DATA_FLAG_L1_VNCR_MAPPED 7
|
||||
#define KVM_HOST_DATA_FLAG_HAS_BRBE 8
|
||||
#define KVM_HOST_DATA_FLAG_TRBE_ENABLED 2
|
||||
#define KVM_HOST_DATA_FLAG_EL1_TRACING_CONFIGURED 3
|
||||
#define KVM_HOST_DATA_FLAG_VCPU_IN_HYP_CONTEXT 4
|
||||
#define KVM_HOST_DATA_FLAG_L1_VNCR_MAPPED 5
|
||||
#define KVM_HOST_DATA_FLAG_HAS_BRBE 6
|
||||
unsigned long flags;
|
||||
|
||||
struct kvm_cpu_context host_ctxt;
|
||||
@@ -1606,7 +1630,7 @@ static inline bool kvm_arch_has_irq_bypass(void)
|
||||
}
|
||||
|
||||
void compute_fgu(struct kvm *kvm, enum fgt_group_id fgt);
|
||||
void get_reg_fixed_bits(struct kvm *kvm, enum vcpu_sysreg reg, u64 *res0, u64 *res1);
|
||||
struct resx get_reg_fixed_bits(struct kvm *kvm, enum vcpu_sysreg reg);
|
||||
void check_feature_map(void);
|
||||
void kvm_vcpu_load_fgt(struct kvm_vcpu *vcpu);
|
||||
|
||||
@@ -1655,4 +1679,6 @@ static __always_inline enum fgt_group_id __fgt_reg_to_group_id(enum vcpu_sysreg
|
||||
p; \
|
||||
})
|
||||
|
||||
long kvm_get_cap_for_kvm_ioctl(unsigned int ioctl, long *ext);
|
||||
|
||||
#endif /* __ARM64_KVM_HOST_H__ */
|
||||
|
||||
@@ -103,6 +103,7 @@ alternative_cb_end
|
||||
void kvm_update_va_mask(struct alt_instr *alt,
|
||||
__le32 *origptr, __le32 *updptr, int nr_inst);
|
||||
void kvm_compute_layout(void);
|
||||
u32 kvm_hyp_va_bits(void);
|
||||
void kvm_apply_hyp_relocations(void);
|
||||
|
||||
#define __hyp_pa(x) (((phys_addr_t)(x)) + hyp_physvirt_offset)
|
||||
@@ -185,7 +186,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu);
|
||||
|
||||
phys_addr_t kvm_mmu_get_httbr(void);
|
||||
phys_addr_t kvm_get_idmap_vector(void);
|
||||
int __init kvm_mmu_init(u32 *hyp_va_bits);
|
||||
int __init kvm_mmu_init(u32 hyp_va_bits);
|
||||
|
||||
static inline void *__kvm_vector_slot2addr(void *base,
|
||||
enum arm64_hyp_spectre_vector slot)
|
||||
|
||||
@@ -87,15 +87,9 @@ typedef u64 kvm_pte_t;
|
||||
|
||||
#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55)
|
||||
|
||||
#define __KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54)
|
||||
#define __KVM_PTE_LEAF_ATTR_HI_S1_UXN BIT(54)
|
||||
#define __KVM_PTE_LEAF_ATTR_HI_S1_PXN BIT(53)
|
||||
|
||||
#define KVM_PTE_LEAF_ATTR_HI_S1_XN \
|
||||
({ cpus_have_final_cap(ARM64_KVM_HVHE) ? \
|
||||
(__KVM_PTE_LEAF_ATTR_HI_S1_UXN | \
|
||||
__KVM_PTE_LEAF_ATTR_HI_S1_PXN) : \
|
||||
__KVM_PTE_LEAF_ATTR_HI_S1_XN; })
|
||||
#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54)
|
||||
#define KVM_PTE_LEAF_ATTR_HI_S1_UXN BIT(54)
|
||||
#define KVM_PTE_LEAF_ATTR_HI_S1_PXN BIT(53)
|
||||
|
||||
#define KVM_PTE_LEAF_ATTR_HI_S2_XN GENMASK(54, 53)
|
||||
|
||||
@@ -237,13 +231,12 @@ struct kvm_pgtable_mm_ops {
|
||||
|
||||
/**
|
||||
* enum kvm_pgtable_stage2_flags - Stage-2 page-table flags.
|
||||
* @KVM_PGTABLE_S2_NOFWB: Don't enforce Normal-WB even if the CPUs have
|
||||
* ARM64_HAS_STAGE2_FWB.
|
||||
* @KVM_PGTABLE_S2_IDMAP: Only use identity mappings.
|
||||
* @KVM_PGTABLE_S2_AS_S1: Final memory attributes are that of Stage-1.
|
||||
*/
|
||||
enum kvm_pgtable_stage2_flags {
|
||||
KVM_PGTABLE_S2_NOFWB = BIT(0),
|
||||
KVM_PGTABLE_S2_IDMAP = BIT(1),
|
||||
KVM_PGTABLE_S2_IDMAP = BIT(0),
|
||||
KVM_PGTABLE_S2_AS_S1 = BIT(1),
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <linux/arm_ffa.h>
|
||||
#include <linux/memblock.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <asm/kvm_host.h>
|
||||
#include <asm/kvm_pgtable.h>
|
||||
|
||||
/* Maximum number of VMs that can co-exist under pKVM. */
|
||||
@@ -23,10 +24,12 @@ void pkvm_destroy_hyp_vm(struct kvm *kvm);
|
||||
int pkvm_create_hyp_vcpu(struct kvm_vcpu *vcpu);
|
||||
|
||||
/*
|
||||
* This functions as an allow-list of protected VM capabilities.
|
||||
* Features not explicitly allowed by this function are denied.
|
||||
* Check whether the specific capability is allowed in pKVM.
|
||||
*
|
||||
* Certain features are allowed only for non-protected VMs in pKVM, which is why
|
||||
* this takes the VM (kvm) as a parameter.
|
||||
*/
|
||||
static inline bool kvm_pvm_ext_allowed(long ext)
|
||||
static inline bool kvm_pkvm_ext_allowed(struct kvm *kvm, long ext)
|
||||
{
|
||||
switch (ext) {
|
||||
case KVM_CAP_IRQCHIP:
|
||||
@@ -42,11 +45,32 @@ static inline bool kvm_pvm_ext_allowed(long ext)
|
||||
case KVM_CAP_ARM_PTRAUTH_ADDRESS:
|
||||
case KVM_CAP_ARM_PTRAUTH_GENERIC:
|
||||
return true;
|
||||
default:
|
||||
case KVM_CAP_ARM_MTE:
|
||||
return false;
|
||||
default:
|
||||
return !kvm || !kvm_vm_is_protected(kvm);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether the KVM VM IOCTL is allowed in pKVM.
|
||||
*
|
||||
* Certain features are allowed only for non-protected VMs in pKVM, which is why
|
||||
* this takes the VM (kvm) as a parameter.
|
||||
*/
|
||||
static inline bool kvm_pkvm_ioctl_allowed(struct kvm *kvm, unsigned int ioctl)
|
||||
{
|
||||
long ext;
|
||||
int r;
|
||||
|
||||
r = kvm_get_cap_for_kvm_ioctl(ioctl, &ext);
|
||||
|
||||
if (WARN_ON_ONCE(r < 0))
|
||||
return false;
|
||||
|
||||
return kvm_pkvm_ext_allowed(kvm, ext);
|
||||
}
|
||||
|
||||
extern struct memblock_region kvm_nvhe_sym(hyp_memory)[];
|
||||
extern unsigned int kvm_nvhe_sym(hyp_memblock_nr);
|
||||
|
||||
|
||||
@@ -175,19 +175,24 @@
|
||||
#define MT_DEVICE_nGnRE 4
|
||||
|
||||
/*
|
||||
* Memory types for Stage-2 translation
|
||||
* Memory types for Stage-2 translation when HCR_EL2.FWB=0. See R_HMNDG,
|
||||
* R_TNHFM, R_GQFSF and I_MCQKW for the details on how these attributes get
|
||||
* combined with Stage-1.
|
||||
*/
|
||||
#define MT_S2_NORMAL 0xf
|
||||
#define MT_S2_NORMAL_NC 0x5
|
||||
#define MT_S2_DEVICE_nGnRE 0x1
|
||||
#define MT_S2_AS_S1 MT_S2_NORMAL
|
||||
|
||||
/*
|
||||
* Memory types for Stage-2 translation when ID_AA64MMFR2_EL1.FWB is 0001
|
||||
* Stage-2 enforces Normal-WB and Device-nGnRE
|
||||
* Memory types for Stage-2 translation when HCR_EL2.FWB=1. Stage-2 enforces
|
||||
* Normal-WB and Device-nGnRE, unless we actively say that S1 wins. See
|
||||
* R_VRJSW and R_RHWZM for details.
|
||||
*/
|
||||
#define MT_S2_FWB_NORMAL 6
|
||||
#define MT_S2_FWB_NORMAL_NC 5
|
||||
#define MT_S2_FWB_DEVICE_nGnRE 1
|
||||
#define MT_S2_FWB_AS_S1 7
|
||||
|
||||
#ifdef CONFIG_ARM64_4K_PAGES
|
||||
#define IOREMAP_MAX_ORDER (PUD_SHIFT)
|
||||
|
||||
@@ -109,10 +109,10 @@ static inline bool __pure lpa2_is_enabled(void)
|
||||
#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
|
||||
#define PAGE_KERNEL_EXEC_CONT __pgprot(_PAGE_KERNEL_EXEC_CONT)
|
||||
|
||||
#define PAGE_S2_MEMATTR(attr, has_fwb) \
|
||||
#define PAGE_S2_MEMATTR(attr) \
|
||||
({ \
|
||||
u64 __val; \
|
||||
if (has_fwb) \
|
||||
if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) \
|
||||
__val = PTE_S2_MEMATTR(MT_S2_FWB_ ## attr); \
|
||||
else \
|
||||
__val = PTE_S2_MEMATTR(MT_S2_ ## attr); \
|
||||
|
||||
@@ -504,7 +504,6 @@
|
||||
#define SYS_VPIDR_EL2 sys_reg(3, 4, 0, 0, 0)
|
||||
#define SYS_VMPIDR_EL2 sys_reg(3, 4, 0, 0, 5)
|
||||
|
||||
#define SYS_SCTLR_EL2 sys_reg(3, 4, 1, 0, 0)
|
||||
#define SYS_ACTLR_EL2 sys_reg(3, 4, 1, 0, 1)
|
||||
#define SYS_SCTLR2_EL2 sys_reg(3, 4, 1, 0, 3)
|
||||
#define SYS_HCR_EL2 sys_reg(3, 4, 1, 1, 0)
|
||||
@@ -517,7 +516,6 @@
|
||||
#define SYS_TTBR1_EL2 sys_reg(3, 4, 2, 0, 1)
|
||||
#define SYS_TCR_EL2 sys_reg(3, 4, 2, 0, 2)
|
||||
#define SYS_VTTBR_EL2 sys_reg(3, 4, 2, 1, 0)
|
||||
#define SYS_VTCR_EL2 sys_reg(3, 4, 2, 1, 2)
|
||||
|
||||
#define SYS_HAFGRTR_EL2 sys_reg(3, 4, 3, 1, 6)
|
||||
#define SYS_SPSR_EL2 sys_reg(3, 4, 4, 0, 0)
|
||||
@@ -561,7 +559,6 @@
|
||||
#define SYS_ICC_SRE_EL2 sys_reg(3, 4, 12, 9, 5)
|
||||
#define SYS_ICH_EISR_EL2 sys_reg(3, 4, 12, 11, 3)
|
||||
#define SYS_ICH_ELRSR_EL2 sys_reg(3, 4, 12, 11, 5)
|
||||
#define SYS_ICH_VMCR_EL2 sys_reg(3, 4, 12, 11, 7)
|
||||
|
||||
#define __SYS__LR0_EL2(x) sys_reg(3, 4, 12, 12, x)
|
||||
#define SYS_ICH_LR0_EL2 __SYS__LR0_EL2(0)
|
||||
@@ -838,12 +835,6 @@
|
||||
#define SCTLR_ELx_A (BIT(1))
|
||||
#define SCTLR_ELx_M (BIT(0))
|
||||
|
||||
/* SCTLR_EL2 specific flags. */
|
||||
#define SCTLR_EL2_RES1 ((BIT(4)) | (BIT(5)) | (BIT(11)) | (BIT(16)) | \
|
||||
(BIT(18)) | (BIT(22)) | (BIT(23)) | (BIT(28)) | \
|
||||
(BIT(29)))
|
||||
|
||||
#define SCTLR_EL2_BT (BIT(36))
|
||||
#ifdef CONFIG_CPU_BIG_ENDIAN
|
||||
#define ENDIAN_SET_EL2 SCTLR_ELx_EE
|
||||
#else
|
||||
@@ -989,26 +980,6 @@
|
||||
#define ICH_LR_PRIORITY_SHIFT 48
|
||||
#define ICH_LR_PRIORITY_MASK (0xffULL << ICH_LR_PRIORITY_SHIFT)
|
||||
|
||||
/* ICH_VMCR_EL2 bit definitions */
|
||||
#define ICH_VMCR_ACK_CTL_SHIFT 2
|
||||
#define ICH_VMCR_ACK_CTL_MASK (1 << ICH_VMCR_ACK_CTL_SHIFT)
|
||||
#define ICH_VMCR_FIQ_EN_SHIFT 3
|
||||
#define ICH_VMCR_FIQ_EN_MASK (1 << ICH_VMCR_FIQ_EN_SHIFT)
|
||||
#define ICH_VMCR_CBPR_SHIFT 4
|
||||
#define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT)
|
||||
#define ICH_VMCR_EOIM_SHIFT 9
|
||||
#define ICH_VMCR_EOIM_MASK (1 << ICH_VMCR_EOIM_SHIFT)
|
||||
#define ICH_VMCR_BPR1_SHIFT 18
|
||||
#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)
|
||||
#define ICH_VMCR_BPR0_SHIFT 21
|
||||
#define ICH_VMCR_BPR0_MASK (7 << ICH_VMCR_BPR0_SHIFT)
|
||||
#define ICH_VMCR_PMR_SHIFT 24
|
||||
#define ICH_VMCR_PMR_MASK (0xffUL << ICH_VMCR_PMR_SHIFT)
|
||||
#define ICH_VMCR_ENG0_SHIFT 0
|
||||
#define ICH_VMCR_ENG0_MASK (1 << ICH_VMCR_ENG0_SHIFT)
|
||||
#define ICH_VMCR_ENG1_SHIFT 1
|
||||
#define ICH_VMCR_ENG1_MASK (1 << ICH_VMCR_ENG1_SHIFT)
|
||||
|
||||
/*
|
||||
* Permission Indirection Extension (PIE) permission encodings.
|
||||
* Encodings with the _O suffix, have overlays applied (Permission Overlay Extension).
|
||||
|
||||
@@ -2335,16 +2335,16 @@ static bool can_trap_icv_dir_el1(const struct arm64_cpu_capabilities *entry,
|
||||
|
||||
BUILD_BUG_ON(ARM64_HAS_ICH_HCR_EL2_TDIR <= ARM64_HAS_GICV3_CPUIF);
|
||||
BUILD_BUG_ON(ARM64_HAS_ICH_HCR_EL2_TDIR <= ARM64_HAS_GICV5_LEGACY);
|
||||
if (!this_cpu_has_cap(ARM64_HAS_GICV3_CPUIF) &&
|
||||
!is_midr_in_range_list(has_vgic_v3))
|
||||
return false;
|
||||
|
||||
if (!is_hyp_mode_available())
|
||||
return false;
|
||||
|
||||
if (this_cpu_has_cap(ARM64_HAS_GICV5_LEGACY))
|
||||
return true;
|
||||
|
||||
if (!this_cpu_has_cap(ARM64_HAS_GICV3_CPUIF) &&
|
||||
!is_midr_in_range_list(has_vgic_v3))
|
||||
return false;
|
||||
|
||||
if (is_kernel_in_hyp_mode())
|
||||
res.a1 = read_sysreg_s(SYS_ICH_VTR_EL2);
|
||||
else
|
||||
|
||||
@@ -299,7 +299,7 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
|
||||
isb
|
||||
0:
|
||||
|
||||
init_el2_hcr HCR_HOST_NVHE_FLAGS
|
||||
init_el2_hcr HCR_HOST_NVHE_FLAGS | HCR_ATA
|
||||
init_el2_state
|
||||
|
||||
/* Hypervisor stub */
|
||||
|
||||
@@ -86,7 +86,6 @@ KVM_NVHE_ALIAS(kvm_patch_vector_branch);
|
||||
KVM_NVHE_ALIAS(kvm_update_va_mask);
|
||||
KVM_NVHE_ALIAS(kvm_get_kimage_voffset);
|
||||
KVM_NVHE_ALIAS(kvm_compute_final_ctr_el0);
|
||||
KVM_NVHE_ALIAS(kvm_pan_patch_el2_entry);
|
||||
KVM_NVHE_ALIAS(spectre_bhb_patch_loop_iter);
|
||||
KVM_NVHE_ALIAS(spectre_bhb_patch_loop_mitigation_enable);
|
||||
KVM_NVHE_ALIAS(spectre_bhb_patch_wa3);
|
||||
|
||||
@@ -1056,10 +1056,14 @@ static void timer_context_init(struct kvm_vcpu *vcpu, int timerid)
|
||||
|
||||
ctxt->timer_id = timerid;
|
||||
|
||||
if (timerid == TIMER_VTIMER)
|
||||
ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;
|
||||
else
|
||||
ctxt->offset.vm_offset = &kvm->arch.timer_data.poffset;
|
||||
if (!kvm_vm_is_protected(vcpu->kvm)) {
|
||||
if (timerid == TIMER_VTIMER)
|
||||
ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;
|
||||
else
|
||||
ctxt->offset.vm_offset = &kvm->arch.timer_data.poffset;
|
||||
} else {
|
||||
ctxt->offset.vm_offset = NULL;
|
||||
}
|
||||
|
||||
hrtimer_setup(&ctxt->hrtimer, kvm_hrtimer_expire, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD);
|
||||
|
||||
@@ -1083,7 +1087,8 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
|
||||
timer_context_init(vcpu, i);
|
||||
|
||||
/* Synchronize offsets across timers of a VM if not already provided */
|
||||
if (!test_bit(KVM_ARCH_FLAG_VM_COUNTER_OFFSET, &vcpu->kvm->arch.flags)) {
|
||||
if (!vcpu_is_protected(vcpu) &&
|
||||
!test_bit(KVM_ARCH_FLAG_VM_COUNTER_OFFSET, &vcpu->kvm->arch.flags)) {
|
||||
timer_set_offset(vcpu_vtimer(vcpu), kvm_phys_timer_read());
|
||||
timer_set_offset(vcpu_ptimer(vcpu), 0);
|
||||
}
|
||||
@@ -1687,6 +1692,9 @@ int kvm_vm_ioctl_set_counter_offset(struct kvm *kvm,
|
||||
if (offset->reserved)
|
||||
return -EINVAL;
|
||||
|
||||
if (kvm_vm_is_protected(kvm))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&kvm->lock);
|
||||
|
||||
if (!kvm_trylock_all_vcpus(kvm)) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user