162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci========================================= 462306a36Sopenharmony_cis390 (IBM Z) Ultravisor and Protected VMs 562306a36Sopenharmony_ci========================================= 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciSummary 862306a36Sopenharmony_ci------- 962306a36Sopenharmony_ciProtected virtual machines (PVM) are KVM VMs that do not allow KVM to 1062306a36Sopenharmony_ciaccess VM state like guest memory or guest registers. Instead, the 1162306a36Sopenharmony_ciPVMs are mostly managed by a new entity called Ultravisor (UV). The UV 1262306a36Sopenharmony_ciprovides an API that can be used by PVMs and KVM to request management 1362306a36Sopenharmony_ciactions. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciEach guest starts in non-protected mode and then may make a request to 1662306a36Sopenharmony_citransition into protected mode. On transition, KVM registers the guest 1762306a36Sopenharmony_ciand its VCPUs with the Ultravisor and prepares everything for running 1862306a36Sopenharmony_ciit. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciThe Ultravisor will secure and decrypt the guest's boot memory 2162306a36Sopenharmony_ci(i.e. kernel/initrd). It will safeguard state changes like VCPU 2262306a36Sopenharmony_cistarts/stops and injected interrupts while the guest is running. 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciAs access to the guest's state, such as the SIE state description, is 2562306a36Sopenharmony_cinormally needed to be able to run a VM, some changes have been made in 2662306a36Sopenharmony_cithe behavior of the SIE instruction. A new format 4 state description 2762306a36Sopenharmony_cihas been introduced, where some fields have different meanings for a 2862306a36Sopenharmony_ciPVM. SIE exits are minimized as much as possible to improve speed and 2962306a36Sopenharmony_cireduce exposed guest state. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciInterrupt injection 3362306a36Sopenharmony_ci------------------- 3462306a36Sopenharmony_ciInterrupt injection is safeguarded by the Ultravisor. As KVM doesn't 3562306a36Sopenharmony_cihave access to the VCPUs' lowcores, injection is handled via the 3662306a36Sopenharmony_ciformat 4 state description. 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciMachine check, external, IO and restart interruptions each can be 3962306a36Sopenharmony_ciinjected on SIE entry via a bit in the interrupt injection control 4062306a36Sopenharmony_cifield (offset 0x54). If the guest cpu is not enabled for the interrupt 4162306a36Sopenharmony_ciat the time of injection, a validity interception is recognized. The 4262306a36Sopenharmony_ciformat 4 state description contains fields in the interception data 4362306a36Sopenharmony_ciblock where data associated with the interrupt can be transported. 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ciProgram and Service Call exceptions have another layer of 4662306a36Sopenharmony_cisafeguarding; they can only be injected for instructions that have 4762306a36Sopenharmony_cibeen intercepted into KVM. The exceptions need to be a valid outcome 4862306a36Sopenharmony_ciof an instruction emulation by KVM, e.g. we can never inject a 4962306a36Sopenharmony_ciaddressing exception as they are reported by SIE since KVM has no 5062306a36Sopenharmony_ciaccess to the guest memory. 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ciMask notification interceptions 5462306a36Sopenharmony_ci------------------------------- 5562306a36Sopenharmony_ciKVM cannot intercept lctl(g) and lpsw(e) anymore in order to be 5662306a36Sopenharmony_cinotified when a PVM enables a certain class of interrupt. As a 5762306a36Sopenharmony_cireplacement, two new interception codes have been introduced: One 5862306a36Sopenharmony_ciindicating that the contents of CRs 0, 6, or 14 have been changed, 5962306a36Sopenharmony_ciindicating different interruption subclasses; and one indicating that 6062306a36Sopenharmony_ciPSW bit 13 has been changed, indicating that a machine check 6162306a36Sopenharmony_ciintervention was requested and those are now enabled. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciInstruction emulation 6462306a36Sopenharmony_ci--------------------- 6562306a36Sopenharmony_ciWith the format 4 state description for PVMs, the SIE instruction already 6662306a36Sopenharmony_ciinterprets more instructions than it does with format 2. It is not able 6762306a36Sopenharmony_cito interpret every instruction, but needs to hand some tasks to KVM; 6862306a36Sopenharmony_citherefore, the SIE and the ultravisor safeguard emulation inputs and outputs. 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciThe control structures associated with SIE provide the Secure 7162306a36Sopenharmony_ciInstruction Data Area (SIDA), the Interception Parameters (IP) and the 7262306a36Sopenharmony_ciSecure Interception General Register Save Area. Guest GRs and most of 7362306a36Sopenharmony_cithe instruction data, such as I/O data structures, are filtered. 7462306a36Sopenharmony_ciInstruction data is copied to and from the SIDA when needed. Guest 7562306a36Sopenharmony_ciGRs are put into / retrieved from the Secure Interception General 7662306a36Sopenharmony_ciRegister Save Area. 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciOnly GR values needed to emulate an instruction will be copied into this 7962306a36Sopenharmony_cisave area and the real register numbers will be hidden. 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciThe Interception Parameters state description field still contains 8262306a36Sopenharmony_cithe bytes of the instruction text, but with pre-set register values 8362306a36Sopenharmony_ciinstead of the actual ones. I.e. each instruction always uses the same 8462306a36Sopenharmony_ciinstruction text, in order not to leak guest instruction text. 8562306a36Sopenharmony_ciThis also implies that the register content that a guest had in r<n> 8662306a36Sopenharmony_cimay be in r<m> from the hypervisor's point of view. 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciThe Secure Instruction Data Area contains instruction storage 8962306a36Sopenharmony_cidata. Instruction data, i.e. data being referenced by an instruction 9062306a36Sopenharmony_cilike the SCCB for sclp, is moved via the SIDA. When an instruction is 9162306a36Sopenharmony_ciintercepted, the SIE will only allow data and program interrupts for 9262306a36Sopenharmony_cithis instruction to be moved to the guest via the two data areas 9362306a36Sopenharmony_cidiscussed before. Other data is either ignored or results in validity 9462306a36Sopenharmony_ciinterceptions. 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciInstruction emulation interceptions 9862306a36Sopenharmony_ci----------------------------------- 9962306a36Sopenharmony_ciThere are two types of SIE secure instruction intercepts: the normal 10062306a36Sopenharmony_ciand the notification type. Normal secure instruction intercepts will 10162306a36Sopenharmony_cimake the guest pending for instruction completion of the intercepted 10262306a36Sopenharmony_ciinstruction type, i.e. on SIE entry it is attempted to complete 10362306a36Sopenharmony_ciemulation of the instruction with the data provided by KVM. That might 10462306a36Sopenharmony_cibe a program exception or instruction completion. 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ciThe notification type intercepts inform KVM about guest environment 10762306a36Sopenharmony_cichanges due to guest instruction interpretation. Such an interception 10862306a36Sopenharmony_ciis recognized, for example, for the store prefix instruction to provide 10962306a36Sopenharmony_cithe new lowcore location. On SIE reentry, any KVM data in the data areas 11062306a36Sopenharmony_ciis ignored and execution continues as if the guest instruction had 11162306a36Sopenharmony_cicompleted. For that reason KVM is not allowed to inject a program 11262306a36Sopenharmony_ciinterrupt. 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ciLinks 11562306a36Sopenharmony_ci----- 11662306a36Sopenharmony_ci`KVM Forum 2019 presentation <https://static.sched.com/hosted_files/kvmforum2019/3b/ibm_protected_vms_s390x.pdf>`_ 117