render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
fbe740
From 026160bc76bab26772c2a80bd50ae55119e3b60b Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <026160bc76bab26772c2a80bd50ae55119e3b60b@dist-git>
fbe740
From: Viktor Mihajlovski <mihajlov@linux.ibm.com>
fbe740
Date: Wed, 24 Jun 2020 13:16:23 +0200
fbe740
Subject: [PATCH] docs: Describe protected virtualization guest setup
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Protected virtualization/IBM Secure Execution for Linux protects
fbe740
guest memory and state from the host.
fbe740
fbe740
Add some basic information about technology and a brief guide
fbe740
on setting up secure guests with libvirt.
fbe740
fbe740
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.ibm.com>
fbe740
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
fbe740
Reviewed-by: Paulo de Rezende Pinatti <ppinatti@linux.ibm.com>
fbe740
Reviewed-by: Erik Skultety <eskultet@redhat.com>
fbe740
(cherry picked from commit f0d0cd6179709461b026f24569a688065e90d766)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1848997
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1850351
fbe740
fbe740
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
fbe740
Message-Id: <cf598d01d242bb56e64e14bfc32cece69341d949.1592996194.git.jdenemar@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 docs/kbase.html.in                 |   3 +
fbe740
 docs/kbase/s390_protected_virt.rst | 189 +++++++++++++++++++++++++++++
fbe740
 2 files changed, 192 insertions(+)
fbe740
 create mode 100644 docs/kbase/s390_protected_virt.rst
fbe740
fbe740
diff --git a/docs/kbase.html.in b/docs/kbase.html.in
fbe740
index f2975960f6..05773db16d 100644
fbe740
--- a/docs/kbase.html.in
fbe740
+++ b/docs/kbase.html.in
fbe740
@@ -14,6 +14,9 @@
fbe740
         
Secure usage
fbe740
         
Secure usage of the libvirt APIs
fbe740
 
fbe740
+        
Protected virtualization on s390
fbe740
+        
Running secure s390 guests with IBM Secure Execution
fbe740
+
fbe740
         
Launch security
fbe740
         
Securely launching VMs with AMD SEV
fbe740
 
fbe740
diff --git a/docs/kbase/s390_protected_virt.rst b/docs/kbase/s390_protected_virt.rst
fbe740
new file mode 100644
fbe740
index 0000000000..f38d16d743
fbe740
--- /dev/null
fbe740
+++ b/docs/kbase/s390_protected_virt.rst
fbe740
@@ -0,0 +1,189 @@
fbe740
+================================
fbe740
+Protected Virtualization on s390
fbe740
+================================
fbe740
+
fbe740
+.. contents::
fbe740
+
fbe740
+Overview
fbe740
+========
fbe740
+
fbe740
+Protected virtualization, also known as IBM Secure Execution is a
fbe740
+hardware-based privacy protection technology for s390x (IBM Z).
fbe740
+It allows to execute virtual machines such that the host system
fbe740
+has no access to a VM's state and memory contents.
fbe740
+
fbe740
+Unlike other similar technologies, the memory of a running guest
fbe740
+is not encrypted but protected by hardware access controls, which
fbe740
+may only be manipulated by trusted system firmware, called
fbe740
+ultravisor.
fbe740
+
fbe740
+For the cases where the host needs access to guest memory (e.g. for
fbe740
+paging), it can request pages to be exported to it. The exported page
fbe740
+will be encrypted with a unique key for the running guest by the
fbe740
+ultravisor. The ultravisor also computes an integrity value for
fbe740
+the page, and stores it in a special table, together with the page
fbe740
+index and a counter. This way it can verify the integrity of
fbe740
+the page content upon re-import into the guest.
fbe740
+
fbe740
+In other cases it may be necessary for a guest to grant the host access
fbe740
+to dedicated memory regions (e.g. for I/O). The guest can request
fbe740
+that the ultravisor removes the memory protection from individual
fbe740
+pages, so that they can be shared with the host. Likewise, the
fbe740
+guest can undo the sharing.
fbe740
+
fbe740
+A secure guest will initially start in a regular non-protected VM.
fbe740
+The start-up is controlled by a small bootstrap program loaded
fbe740
+into memory together with encrypted operating system components and
fbe740
+a control structure (the PV header).
fbe740
+The operating system components (e.g. Linux kernel, initial RAM
fbe740
+file system, kernel parameters) are encrypted and integrity
fbe740
+protected. The component encryption keys and integrity values are
fbe740
+stored in the PV header.
fbe740
+The PV header is wrapped with a public key belonging to a specific
fbe740
+system (in fact it can be wrapped with multiple such keys). The
fbe740
+matching private key is only accessible by trusted hardware and
fbe740
+firmware in that specific system.
fbe740
+Consequently, such a secure guest boot image can only be run on the
fbe740
+systems it has been prepared for. Its contents can't be decrypted
fbe740
+without access to the private key and it can't be modified as
fbe740
+it is integrity protected.
fbe740
+
fbe740
+Host Requirements
fbe740
+=================
fbe740
+
fbe740
+IBM Secure Execution for Linux has some hardware and firmware
fbe740
+requirements. The system hardware must be an IBM z15 (or newer),
fbe740
+or an IBM LinuxONE III (or newer).
fbe740
+
fbe740
+It is also necessary that the IBM Secure Execution feature is
fbe740
+enabled for that system. With libvirt >= 6.5.0 you can run
fbe740
+``libvirt-host--validate`` or otherwise check for facility '158', e.g.
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   $ grep facilities /proc/cpuinfo | grep 158
fbe740
+
fbe740
+The kernel must include the protected virtualization support
fbe740
+which can be verified by checking for the presence of directory
fbe740
+``/sys/firmware/uv``. It will only be present when both the
fbe740
+hardware and the kernel support are available.
fbe740
+
fbe740
+Finally, the host operating system must donate some memory to
fbe740
+the ultravisor needed to store memory security information.
fbe740
+This is achieved by specifying the following kernel command
fbe740
+line parameter to the host boot configuration
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   prot_virt=1
fbe740
+
fbe740
+
fbe740
+Guest Requirements
fbe740
+==================
fbe740
+
fbe740
+Guest Boot
fbe740
+----------
fbe740
+
fbe740
+To start a guest in protected virtualization secure mode, the
fbe740
+boot image must have been prepared first with the program
fbe740
+``genprotimg`` using the correct public key for this host.
fbe740
+``genprotimg`` is part of the package ``s390-tools``, or
fbe740
+``s390-utils``, depending on the Linux distribution being used.
fbe740
+It can also be found at
fbe740
+`<https://github.com/ibm-s390-tools/s390-tools/tree/master/genprotimg>`_
fbe740
+
fbe740
+The guests have to be configured to use the host CPU model, which
fbe740
+must contain the ``unpack`` facility indicating ultravisor guest support.
fbe740
+
fbe740
+With the following command it's possible to check whether the host
fbe740
+CPU model satisfies the requirement
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   $ virsh domcapabilities | grep unpack
fbe740
+
fbe740
+which should return
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   <feature policy='require' name='unpack'/>
fbe740
+
fbe740
+Note that on hosts with libvirt < 6.5.0 if the check fails despite
fbe740
+the host system actually supporting protected virtualization guests,
fbe740
+this can be caused by a stale libvirt capabilities cache.
fbe740
+To recover, run the following commands
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   $ systemctl stop libvirtd
fbe740
+   $ rm /var/cache/libvirt/qemu/capabilities/*.xml
fbe740
+   $ systemctl start libvirtd
fbe740
+
fbe740
+
fbe740
+Guest I/O
fbe740
+---------
fbe740
+
fbe740
+Protected virtualization guests support I/O using virtio devices.
fbe740
+As the virtio data structures of secure guests are not accessible
fbe740
+by the host, it is necessary to use shared memory ('bounce buffers').
fbe740
+
fbe740
+To enable virtio devices to use shared buffers, it is necessary
fbe740
+to configure them with platform_iommu enabled. This can done by adding
fbe740
+``iommu='on'`` to the driver element of a virtio device definition in the
fbe740
+guest's XML, e.g.
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   <interface type='network'>
fbe740
+     <source network='default'/>
fbe740
+     <model type='virtio'/>
fbe740
+     <driver name='vhost' iommu='on'/>
fbe740
+   </interface>
fbe740
+
fbe740
+It is mandatory to define all virtio bus devices in this way to
fbe740
+prevent the host from attempting to access protected memory.
fbe740
+Ballooning will not work and is fenced by QEMU. It should be
fbe740
+disabled by specifying
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   <memballoon model='none'/>
fbe740
+
fbe740
+Finally, the guest Linux must be instructed to allocate I/O
fbe740
+buffers using memory shared between host and guest using SWIOTLB.
fbe740
+This is done by adding ``swiotlb=nnn`` to the guest's kernel command
fbe740
+line string, where ``nnn`` stands for the number of statically
fbe740
+allocated 2K entries. A commonly used value for swiotlb is 262144.
fbe740
+
fbe740
+Example guest definition
fbe740
+========================
fbe740
+
fbe740
+Minimal domain XML for a protected virtualization guest, essentially
fbe740
+it's mostly about the ``iommu`` property
fbe740
+
fbe740
+::
fbe740
+
fbe740
+   <domain type='kvm'>
fbe740
+     <name>protected</name>
fbe740
+     <memory unit='KiB'>2048000</memory>
fbe740
+     <currentMemory unit='KiB'>2048000</currentMemory>
fbe740
+     <vcpu>1</vcpu>
fbe740
+     <os>
fbe740
+       <type arch='s390x'>hvm</type>
fbe740
+     </os>
fbe740
+     <cpu mode='host-model'/>
fbe740
+     <devices>
fbe740
+       <disk type='file' device='disk'>
fbe740
+         <driver name='qemu' type='qcow2' cache='none' io='native' iommu='on'>
fbe740
+         <source file='/var/lib/libvirt/images/protected.qcow2'/>
fbe740
+         <target dev='vda' bus='virtio'/>
fbe740
+       </disk>
fbe740
+       <interface type='network'>
fbe740
+         <driver iommu='on'/>
fbe740
+         <source network='default'/>
fbe740
+         <model type='virtio'/>
fbe740
+       </interface>
fbe740
+       <console type='pty'/>
fbe740
+       <memballoon model='none'/>
fbe740
+     </devices>
fbe740
+   </domain>
fbe740
-- 
fbe740
2.27.0
fbe740