18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci=========================================
48c2ecf20Sopenharmony_cis390 (IBM Z) Ultravisor and Protected VMs
58c2ecf20Sopenharmony_ci=========================================
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciSummary
88c2ecf20Sopenharmony_ci-------
98c2ecf20Sopenharmony_ciProtected virtual machines (PVM) are KVM VMs that do not allow KVM to
108c2ecf20Sopenharmony_ciaccess VM state like guest memory or guest registers. Instead, the
118c2ecf20Sopenharmony_ciPVMs are mostly managed by a new entity called Ultravisor (UV). The UV
128c2ecf20Sopenharmony_ciprovides an API that can be used by PVMs and KVM to request management
138c2ecf20Sopenharmony_ciactions.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciEach guest starts in non-protected mode and then may make a request to
168c2ecf20Sopenharmony_citransition into protected mode. On transition, KVM registers the guest
178c2ecf20Sopenharmony_ciand its VCPUs with the Ultravisor and prepares everything for running
188c2ecf20Sopenharmony_ciit.
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciThe Ultravisor will secure and decrypt the guest's boot memory
218c2ecf20Sopenharmony_ci(i.e. kernel/initrd). It will safeguard state changes like VCPU
228c2ecf20Sopenharmony_cistarts/stops and injected interrupts while the guest is running.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciAs access to the guest's state, such as the SIE state description, is
258c2ecf20Sopenharmony_cinormally needed to be able to run a VM, some changes have been made in
268c2ecf20Sopenharmony_cithe behavior of the SIE instruction. A new format 4 state description
278c2ecf20Sopenharmony_cihas been introduced, where some fields have different meanings for a
288c2ecf20Sopenharmony_ciPVM. SIE exits are minimized as much as possible to improve speed and
298c2ecf20Sopenharmony_cireduce exposed guest state.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciInterrupt injection
338c2ecf20Sopenharmony_ci-------------------
348c2ecf20Sopenharmony_ciInterrupt injection is safeguarded by the Ultravisor. As KVM doesn't
358c2ecf20Sopenharmony_cihave access to the VCPUs' lowcores, injection is handled via the
368c2ecf20Sopenharmony_ciformat 4 state description.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciMachine check, external, IO and restart interruptions each can be
398c2ecf20Sopenharmony_ciinjected on SIE entry via a bit in the interrupt injection control
408c2ecf20Sopenharmony_cifield (offset 0x54). If the guest cpu is not enabled for the interrupt
418c2ecf20Sopenharmony_ciat the time of injection, a validity interception is recognized. The
428c2ecf20Sopenharmony_ciformat 4 state description contains fields in the interception data
438c2ecf20Sopenharmony_ciblock where data associated with the interrupt can be transported.
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciProgram and Service Call exceptions have another layer of
468c2ecf20Sopenharmony_cisafeguarding; they can only be injected for instructions that have
478c2ecf20Sopenharmony_cibeen intercepted into KVM. The exceptions need to be a valid outcome
488c2ecf20Sopenharmony_ciof an instruction emulation by KVM, e.g. we can never inject a
498c2ecf20Sopenharmony_ciaddressing exception as they are reported by SIE since KVM has no
508c2ecf20Sopenharmony_ciaccess to the guest memory.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciMask notification interceptions
548c2ecf20Sopenharmony_ci-------------------------------
558c2ecf20Sopenharmony_ciKVM cannot intercept lctl(g) and lpsw(e) anymore in order to be
568c2ecf20Sopenharmony_cinotified when a PVM enables a certain class of interrupt.  As a
578c2ecf20Sopenharmony_cireplacement, two new interception codes have been introduced: One
588c2ecf20Sopenharmony_ciindicating that the contents of CRs 0, 6, or 14 have been changed,
598c2ecf20Sopenharmony_ciindicating different interruption subclasses; and one indicating that
608c2ecf20Sopenharmony_ciPSW bit 13 has been changed, indicating that a machine check
618c2ecf20Sopenharmony_ciintervention was requested and those are now enabled.
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciInstruction emulation
648c2ecf20Sopenharmony_ci---------------------
658c2ecf20Sopenharmony_ciWith the format 4 state description for PVMs, the SIE instruction already
668c2ecf20Sopenharmony_ciinterprets more instructions than it does with format 2. It is not able
678c2ecf20Sopenharmony_cito interpret every instruction, but needs to hand some tasks to KVM;
688c2ecf20Sopenharmony_citherefore, the SIE and the ultravisor safeguard emulation inputs and outputs.
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciThe control structures associated with SIE provide the Secure
718c2ecf20Sopenharmony_ciInstruction Data Area (SIDA), the Interception Parameters (IP) and the
728c2ecf20Sopenharmony_ciSecure Interception General Register Save Area.  Guest GRs and most of
738c2ecf20Sopenharmony_cithe instruction data, such as I/O data structures, are filtered.
748c2ecf20Sopenharmony_ciInstruction data is copied to and from the SIDA when needed.  Guest
758c2ecf20Sopenharmony_ciGRs are put into / retrieved from the Secure Interception General
768c2ecf20Sopenharmony_ciRegister Save Area.
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciOnly GR values needed to emulate an instruction will be copied into this
798c2ecf20Sopenharmony_cisave area and the real register numbers will be hidden.
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciThe Interception Parameters state description field still contains
828c2ecf20Sopenharmony_cithe bytes of the instruction text, but with pre-set register values
838c2ecf20Sopenharmony_ciinstead of the actual ones. I.e. each instruction always uses the same
848c2ecf20Sopenharmony_ciinstruction text, in order not to leak guest instruction text.
858c2ecf20Sopenharmony_ciThis also implies that the register content that a guest had in r<n>
868c2ecf20Sopenharmony_cimay be in r<m> from the hypervisor's point of view.
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciThe Secure Instruction Data Area contains instruction storage
898c2ecf20Sopenharmony_cidata. Instruction data, i.e. data being referenced by an instruction
908c2ecf20Sopenharmony_cilike the SCCB for sclp, is moved via the SIDA. When an instruction is
918c2ecf20Sopenharmony_ciintercepted, the SIE will only allow data and program interrupts for
928c2ecf20Sopenharmony_cithis instruction to be moved to the guest via the two data areas
938c2ecf20Sopenharmony_cidiscussed before. Other data is either ignored or results in validity
948c2ecf20Sopenharmony_ciinterceptions.
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciInstruction emulation interceptions
988c2ecf20Sopenharmony_ci-----------------------------------
998c2ecf20Sopenharmony_ciThere are two types of SIE secure instruction intercepts: the normal
1008c2ecf20Sopenharmony_ciand the notification type. Normal secure instruction intercepts will
1018c2ecf20Sopenharmony_cimake the guest pending for instruction completion of the intercepted
1028c2ecf20Sopenharmony_ciinstruction type, i.e. on SIE entry it is attempted to complete
1038c2ecf20Sopenharmony_ciemulation of the instruction with the data provided by KVM. That might
1048c2ecf20Sopenharmony_cibe a program exception or instruction completion.
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ciThe notification type intercepts inform KVM about guest environment
1078c2ecf20Sopenharmony_cichanges due to guest instruction interpretation. Such an interception
1088c2ecf20Sopenharmony_ciis recognized, for example, for the store prefix instruction to provide
1098c2ecf20Sopenharmony_cithe new lowcore location. On SIE reentry, any KVM data in the data areas
1108c2ecf20Sopenharmony_ciis ignored and execution continues as if the guest instruction had
1118c2ecf20Sopenharmony_cicompleted. For that reason KVM is not allowed to inject a program
1128c2ecf20Sopenharmony_ciinterrupt.
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ciLinks
1158c2ecf20Sopenharmony_ci-----
1168c2ecf20Sopenharmony_ci`KVM Forum 2019 presentation <https://static.sched.com/hosted_files/kvmforum2019/3b/ibm_protected_vms_s390x.pdf>`_
117