mostly i386 patches for 2024-06-04
Subsystems (2)
The following changes since commit 3b2fe44bb7f605f179e5e7feb2c13c2eb3abbb80:
Merge tag 'pull-request-2024-05-29' of https://gitlab.com/thuth/qemu into staging (2024-05-29 08:38:20 -0700)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to ba849076b6fc2290275ce7491547f6ae831cd2aa:
hw/i386: Add support for loading BIOS using guest_memfd (2024-06-04 08:40:46 +0200)
----------------------------------------------------------------
* virtio-blk: remove SCSI passthrough functionality
* require x86-64-v2 baseline ISA
* SEV-SNP host support
* fix xsave.flat with TCG
* fixes for CPUID checks done by TCG
----------------------------------------------------------------
Brijesh Singh (6):
i386/sev: Introduce 'sev-snp-guest' object
i386/sev: Add the SNP launch start context
i386/sev: Add handling to encrypt/finalize guest launch data hw/i386/sev: Add function to get SEV metadata from OVMF header i386/sev: Add support for populating OVMF metadata pages hw/i386/sev: Add support to encrypt BIOS when SEV-SNP is enabled
Dov Murik (3):
i386/sev: Extract build_kernel_loader_hashes i386/sev: Reorder struct declarations i386/sev: Allow measured direct kernel boot on SNP
Michael Roth (11):
i386/sev: Introduce "sev-common" type to encapsulate common SEV state i386/sev: Add a sev_snp_enabled() helper
i386/cpu: Set SEV-SNP CPUID bit when SNP enabled
i386/sev: Don't return launch measurements for SEV-SNP guests i386/sev: Update query-sev QAPI format to handle SEV-SNP i386/sev: Set CPU state to protected once SNP guest payload is finalized i386/sev: Add support for SNP CPUID validation
i386/kvm: Add KVM_EXIT_HYPERCALL handling for KVM_HC_MAP_GPA_RANGE i386/sev: Enable KVM_HC_MAP_GPA_RANGE hcall for SNP guests hw/i386/sev: Use guest_memfd for legacy ROMs
hw/i386: Add support for loading BIOS using guest_memfd
Pankaj Gupta (7):
linux-headers: Update to current kvm/next i386/sev: Replace error_report with error_setg i386/sev: Move sev_launch_update to separate class method i386/sev: Move sev_launch_finish to separate class method i386/sev: Add sev_kvm_init() override for SEV class i386/sev: Add snp_kvm_init() override for SNP class i386/sev: Invoke launch_updata_data() for SNP class
Paolo Bonzini (14):
virtio-blk: remove SCSI passthrough functionality host/i386: nothing looks at CPUINFO_SSE4
meson: assume x86-64-v2 baseline ISA
host/i386: assume presence of CMOV
host/i386: assume presence of SSE2
host/i386: assume presence of SSSE3
host/i386: assume presence of POPCNT
target/i386: fix xsave.flat from kvm-unit-tests
update-linux-headers: fix forwarding to asm-generic headers
update-linux-headers: move pvpanic.h to correct directory
update-linux-headers: import linux/kvm_para.h header
machine: allow early use of machine_require_guest_memfd i386/sev: Add a class method to determine KVM VM type for SNP guests i386/sev: Invoke launch_updata_data() for SEV class
Xiaoyao Li (1):
memory: Introduce memory_region_init_ram_guest_memfd()
Xinyu Li (2):
target/i386: fix SSE and SSE2 feature check target/i386: fix memory opsize for Mov to/from Seg
Zhao Liu (1):
target/i386/tcg: Fix RDPID feature check
docs/about/deprecated.rst | 10 -
docs/about/removed-features.rst | 8 +
docs/system/i386/amd-memory-encryption.rst | 70 +-
meson.build | 10 +-
qapi/misc-target.json | 72 +-
qapi/qom.json | 98 +-
host/include/i386/host/cpuinfo.h | 4 -
include/exec/confidential-guest-support.h | 5 +
include/exec/memory.h | 6 +
include/hw/boards.h | 1 -
include/hw/i386/pc.h | 28 +
include/hw/i386/x86.h | 2 +-
include/standard-headers/linux/kvm_para.h | 38 +
include/standard-headers/{linux => misc}/pvpanic.h | 0
linux-headers/asm-loongarch/kvm.h | 4 +
linux-headers/asm-riscv/kvm.h | 1 +
linux-headers/asm-x86/kvm.h | 52 +-
linux-headers/asm-x86/kvm_para.h | 1 +
linux-headers/linux/kvm_para.h | 2 +
linux-headers/linux/vhost.h | 15 +-
target/i386/kvm/kvm_i386.h | 1 +
target/i386/sev.h | 13 +-
target/i386/tcg/decode-new.h | 3 +
tcg/i386/tcg-target.h | 5 +-
hw/block/virtio-blk.c | 166 +-
hw/core/machine.c | 4 +-
hw/i386/pc.c | 14 +-
hw/i386/pc_sysfw.c | 35 +-
hw/i386/x86-common.c | 19 +-
hw/misc/pvpanic-isa.c | 2 +-
hw/misc/pvpanic-pci.c | 2 +-
hw/misc/pvpanic.c | 2 +-
system/memory.c | 24 +
target/i386/cpu.c | 1 +
target/i386/kvm/kvm.c | 56 +
target/i386/sev-sysemu-stub.c | 6 +-
target/i386/sev.c | 1581 +++++++++++++++-----
target/i386/tcg/fpu_helper.c | 5 +
target/i386/tcg/translate.c | 2 +-
util/bufferiszero.c | 4 +-
util/cpuinfo-i386.c | 8 +-
target/i386/tcg/decode-new.c.inc | 17 +-
tcg/i386/tcg-target.c.inc | 15 +-
scripts/update-linux-headers.sh | 37 +-
target/i386/kvm/trace-events | 1 +
target/i386/trace-events | 3 +
46 files changed, 1844 insertions(+), 609 deletions(-)
create mode 100644 include/standard-headers/linux/kvm_para.h
rename include/standard-headers/{linux => misc}/pvpanic.h (100%)
create mode 100644 linux-headers/asm-x86/kvm_para.h
create mode 100644 linux-headers/linux/kvm_para.hSignature · 1 line
2.45.1
[PULL 02/45] host/i386: nothing looks at CPUINFO_SSE4
The only user was the SSE4.1 variant of buffer_is_zero, which has been removed; code to compute CPUINFO_SSE4 is dead.
--- host/include/i386/host/cpuinfo.h | 1 - util/cpuinfo-i386.c | 1 - 2 files changed, 2 deletions(-)
host/include/i386/host/cpuinfo.h +0 -1
@@ -16,7 +16,6 @@#define CPUINFO_BMI1 (1u << 5)#define CPUINFO_BMI2 (1u << 6)#define CPUINFO_SSE2 (1u << 7) -#define CPUINFO_SSE4 (1u << 8)#define CPUINFO_AVX1 (1u << 9)#define CPUINFO_AVX2 (1u << 10)#define CPUINFO_AVX512F (1u << 11)
util/cpuinfo-i386.c +0 -1
@@ -36,7 +36,6 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) info |= (d & bit_CMOV ?CPUINFO_CMOV :0 ); info |= (d & bit_SSE2 ?CPUINFO_SSE2 :0 ); - info |= (c & bit_SSE4_1 ?CPUINFO_SSE4 :0 ); info |= (c & bit_MOVBE ?CPUINFO_MOVBE :0 ); info |= (c & bit_POPCNT ?CPUINFO_POPCNT :0 ); info |= (c & bit_PCLMUL ?CPUINFO_PCLMUL :0 );
Signature · 1 line
2.45.1
[PULL 06/45] host/i386: assume presence of SSSE3
In reply to Paolo BonziniQEMU now requires an x86-64-v2 host, which has SSSE3 instructions (notably, PSHUFB which is used by QEMU's AES implementation). Do not bother checking it.
--- util/cpuinfo-i386.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
util/cpuinfo-i386.c +2 -2
@@ -38,8 +38,8 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) info |= (c & bit_POPCNT ?CPUINFO_POPCNT :0 ); info |= (c & bit_PCLMUL ?CPUINFO_PCLMUL :0 ); -/* Our AES support requires PSHUFB as well. */ - info |= ((c & bit_AES) && (c & bit_SSSE3) ?CPUINFO_AES :0 ); +/* NOTE: our AES support requires SSSE3 (PSHUFB) as well. */ + info |= (c & bit_AES) ?CPUINFO_AES :0 ;/* For AVX features, we must check available and usable. */ if ((c & bit_AVX) && (c & bit_OSXSAVE)) {
Signature · 1 line
2.45.1
[PULL 21/45] i386/sev: Introduce 'sev-snp-guest' object
In reply to Paolo BonziniFrom: Brijesh Singh <[email protected]>
SEV-SNP support relies on a different set of properties/state than the existing 'sev-guest' object. This patch introduces the 'sev-snp-guest' object, which can be used to configure an SEV-SNP guest. For example, a default-configured SEV-SNP guest with no additional information passed in for use with attestation:
-object sev-snp-guest,id=sev0
or a fully-specified SEV-SNP guest where all spec-defined binary blobs are passed in as base64-encoded strings:
-object sev-snp-guest,id=sev0, \
policy=0x30000, \
init-flags=0, \
id-block=YWFhYWFhYWFhYWFhYWFhCg==, \
id-auth=CxHK/OKLkXGn/KpAC7Wl1FSiisWDbGTEKz..., \
author-key-enabled=on, \
host-data=LNkCWBRC5CcdGXirbNUV1OrsR28s..., \
guest-visible-workarounds=AA==, \See the QAPI schema updates included in this patch for more usage details.
In some cases these blobs may be up to 4096 characters, but this is generally well below the default limit for linux hosts where command-line sizes are defined by the sysconf-configurable ARG_MAX value, which defaults to 2097152 characters for Ubuntu hosts, for example.
Message-ID: <[email protected]>
--- docs/system/i386/amd-memory-encryption.rst | 70 +++++- qapi/qom.json | 58 +++++ target/i386/sev.h | 1 + target/i386/sev.c | 253 +++++++++++++++++++++ 4 files changed, 380 insertions(+), 2 deletions(-)
docs/system/i386/amd-memory-encryption.rst +68 -2
@@ -25,8 +25,8 @@ support for notifying a guest's operating system when certain types of VMEXITs are about to occur. This allows the guest to selectively share information with the hypervisor to satisfy the requested function. -Launching ---------- +Launching (SEV and SEV-ES) +-------------------------- Boot images (such as bios) must be encrypted before a guest can be booted. The ``MEMORY_ENCRYPT_OP`` ioctl provides commands to encrypt the images: ``LAUNCH_START``,
@@ -161,6 +161,72 @@ The value of GCTX.LD is If kernel hashes are not used, or SEV-ES is disabled, use empty blobs for ``kernel_hashes_blob`` and ``vmsas_blob`` as needed. +Launching (SEV-SNP) +------------------- +Boot images (such as bios) must be encrypted before a guest can be booted. The +``MEMORY_ENCRYPT_OP`` ioctl provides commands to encrypt the images: +``SNP_LAUNCH_START``, ``SNP_LAUNCH_UPDATE``, and ``SNP_LAUNCH_FINISH``. These +three commands communicate with SEV-SNP firmware to generate a fresh memory +encryption key for the VM, encrypt the boot images for a successful launch. For +more details on the SEV-SNP firmware interfaces used by these commands please +see the SEV-SNP Firmware ABI. + +``SNP_LAUNCH_START`` is called first to create a cryptographic launch context +within the firmware. To create this context, the guest owner must provide a +guest policy and other parameters as described in the SEV-SNP firmware +specification. The launch parameters should be specified as described in the +QAPI schema for the sev-snp-guest object. + +The ``SNP_LAUNCH_START`` uses the following parameters, which can be configured +by the corresponding parameters documented in the QAPI schema for the +'sev-snp-guest' object. + ++--------+-------+----------+-------------------------------------------------+ +| key | type | default | meaning | ++---------------------------+-------------------------------------------------+ +| policy | hex | 0x30000 | a 64-bit guest policy | ++---------------------------+-------------------------------------------------+ +| guest-visible-workarounds | string| 0 | 16-byte base64 encoded string| +| | | | for guest OS visible | +| | | | workarounds. | ++---------------------------+-------------------------------------------------+ + +``SNP_LAUNCH_UPDATE`` encrypts the memory region using the cryptographic context +created via the ``SNP_LAUNCH_START`` command. If required, this command can be +called multiple times to encrypt different memory regions. The command also +calculates the measurement of the memory contents as it encrypts. + +``SNP_LAUNCH_FINISH`` finalizes the guest launch flow. Optionally, while +finalizing the launch the firmware can perform checks on the launch digest +computing through the ``SNP_LAUNCH_UPDATE``. To perform the check the user must +supply the id block, authentication blob and host data that should be included +in the attestation report. See the SEV-SNP spec for further details. + +The ``SNP_LAUNCH_FINISH`` uses the following parameters, which can be configured +by the corresponding parameters documented in the QAPI schema for the +'sev-snp-guest' object. + ++--------------------+-------+----------+-------------------------------------+ +| key | type | default | meaning | ++--------------------+-------+----------+-------------------------------------+ +| id-block | string| none | base64 encoded ID block | ++--------------------+-------+----------+-------------------------------------+ +| id-auth | string| none | base64 encoded authentication | +| | | | information | ++--------------------+-------+----------+-------------------------------------+ +| author-key-enabled | bool | 0 | auth block contains author key | ++--------------------+-------+----------+-------------------------------------+ +| host_data | string| none | host provided data | ++--------------------+-------+----------+-------------------------------------+ + +To launch a SEV-SNP guest (additional parameters are documented in the QAPI +schema for the 'sev-snp-guest' object):: + + # ${QEMU} \ + -machine ...,confidential-guest-support=sev0 \ + -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1 + + Debugging ---------
qapi/qom.json +58 -0
76 lines not on this page · raw message
target/i386/sev.h +1 -0
@@ -22,6 +22,7 @@#define TYPE_SEV_COMMON "sev-common"#define TYPE_SEV_GUEST "sev-guest" +#define TYPE_SEV_SNP_GUEST "sev-snp-guest"#define SEV_POLICY_NODBG 0x1#define SEV_POLICY_NOKS 0x2
target/i386/sev.c +253 -0
278 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PULL 21/45] i386/sev: Introduce 'sev-snp-guest' object
Quoted 23 lines · Paolo Bonzini
From: Brijesh Singh <[email protected]>
SEV-SNP support relies on a different set of properties/state than the existing 'sev-guest' object. This patch introduces the 'sev-snp-guest' object, which can be used to configure an SEV-SNP guest. For example, a default-configured SEV-SNP guest with no additional information passed in for use with attestation:
-object sev-snp-guest,id=sev0
or a fully-specified SEV-SNP guest where all spec-defined binary blobs are passed in as base64-encoded strings:
-object sev-snp-guest,id=sev0, \ policy=0x30000, \ init-flags=0, \ id-block=YWFhYWFhYWFhYWFhYWFhCg==, \ id-auth=CxHK/OKLkXGn/KpAC7Wl1FSiisWDbGTEKz..., \ author-key-enabled=on, \ host-data=LNkCWBRC5CcdGXirbNUV1OrsR28s..., \ guest-visible-workarounds=AA==, \
Quoted 8 lines
See the QAPI schema updates included in this patch for more usage details.
In some cases these blobs may be up to 4096 characters, but this is generally well below the default limit for linux hosts where command-line sizes are defined by the sysconf-configurable
ARG_MAXvalue, which defaults to 2097152 characters for Ubuntu hosts, for example.
Hi; Coverity reports (CID 1546887) an issue in this code:
Quoted 14 lines
target/i386/sev.c +14
-0+static void +sev_snp_guest_set_id_block (Object *obj,const char *value,Error **errp) +{ +SevSnpGuestState *sev_snp_guest =SEV_SNP_GUEST (obj); +struct kvm_sev_snp_launch_finish *finish = &sev_snp_guest->kvm_finish_conf; +gsize len; + +g_free (sev_snp_guest->id_block); +g_free ((guchar *)finish->id_block_uaddr); + +/* store the base64 str so we don't need to re-encode in getter */ + sev_snp_guest->id_block =g_strdup (value); + + finish->id_block_uaddr =
target/i386/sev.c static const TypeInfo sev_guest_info = { · line 1602
Quoted 10 lines
target/i386/sev.c +10
-0+ (uint64_t )qbase64_decode (sev_snp_guest->id_block,-1 , &len, errp); + +if (!finish->id_block_uaddr) { +return ; + } + +if (len !=KVM_SEV_SNP_ID_BLOCK_SIZE ) { +error_setg (errp,"parameter length of %lu not equal to %u" , + len,KVM_SEV_SNP_ID_BLOCK_SIZE ); +return ;
Here if len is not 96 then we return early...
target/i386/sev.c static const TypeInfo sev_guest_info = { · line 1605
Quoted 3 lines
target/i386/sev.c +3
-0+ } + + finish->id_block_en = (len) ?1 :0 ;
...but here we check whether len is 0, which it can never be.
What was the intention here?
Side notes: you don't need to cast the argument to g_free(); and you don't need to put brackets around a single argument like "len".
thanks
-- PMM
[PULL 20/45] i386/sev: Move sev_launch_finish to separate class method
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
When sev-snp-guest objects are introduced there will be a number of differences in how the launch finish is handled compared to the existing sev-guest object. Move sev_launch_finish() to a class method to make it easier to implement SNP-specific launch update functionality later.
Message-ID: <[email protected]>
--- target/i386/sev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target/i386/sev.c +7 -4
@@ -71,6 +71,7 @@ struct SevCommonStateClass {/* public */ int (*launch_start)(SevCommonState *sev_common); +void (*launch_finish)(SevCommonState *sev_common); };/**
@@ -801,12 +802,12 @@ static Notifier sev_machine_done_notify = { };static void -sev_launch_finish (SevGuestState *sev_guest) +sev_launch_finish (SevCommonState *sev_common) {int ret, error;trace_kvm_sev_launch_finish (); - ret =sev_ioctl (SEV_COMMON (sev_guest)->sev_fd,KVM_SEV_LAUNCH_FINISH ,0 , + ret =sev_ioctl (sev_common->sev_fd,KVM_SEV_LAUNCH_FINISH ,0 , &error);if (ret) { error_report("%s: LAUNCH_FINISH ret=%d fw_error=%d '%s'",
@@ -814,7 +815,7 @@ sev_launch_finish(SevGuestState *sev_guest)exit (1 ); } -sev_set_guest_state (SEV_COMMON (sev_guest),SEV_STATE_RUNNING ); +sev_set_guest_state (sev_common,SEV_STATE_RUNNING );/* add migration blocker */ error_setg(&sev_mig_blocker,
@@ -826,10 +827,11 @@ static void sev_vm_state_change(void *opaque, bool running, RunState state) {SevCommonState *sev_common = opaque; +SevCommonStateClass *klass =SEV_COMMON_GET_CLASS (opaque);if (running) {if (!sev_check_state (sev_common,SEV_STATE_RUNNING )) { -sev_launch_finish (SEV_GUEST (sev_common)); + klass->launch_finish (sev_common); } } }
@@ -1457,6 +1459,7 @@ sev_guest_class_init(ObjectClass *oc, void *data)SevCommonStateClass *klass =SEV_COMMON_CLASS (oc); klass->launch_start = sev_launch_start; + klass->launch_finish = sev_launch_finish; object_class_property_add_str(oc, "dh-cert-file", sev_guest_get_dh_cert_file,
Signature · 1 line
2.45.1
[PULL 13/45] update-linux-headers: move pvpanic.h to correct directory
In reply to Paolo BonziniLinux has <misc/pvpanic.h>, not <linux/pvpanic.h>. Use the same directory for QEMU's include/standard-headers/ copy.
---
include/standard-headers/{linux => misc}/pvpanic.h | 0
hw/misc/pvpanic-isa.c | 2 +-
hw/misc/pvpanic-pci.c | 2 +-
hw/misc/pvpanic.c | 2 +-
scripts/update-linux-headers.sh | 6 ++++--
5 files changed, 7 insertions(+), 5 deletions(-)
rename include/standard-headers/{linux => misc}/pvpanic.h (100%)include/standard-headers/misc/pvpanic.h renamed from include/standard-headers/linux/pvpanic.h +0 -0
hw/misc/pvpanic-isa.c +1 -1
@@ -21,7 +21,7 @@#include "hw/misc/pvpanic.h" #include "qom/object.h" #include "hw/isa/isa.h" -#include "standard-headers/linux/pvpanic.h" +#include "standard-headers/misc/pvpanic.h" #include "hw/acpi/acpi_aml_interface.h" OBJECT_DECLARE_SIMPLE_TYPE (PVPanicISAState,PVPANIC_ISA_DEVICE )
hw/misc/pvpanic-pci.c +1 -1
@@ -21,7 +21,7 @@#include "hw/misc/pvpanic.h" #include "qom/object.h" #include "hw/pci/pci_device.h" -#include "standard-headers/linux/pvpanic.h" +#include "standard-headers/misc/pvpanic.h" OBJECT_DECLARE_SIMPLE_TYPE (PVPanicPCIState,PVPANIC_PCI_DEVICE )
hw/misc/pvpanic.c +1 -1
@@ -21,7 +21,7 @@#include "hw/qdev-properties.h" #include "hw/misc/pvpanic.h" #include "qom/object.h" -#include "standard-headers/linux/pvpanic.h" +#include "standard-headers/misc/pvpanic.h" static void handle_event (int event) {
scripts/update-linux-headers.sh +4 -2
@@ -231,10 +231,12 @@ for i in "$hdrdir"/include/linux/*virtio*.h \ "$hdrdir/include/linux/const.h" \ "$hdrdir/include/linux/kernel.h" \ "$hdrdir/include/linux/vhost_types.h" \ - "$hdrdir/include/linux/sysinfo.h" \ - "$hdrdir/include/misc/pvpanic.h"; do + "$hdrdir/include/linux/sysinfo.h"; do cp_portable "$i" "$output/include/standard-headers/linux" done +mkdir -p "$output/include/standard-headers/misc" +cp_portable "$hdrdir/include/misc/pvpanic.h" \ + "$output/include/standard-headers/misc" mkdir -p "$output/include/standard-headers/drm" cp_portable "$hdrdir/include/drm/drm_fourcc.h" \ "$output/include/standard-headers/drm"
Signature · 1 line
2.45.1
[PULL 03/45] meson: assume x86-64-v2 baseline ISA
In reply to Paolo Bonzinix86-64-v2 processors were released in 2008, assume that we have one. Unfortunately there is no GCC flag to enable all the features without disabling what came after; so enable them one by one.
--- meson.build | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
meson.build +7 -3
@@ -336,9 +336,13 @@ if host_arch == 'i386' and not cc.links(''' qemu_common_flags = ['-march=i486'] + qemu_common_flags endif -# ??? Only extremely old AMD cpus do not have cmpxchg16b. -# If we truly care, we should simply detect this case at -# runtime and generate the fallback to serial emulation. +# Assume x86-64-v2 (minus CMPXCHG16B for 32-bit code) +if host_arch == 'i386' + qemu_common_flags = ['-mfpmath=sse'] + qemu_common_flags +endif +if host_arch in ['i386', 'x86_64'] + qemu_common_flags = ['-mpopcnt', '-msse4.2'] + qemu_common_flags +endif if host_arch == 'x86_64' qemu_common_flags = ['-mcx16'] + qemu_common_flags endif
Signature · 1 line
2.45.1
[PULL 15/45] update-linux-headers: import linux/kvm_para.h header
In reply to Paolo BonziniRight now QEMU is importing arch/x86/include/uapi/asm/kvm_para.h because it includes definitions for kvmclock and for KVM CPUID bits. However, other definitions for KVM hypercall values and return codes are included in include/uapi/linux/kvm_para.h and they will be used by SEV-SNP.
To ensure that it is possible to include both <linux/kvm_para.h> and "standard-headers/asm-x86/kvm_para.h" without conflicts, provide linux/kvm_para.h as a portable header too, and forward linux-headers/ files to those in include/standard-headers. Note that <linux/kvm_para.h> will include architecture-specific definitions as well, but "standard-headers/linux/kvm_para.h" will not because it can be used in architecture-independent files.
This could easily be extended to other architectures, but right now they do not need any symbol in their specific kvm_para.h files.
--- include/standard-headers/linux/kvm_para.h | 38 +++++++++++++++++++++++ linux-headers/asm-x86/kvm_para.h | 1 + linux-headers/linux/kvm_para.h | 2 ++ scripts/update-linux-headers.sh | 22 ++++++++++++- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 include/standard-headers/linux/kvm_para.h create mode 100644 linux-headers/asm-x86/kvm_para.h create mode 100644 linux-headers/linux/kvm_para.h
include/standard-headers/linux/kvm_para.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __LINUX_KVM_PARA_H +#define __LINUX_KVM_PARA_H + +/* +* This header file provides a method for making a hypercall to the host +* Architectures should define: +* - kvm_hypercall0, kvm_hypercall1... +* - kvm_arch_para_features +* - kvm_para_available +*/ + +/* Return values for hypercalls */ +#define KVM_ENOSYS 1000 +#define KVM_EFAULT EFAULT +#define KVM_EINVAL EINVAL +#define KVM_E2BIG E2BIG +#define KVM_EPERM EPERM +#define KVM_EOPNOTSUPP 95 + +#define KVM_HC_VAPIC_POLL_IRQ 1 +#define KVM_HC_MMU_OP 2 +#define KVM_HC_FEATURES 3 +#define KVM_HC_PPC_MAP_MAGIC_PAGE 4 +#define KVM_HC_KICK_CPU 5 +#define KVM_HC_MIPS_GET_CLOCK_FREQ 6 +#define KVM_HC_MIPS_EXIT_VM 7 +#define KVM_HC_MIPS_CONSOLE_OUTPUT 8 +#define KVM_HC_CLOCK_PAIRING 9 +#define KVM_HC_SEND_IPI 10 +#define KVM_HC_SCHED_YIELD 11 +#define KVM_HC_MAP_GPA_RANGE 12 + +/* +* hypercalls use architecture specific +*/ + +#endif /* __LINUX_KVM_PARA_H */
linux-headers/asm-x86/kvm_para.h new file +1 -0
@@ -0,0 +1 @@ +#include "standard-headers/asm-x86/kvm_para.h"
linux-headers/linux/kvm_para.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "standard-headers/linux/kvm_para.h" +#include <asm/kvm_para.h>
scripts/update-linux-headers.sh +21 -1
@@ -63,6 +63,7 @@ cp_portable() { -e 'linux/kernel' \ -e 'linux/sysinfo' \ -e 'asm/setup_data.h' \ + -e 'asm/kvm_para.h' \ > /dev/null then echo "Unexpected #include in input file $f".
@@ -70,6 +71,15 @@ cp_portable() { fi header=$(basename "$f"); + + if test -z "$arch"; then + # Let users of include/standard-headers/linux/ headers pick the + # asm-* header that they care about + arch_cmd='/<asm\/\([^>]*\)>/d' + else + arch_cmd='s/<asm\/\([^>]*\)>/"standard-headers\/asm-'$arch'\/\1"/' + fi + sed -e 's/__aligned_u64/__u64 __attribute__((aligned(8)))/g' \ -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \ -e 's/u\([0-9][0-9]*\)/uint\1_t/g' \
@@ -78,7 +88,7 @@ cp_portable() { -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \ -e 's/"\(input-event-codes\.h\)"/"standard-headers\/linux\/\1"/' \ -e 's/<linux\/\([^>]*\)>/"standard-headers\/linux\/\1"/' \ - -e 's/<asm\/\([^>]*\)>/"standard-headers\/asm-'$arch'\/\1"/' \ + -e "$arch_cmd" \ -e 's/__bitwise//' \ -e 's/__attribute__((packed))/QEMU_PACKED/' \ -e 's/__inline__/inline/' \
@@ -158,7 +168,12 @@ EOF cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/" cp "$hdrdir/include/asm/unistd_x32.h" "$output/linux-headers/asm-x86/" cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-x86/" + cp_portable "$hdrdir/include/asm/kvm_para.h" "$output/include/standard-headers/asm-$arch" + cat <<EOF >$output/linux-headers/asm-$arch/kvm_para.h +#include "standard-headers/asm-$arch/kvm_para.h" +EOF + # Remove everything except the macros from bootparam.h avoiding the # unnecessary import of several video/ist/etc headers sed -e '/__ASSEMBLY__/,/__ASSEMBLY__/d' \
@@ -208,6 +223,10 @@ if [ -d "$linux/LICENSES" ]; then done fi +cat <<EOF >$output/linux-headers/linux/kvm_para.h +#include "standard-headers/linux/kvm_para.h" +#include <asm/kvm_para.h> +EOF cat <<EOF >$output/linux-headers/linux/virtio_config.h #include "standard-headers/linux/virtio_config.h" EOF
@@ -230,6 +249,7 @@ for i in "$hdrdir"/include/linux/*virtio*.h \ "$hdrdir/include/linux/ethtool.h" \ "$hdrdir/include/linux/const.h" \ "$hdrdir/include/linux/kernel.h" \ + "$hdrdir/include/linux/kvm_para.h" \ "$hdrdir/include/linux/vhost_types.h" \ "$hdrdir/include/linux/sysinfo.h"; do cp_portable "$i" "$output/include/standard-headers/linux"
Signature · 1 line
2.45.1
[PULL 14/45] linux-headers: Update to current kvm/next
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
This updates kernel headers to commit 6f627b425378 ("KVM: SVM: Add module parameter to enable SEV-SNP", 2024-05-12). The SNP host patches will be included in Linux 6.11, to be released next July.
Also brings in an linux-headers/linux/vhost.h fix from v6.9-rc4.
Message-ID: <[email protected]>
--- linux-headers/asm-loongarch/kvm.h | 4 +++ linux-headers/asm-riscv/kvm.h | 1 + linux-headers/asm-x86/kvm.h | 52 ++++++++++++++++++++++++++++++- linux-headers/linux/vhost.h | 15 ++++----- 4 files changed, 64 insertions(+), 8 deletions(-)
linux-headers/asm-loongarch/kvm.h +4 -0
@@ -17,6 +17,8 @@#define KVM_COALESCED_MMIO_PAGE_OFFSET 1#define KVM_DIRTY_LOG_PAGE_OFFSET 64 +#define KVM_GUESTDBG_USE_SW_BP 0x00010000 +/* * for KVM_GET_REGS and KVM_SET_REGS */
@@ -72,6 +74,8 @@ struct kvm_fpu {#define KVM_REG_LOONGARCH_COUNTER (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 1)#define KVM_REG_LOONGARCH_VCPU_RESET (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 2) +/* Debugging: Special instruction for software breakpoint */ +#define KVM_REG_LOONGARCH_DEBUG_INST (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 3)#define LOONGARCH_REG_SHIFT 3#define LOONGARCH_REG_64 (TYPE ,REG ) (TYPE | KVM_REG_SIZE_U64 | (REG << LOONGARCH_REG_SHIFT))
linux-headers/asm-riscv/kvm.h +1 -0
@@ -167,6 +167,7 @@ enum KVM_RISCV_ISA_EXT_ID {KVM_RISCV_ISA_EXT_ZFA ,KVM_RISCV_ISA_EXT_ZTSO ,KVM_RISCV_ISA_EXT_ZACAS , +KVM_RISCV_ISA_EXT_SSCOFPMF , KVM_RISCV_ISA_EXT_MAX, };
linux-headers/asm-x86/kvm.h +51 -1
75 lines not on this page · raw message
linux-headers/linux/vhost.h +8 -7
@@ -179,12 +179,6 @@/* Get the config size */ #define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32) -/* Get the count of all virtqueues */ -#define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32) - -/* Get the number of virtqueue groups. */ -#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32) -/* Get the number of address spaces. */ #define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int)
@@ -228,10 +222,17 @@#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ struct vhost_vring_state) + +/* Get the count of all virtqueues */ +#define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32) + +/* Get the number of virtqueue groups. */ +#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32) +/* Get the queue size of a specific virtqueue. * userspace set the vring index in vhost_vring_state.index * kernel set the queue size in vhost_vring_state.num */ -#define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x80, \ +#define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ struct vhost_vring_state)#endif
Signature · 1 line
2.45.1
[PULL 19/45] i386/sev: Move sev_launch_update to separate class method
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
When sev-snp-guest objects are introduced there will be a number of differences in how the launch data is handled compared to the existing sev-guest object. Move sev_launch_start() to a class method to make it easier to implement SNP-specific launch update functionality later.
Message-ID: <[email protected]>
--- target/i386/sev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
target/i386/sev.c +10 -3
@@ -69,6 +69,8 @@ struct SevCommonState {struct SevCommonStateClass {X86ConfidentialGuestClass parent_class; +/* public */ +int (*launch_start)(SevCommonState *sev_common); };/**
@@ -632,16 +634,16 @@ sev_read_file_base64(const char *filename, guchar **data, gsize *len) }static int -sev_launch_start (SevGuestState *sev_guest) +sev_launch_start (SevCommonState *sev_common) {gsize sz;int ret =1 ;int fw_error, rc; +SevGuestState *sev_guest =SEV_GUEST (sev_common);struct kvm_sev_launch_start start = { .handle = sev_guest->handle, .policy = sev_guest->policy };guchar *session =NULL , *dh_cert =NULL ; -SevCommonState *sev_common =SEV_COMMON (sev_guest);if (sev_guest->session_file) {if (sev_read_file_base64 (sev_guest->session_file, &session, &sz) <0 ) {
@@ -862,6 +864,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)uint32_t ebx;uint32_t host_cbitpos;struct sev_user_data_status status = {}; +SevCommonStateClass *klass =SEV_COMMON_GET_CLASS (cgs); ret =ram_block_discard_disable (true);if (ret) {
@@ -952,7 +955,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) goto err; } -sev_launch_start (SEV_GUEST (sev_common)); + ret = klass->launch_start (sev_common);if (ret) {error_setg (errp,"%s: failed to create encryption context" , __func__); goto err;
@@ -1451,6 +1454,10 @@ static void sev_guest_set_legacy_vm_type(Object *obj, bool value, Error **errp)static void sev_guest_class_init (ObjectClass *oc,void *data) { +SevCommonStateClass *klass =SEV_COMMON_CLASS (oc); + + klass->launch_start = sev_launch_start; +object_class_property_add_str (oc,"dh-cert-file" , sev_guest_get_dh_cert_file, sev_guest_set_dh_cert_file);
Signature · 1 line
2.45.1
[PULL 24/45] i386/sev: Add snp_kvm_init() override for SNP class
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
SNP does not support SMM and requires guest_memfd for private guest memory, so add SNP specific kvm_init() functionality in snp_kvm_init() class method.
Message-ID: <[email protected]>
--- target/i386/sev.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
target/i386/sev.c +23 -1
@@ -885,12 +885,12 @@ out:static int sev_common_kvm_init (ConfidentialGuestSupport *cgs,Error **errp) { -SevCommonState *sev_common =SEV_COMMON (cgs);char *devname;int ret, fw_error, cmd;uint32_t ebx;uint32_t host_cbitpos;struct sev_user_data_status status = {}; +SevCommonState *sev_common =SEV_COMMON (cgs);SevCommonStateClass *klass =SEV_COMMON_GET_CLASS (cgs); sev_common->state =SEV_STATE_UNINIT ;
@@ -1030,6 +1030,21 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)return 0 ; } +static int sev_snp_kvm_init (ConfidentialGuestSupport *cgs,Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +X86MachineState *x86ms =X86_MACHINE (ms); + +if (x86ms->smm ==ON_OFF_AUTO_AUTO ) { + x86ms->smm =ON_OFF_AUTO_OFF ; + }else if (x86ms->smm ==ON_OFF_AUTO_ON ) { +error_setg (errp,"SEV-SNP does not support SMM." ); +return -1 ; + } + +return 0 ; +} +int sev_encrypt_flash (uint8_t *ptr,uint64_t len,Error **errp) {
@@ -1752,6 +1767,10 @@ sev_snp_guest_set_host_data(Object *obj, const char *value, Error **errp)static void sev_snp_guest_class_init (ObjectClass *oc,void *data) { +SevCommonStateClass *klass =SEV_COMMON_CLASS (oc); + + klass->kvm_init = sev_snp_kvm_init; +object_class_property_add (oc,"policy" ,"uint64" , sev_snp_guest_get_policy, sev_snp_guest_set_policy,NULL ,NULL );
@@ -1778,8 +1797,11 @@ sev_snp_guest_class_init(ObjectClass *oc, void *data)static void sev_snp_guest_instance_init (Object *obj) { +ConfidentialGuestSupport *cgs =CONFIDENTIAL_GUEST_SUPPORT (obj);SevSnpGuestState *sev_snp_guest =SEV_SNP_GUEST (obj); + cgs->require_guest_memfd = true; +/* default init/start/finish params for kvm */ sev_snp_guest->kvm_start_conf.policy =DEFAULT_SEV_SNP_POLICY ; }
Signature · 1 line
2.45.1
[PULL 23/45] i386/sev: Add sev_kvm_init() override for SEV class
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
Some aspects of the init routine SEV are specific to SEV and not applicable for SNP guests, so move the SEV-specific bits into separate class method and retain only the common functionality.
Message-ID: <[email protected]>
--- target/i386/sev.c | 72 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 21 deletions(-)
target/i386/sev.c +51 -21
@@ -73,6 +73,7 @@ struct SevCommonStateClass {/* public */ int (*launch_start)(SevCommonState *sev_common);void (*launch_finish)(SevCommonState *sev_common); +int (*kvm_init)(ConfidentialGuestSupport *cgs,Error **errp); };/**
@@ -882,7 +883,7 @@ out:return sev_common->kvm_type; } -static int sev_kvm_init (ConfidentialGuestSupport *cgs,Error **errp) +static int sev_common_kvm_init (ConfidentialGuestSupport *cgs,Error **errp) {SevCommonState *sev_common =SEV_COMMON (cgs);char *devname;
@@ -892,12 +893,6 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)struct sev_user_data_status status = {};SevCommonStateClass *klass =SEV_COMMON_GET_CLASS (cgs); - ret =ram_block_discard_disable (true); -if (ret) { -error_report ("%s: cannot disable RAM discard" , __func__); -return -1 ; - } - sev_common->state =SEV_STATE_UNINIT ;host_cpuid (0x8000001F ,0 ,NULL , &ebx,NULL ,NULL );
@@ -911,7 +906,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)if (host_cbitpos != sev_common->cbitpos) {error_setg (errp,"%s: cbitpos check failed, host '%d' requested '%d'" , __func__, host_cbitpos, sev_common->cbitpos); - goto err; +return -1 ; }/*
@@ -924,7 +919,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)error_setg (errp,"%s: reduced_phys_bits check failed," " it should be in the range of 1 to 63, requested '%d'" , __func__, sev_common->reduced_phys_bits); - goto err; +return -1 ; } devname =object_property_get_str (OBJECT (sev_common),"sev-device" ,NULL );
@@ -933,7 +928,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)error_setg (errp,"%s: Failed to open %s '%s'" , __func__, devname,strerror (errno));g_free (devname); - goto err; +return -1 ; }g_free (devname);
@@ -943,7 +938,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)error_setg (errp,"%s: failed to get platform status ret=%d " "fw_error='%d: %s'" , __func__, ret, fw_error,fw_error_to_str (fw_error)); - goto err; +return -1 ; } sev_common->build_id = status.build; sev_common->api_major = status.api_major;
@@ -953,7 +948,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)if (!kvm_kernel_irqchip_allowed ()) {error_setg (errp,"%s: SEV-ES guests require in-kernel irqchip" "support" , __func__); - goto err; +return -1 ; } }
@@ -962,7 +957,7 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)error_setg (errp,"%s: guest policy requires SEV-ES, but " "host SEV-ES support unavailable" , __func__); - goto err; +return -1 ; } }
@@ -980,25 +975,59 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)if (ret) {error_setg (errp,"%s: failed to initialize ret=%d fw_error=%d '%s'" , __func__, ret, fw_error,fw_error_to_str (fw_error)); - goto err; +return -1 ; } ret = klass->launch_start (sev_common);if (ret) {error_setg (errp,"%s: failed to create encryption context" , __func__); - goto err; +return -1 ; + } + +if (klass->kvm_init && klass->kvm_init (cgs, errp)) { +return -1 ; } -ram_block_notifier_add (&sev_ram_notifier); -qemu_add_machine_init_done_notifier (&sev_machine_done_notify);qemu_add_vm_change_state_handler (sev_vm_state_change, sev_common); cgs->ready = true;return 0 ; -err: -ram_block_discard_disable (false); -return -1 ; +} + +static int sev_kvm_init (ConfidentialGuestSupport *cgs,Error **errp) +{ +int ret; + +/* +* SEV/SEV-ES rely on pinned memory to back guest RAM so discarding +* isn't actually possible. With SNP, only guest_memfd pages are used +* for private guest memory, so discarding of shared memory is still +* possible.. +*/ + ret =ram_block_discard_disable (true); +if (ret) { +error_setg (errp,"%s: cannot disable RAM discard" , __func__); +return -1 ; + } + +/* +* SEV uses these notifiers to register/pin pages prior to guest use, +* but SNP relies on guest_memfd for private pages, which has its +* own internal mechanisms for registering/pinning private memory. +*/ +ram_block_notifier_add (&sev_ram_notifier); + +/* +* The machine done notify event is used for SEV guests to get the +* measurement of the encrypted images. When SEV-SNP is enabled, the +* measurement is part of the guest attestation process where it can +* be collected without any reliance on the VMM. So skip registering +* the notifier for SNP in favor of using guest attestation instead. +*/ +qemu_add_machine_init_done_notifier (&sev_machine_done_notify); + +return 0 ; }int
@@ -1397,7 +1426,7 @@ sev_common_class_init(ObjectClass *oc, void *data)ConfidentialGuestSupportClass *klass =CONFIDENTIAL_GUEST_SUPPORT_CLASS (oc);X86ConfidentialGuestClass *x86_klass =X86_CONFIDENTIAL_GUEST_CLASS (oc); - klass->kvm_init = sev_kvm_init; + klass->kvm_init = sev_common_kvm_init; x86_klass->kvm_type = sev_kvm_type; object_class_property_add_str(oc, "sev-device",
@@ -1486,6 +1515,7 @@ sev_guest_class_init(ObjectClass *oc, void *data) klass->launch_start = sev_launch_start; klass->launch_finish = sev_launch_finish; + klass->kvm_init = sev_kvm_init; object_class_property_add_str(oc, "dh-cert-file", sev_guest_get_dh_cert_file,
Signature · 1 line
2.45.1
[PULL 09/45] target/i386: fix memory opsize for Mov to/from Seg
In reply to Paolo BonziniFrom: Xinyu Li <[email protected]>
This commit fixes an issue with MOV instructions (0x8C and 0x8E) involving segment registers; MOV to segment register's source is 16-bit, while MOV from segment register has to explicitly set the memory operand size to 16 bits. Introduce a new flag X86_SPECIAL_Op0_Mw to handle this specification correctly.
Message-ID: <[email protected]>
--- target/i386/tcg/decode-new.h | 3 +++ target/i386/tcg/decode-new.c.inc | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
target/i386/tcg/decode-new.h +3 -0
@@ -203,6 +203,9 @@ typedef enum X86InsnSpecial {/* When loaded into s->T0, register operand 1 is zero/sign extended. */ X86_SPECIAL_SExtT0, X86_SPECIAL_ZExtT0, + +/* Memory operand size of MOV from segment register is MO_16 */ + X86_SPECIAL_Op0_Mw, } X86InsnSpecial;/*
target/i386/tcg/decode-new.c.inc +11 -2
@@ -202,6 +202,7 @@ #define avx_movx .special = X86_SPECIAL_AVXExtMov, #define sextT0 .special = X86_SPECIAL_SExtT0, #define zextT0 .special = X86_SPECIAL_ZExtT0, +#define op0_Mw .special = X86_SPECIAL_Op0_Mw, #define vex1 .vex_class = 1, #define vex1_rep3 .vex_class = 1, .vex_special = X86_VEX_REPScalar,
@@ -1576,9 +1577,10 @@ static const X86OpEntry opcodes_root[256] = { [0x89] = X86_OP_ENTRY3(MOV, E,v, G,v, None, None), [0x8A] = X86_OP_ENTRY3(MOV, G,b, E,b, None, None), [0x8B] = X86_OP_ENTRY3(MOV, G,v, E,v, None, None), - [0x8C] = X86_OP_ENTRY3(MOV, E,v, S,w, None, None), + /* Missing in Table A-2: memory destination is always 16-bit. */ + [0x8C] = X86_OP_ENTRY3(MOV, E,v, S,w, None, None, op0_Mw), [0x8D] = X86_OP_ENTRY3(LEA, G,v, M,v, None, None, noseg), - [0x8E] = X86_OP_ENTRY3(MOV, S,w, E,v, None, None), + [0x8E] = X86_OP_ENTRY3(MOV, S,w, E,w, None, None), [0x8F] = X86_OP_GROUPw(group1A, E,v), [0x98] = X86_OP_ENTRY1(CBW, 0,v), /* rAX */
@@ -2514,6 +2516,13 @@ static void disas_insn(DisasContext *s, CPUState *cpu) s->override = -1; break; + case X86_SPECIAL_Op0_Mw: + assert(decode.op[0].unit == X86_OP_INT); + if (decode.op[0].has_ea) { + decode.op[0].ot = MO_16; + } + break; + default: break; }
Signature · 1 line
2.45.1
[PULL 11/45] target/i386: fix xsave.flat from kvm-unit-tests
In reply to Paolo Bonzinixsave.flat checks that "executing the XSETBV instruction causes a general- protection fault (#GP) if ECX = 0 and EAX[2:1] has the value 10b". QEMU allows that option, so the test fails. Add the condition.
--- target/i386/tcg/fpu_helper.c | 5 +++++ 1 file changed, 5 insertions(+)
target/i386/tcg/fpu_helper.c +5 -0
@@ -3142,6 +3142,11 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask) goto do_gpf; } +/* SSE can be disabled, but only if AVX is disabled too. */ +if ((mask & (XSTATE_SSE_MASK |XSTATE_YMM_MASK )) ==XSTATE_YMM_MASK ) { + goto do_gpf; + } +/* Disallow enabling unimplemented features. */ cpu_x86_cpuid (env,0x0d ,0 , &ena_lo, &dummy, &dummy, &ena_hi); ena = ((uint64_t )ena_hi <<32 ) | ena_lo;
Signature · 1 line
2.45.1
[PULL 18/45] i386/sev: Introduce "sev-common" type to encapsulate common SEV state
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
Currently all SEV/SEV-ES functionality is managed through a single 'sev-guest' QOM type. With upcoming support for SEV-SNP, taking this same approach won't work well since some of the properties/state managed by 'sev-guest' is not applicable to SEV-SNP, which will instead rely on a new QOM type with its own set of properties/state.
To prepare for this, this patch moves common state into an abstract 'sev-common' parent type to encapsulate properties/state that are common to both SEV/SEV-ES and SEV-SNP, leaving only SEV/SEV-ES-specific properties/state in the current 'sev-guest' type. This should not affect current behavior or command-line options.
As part of this patch, some related changes are also made:
- a static 'sev_guest' variable is currently used to keep track of the 'sev-guest' instance. SEV-SNP would similarly introduce an 'sev_snp_guest' static variable. But these instances are now available via qdev_get_machine()->cgs, so switch to using that instead and drop the static variable.
- 'sev_guest' is currently used as the name for the static variable holding a pointer to the 'sev-guest' instance. Re-purpose the name as a local variable referring the 'sev-guest' instance, and use that consistently throughout the code so it can be easily distinguished from sev-common/sev-snp-guest instances.
- 'sev' is generally used as the name for local variables holding a pointer to the 'sev-guest' instance. In cases where that now points to common state, use the name 'sev_common'; in cases where that now points to state specific to 'sev-guest' instance, use the name 'sev_guest'
In order to enable kernel-hashes for SNP, pull it from SevGuestProperties to its parent SevCommonProperties so it will be available for both SEV and SNP.
Message-ID: <[email protected]>
--- qapi/qom.json | 40 ++-- target/i386/sev.h | 3 + target/i386/sev.c | 493 ++++++++++++++++++++++++++-------------------- 3 files changed, 303 insertions(+), 233 deletions(-)
qapi/qom.json +25 -15
@@ -875,20 +875,12 @@ 'data': { '*filename': 'str' } } ## -# @SevGuestProperties: +# @SevCommonProperties: # -# Properties for sev-guest objects. +# Properties common to objects that are derivatives of sev-common. # # @sev-device: SEV device to use (default: "/dev/sev") # -# @dh-cert-file: guest owners DH certificate (encoded with base64) -# -# @session-file: guest owners session parameters (encoded with base64) -# -# @policy: SEV policy value (default: 0x1) -# -# @handle: SEV firmware handle (default: 0) -# # @cbitpos: C-bit location in page table entry (default: 0) # # @reduced-phys-bits: number of bits in physical addresses that become
@@ -898,6 +890,27 @@ # designated guest firmware page for measured boot with -kernel # (default: false) (since 6.2) # +# Since: 9.1 +## +{ 'struct': 'SevCommonProperties', + 'data': { '*sev-device': 'str', + '*cbitpos': 'uint32', + 'reduced-phys-bits': 'uint32', + '*kernel-hashes': 'bool' } } + +## +# @SevGuestProperties: +# +# Properties for sev-guest objects. +# +# @dh-cert-file: guest owners DH certificate (encoded with base64) +# +# @session-file: guest owners session parameters (encoded with base64) +# +# @policy: SEV policy value (default: 0x1) +# +# @handle: SEV firmware handle (default: 0) +# # @legacy-vm-type: Use legacy KVM_SEV_INIT KVM interface for creating the VM. # The newer KVM_SEV_INIT2 interface syncs additional vCPU # state when initializing the VMSA structures, which will
@@ -909,14 +922,11 @@ # Since: 2.12 ## { 'struct': 'SevGuestProperties', - 'data': { '*sev-device': 'str', - '*dh-cert-file': 'str', + 'base': 'SevCommonProperties', + 'data': { '*dh-cert-file': 'str', '*session-file': 'str', '*policy': 'uint32', '*handle': 'uint32', - '*cbitpos': 'uint32', - 'reduced-phys-bits': 'uint32', - '*kernel-hashes': 'bool', '*legacy-vm-type': 'bool' } } ##
target/i386/sev.h +3 -0
@@ -20,6 +20,9 @@#include "exec/confidential-guest-support.h" +#define TYPE_SEV_COMMON "sev-common" +#define TYPE_SEV_GUEST "sev-guest" +#define SEV_POLICY_NODBG 0x1#define SEV_POLICY_NOKS 0x2#define SEV_POLICY_ES 0x4
target/i386/sev.c +275 -218
913 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PULL 18/45] i386/sev: Introduce "sev-common" type to encapsulate common SEV state
Quoted 35 lines · Paolo Bonzini
From: Michael Roth <[email protected]>
Currently all SEV/SEV-ES functionality is managed through a single 'sev-guest' QOM type. With upcoming support for SEV-SNP, taking this same approach won't work well since some of the properties/state managed by 'sev-guest' is not applicable to SEV-SNP, which will instead rely on a new QOM type with its own set of properties/state.
To prepare for this, this patch moves common state into an abstract 'sev-common' parent type to encapsulate properties/state that are common to both SEV/SEV-ES and SEV-SNP, leaving only SEV/SEV-ES-specific properties/state in the current 'sev-guest' type. This should not affect current behavior or command-line options.
As part of this patch, some related changes are also made:
- a static '
sev_guest' variable is currently used to keep track of the 'sev-guest' instance. SEV-SNP would similarly introduce an 'sev_snp_guest' static variable. But these instances are now available via qdev_get_machine()->cgs, so switch to using that instead and drop the static variable.- '
sev_guest' is currently used as the name for the static variable holding a pointer to the 'sev-guest' instance. Re-purpose the name as a local variable referring the 'sev-guest' instance, and use that consistently throughout the code so it can be easily distinguished from sev-common/sev-snp-guest instances.- 'sev' is generally used as the name for local variables holding a pointer to the 'sev-guest' instance. In cases where that now points to common state, use the name '
sev_common'; in cases where that now points to state specific to 'sev-guest' instance, use the name 'sev_guest'
Quoted 3 lines
In order to enable kernel-hashes for SNP, pull it from SevGuestProperties to its parent SevCommonProperties so it will be available for both SEV and SNP.
Hi; Coverity points out a problem in this code (CID 1546885):
target/i386/sev.c static SevCapability *sev_get_capabilities(Error **errp) · line 496
Quoted 8 lines
target/i386/sev.c +3
-1@@ -540,12 +491,21 @@ static SevCapability *sev_get_capabilities(Error **errp)return NULL ; } - fd =open (DEFAULT_SEV_DEVICE ,O_RDWR ); + sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); +if (!sev_common) { +error_setg (errp,"SEV is not configured" );
Here we check for a NULL pointer, but we forget to "return", so execution will continue on...
target/i386/sev.c static SevCapability *sev_get_capabilities(Error **errp) · line 500
Quoted 4 lines
target/i386/sev.c +4
-0+ } + + sev_device =object_property_get_str (OBJECT (sev_common),"sev-device" , + &error_abort);
...and QEMU will crash here when object_property_get_str() dereferences the NULL pointer.
Adding a "return NULL;" should fix this.
thanks
-- PMM
[PULL 42/45] i386/sev: Allow measured direct kernel boot on SNP
In reply to Paolo BonziniFrom: Dov Murik <[email protected]>
In SNP, the hashes page designated with a specific metadata entry published in AmdSev OVMF.
Therefore, if the user enabled kernel hashes (for measured direct boot), QEMU should prepare the content of hashes table, and during the processing of the metadata entry it copy the content into the designated page and encrypt it.
Note that in SNP (unlike SEV and SEV-ES) the measurements is done in whole 4KB pages. Therefore QEMU zeros the whole page that includes the hashes table, and fills in the kernel hashes area in that page, and then encrypts the whole page. The rest of the page is reserved for SEV launch secrets which are not usable anyway on SNP.
If the user disabled kernel hashes, QEMU pre-validates the kernel hashes page as a zero page.
Message-ID: <[email protected]>
--- include/hw/i386/pc.h | 2 + target/i386/sev.c | 113 ++++++++++++++++++++++++++++++++----------- 2 files changed, 86 insertions(+), 29 deletions(-)
include/hw/i386/pc.h +2 -0
@@ -172,6 +172,8 @@ typedef enum {SEV_DESC_TYPE_SNP_SECRETS ,/* The section contains address that can be used as a CPUID page */ SEV_DESC_TYPE_CPUID , +/* The section contains the region for kernel hashes for measured direct boot */ +SEV_DESC_TYPE_SNP_KERNEL_HASHES =0x10 , } ovmf_sev_metadata_desc_type;
target/i386/sev.c +84 -29
166 lines not on this page · raw message
Signature · 1 line
2.45.1
[PULL 12/45] update-linux-headers: fix forwarding to asm-generic headers
In reply to Paolo BonziniAfer commit 3efc75ad9d9 ("scripts/update-linux-headers.sh: Remove temporary directory inbetween", 2024-05-29), updating linux-headers/ results in errors such as
cp: cannot stat '/tmp/tmp.1A1Eejh1UE/headers/include/asm/bitsperlong.h': No such file or directory
because Loongarch does not have an asm/bitsperlong.h file and uses the generic version. Before commit 3efc75ad9d9, the missing file would incorrectly cause stale files to be included in linux-headers/. The files were never committed to qemu.git, but were wrong nevertheless. The build would just use the system version of the files, which is opposite to the idea of importing Linux header files into QEMU's tree.
Create forwarding headers, resembling the ones that are generated during a kernel build by scripts/Makefile.asm-generic, if a file is only installed under include/asm-generic/.
--- scripts/update-linux-headers.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +8 -1
@@ -118,7 +118,14 @@ for arch in $ARCHLIST; do rm -rf "$output/linux-headers/asm-$arch" mkdir -p "$output/linux-headers/asm-$arch" for header in kvm.h unistd.h bitsperlong.h mman.h; do - cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch" + if test -f "$hdrdir/include/asm/$header"; then + cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch" + elif test -f "$hdrdir/include/asm-generic/$header"; then + # not installed as <asm/$header>, but used as such in kernel sources + cat <<EOF >$output/linux-headers/asm-$arch/$header +#include <asm-generic/$header> +EOF + fi done if [ $arch = mips ]; then
Signature · 1 line
2.45.1
[PULL 22/45] i386/sev: Add a sev_snp_enabled() helper
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
Add a simple helper to check if the current guest type is SNP. Also have SNP-enabled imply that SEV-ES is enabled as well, and fix up any places where the sev_es_enabled() check is expecting a pure/non-SNP guest.
Message-ID: <[email protected]>
--- target/i386/sev.h | 2 ++ target/i386/sev.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
target/i386/sev.h +2 -0
@@ -45,9 +45,11 @@ typedef struct SevKernelLoaderContext {#ifdef CONFIG_SEV bool sev_enabled (void );bool sev_es_enabled (void ); +bool sev_snp_enabled (void );#else #define sev_enabled () 0#define sev_es_enabled () 0 +#define sev_snp_enabled () 0#endif uint32_t sev_get_cbit_position (void );
target/i386/sev.c +12 -1
@@ -325,12 +325,21 @@ sev_enabled(void)return !!object_dynamic_cast (OBJECT (cgs),TYPE_SEV_COMMON ); } +bool +sev_snp_enabled (void ) +{ +ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; + +return !!object_dynamic_cast (OBJECT (cgs),TYPE_SEV_SNP_GUEST ); +} +bool sev_es_enabled (void ) {ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; -return sev_enabled () && (SEV_GUEST (cgs)->policy &SEV_POLICY_ES ); +return sev_snp_enabled () || + (sev_enabled () &&SEV_GUEST (cgs)->policy &SEV_POLICY_ES ); }uint32_t
@@ -946,7 +955,9 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) "support", __func__); goto err; } + } +if (sev_es_enabled () && !sev_snp_enabled ()) {if (!(status.flags &SEV_STATUS_FLAGS_CONFIG_ES )) { error_setg(errp, "%s: guest policy requires SEV-ES, but " "host SEV-ES support unavailable",
Signature · 1 line
2.45.1
[PULL 41/45] i386/sev: Reorder struct declarations
In reply to Paolo BonziniFrom: Dov Murik <[email protected]>
Move the declaration of PaddedSevHashTable before SevSnpGuest so we can add a new such field to the latter.
No functional change intended.
Message-ID: <[email protected]>
--- target/i386/sev.c | 84 +++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 42 deletions(-)
target/i386/sev.c +42 -42
@@ -46,6 +46,48 @@ OBJECT_DECLARE_TYPE(SevCommonState, SevCommonStateClass, SEV_COMMON) OBJECT_DECLARE_TYPE(SevGuestState, SevCommonStateClass, SEV_GUEST)OBJECT_DECLARE_TYPE (SevSnpGuestState, SevCommonStateClass,SEV_SNP_GUEST ) +/* hard code sha256 digest size */ +#define HASH_SIZE 32 + +typedef struct QEMU_PACKED SevHashTableEntry { +QemuUUID guid; +uint16_t len; +uint8_t hash[HASH_SIZE ]; +} SevHashTableEntry; + +typedef struct QEMU_PACKED SevHashTable { +QemuUUID guid; +uint16_t len; +SevHashTableEntry cmdline; +SevHashTableEntry initrd; +SevHashTableEntry kernel; +} SevHashTable; + +/* +* Data encrypted by sev_encrypt_flash() must be padded to a multiple of +* 16 bytes. +*/ +typedef struct QEMU_PACKED PaddedSevHashTable { +SevHashTable ht; +uint8_t padding[ROUND_UP (sizeof (SevHashTable),16 ) -sizeof (SevHashTable)]; +} PaddedSevHashTable; + +QEMU_BUILD_BUG_ON (sizeof (PaddedSevHashTable) %16 !=0 ); + +#define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e" +typedef struct __attribute__((__packed__ ))SevInfoBlock { +/* SEV-ES Reset Vector Address */ +uint32_t reset_addr; +}SevInfoBlock ; + +#define SEV_HASH_TABLE_RV_GUID "7255371f-3a3b-4b04-927b-1da6efa8d454" +typedef struct QEMU_PACKED SevHashTableDescriptor { +/* SEV hash table area guest address */ +uint32_t base; +/* SEV hash table area size (in bytes) */ +uint32_t size; +} SevHashTableDescriptor; +struct SevCommonState {X86ConfidentialGuest parent_obj;
@@ -128,48 +170,6 @@ typedef struct SevLaunchUpdateData { static QTAILQ_HEAD(, SevLaunchUpdateData) launch_update; -#define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e" -typedef struct __attribute__((__packed__ ))SevInfoBlock { -/* SEV-ES Reset Vector Address */ -uint32_t reset_addr; -}SevInfoBlock ; - -#define SEV_HASH_TABLE_RV_GUID "7255371f-3a3b-4b04-927b-1da6efa8d454" -typedef struct QEMU_PACKED SevHashTableDescriptor { -/* SEV hash table area guest address */ -uint32_t base; -/* SEV hash table area size (in bytes) */ -uint32_t size; -} SevHashTableDescriptor; - -/* hard code sha256 digest size */ -#define HASH_SIZE 32 - -typedef struct QEMU_PACKED SevHashTableEntry { -QemuUUID guid; -uint16_t len; -uint8_t hash[HASH_SIZE ]; -} SevHashTableEntry; - -typedef struct QEMU_PACKED SevHashTable { -QemuUUID guid; -uint16_t len; -SevHashTableEntry cmdline; -SevHashTableEntry initrd; -SevHashTableEntry kernel; -} SevHashTable; - -/* -* Data encrypted by sev_encrypt_flash() must be padded to a multiple of -* 16 bytes. -*/ -typedef struct QEMU_PACKED PaddedSevHashTable { -SevHashTable ht; -uint8_t padding[ROUND_UP (sizeof (SevHashTable),16 ) -sizeof (SevHashTable)]; -} PaddedSevHashTable; - -QEMU_BUILD_BUG_ON (sizeof (PaddedSevHashTable) %16 !=0 ); -static Error *sev_mig_blocker;static const char *const sev_fw_errlist[] = {
Signature · 1 line
2.45.1
[PULL 26/45] i386/sev: Don't return launch measurements for SEV-SNP guests
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
For SEV-SNP guests, launch measurement is queried from within the guest during attestation, so don't attempt to return it as part of query-sev-launch-measure.
Message-ID: <[email protected]>
--- target/i386/sev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target/i386/sev.c +3 -1
@@ -795,7 +795,9 @@ sev_launch_get_measure(Notifier *notifier, void *unused)static char *sev_get_launch_measurement (void ) { -SevGuestState *sev_guest =SEV_GUEST (MACHINE (qdev_get_machine ())->cgs); +ConfidentialGuestSupport *cgs =MACHINE (qdev_get_machine ())->cgs; +SevGuestState *sev_guest = + (SevGuestState *)object_dynamic_cast (OBJECT (cgs),TYPE_SEV_GUEST );if (sev_guest &&SEV_COMMON (sev_guest)->state >=SEV_STATE_LAUNCH_SECRET ) {
Signature · 1 line
2.45.1
[PULL 07/45] host/i386: assume presence of POPCNT
In reply to Paolo BonziniQEMU now requires an x86-64-v2 host, which has the POPCNT instruction. Use it freely in TCG-generated code.
--- host/include/i386/host/cpuinfo.h | 1 - tcg/i386/tcg-target.h | 5 ++--- util/cpuinfo-i386.c | 1 - 3 files changed, 2 insertions(+), 5 deletions(-)
host/include/i386/host/cpuinfo.h +0 -1
@@ -11,7 +11,6 @@#define CPUINFO_ALWAYS (1u << 0)/* so cpuinfo is nonzero */ #define CPUINFO_MOVBE (1u << 2)#define CPUINFO_LZCNT (1u << 3) -#define CPUINFO_POPCNT (1u << 4)#define CPUINFO_BMI1 (1u << 5)#define CPUINFO_BMI2 (1u << 6)#define CPUINFO_AVX1 (1u << 9)
tcg/i386/tcg-target.h +2 -3
@@ -111,7 +111,6 @@ typedef enum {#endif #define have_bmi1 (cpuinfo & CPUINFO_BMI1) -#define have_popcnt (cpuinfo & CPUINFO_POPCNT)#define have_avx1 (cpuinfo & CPUINFO_AVX1)#define have_avx2 (cpuinfo & CPUINFO_AVX2)#define have_movbe (cpuinfo & CPUINFO_MOVBE)
@@ -143,7 +142,7 @@ typedef enum {#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_clz_i32 1#define TCG_TARGET_HAS_ctz_i32 1 -#define TCG_TARGET_HAS_ctpop_i32 have_popcnt +#define TCG_TARGET_HAS_ctpop_i32 1#define TCG_TARGET_HAS_deposit_i32 1#define TCG_TARGET_HAS_extract_i32 1#define TCG_TARGET_HAS_sextract_i32 1
@@ -178,7 +177,7 @@ typedef enum {#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_clz_i64 1#define TCG_TARGET_HAS_ctz_i64 1 -#define TCG_TARGET_HAS_ctpop_i64 have_popcnt +#define TCG_TARGET_HAS_ctpop_i64 1#define TCG_TARGET_HAS_deposit_i64 1#define TCG_TARGET_HAS_extract_i64 1#define TCG_TARGET_HAS_sextract_i64 0
util/cpuinfo-i386.c +0 -1
@@ -35,7 +35,6 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)__cpuid (1 , a, b, c, d); info |= (c & bit_MOVBE ?CPUINFO_MOVBE :0 ); - info |= (c & bit_POPCNT ?CPUINFO_POPCNT :0 ); info |= (c & bit_PCLMUL ?CPUINFO_PCLMUL :0 );/* NOTE: our AES support requires SSSE3 (PSHUFB) as well. */
Signature · 1 line
2.45.1
[PULL 36/45] i386/sev: Invoke launch_updata_data() for SEV class
In reply to Paolo BonziniAdd launch_update_data() in SevCommonStateClass and invoke as sev_launch_update_data() for SEV object.
Message-ID: <[email protected]>
--- target/i386/sev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
target/i386/sev.c +8 -3
@@ -74,6 +74,7 @@ struct SevCommonStateClass {/* public */ int (*launch_start)(SevCommonState *sev_common);void (*launch_finish)(SevCommonState *sev_common); +int (*launch_update_data)(SevCommonState *sev_common,hwaddr gpa,uint8_t *ptr,uint64_t len);int (*kvm_init)(ConfidentialGuestSupport *cgs,Error **errp); };
@@ -929,7 +930,7 @@ out: }static int -sev_launch_update_data (SevGuestState *sev_guest,uint8_t *addr,uint64_t len) +sev_launch_update_data (SevCommonState *sev_common,hwaddr gpa,uint8_t *addr,uint64_t len) {int ret, fw_error;struct kvm_sev_launch_update_data update;
@@ -941,7 +942,7 @@ sev_launch_update_data(SevGuestState *sev_guest, uint8_t *addr, uint64_t len) update.uaddr = (uintptr_t )addr; update.len = len;trace_kvm_sev_launch_update_data (addr, len); - ret =sev_ioctl (SEV_COMMON (sev_guest)->sev_fd,KVM_SEV_LAUNCH_UPDATE_DATA , + ret =sev_ioctl (sev_common->sev_fd,KVM_SEV_LAUNCH_UPDATE_DATA , &update, &fw_error);if (ret) { error_report("%s: LAUNCH_UPDATE ret=%d fw_error=%d '%s'",
@@ -1487,6 +1488,7 @@ int sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp) { SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); +SevCommonStateClass *klass =SEV_COMMON_GET_CLASS (sev_common);if (!sev_common) {return 0 ;
@@ -1494,7 +1496,9 @@ sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp)/* if SEV is in update state then encrypt the data else do nothing */ if (sev_check_state (sev_common,SEV_STATE_LAUNCH_UPDATE )) { -int ret =sev_launch_update_data (SEV_GUEST (sev_common), ptr, len); +int ret; + + ret = klass->launch_update_data (sev_common, gpa, ptr, len);if (ret <0 ) {error_setg (errp,"SEV: Failed to encrypt pflash rom" );return ret;
@@ -1968,6 +1972,7 @@ sev_guest_class_init(ObjectClass *oc, void *data) klass->launch_start = sev_launch_start; klass->launch_finish = sev_launch_finish; + klass->launch_update_data = sev_launch_update_data; klass->kvm_init = sev_kvm_init; x86_klass->kvm_type = sev_kvm_type;
Signature · 1 line
2.45.1
Re: [PULL 36/45] i386/sev: Invoke launch_updata_data() for SEV class
Quoted 7 lines · Paolo Bonzini
Add
launch_update_data()in SevCommonStateClass and invoke assev_launch_update_data()for SEV object.Signed-off-by Pankaj Gupta <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
Hi; Coverity points out an issue in this code (CID 1546886):
Quoted 4 lines
sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp){ SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs);+ SevCommonStateClass *klass =
SEV_COMMON_GET_CLASS(sev_common);
SEV_COMMON_GET_CLASS() dereferences the pointer it is passed, so it isn't valid to pass it a NULL pointer...
Quoted 3 lines
if (!sev_common) {
return 0;...but we don't do the "return failure if passed NULL" until after we've dereferenced sev_common.
The get-the-class-pointer operation should be done after this check, I think.
thanks
-- PMM
[PULL 30/45] i386/sev: Add handling to encrypt/finalize guest launch data
In reply to Paolo BonziniFrom: Brijesh Singh <[email protected]>
Process any queued up launch data and encrypt/measure it into the SNP guest instance prior to initial guest launch.
This also updates the KVM_SEV_SNP_LAUNCH_UPDATE call to handle partial update responses.
Message-ID: <[email protected]>
--- target/i386/sev.c | 112 ++++++++++++++++++++++++++++++++++++++- target/i386/trace-events | 2 + 2 files changed, 113 insertions(+), 1 deletion(-)
target/i386/sev.c +111 -1
@@ -756,6 +756,76 @@ out:return ret; } +static const char * +snp_page_type_to_str (int type) +{ +switch (type) { +case KVM_SEV_SNP_PAGE_TYPE_NORMAL :return "Normal" ; +case KVM_SEV_SNP_PAGE_TYPE_ZERO :return "Zero" ; +case KVM_SEV_SNP_PAGE_TYPE_UNMEASURED :return "Unmeasured" ; +case KVM_SEV_SNP_PAGE_TYPE_SECRETS :return "Secrets" ; +case KVM_SEV_SNP_PAGE_TYPE_CPUID :return "Cpuid" ; +default :return "unknown" ; + } +} + +static int +sev_snp_launch_update (SevSnpGuestState *sev_snp_guest, +SevLaunchUpdateData *data) +{ +int ret, fw_error; +struct kvm_sev_snp_launch_update update = {0 }; + +if (!data->hva || !data->len) { +error_report ("SNP_LAUNCH_UPDATE called with invalid address" +"/ length: %p / %lx" , + data->hva, data->len); +return 1 ; + } + + update.uaddr = (__u64 )(unsigned long )data->hva; + update.gfn_start = data->gpa >>TARGET_PAGE_BITS ; + update.len = data->len; + update.type = data->type; + +/* +* KVM_SEV_SNP_LAUNCH_UPDATE requires that GPA ranges have the private +* memory attribute set in advance. +*/ + ret =kvm_set_memory_attributes_private (data->gpa, data->len); +if (ret) { +error_report ("SEV-SNP: failed to configure initial" +"private guest memory" ); + goto out; + } + +while (update.len || ret == -EAGAIN ) { +trace_kvm_sev_snp_launch_update (update.uaddr, update.gfn_start << +TARGET_PAGE_BITS , update.len, +snp_page_type_to_str (update.type)); + + ret =sev_ioctl (SEV_COMMON (sev_snp_guest)->sev_fd, +KVM_SEV_SNP_LAUNCH_UPDATE , + &update, &fw_error); +if (ret && ret != -EAGAIN ) { +error_report ("SNP_LAUNCH_UPDATE ret=%d fw_error=%d '%s'" , + ret, fw_error,fw_error_to_str (fw_error)); +break ; + } + } + +out: +if (!ret && update.gfn_start <<TARGET_PAGE_BITS != data->gpa + data->len) { +error_report ("SEV-SNP: expected update of GPA range %lx-%lx," +"got GPA range %lx-%llx" , + data->gpa, data->gpa + data->len, data->gpa, + update.gfn_start <<TARGET_PAGE_BITS ); + ret = -EIO ; + } + +return ret; +} +static int sev_launch_update_data (SevGuestState *sev_guest,uint8_t *addr,uint64_t len) {
@@ -901,6 +971,46 @@ sev_launch_finish(SevCommonState *sev_common)migrate_add_blocker (&sev_mig_blocker, &error_fatal); } +static void +sev_snp_launch_finish (SevCommonState *sev_common) +{ +int ret, error; +Error *local_err =NULL ; +SevLaunchUpdateData *data; +SevSnpGuestState *sev_snp =SEV_SNP_GUEST (sev_common); +struct kvm_sev_snp_launch_finish *finish = &sev_snp->kvm_finish_conf; + + QTAILQ_FOREACH(data, &launch_update, next) { + ret =sev_snp_launch_update (sev_snp, data); +if (ret) { +exit (1 ); + } + } + +trace_kvm_sev_snp_launch_finish (sev_snp->id_block, sev_snp->id_auth, + sev_snp->host_data); + ret =sev_ioctl (sev_common->sev_fd,KVM_SEV_SNP_LAUNCH_FINISH , + finish, &error); +if (ret) { +error_report ("SNP_LAUNCH_FINISH ret=%d fw_error=%d '%s'" , + ret, error,fw_error_to_str (error)); +exit (1 ); + } + +sev_set_guest_state (sev_common,SEV_STATE_RUNNING ); + +/* add migration blocker */ +error_setg (&sev_mig_blocker, +"SEV-SNP: Migration is not implemented" ); + ret =migrate_add_blocker (&sev_mig_blocker, &local_err); +if (local_err) { +error_report_err (local_err); +error_free (sev_mig_blocker); +exit (1 ); + } +} + +static void sev_vm_state_change (void *opaque,bool running,RunState state) {
@@ -1832,10 +1942,10 @@ sev_snp_guest_class_init(ObjectClass *oc, void *data)X86ConfidentialGuestClass *x86_klass =X86_CONFIDENTIAL_GUEST_CLASS (oc); klass->launch_start = sev_snp_launch_start; + klass->launch_finish = sev_snp_launch_finish; klass->kvm_init = sev_snp_kvm_init; x86_klass->kvm_type = sev_snp_kvm_type; -object_class_property_add (oc,"policy" ,"uint64" , sev_snp_guest_get_policy, sev_snp_guest_set_policy,NULL ,NULL );
target/i386/trace-events +2 -0
@@ -12,3 +12,5 @@ kvm_sev_launch_finish(void) "" kvm_sev_launch_secret(uint64_t hpa, uint64_t hva, uint64_t secret, int len) "hpa 0x%" PRIx64 " hva 0x%" PRIx64 " data 0x%" PRIx64 " len %d" kvm_sev_attestation_report(const char *mnonce, const char *data) "mnonce %s data %s" kvm_sev_snp_launch_start(uint64_t policy, char *gosvw) "policy 0x%" PRIx64 " gosvw %s" +kvm_sev_snp_launch_update(uint64_t src, uint64_t gpa, uint64_t len, const char *type) "src 0x%" PRIx64 " gpa 0x%" PRIx64 " len 0x%" PRIx64 " (%s page)" +kvm_sev_snp_launch_finish(char *id_block, char *id_auth, char *host_data) "id_block %s id_auth %s host_data %s"
Signature · 1 line
2.45.1
Re: [PULL 30/45] i386/sev: Add handling to encrypt/finalize guest launch data
Quoted 42 lines · Paolo Bonzini
From: Brijesh Singh <[email protected]>
Process any queued up launch data and encrypt/measure it into the SNP guest instance prior to initial guest launch.
This also updates the
KVM_SEV_SNP_LAUNCH_UPDATEcall to handle partial update responses.Signed-off-by Brijesh Singh <[email protected]>Co-developed-by Michael Roth <[email protected]>Signed-off-by Michael Roth <[email protected]>Co-developed-by Pankaj Gupta <[email protected]>Signed-off-by Pankaj Gupta <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/sev.c | 112 ++++++++++++++++++++++++++++++++++++++- target/i386/trace-events | 2 + 2 files changed, 113 insertions(+), 1 deletion(-)target/i386/sev.c +14
-0@@ -756,6 +756,76 @@ out:return ret; } +static const char * +snp_page_type_to_str (int type) +{ +switch (type) { +case KVM_SEV_SNP_PAGE_TYPE_NORMAL :return "Normal" ; +case KVM_SEV_SNP_PAGE_TYPE_ZERO :return "Zero" ; +case KVM_SEV_SNP_PAGE_TYPE_UNMEASURED :return "Unmeasured" ; +case KVM_SEV_SNP_PAGE_TYPE_SECRETS :return "Secrets" ; +case KVM_SEV_SNP_PAGE_TYPE_CPUID :return "Cpuid" ; +default :return "unknown" ; + } +} + +static int
target/i386/sev.c out: · line 782
Quoted 10 lines
target/i386/sev.c +10
-0+sev_snp_launch_update (SevSnpGuestState *sev_snp_guest, + SevLaunchUpdateData *data) +{ +int ret, fw_error; +struct kvm_sev_snp_launch_update update = {0 }; + +if (!data->hva || !data->len) { +error_report ("SNP_LAUNCH_UPDATE called with invalid address" +"/ length: %p / %lx" , + data->hva, data->len);
This patch does not compile on 32-bit x86:
../src/target/i386/sev.c: In function 'sev_snp_launch_update':../src/target/i386/sev.c:886:22: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'} [-Werror=format=]
886 | error_report("SNP_LAUNCH_UPDATE called with invalid address"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
887 | "/ length: %p / %lx",
888 | data->hva, data->len);
| ~~~~~~~~~
| |
| uint64_t {aka long long unsigned int}
../src/target/i386/sev.c:935:22: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'hwaddr' {aka 'long long unsigned int'} [-Werror=format=]
935 | error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936 | "got GPA range %lx-%llx",
937 | data->gpa, data->gpa + data->len, data->gpa,
| ~~~~~~~~~
| |
| hwaddr {aka long long unsigned int}
../src/target/i386/sev.c:935:22: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'long long unsigned int' [-Werror=format=]
935 | error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936 | "got GPA range %lx-%llx",
937 | data->gpa, data->gpa + data->len, data->gpa,
| ~~~~~~~~~~~~~~~~~~~~~
| |
| long long unsigned int
../src/target/i386/sev.c:935:22: error: format '%lx' expects argument of type 'long unsigned int', but argument 4 has type 'hwaddr' {aka 'long long unsigned int'} [-Werror=format=]
935 | error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936 | "got GPA range %lx-%llx",
937 | data->gpa, data->gpa + data->len, data->gpa,
| ~~~~~~~~~
| |
| hwaddr {aka long long unsigned int}
In file included from ../src/target/i386/sev.c:22:../src/target/i386/sev.c: In function 'sev_snp_guest_set_guest_visible_workarounds':/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'} [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2149:9: note: in expansion of macro 'error_setg'
2149 | error_setg(errp, "parameter length of %lu exceeds max of %lu",
| ^~~~~~~~~~
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 7 has type 'unsigned int' [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2149:9: note: in expansion of macro 'error_setg'
2149 | error_setg(errp, "parameter length of %lu exceeds max of %lu",
| ^~~~~~~~~~../src/target/i386/sev.c: In function 'sev_snp_guest_set_id_block':../src/target/i386/sev.c:2174:12: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
2174 | g_free((guchar *)finish->id_block_uaddr);
| ^../src/target/i386/sev.c:2180:9: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
2180 | (uint64_t)qbase64_decode(sev_snp_guest->id_block, -1, &len, errp);
| ^
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'} [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2187:9: note: in expansion of macro 'error_setg'
2187 | error_setg(errp, "parameter length of %lu not equal to %u",
| ^~~~~~~~~~../src/target/i386/sev.c: In function 'sev_snp_guest_set_id_auth':../src/target/i386/sev.c:2211:12: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
2211 | g_free((guchar *)finish->id_auth_uaddr);
| ^../src/target/i386/sev.c:2217:9: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
2217 | (uint64_t)qbase64_decode(sev_snp_guest->id_auth, -1, &len, errp);
| ^
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'} [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2224:9: note: in expansion of macro 'error_setg'
2224 | error_setg(errp, "parameter length:ID_AUTH %lu exceeds max of %u",
| ^~~~~~~~~~
../src/target/i386/sev.c: In function 'sev_snp_guest_set_host_data':
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'} [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2290:9: note: in expansion of macro 'error_setg'
2290 | error_setg(errp, "parameter length of %lu not equal to %lu",
| ^~~~~~~~~~
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 7 has type 'unsigned int' [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2290:9: note: in expansion of macro 'error_setg'
2290 | error_setg(errp, "parameter length of %lu not equal to %lu",
| ^~~~~~~~~~cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
r~
[PULL 38/45] i386/kvm: Add KVM_EXIT_HYPERCALL handling for KVM_HC_MAP_GPA_RANGE
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
KVM_HC_MAP_GPA_RANGE will be used to send requests to userspace for private/shared memory attribute updates requested by the guest. Implement handling for that use-case along with some basic infrastructure for enabling specific hypercall events.
Message-ID: <[email protected]>
--- target/i386/kvm/kvm_i386.h | 1 + target/i386/kvm/kvm.c | 55 ++++++++++++++++++++++++++++++++++++ target/i386/kvm/trace-events | 1 + 3 files changed, 57 insertions(+)
target/i386/kvm/kvm_i386.h +1 -0
@@ -33,6 +33,7 @@bool kvm_has_smm (void );bool kvm_enable_x2apic (void );bool kvm_hv_vpindex_settable (void ); +bool kvm_enable_hypercall (uint64_t enable_mask);bool kvm_enable_sgx_provisioning (KVMState *s);bool kvm_hyperv_expand_features (X86CPU *cpu,Error **errp);
target/i386/kvm/kvm.c +55 -0
79 lines not on this page · raw message
target/i386/kvm/trace-events +1 -0
@@ -5,6 +5,7 @@ kvm_x86_fixup_msi_error(uint32_t gsi) "VT-d failed to remap interrupt for GSI %" kvm_x86_add_msi_route(int virq) "Adding route entry for virq %d" kvm_x86_remove_msi_route(int virq) "Removing route entry for virq %d" kvm_x86_update_msi_routes(int num) "Updated %d MSI routes" +kvm_hc_map_gpa_range(uint64_t gpa, uint64_t size, uint64_t attributes, uint64_t flags) "gpa 0x%" PRIx64 " size 0x%" PRIx64 " attributes 0x%" PRIx64 " flags 0x%" PRIx64 # xen-emu.c kvm_xen_hypercall(int cpu, uint8_t cpl, uint64_t input, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t ret) "xen_hypercall: cpu %d cpl %d input %" PRIu64 " a0 0x%" PRIx64 " a1 0x%" PRIx64 " a2 0x%" PRIx64" ret 0x%" PRIx64
Signature · 1 line
2.45.1
[PULL 44/45] hw/i386/sev: Use guest_memfd for legacy ROMs
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
Current SNP guest kernels will attempt to access these regions with with C-bit set, so guest_memfd is needed to handle that. Otherwise, kvm_convert_memory() will fail when the guest kernel tries to access it and QEMU attempts to call KVM_SET_MEMORY_ATTRIBUTES to set these ranges to private.
Whether guests should actually try to access ROM regions in this way (or need to deal with legacy ROM regions at all), is a separate issue to be addressed on kernel side, but current SNP guest kernels will exhibit this behavior and so this handling is needed to allow QEMU to continue running existing SNP guest kernels.
Message-ID: <[email protected]>
--- hw/i386/pc.c | 14 ++++++++++---- hw/i386/pc_sysfw.c | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-)
hw/i386/pc.c +10 -4
@@ -62,6 +62,7 @@#include "hw/mem/memory-device.h" #include "e820_memory_layout.h" #include "trace.h" +#include "sev.h" #include CONFIG_DEVICES #ifdef CONFIG_XEN_EMU
@@ -1022,10 +1023,15 @@ void pc_memory_init(PCMachineState *pcms,pc_system_firmware_init (pcms, rom_memory); option_rom_mr =g_malloc (sizeof (*option_rom_mr)); -memory_region_init_ram (option_rom_mr,NULL ,"pc.rom" ,PC_ROM_SIZE , - &error_fatal); -if (pcmc->pci_enabled) { -memory_region_set_readonly (option_rom_mr, true); +if (machine_require_guest_memfd (machine)) { +memory_region_init_ram_guest_memfd (option_rom_mr,NULL ,"pc.rom" , +PC_ROM_SIZE , &error_fatal); + }else { +memory_region_init_ram (option_rom_mr,NULL ,"pc.rom" ,PC_ROM_SIZE , + &error_fatal); +if (pcmc->pci_enabled) { +memory_region_set_readonly (option_rom_mr, true); + } } memory_region_add_subregion_overlap(rom_memory, PC_ROM_MIN_VGA,
hw/i386/pc_sysfw.c +13 -6
@@ -40,8 +40,8 @@#define FLASH_SECTOR_SIZE 4096 -static void pc_isa_bios_init (MemoryRegion *isa_bios,MemoryRegion *rom_memory, -MemoryRegion *flash_mem) +static void pc_isa_bios_init (PCMachineState *pcms,MemoryRegion *isa_bios, +MemoryRegion *rom_memory,MemoryRegion *flash_mem) {int isa_bios_size;uint64_t flash_size;
@@ -51,8 +51,13 @@ static void pc_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *rom_memory,/* map the last 128KB of the BIOS in ISA space */ isa_bios_size =MIN (flash_size,128 * KiB); -memory_region_init_ram (isa_bios,NULL ,"isa-bios" , isa_bios_size, - &error_fatal); +if (machine_require_guest_memfd (MACHINE (pcms))) { +memory_region_init_ram_guest_memfd (isa_bios,NULL ,"isa-bios" , + isa_bios_size, &error_fatal); + }else { +memory_region_init_ram (isa_bios,NULL ,"isa-bios" , isa_bios_size, + &error_fatal); + } memory_region_add_subregion_overlap(rom_memory, 0x100000 - isa_bios_size, isa_bios,
@@ -65,7 +70,9 @@ static void pc_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *rom_memory, ((uint8_t *)flash_ptr) + (flash_size - isa_bios_size), isa_bios_size); -memory_region_set_readonly (isa_bios, true); +if (!machine_require_guest_memfd (current_machine)) { +memory_region_set_readonly (isa_bios, true); + } } static PFlashCFI01 *pc_pflash_create(PCMachineState *pcms,
@@ -191,7 +198,7 @@ static void pc_system_flash_map(PCMachineState *pcms,x86_isa_bios_init (&x86ms->isa_bios, rom_memory, flash_mem, true); }else { -pc_isa_bios_init (&x86ms->isa_bios, rom_memory, flash_mem); +pc_isa_bios_init (pcms, &x86ms->isa_bios, rom_memory, flash_mem); }/* Encrypt the pflash boot ROM */
Signature · 1 line
2.45.1
[PULL 16/45] machine: allow early use of machine_require_guest_memfd
In reply to Paolo BonziniAsk the ConfidentialGuestSupport object whether to use guest_memfd for KVM-backend private memory. This bool can be set in instance_init (or user_complete) so that it is available when the machine is created.
--- include/exec/confidential-guest-support.h | 5 +++++ include/hw/boards.h | 1 - hw/core/machine.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-)
include/exec/confidential-guest-support.h +5 -0
@@ -31,6 +31,11 @@ OBJECT_DECLARE_TYPE(ConfidentialGuestSupport,struct ConfidentialGuestSupport {Object parent; +/* +* True if the machine should use guest_memfd for RAM. +*/ +bool require_guest_memfd; +/* * ready: flag set by CGS initialization code once it's ready to * start executing instructions in a potentially-secure
include/hw/boards.h +0 -1
@@ -375,7 +375,6 @@ struct MachineState {char *dt_compatible;bool dump_guest_core;bool mem_merge; -bool require_guest_memfd;bool usb;bool usb_disabled;char *firmware;
hw/core/machine.c +1 -1
@@ -1216,7 +1216,7 @@ bool machine_mem_merge(MachineState *machine)bool machine_require_guest_memfd (MachineState *machine) { -return machine->require_guest_memfd; +return machine->cgs && machine->cgs->require_guest_memfd; }static char *cpu_slot_to_string (const CPUArchId *cpu)
Signature · 1 line
2.45.1
[PULL 29/45] i386/sev: Add the SNP launch start context
In reply to Paolo BonziniFrom: Brijesh Singh <[email protected]>
The SNP_LAUNCH_START is called first to create a cryptographic launch context within the firmware.
Message-ID: <[email protected]>
--- target/i386/sev.c | 39 +++++++++++++++++++++++++++++++++++++++ target/i386/trace-events | 1 + 2 files changed, 40 insertions(+)
target/i386/sev.c +39 -0
@@ -39,6 +39,7 @@#include "confidential-guest.h" #include "hw/i386/pc.h" #include "exec/address-spaces.h" +#include "qemu/queue.h" OBJECT_DECLARE_TYPE(SevCommonState, SevCommonStateClass, SEV_COMMON)OBJECT_DECLARE_TYPE (SevGuestState, SevCommonStateClass,SEV_GUEST )
@@ -115,6 +116,16 @@ struct SevSnpGuestState {#define DEFAULT_SEV_DEVICE "/dev/sev"#define DEFAULT_SEV_SNP_POLICY 0x30000 +typedef struct SevLaunchUpdateData { +QTAILQ_ENTRY (SevLaunchUpdateData) next; +hwaddr gpa; +void *hva; +uint64_t len; +int type; +}SevLaunchUpdateData ; + +static QTAILQ_HEAD(, SevLaunchUpdateData) launch_update; +#define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e" typedef struct __attribute__((__packed__)) SevInfoBlock { /* SEV-ES Reset Vector Address */
@@ -674,6 +685,31 @@ sev_read_file_base64(const char *filename, guchar **data, gsize *len)return 0 ; } +static int +sev_snp_launch_start (SevCommonState *sev_common) +{ +int fw_error, rc; +SevSnpGuestState *sev_snp_guest =SEV_SNP_GUEST (sev_common); +struct kvm_sev_snp_launch_start *start = &sev_snp_guest->kvm_start_conf; + +trace_kvm_sev_snp_launch_start (start->policy, + sev_snp_guest->guest_visible_workarounds); + + rc =sev_ioctl (sev_common->sev_fd,KVM_SEV_SNP_LAUNCH_START , + start, &fw_error); +if (rc <0 ) { +error_report ("%s: SNP_LAUNCH_START ret=%d fw_error=%d '%s'" , + __func__, rc, fw_error,fw_error_to_str (fw_error)); +return 1 ; + } + +QTAILQ_INIT (&launch_update); + +sev_set_guest_state (sev_common,SEV_STATE_LAUNCH_UPDATE ); + +return 0 ; +} +static int sev_launch_start (SevCommonState *sev_common) {
@@ -1003,6 +1039,7 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) } ret = klass->launch_start (sev_common); +if (ret) {error_setg (errp,"%s: failed to create encryption context" , __func__);return -1 ;
@@ -1794,9 +1831,11 @@ sev_snp_guest_class_init(ObjectClass *oc, void *data)SevCommonStateClass *klass =SEV_COMMON_CLASS (oc);X86ConfidentialGuestClass *x86_klass =X86_CONFIDENTIAL_GUEST_CLASS (oc); + klass->launch_start = sev_snp_launch_start; klass->kvm_init = sev_snp_kvm_init; x86_klass->kvm_type = sev_snp_kvm_type; +object_class_property_add (oc,"policy" ,"uint64" , sev_snp_guest_get_policy, sev_snp_guest_set_policy,NULL ,NULL );
target/i386/trace-events +1 -0
@@ -11,3 +11,4 @@ kvm_sev_launch_measurement(const char *value) "data %s" kvm_sev_launch_finish(void) "" kvm_sev_launch_secret(uint64_t hpa, uint64_t hva, uint64_t secret, int len) "hpa 0x%" PRIx64 " hva 0x%" PRIx64 " data 0x%" PRIx64 " len %d" kvm_sev_attestation_report(const char *mnonce, const char *data) "mnonce %s data %s" +kvm_sev_snp_launch_start(uint64_t policy, char *gosvw) "policy 0x%" PRIx64 " gosvw %s"
Signature · 1 line
2.45.1
[PULL 34/45] i386/sev: Add support for SNP CPUID validation
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
SEV-SNP firmware allows a special guest page to be populated with a table of guest CPUID values so that they can be validated through firmware before being loaded into encrypted guest memory where they can be used in place of hypervisor-provided values[1].
As part of SEV-SNP guest initialization, use this interface to validate the CPUID entries reported by KVM_GET_CPUID2 prior to initial guest start and populate the CPUID page reserved by OVMF with the resulting encrypted data.
[1] SEV SNP Firmware ABI Specification, Rev. 0.8, 8.13.2.6
Message-ID: <[email protected]>
--- target/i386/sev.c | 164 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 2 deletions(-)
target/i386/sev.c +162 -2
@@ -200,6 +200,36 @@ static const char *const sev_fw_errlist[] = {#define SEV_FW_MAX_ERROR ARRAY_SIZE(sev_fw_errlist) +/* <linux/kvm.h> doesn't expose this, so re-use the max from kvm.c */ +#define KVM_MAX_CPUID_ENTRIES 100 + +typedef struct KvmCpuidInfo { +struct kvm_cpuid2 cpuid; +struct kvm_cpuid_entry2 entries[KVM_MAX_CPUID_ENTRIES ]; +}KvmCpuidInfo ; + +#define SNP_CPUID_FUNCTION_MAXCOUNT 64 +#define SNP_CPUID_FUNCTION_UNKNOWN 0xFFFFFFFF + +typedef struct { +uint32_t eax_in; +uint32_t ecx_in; +uint64_t xcr0_in; +uint64_t xss_in; +uint32_t eax; +uint32_t ebx; +uint32_t ecx; +uint32_t edx; +uint64_t reserved; +} __attribute__((packed))SnpCpuidFunc ; + +typedef struct { +uint32_t count; +uint32_t reserved1; +uint64_t reserved2; +SnpCpuidFunc entries[SNP_CPUID_FUNCTION_MAXCOUNT ]; +} __attribute__((packed))SnpCpuidInfo ; +static int sev_ioctl (int fd,int cmd,void *data,int *error) {
@@ -788,6 +818,35 @@ out:return ret; } +static void +sev_snp_cpuid_report_mismatches (SnpCpuidInfo *old, +SnpCpuidInfo *new) +{ +size_t i; + +if (old->count != new->count) { +error_report ("SEV-SNP: CPUID validation failed due to count mismatch," +"provided: %d, expected: %d" , old->count, new->count); +return ; + } + +for (i =0 ; i < old->count; i++) { +SnpCpuidFunc *old_func, *new_func; + + old_func = &old->entries[i]; + new_func = &new->entries[i]; + +if (memcmp (old_func, new_func,sizeof (SnpCpuidFunc))) { +error_report ("SEV-SNP: CPUID validation failed for function 0x%x, index: 0x%x" +"provided: eax:0x%08x, ebx: 0x%08x, ecx: 0x%08x, edx: 0x%08x" +"expected: eax:0x%08x, ebx: 0x%08x, ecx: 0x%08x, edx: 0x%08x" , + old_func->eax_in, old_func->ecx_in, + old_func->eax, old_func->ebx, old_func->ecx, old_func->edx, + new_func->eax, new_func->ebx, new_func->ecx, new_func->edx); + } + } +} +static const char *snp_page_type_to_str (int type) {
@@ -806,6 +865,7 @@ sev_snp_launch_update(SevSnpGuestState *sev_snp_guest, SevLaunchUpdateData *data) {int ret, fw_error; +SnpCpuidInfo snp_cpuid_info;struct kvm_sev_snp_launch_update update = {0 };if (!data->hva || !data->len) {
@@ -815,6 +875,11 @@ sev_snp_launch_update(SevSnpGuestState *sev_snp_guest,return 1 ; } +if (data->type ==KVM_SEV_SNP_PAGE_TYPE_CPUID ) { +/* Save a copy for comparison in case the LAUNCH_UPDATE fails */ +memcpy (&snp_cpuid_info, data->hva,sizeof (snp_cpuid_info)); + } + update.uaddr = (__u64 )(unsigned long )data->hva; update.gfn_start = data->gpa >>TARGET_PAGE_BITS ; update.len = data->len;
@@ -842,6 +907,11 @@ sev_snp_launch_update(SevSnpGuestState *sev_snp_guest,if (ret && ret != -EAGAIN ) {error_report ("SNP_LAUNCH_UPDATE ret=%d fw_error=%d '%s'" , ret, fw_error,fw_error_to_str (fw_error)); + +if (data->type ==KVM_SEV_SNP_PAGE_TYPE_CPUID ) { +sev_snp_cpuid_report_mismatches (&snp_cpuid_info, data->hva); +error_report ("SEV-SNP: failed update CPUID page" ); + }break ; } }
@@ -1004,7 +1074,8 @@ sev_launch_finish(SevCommonState *sev_common) }static int -snp_launch_update_data (uint64_t gpa,void *hva,uint32_t len,int type) +snp_launch_update_data (uint64_t gpa,void *hva, +uint32_t len,int type) {SevLaunchUpdateData *data;
@@ -1019,6 +1090,90 @@ snp_launch_update_data(uint64_t gpa, void *hva, uint32_t len, int type)return 0 ; } +static int +sev_snp_cpuid_info_fill (SnpCpuidInfo *snp_cpuid_info, +const KvmCpuidInfo *kvm_cpuid_info) +{ +size_t i; + +if (kvm_cpuid_info->cpuid.nent >SNP_CPUID_FUNCTION_MAXCOUNT ) { +error_report ("SEV-SNP: CPUID entry count (%d) exceeds max (%d)" , + kvm_cpuid_info->cpuid.nent,SNP_CPUID_FUNCTION_MAXCOUNT ); +return -1 ; + } + +memset (snp_cpuid_info,0 ,sizeof (*snp_cpuid_info)); + +for (i =0 ; i < kvm_cpuid_info->cpuid.nent; i++) { +const struct kvm_cpuid_entry2 *kvm_cpuid_entry; +SnpCpuidFunc *snp_cpuid_entry; + + kvm_cpuid_entry = &kvm_cpuid_info->entries[i]; + snp_cpuid_entry = &snp_cpuid_info->entries[i]; + + snp_cpuid_entry->eax_in = kvm_cpuid_entry->function; +if (kvm_cpuid_entry->flags ==KVM_CPUID_FLAG_SIGNIFCANT_INDEX ) { + snp_cpuid_entry->ecx_in = kvm_cpuid_entry->index; + } + snp_cpuid_entry->eax = kvm_cpuid_entry->eax; + snp_cpuid_entry->ebx = kvm_cpuid_entry->ebx; + snp_cpuid_entry->ecx = kvm_cpuid_entry->ecx; + snp_cpuid_entry->edx = kvm_cpuid_entry->edx; + +/* +* Guest kernels will calculate EBX themselves using the 0xD +* subfunctions corresponding to the individual XSAVE areas, so only +* encode the base XSAVE size in the initial leaves, corresponding +* to the initial XCR0=1 state. +*/ +if (snp_cpuid_entry->eax_in ==0xD && + (snp_cpuid_entry->ecx_in ==0x0 || snp_cpuid_entry->ecx_in ==0x1 )) { + snp_cpuid_entry->ebx =0x240 ; + snp_cpuid_entry->xcr0_in =1 ; + snp_cpuid_entry->xss_in =0 ; + } + } + + snp_cpuid_info->count = i; + +return 0 ; +} + +static int +snp_launch_update_cpuid (uint32_t cpuid_addr,void *hva,uint32_t cpuid_len) +{ +KvmCpuidInfo kvm_cpuid_info = {0 }; +SnpCpuidInfo snp_cpuid_info; +CPUState *cs = first_cpu; +int ret; +uint32_t i =0 ; + +assert (sizeof (snp_cpuid_info) <= cpuid_len); + +/* get the cpuid list from KVM */ +do { + kvm_cpuid_info.cpuid.nent = ++i; + ret =kvm_vcpu_ioctl (cs,KVM_GET_CPUID2 , &kvm_cpuid_info); + }while (ret == -E2BIG ); + +if (ret) { +error_report ("SEV-SNP: unable to query CPUID values for CPU: '%s'" , +strerror (-ret)); +return 1 ; + } + + ret =sev_snp_cpuid_info_fill (&snp_cpuid_info, &kvm_cpuid_info); +if (ret) { +error_report ("SEV-SNP: failed to generate CPUID table information" ); +return 1 ; + } + +memcpy (hva, &snp_cpuid_info,sizeof (snp_cpuid_info)); + +return snp_launch_update_data (cpuid_addr, hva, cpuid_len, +KVM_SEV_SNP_PAGE_TYPE_CPUID ); +} +static int snp_metadata_desc_to_page_type (int desc_type) {
@@ -1053,7 +1208,12 @@ snp_populate_metadata_pages(SevSnpGuestState *sev_snp,exit (1 ); } - ret =snp_launch_update_data (desc->base, hva, desc->len, type); +if (type ==KVM_SEV_SNP_PAGE_TYPE_CPUID ) { + ret =snp_launch_update_cpuid (desc->base, hva, desc->len); + }else { + ret =snp_launch_update_data (desc->base, hva, desc->len, type); + } +if (ret) {error_report ("%s: Failed to add metadata page gpa 0x%x+%x type %d" , __func__, desc->base, desc->len, desc->type);
Signature · 1 line
2.45.1
[PULL 25/45] i386/cpu: Set SEV-SNP CPUID bit when SNP enabled
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
SNP guests will rely on this bit to determine certain feature support.
Message-ID: <[email protected]>
--- target/i386/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/i386/cpu.c +1 -0
@@ -6979,6 +6979,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if (sev_enabled ()) { *eax =0x2 ; *eax |=sev_es_enabled () ?0x8 :0 ; + *eax |=sev_snp_enabled () ?0x10 :0 ; *ebx =sev_get_cbit_position () &0x3f ;/* EBX[5:0] */ *ebx |= (sev_get_reduced_phys_bits () &0x3f ) <<6 ;/* EBX[11:6] */ }
Signature · 1 line
2.45.1
[PULL 33/45] i386/sev: Add support for populating OVMF metadata pages
In reply to Paolo BonziniFrom: Brijesh Singh <[email protected]>
OVMF reserves various pages so they can be pre-initialized/validated prior to launching the guest. Add support for populating these pages with the expected content.
Message-ID: <[email protected]>
--- target/i386/sev.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
target/i386/sev.c +74 -0
@@ -1003,15 +1003,89 @@ sev_launch_finish(SevCommonState *sev_common)migrate_add_blocker (&sev_mig_blocker, &error_fatal); } +static int +snp_launch_update_data (uint64_t gpa,void *hva,uint32_t len,int type) +{ +SevLaunchUpdateData *data; + + data =g_new0 (SevLaunchUpdateData,1 ); + data->gpa = gpa; + data->hva = hva; + data->len = len; + data->type = type; + +QTAILQ_INSERT_TAIL (&launch_update, data, next); + +return 0 ; +} + +static int +snp_metadata_desc_to_page_type (int desc_type) +{ +switch (desc_type) { +/* Add the umeasured prevalidated pages as a zero page */ +case SEV_DESC_TYPE_SNP_SEC_MEM :return KVM_SEV_SNP_PAGE_TYPE_ZERO ; +case SEV_DESC_TYPE_SNP_SECRETS :return KVM_SEV_SNP_PAGE_TYPE_SECRETS ; +case SEV_DESC_TYPE_CPUID :return KVM_SEV_SNP_PAGE_TYPE_CPUID ; +default : +return KVM_SEV_SNP_PAGE_TYPE_ZERO ; + } +} + +static void +snp_populate_metadata_pages (SevSnpGuestState *sev_snp, +OvmfSevMetadata *metadata) +{ +OvmfSevMetadataDesc *desc; +int type, ret, i; +void *hva; +MemoryRegion *mr =NULL ; + +for (i =0 ; i < metadata->num_desc; i++) { + desc = &metadata->descs[i]; + + type =snp_metadata_desc_to_page_type (desc->type); + + hva =gpa2hva (&mr, desc->base, desc->len,NULL ); +if (!hva) { +error_report ("%s: Failed to get HVA for GPA 0x%x sz 0x%x" , + __func__, desc->base, desc->len); +exit (1 ); + } + + ret =snp_launch_update_data (desc->base, hva, desc->len, type); +if (ret) { +error_report ("%s: Failed to add metadata page gpa 0x%x+%x type %d" , + __func__, desc->base, desc->len, desc->type); +exit (1 ); + } + } +} +static void sev_snp_launch_finish (SevCommonState *sev_common) {int ret, error;Error *local_err =NULL ; +OvmfSevMetadata *metadata;SevLaunchUpdateData *data;SevSnpGuestState *sev_snp =SEV_SNP_GUEST (sev_common);struct kvm_sev_snp_launch_finish *finish = &sev_snp->kvm_finish_conf; +/* +* To boot the SNP guest, the hypervisor is required to populate the CPUID +* and Secrets page before finalizing the launch flow. The location of +* the secrets and CPUID page is available through the OVMF metadata GUID. +*/ + metadata =pc_system_get_ovmf_sev_metadata_ptr (); +if (metadata ==NULL ) { +error_report ("%s: Failed to locate SEV metadata header" , __func__); +exit (1 ); + } + +/* Populate all the metadata pages */ +snp_populate_metadata_pages (sev_snp, metadata); + QTAILQ_FOREACH(data, &launch_update, next) { ret =sev_snp_launch_update (sev_snp, data);if (ret) {
Signature · 1 line
2.45.1
[PULL 08/45] target/i386: fix SSE and SSE2 feature check
In reply to Paolo BonziniFrom: Xinyu Li <[email protected]>
Features check of CPUID_SSE and CPUID_SSE2 should use cpuid_features, rather than cpuid_ext_features.
Message-ID: <[email protected]>
--- target/i386/tcg/decode-new.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/tcg/decode-new.c.inc +2 -2
@@ -2041,9 +2041,9 @@ static bool has_cpuid_feature(DisasContext *s, X86CPUIDFeature cpuid) case X86_FEAT_PCLMULQDQ: return (s->cpuid_ext_features & CPUID_EXT_PCLMULQDQ); case X86_FEAT_SSE: - return (s->cpuid_ext_features & CPUID_SSE); + return (s->cpuid_features & CPUID_SSE); case X86_FEAT_SSE2: - return (s->cpuid_ext_features & CPUID_SSE2); + return (s->cpuid_features & CPUID_SSE2); case X86_FEAT_SSE3: return (s->cpuid_ext_features & CPUID_EXT_SSE3); case X86_FEAT_SSSE3:
Signature · 1 line
2.45.1
[PULL 31/45] i386/sev: Set CPU state to protected once SNP guest payload is finalized
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
Once KVM_SNP_LAUNCH_FINISH is called the vCPU state is copied into the vCPU's VMSA page and measured/encrypted. Any attempt to read/write CPU state afterward will only be acting on the initial data and so are effectively no-ops.
Set the vCPU state to protected at this point so that QEMU don't continue trying to re-sync vCPU data during guest runtime.
Message-ID: <[email protected]>
--- target/i386/sev.c | 1 + 1 file changed, 1 insertion(+)
target/i386/sev.c +1 -0
@@ -997,6 +997,7 @@ sev_snp_launch_finish(SevCommonState *sev_common)exit (1 ); } +kvm_mark_guest_state_protected ();sev_set_guest_state (sev_common,SEV_STATE_RUNNING );/* add migration blocker */
Signature · 1 line
2.45.1
[PULL 27/45] i386/sev: Add a class method to determine KVM VM type for SNP guests
In reply to Paolo BonziniSEV guests can use either KVM_X86_DEFAULT_VM, KVM_X86_SEV_VM, or KVM_X86_SEV_ES_VM depending on the configuration and what the host kernel supports. SNP guests on the other hand can only ever use KVM_X86_SNP_VM, so split determination of VM type out into a separate class method that can be set accordingly for sev-guest vs. sev-snp-guest objects and add handling for SNP.
Message-ID: <[email protected]>
--- target/i386/kvm/kvm.c | 1 + target/i386/sev.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-)
target/i386/kvm/kvm.c +1 -0
@@ -167,6 +167,7 @@ static const char *vm_type_name[] = { [KVM_X86_DEFAULT_VM] = "default", [KVM_X86_SEV_VM] = "SEV", [KVM_X86_SEV_ES_VM] = "SEV-ES", + [KVM_X86_SNP_VM] = "SEV-SNP", };bool kvm_is_vm_type_supported (int type)
target/i386/sev.c +12 -3
@@ -885,6 +885,11 @@ out:return sev_common->kvm_type; } +static int sev_snp_kvm_type (X86ConfidentialGuest *cg) +{ +return KVM_X86_SNP_VM ; +} +static int sev_common_kvm_init (ConfidentialGuestSupport *cgs,Error **errp) {char *devname;
@@ -894,6 +899,8 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)struct sev_user_data_status status = {};SevCommonState *sev_common =SEV_COMMON (cgs);SevCommonStateClass *klass =SEV_COMMON_GET_CLASS (cgs); +X86ConfidentialGuestClass *x86_klass = +X86_CONFIDENTIAL_GUEST_GET_CLASS (cgs); sev_common->state =SEV_STATE_UNINIT ;
@@ -964,7 +971,7 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) }trace_kvm_sev_init (); -if (sev_kvm_type (X86_CONFIDENTIAL_GUEST (sev_common)) ==KVM_X86_DEFAULT_VM ) { +if (x86_klass->kvm_type (X86_CONFIDENTIAL_GUEST (sev_common)) ==KVM_X86_DEFAULT_VM ) { cmd =sev_es_enabled () ?KVM_SEV_ES_INIT :KVM_SEV_INIT ; ret =sev_ioctl (sev_common->sev_fd, cmd,NULL , &fw_error);
@@ -1441,10 +1448,8 @@ static void sev_common_class_init(ObjectClass *oc, void *data) {ConfidentialGuestSupportClass *klass =CONFIDENTIAL_GUEST_SUPPORT_CLASS (oc); -X86ConfidentialGuestClass *x86_klass =X86_CONFIDENTIAL_GUEST_CLASS (oc); klass->kvm_init = sev_common_kvm_init; - x86_klass->kvm_type = sev_kvm_type; object_class_property_add_str(oc, "sev-device", sev_common_get_sev_device,
@@ -1529,10 +1534,12 @@ static void sev_guest_class_init(ObjectClass *oc, void *data) {SevCommonStateClass *klass =SEV_COMMON_CLASS (oc); +X86ConfidentialGuestClass *x86_klass =X86_CONFIDENTIAL_GUEST_CLASS (oc); klass->launch_start = sev_launch_start; klass->launch_finish = sev_launch_finish; klass->kvm_init = sev_kvm_init; + x86_klass->kvm_type = sev_kvm_type; object_class_property_add_str(oc, "dh-cert-file", sev_guest_get_dh_cert_file,
@@ -1770,8 +1777,10 @@ static void sev_snp_guest_class_init(ObjectClass *oc, void *data) {SevCommonStateClass *klass =SEV_COMMON_CLASS (oc); +X86ConfidentialGuestClass *x86_klass =X86_CONFIDENTIAL_GUEST_CLASS (oc); klass->kvm_init = sev_snp_kvm_init; + x86_klass->kvm_type = sev_snp_kvm_type; object_class_property_add(oc, "policy", "uint64", sev_snp_guest_get_policy,
Signature · 1 line
2.45.1
[PULL 17/45] i386/sev: Replace error_report with error_setg
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
Message-ID: <[email protected]>
--- target/i386/sev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/i386/sev.c +3 -3
@@ -952,13 +952,13 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)if (sev_es_enabled ()) {if (!kvm_kernel_irqchip_allowed ()) { -error_report ("%s: SEV-ES guests require in-kernel irqchip support" , - __func__); +error_setg (errp,"%s: SEV-ES guests require in-kernel irqchip" +"support" , __func__); goto err; }if (!(status.flags &SEV_STATUS_FLAGS_CONFIG_ES )) { -error_report ("%s: guest policy requires SEV-ES, but " +error_setg (errp,"%s: guest policy requires SEV-ES, but " "host SEV-ES support unavailable" , __func__); goto err;
Signature · 1 line
2.45.1
[PULL 28/45] i386/sev: Update query-sev QAPI format to handle SEV-SNP
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
Most of the current 'query-sev' command is relevant to both legacy SEV/SEV-ES guests and SEV-SNP guests, with 2 exceptions:
- 'policy' is a 64-bit field for SEV-SNP, not 32-bit, and the meaning of the bit positions has changed
- 'handle' is not relevant to SEV-SNP
To address this, this patch adds a new 'sev-type' field that can be used as a discriminator to select between SEV and SEV-SNP-specific fields/formats without breaking compatibility for existing management tools (so long as management tools that add support for launching SEV-SNP guest update their handling of query-sev appropriately).
The corresponding HMP command has also been fixed up similarly.
Message-ID: <[email protected]>
--- qapi/misc-target.json | 72 ++++++++++++++++++++++++++++++++++--------- target/i386/sev.h | 3 ++ target/i386/sev.c | 57 +++++++++++++++++++++------------- 3 files changed, 97 insertions(+), 35 deletions(-)
qapi/misc-target.json +58 -14
@@ -47,6 +47,50 @@ 'send-update', 'receive-update' ], 'if': 'TARGET_I386' } +## +# @SevGuestType: +# +# An enumeration indicating the type of SEV guest being run. +# +# @sev: The guest is a legacy SEV or SEV-ES guest. +# +# @sev-snp: The guest is an SEV-SNP guest. +# +# Since: 6.2 +## +{ 'enum': 'SevGuestType', + 'data': [ 'sev', 'sev-snp' ], + 'if': 'TARGET_I386' } + +## +# @SevGuestInfo: +# +# Information specific to legacy SEV/SEV-ES guests. +# +# @policy: SEV policy value +# +# @handle: SEV firmware handle +# +# Since: 2.12 +## +{ 'struct': 'SevGuestInfo', + 'data': { 'policy': 'uint32', + 'handle': 'uint32' }, + 'if': 'TARGET_I386' } + +## +# @SevSnpGuestInfo: +# +# Information specific to SEV-SNP guests. +# +# @snp-policy: SEV-SNP policy value +# +# Since: 9.1 +## +{ 'struct': 'SevSnpGuestInfo', + 'data': { 'snp-policy': 'uint64' }, + 'if': 'TARGET_I386' } + ## # @SevInfo: #
@@ -60,25 +104,25 @@ # # @build-id: SEV FW build id # -# @policy: SEV policy value -# # @state: SEV guest state # -# @handle: SEV firmware handle +# @sev-type: Type of SEV guest being run # # Since: 2.12 ## -{ 'struct': 'SevInfo', - 'data': { 'enabled': 'bool', - 'api-major': 'uint8', - 'api-minor' : 'uint8', - 'build-id' : 'uint8', - 'policy' : 'uint32', - 'state' : 'SevState', - 'handle' : 'uint32' - }, - 'if': 'TARGET_I386' -} +{ 'union': 'SevInfo', + 'base': { 'enabled': 'bool', + 'api-major': 'uint8', + 'api-minor' : 'uint8', + 'build-id' : 'uint8', + 'state' : 'SevState', + 'sev-type' : 'SevGuestType' }, + 'discriminator': 'sev-type', + 'data': { + 'sev': 'SevGuestInfo', + 'sev-snp': 'SevSnpGuestInfo' }, + 'if': 'TARGET_I386' } + ## # @query-sev:
target/i386/sev.h +3 -0
@@ -31,6 +31,9 @@#define SEV_POLICY_DOMAIN 0x10#define SEV_POLICY_SEV 0x20 +#define SEV_SNP_POLICY_SMT 0x10000 +#define SEV_SNP_POLICY_DBG 0x80000 + typedef struct SevKernelLoaderContext { char *setup_data; size_t setup_size;
target/i386/sev.c +36 -21
81 lines not on this page · raw message
Signature · 1 line
2.45.1
[PULL 32/45] hw/i386/sev: Add function to get SEV metadata from OVMF header
In reply to Paolo BonziniFrom: Brijesh Singh <[email protected]>
A recent version of OVMF expanded the reset vector GUID list to add SEV-specific metadata GUID. The SEV metadata describes the reserved memory regions such as the secrets and CPUID page used during the SEV-SNP guest launch.
The pc_system_get_ovmf_sev_metadata_ptr() is used to retieve the SEV metadata pointer from the OVMF GUID list.
Message-ID: <[email protected]>
--- include/hw/i386/pc.h | 26 ++++++++++++++++++++++++++ target/i386/sev.h | 2 ++ hw/i386/pc_sysfw.c | 4 ++++ target/i386/sev-sysemu-stub.c | 4 ++++ target/i386/sev.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+)
include/hw/i386/pc.h +26 -0
@@ -164,6 +164,32 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int level);#define PCI_HOST_ABOVE_4G_MEM_SIZE "above-4g-mem-size"#define PCI_HOST_PROP_SMM_RANGES "smm-ranges" +typedef enum { +SEV_DESC_TYPE_UNDEF , +/* The section contains the region that must be validated by the VMM. */ +SEV_DESC_TYPE_SNP_SEC_MEM , +/* The section contains the SNP secrets page */ +SEV_DESC_TYPE_SNP_SECRETS , +/* The section contains address that can be used as a CPUID page */ +SEV_DESC_TYPE_CPUID , + +}ovmf_sev_metadata_desc_type ; + +typedef struct __attribute__((__packed__ ))OvmfSevMetadataDesc { +uint32_t base; +uint32_t len; +ovmf_sev_metadata_desc_type type; +}OvmfSevMetadataDesc ; + +typedef struct __attribute__((__packed__ ))OvmfSevMetadata { +uint8_t signature[4 ]; +uint32_t len; +uint32_t version; +uint32_t num_desc; +OvmfSevMetadataDesc descs[]; +}OvmfSevMetadata ; + +OvmfSevMetadata *pc_system_get_ovmf_sev_metadata_ptr (void );void pc_pci_as_mapping_init (MemoryRegion *system_memory,MemoryRegion *pci_address_space);
target/i386/sev.h +2 -0
@@ -66,4 +66,6 @@ int sev_inject_launch_secret(const char *hdr, const char *secret,int sev_es_save_reset_vector (void *flash_ptr,uint64_t flash_size);void sev_es_set_reset_vector (CPUState *cpu); +void pc_system_parse_sev_metadata (uint8_t *flash_ptr,size_t flash_size); +#endif
hw/i386/pc_sysfw.c +4 -0
@@ -260,6 +260,10 @@ void x86_firmware_configure(void *ptr, int size)pc_system_parse_ovmf_flash (ptr, size);if (sev_enabled ()) { + +/* Copy the SEV metadata table (if it exists) */ +pc_system_parse_sev_metadata (ptr, size); + ret =sev_es_save_reset_vector (ptr, size);if (ret) {error_report ("failed to locate and/or save reset vector" );
target/i386/sev-sysemu-stub.c +4 -0
@@ -67,3 +67,7 @@ void hmp_info_sev(Monitor *mon, const QDict *qdict) {monitor_printf (mon,"SEV is not available in this QEMU\n" ); } + +void pc_system_parse_sev_metadata (uint8_t *flash_ptr,size_t flash_size) +{ +}
target/i386/sev.c +32 -0
@@ -597,6 +597,38 @@ SevCapability *qmp_query_sev_capabilities(Error **errp)return sev_get_capabilities (errp); } +static OvmfSevMetadata *ovmf_sev_metadata_table; + +#define OVMF_SEV_META_DATA_GUID "dc886566-984a-4798-A75e-5585a7bf67cc" +typedef struct __attribute__((__packed__ ))OvmfSevMetadataOffset { +uint32_t offset; +}OvmfSevMetadataOffset ; + +OvmfSevMetadata *pc_system_get_ovmf_sev_metadata_ptr (void ) +{ +return ovmf_sev_metadata_table; +} + +void pc_system_parse_sev_metadata (uint8_t *flash_ptr,size_t flash_size) +{ +OvmfSevMetadata *metadata; +OvmfSevMetadataOffset *data; + +if (!pc_system_ovmf_table_find (OVMF_SEV_META_DATA_GUID , (uint8_t **)&data, +NULL )) { +return ; + } + + metadata = (OvmfSevMetadata *)(flash_ptr + flash_size - data->offset); +if (memcmp (metadata->signature,"ASEV" ,4 ) !=0 || + metadata->len <sizeof (OvmfSevMetadata) || + metadata->len > flash_size - data->offset) { +return ; + } + + ovmf_sev_metadata_table =g_memdup2 (metadata, metadata->len); +} +static SevAttestationReport *sev_get_attestation_report (const char *mnonce,Error **errp) {
Signature · 1 line
2.45.1
[PULL 40/45] i386/sev: Extract build_kernel_loader_hashes
In reply to Paolo BonziniFrom: Dov Murik <[email protected]>
Extract the building of the kernel hashes table out from sev_add_kernel_loader_hashes() to allow building it in other memory areas (for SNP support).
No functional change intended.
Message-ID: <[email protected]>
--- target/i386/sev.c | 102 ++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 44 deletions(-)
target/i386/sev.c +58 -44
@@ -1754,45 +1754,16 @@ static const QemuUUID sev_cmdline_entry_guid = { 0x4d, 0x36, 0xab, 0x2a) }; -/* -* Add the hashes of the linux kernel/initrd/cmdline to an encrypted guest page -* which is included in SEV's initial memory measurement. -*/ -bool sev_add_kernel_loader_hashes (SevKernelLoaderContext *ctx,Error **errp) +static bool build_kernel_loader_hashes (PaddedSevHashTable *padded_ht, +SevKernelLoaderContext *ctx, +Error **errp) { -uint8_t *data; -SevHashTableDescriptor *area;SevHashTable *ht; -PaddedSevHashTable *padded_ht;uint8_t cmdline_hash[HASH_SIZE ];uint8_t initrd_hash[HASH_SIZE ];uint8_t kernel_hash[HASH_SIZE ];uint8_t *hashp;size_t hash_len =HASH_SIZE ; -hwaddr mapped_len =sizeof (*padded_ht); -MemTxAttrs attrs = {0 }; -bool ret = true; -SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); - -/* -* Only add the kernel hashes if the sev-guest configuration explicitly -* stated kernel-hashes=on. -*/ -if (!sev_common->kernel_hashes) { -return false; - } - -if (!pc_system_ovmf_table_find (SEV_HASH_TABLE_RV_GUID , &data,NULL )) { -error_setg (errp,"SEV: kernel specified but guest firmware " -"has no hashes table GUID" ); -return false; - } - area = (SevHashTableDescriptor *)data; -if (!area->base || area->size <sizeof (PaddedSevHashTable)) { -error_setg (errp,"SEV: guest firmware hashes table area is invalid " -"(base=0x%x size=0x%x)" , area->base, area->size); -return false; - }/* * Calculate hash of kernel command-line with the terminating null byte. If
@@ -1829,16 +1800,6 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp) }assert (hash_len ==HASH_SIZE ); -/* -* Populate the hashes table in the guest's memory at the OVMF-designated -* area for the SEV hashes table -*/ - padded_ht =address_space_map (&address_space_memory, area->base, - &mapped_len, true, attrs); -if (!padded_ht || mapped_len !=sizeof (*padded_ht)) { -error_setg (errp,"SEV: cannot map hashes table guest memory area" ); -return false; - } ht = &padded_ht->ht; ht->guid = sev_hash_table_header_guid;
@@ -1859,8 +1820,61 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)/* zero the excess data so the measurement can be reliably calculated */ memset (padded_ht->padding,0 ,sizeof (padded_ht->padding)); -if (sev_encrypt_flash (area->base, (uint8_t *)padded_ht, -sizeof (*padded_ht), errp) <0 ) { +return true; +} + +/* +* Add the hashes of the linux kernel/initrd/cmdline to an encrypted guest page +* which is included in SEV's initial memory measurement. +*/ +bool sev_add_kernel_loader_hashes (SevKernelLoaderContext *ctx,Error **errp) +{ +uint8_t *data; +SevHashTableDescriptor *area; +PaddedSevHashTable *padded_ht; +hwaddr mapped_len =sizeof (*padded_ht); +MemTxAttrs attrs = {0 }; +bool ret = true; +SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs); + +/* +* Only add the kernel hashes if the sev-guest configuration explicitly +* stated kernel-hashes=on. +*/ +if (!sev_common->kernel_hashes) { +return false; + } + +if (!pc_system_ovmf_table_find (SEV_HASH_TABLE_RV_GUID , &data,NULL )) { +error_setg (errp,"SEV: kernel specified but guest firmware " +"has no hashes table GUID" ); +return false; + } + + area = (SevHashTableDescriptor *)data; +if (!area->base || area->size <sizeof (PaddedSevHashTable)) { +error_setg (errp,"SEV: guest firmware hashes table area is invalid " +"(base=0x%x size=0x%x)" , area->base, area->size); +return false; + } + +/* +* Populate the hashes table in the guest's memory at the OVMF-designated +* area for the SEV hashes table +*/ + padded_ht =address_space_map (&address_space_memory, area->base, + &mapped_len, true, attrs); +if (!padded_ht || mapped_len !=sizeof (*padded_ht)) { +error_setg (errp,"SEV: cannot map hashes table guest memory area" ); +return false; + } + +if (build_kernel_loader_hashes (padded_ht, ctx, errp)) { +if (sev_encrypt_flash (area->base, (uint8_t *)padded_ht, +sizeof (*padded_ht), errp) <0 ) { + ret = false; + } + }else { ret = false; }
Signature · 1 line
2.45.1
[PULL 45/45] hw/i386: Add support for loading BIOS using guest_memfd
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
When guest_memfd is enabled, the BIOS is generally part of the initial encrypted guest image and will be accessed as private guest memory. Add the necessary changes to set up the associated RAM region with a guest_memfd backend to allow for this.
Current support centers around using -bios to load the BIOS data. Support for loading the BIOS via pflash requires additional enablement since those interfaces rely on the use of ROM memory regions which make use of the KVM_MEM_READONLY memslot flag, which is not supported for guest_memfd-backed memslots.
Message-ID: <[email protected]>
--- hw/i386/x86-common.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
hw/i386/x86-common.c +12 -5
@@ -1001,8 +1001,13 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, (bios_size % 65536) != 0) { goto bios_error; } -memory_region_init_ram (&x86ms->bios,NULL ,"pc.bios" , bios_size, - &error_fatal); +if (machine_require_guest_memfd (MACHINE (x86ms))) { +memory_region_init_ram_guest_memfd (&x86ms->bios,NULL ,"pc.bios" , + bios_size, &error_fatal); + }else { +memory_region_init_ram (&x86ms->bios,NULL ,"pc.bios" , + bios_size, &error_fatal); + }if (sev_enabled ()) {/* * The concept of a "reset" simply doesn't exist for
@@ -1023,9 +1028,11 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, }g_free (filename); -/* map the last 128KB of the BIOS in ISA space */ -x86_isa_bios_init (&x86ms->isa_bios, rom_memory, &x86ms->bios, - !isapc_ram_fw); +if (!machine_require_guest_memfd (MACHINE (x86ms))) { +/* map the last 128KB of the BIOS in ISA space */ +x86_isa_bios_init (&x86ms->isa_bios, rom_memory, &x86ms->bios, + !isapc_ram_fw); + }/* map all the bios at the top of memory */ memory_region_add_subregion(rom_memory,
Signature · 1 line
2.45.1
[PULL 43/45] memory: Introduce memory_region_init_ram_guest_memfd()
In reply to Paolo BonziniFrom: Xiaoyao Li <[email protected]>
Introduce memory_region_init_ram_guest_memfd() to allocate private guset memfd on the MemoryRegion initialization. It's for the use case of TDVF, which must be private on TDX case.
Message-ID: <[email protected]>
--- include/exec/memory.h | 6 ++++++ system/memory.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
include/exec/memory.h +6 -0
@@ -1638,6 +1638,12 @@ bool memory_region_init_ram(MemoryRegion *mr,uint64_t size, Error **errp); +bool memory_region_init_ram_guest_memfd (MemoryRegion *mr, +Object *owner, +const char *name, +uint64_t size, +Error **errp); +/** * memory_region_init_rom: Initialize a ROM memory region. *
system/memory.c +24 -0
@@ -3649,6 +3649,30 @@ bool memory_region_init_ram(MemoryRegion *mr,return true; } +bool memory_region_init_ram_guest_memfd (MemoryRegion *mr, +Object *owner, +const char *name, +uint64_t size, +Error **errp) +{ +DeviceState *owner_dev; + +if (!memory_region_init_ram_flags_nomigrate (mr, owner, name, size, +RAM_GUEST_MEMFD , errp)) { +return false; + } +/* This will assert if owner is neither NULL nor a DeviceState. +* We only want the owner here for the purposes of defining a +* unique name for migration. TODO: Ideally we should implement +* a naming scheme for Objects which are not DeviceStates, in +* which case we can relax this restriction. +*/ + owner_dev =DEVICE (owner); +vmstate_register_ram (mr, owner_dev); + +return true; +} + bool memory_region_init_rom(MemoryRegion *mr, Object *owner, const char *name,
Signature · 1 line
2.45.1
[PULL 01/45] virtio-blk: remove SCSI passthrough functionality
In reply to Paolo BonziniThe legacy SCSI passthrough functionality has never been enabled for VIRTIO 1.0 and was deprecated more than four years ago.
Get rid of it---almost, because QEMU is advertising it unconditionally for legacy virtio-blk devices. Just parse the header and return a nonzero status.
--- docs/about/deprecated.rst | 10 -- docs/about/removed-features.rst | 8 ++ hw/block/virtio-blk.c | 166 +++----------------------------- hw/core/machine.c | 2 - 4 files changed, 19 insertions(+), 167 deletions(-)
docs/about/deprecated.rst +0 -10
@@ -296,16 +296,6 @@ Device options Emulated device options ''''''''''''''''''''''' -``-device virtio-blk,scsi=on|off`` (since 5.0) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The virtio-blk SCSI passthrough feature is a legacy VIRTIO feature. VIRTIO 1.0 -and later do not support it because the virtio-scsi device was introduced for -full SCSI support. Use virtio-scsi instead when SCSI passthrough is required. - -Note this also applies to ``-device virtio-blk-pci,scsi=on|off``, which is an -alias. - ``-device nvme-ns,eui64-default=on|off`` (since 7.1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
docs/about/removed-features.rst +8 -0
@@ -510,6 +510,14 @@ than zero. Removed along with the ``compression`` migration capability. +``-device virtio-blk,scsi=on|off`` (since 9.1) +'''''''''''''''''''''''''''''''''''''''''''''' + +The virtio-blk SCSI passthrough feature is a legacy VIRTIO feature. VIRTIO 1.0 +and later do not support it because the virtio-scsi device was introduced for +full SCSI support. Use virtio-scsi instead when SCSI passthrough is required. + + User-mode emulator command line arguments -----------------------------------------
hw/block/virtio-blk.c +11 -155
206 lines not on this page · raw message
hw/core/machine.c +0 -2
@@ -265,8 +265,6 @@ GlobalProperty hw_compat_2_5[] = {const size_t hw_compat_2_5_len =G_N_ELEMENTS (hw_compat_2_5);GlobalProperty hw_compat_2_4[] = { -/* Optional because the 'scsi' property is Linux-only */ - {"virtio-blk-device" ,"scsi" ,"true" , .optional = true }, {"e1000" ,"extra_mac_registers" ,"off" }, {"virtio-pci" ,"x-disable-pcie" ,"on" }, {"virtio-pci" ,"migrate-extra" ,"off" },
Signature · 1 line
2.45.1
Re: [PULL 01/45] virtio-blk: remove SCSI passthrough functionality
Quoted 26 lines · Paolo Bonzini
The legacy SCSI passthrough functionality has never been enabled for VIRTIO 1.0 and was deprecated more than four years ago.
Get rid of it---almost, because QEMU is advertising it unconditionally for legacy virtio-blk devices. Just parse the header and return a nonzero status.
Signed-off-by Paolo Bonzini<[email protected]>--- docs/about/deprecated.rst | 10 -- docs/about/removed-features.rst | 8 ++ hw/block/virtio-blk.c | 166 +++----------------------------- hw/core/machine.c | 2 - 4 files changed, 19 insertions(+), 167 deletions(-)docs/about/deprecated.rst +0
-3@@ -296,16 +296,6 @@ Device options Emulated device options ''''''''''''''''''''''' -``-device virtio-blk,scsi=on|off`` (since 5.0) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -
docs/about/deprecated.rst Device options · line 301
Quoted 10 lines
docs/about/deprecated.rst +0
-7-The virtio-blk SCSI passthrough feature is a legacy VIRTIO feature. VIRTIO 1.0 -and later do not support it because the virtio-scsi device was introduced for -full SCSI support. Use virtio-scsi instead when SCSI passthrough is required. - -Note this also applies to ``-device virtio-blk-pci,scsi=on|off``, which is an -alias. - ``-device nvme-ns,eui64-default=on|off`` (since 7.1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Still used by avocado/tuxrun_baselines.py:TuxRunBaselineTest.test_ppc64, and so causes a new failure.
r~
[PULL 10/45] target/i386/tcg: Fix RDPID feature check
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
DisasContext.cpuid_ext_features indicates CPUID.01H.ECX.
Use DisasContext.cpuid_7_0_ecx_features field to check RDPID feature bit (CPUID_7_0_ECX_RDPID).
Message-ID: <[email protected]>
--- target/i386/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/translate.c +1 -1
@@ -3199,7 +3199,7 @@ static void disas_insn_old(DisasContext *s, CPUState *cpu, int b) goto illegal_op; }if (s->prefix &PREFIX_REPZ ) { -if (!(s->cpuid_ext_features &CPUID_7_0_ECX_RDPID )) { +if (!(s->cpuid_7_0_ecx_features &CPUID_7_0_ECX_RDPID )) { goto illegal_op; }gen_helper_rdpid (s->T0, tcg_env);
Signature · 1 line
2.45.1
[PULL 39/45] i386/sev: Enable KVM_HC_MAP_GPA_RANGE hcall for SNP guests
In reply to Paolo BonziniFrom: Michael Roth <[email protected]>
KVM will forward GHCB page-state change requests to userspace in the form of KVM_HC_MAP_GPA_RANGE, so make sure the hypercall handling is enabled for SNP guests.
Message-ID: <[email protected]>
--- target/i386/sev.c | 5 +++++ 1 file changed, 5 insertions(+)
target/i386/sev.c +5 -0
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include <linux/kvm.h> +#include <linux/kvm_para.h> #include <linux/psp-sev.h> #include <sys/ioctl.h>
@@ -758,6 +759,10 @@ sev_snp_launch_start(SevCommonState *sev_common)trace_kvm_sev_snp_launch_start (start->policy, sev_snp_guest->guest_visible_workarounds); +if (!kvm_enable_hypercall (BIT_ULL (KVM_HC_MAP_GPA_RANGE ))) { +return 1 ; + } + rc =sev_ioctl (sev_common->sev_fd,KVM_SEV_SNP_LAUNCH_START , start, &fw_error);if (rc <0 ) {
Signature · 1 line
2.45.1
[PULL 37/45] i386/sev: Invoke launch_updata_data() for SNP class
In reply to Paolo BonziniFrom: Pankaj Gupta <[email protected]>
Invoke as sev_snp_launch_update_data() for SNP object.
Message-ID: <[email protected]>
--- target/i386/sev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
target/i386/sev.c +10 -0
@@ -1091,6 +1091,15 @@ snp_launch_update_data(uint64_t gpa, void *hva,return 0 ; } +static int +sev_snp_launch_update_data (SevCommonState *sev_common,hwaddr gpa, +uint8_t *ptr,uint64_t len) +{ +int ret =snp_launch_update_data (gpa, ptr, len, +KVM_SEV_SNP_PAGE_TYPE_NORMAL ); +return ret; +} +static int sev_snp_cpuid_info_fill (SnpCpuidInfo *snp_cpuid_info,const KvmCpuidInfo *kvm_cpuid_info)
@@ -2216,6 +2225,7 @@ sev_snp_guest_class_init(ObjectClass *oc, void *data) klass->launch_start = sev_snp_launch_start; klass->launch_finish = sev_snp_launch_finish; + klass->launch_update_data = sev_snp_launch_update_data; klass->kvm_init = sev_snp_kvm_init; x86_klass->kvm_type = sev_snp_kvm_type;
Signature · 1 line
2.45.1
[PULL 04/45] host/i386: assume presence of CMOV
In reply to Paolo BonziniQEMU now requires an x86-64-v2 host, which always has CMOV. Use it freely in TCG generated code.
--- host/include/i386/host/cpuinfo.h | 1 - util/cpuinfo-i386.c | 1 - tcg/i386/tcg-target.c.inc | 15 +-------------- 3 files changed, 1 insertion(+), 16 deletions(-)
host/include/i386/host/cpuinfo.h +0 -1
@@ -9,7 +9,6 @@/* Digested version of <cpuid.h> */ #define CPUINFO_ALWAYS (1u << 0)/* so cpuinfo is nonzero */ -#define CPUINFO_CMOV (1u << 1)#define CPUINFO_MOVBE (1u << 2)#define CPUINFO_LZCNT (1u << 3)#define CPUINFO_POPCNT (1u << 4)
util/cpuinfo-i386.c +0 -1
@@ -34,7 +34,6 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)if (max >=1 ) {__cpuid (1 , a, b, c, d); - info |= (d & bit_CMOV ?CPUINFO_CMOV :0 ); info |= (d & bit_SSE2 ?CPUINFO_SSE2 :0 ); info |= (c & bit_MOVBE ?CPUINFO_MOVBE :0 ); info |= (c & bit_POPCNT ?CPUINFO_POPCNT :0 );
tcg/i386/tcg-target.c.inc +1 -14
@@ -157,12 +157,6 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) #define SOFTMMU_RESERVE_REGS \ (tcg_use_softmmu ? (1 << TCG_REG_L0) | (1 << TCG_REG_L1) : 0) -/* For 64-bit, we always know that CMOV is available. */ -#if TCG_TARGET_REG_BITS == 64 -# define have_cmov true -#else -# define have_cmov (cpuinfo & CPUINFO_CMOV) -#endif #define have_bmi2 (cpuinfo & CPUINFO_BMI2) #define have_lzcnt (cpuinfo & CPUINFO_LZCNT)
@@ -1815,14 +1809,7 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, static void tcg_out_cmov(TCGContext *s, int jcc, int rexw, TCGReg dest, TCGReg v1) { - if (have_cmov) { - tcg_out_modrm(s, OPC_CMOVCC | jcc | rexw, dest, v1); - } else { - TCGLabel *over = gen_new_label(); - tcg_out_jxx(s, jcc ^ 1, over, 1); - tcg_out_mov(s, TCG_TYPE_I32, dest, v1); - tcg_out_label(s, over); - } + tcg_out_modrm(s, OPC_CMOVCC | jcc | rexw, dest, v1); } static void tcg_out_movcond(TCGContext *s, int rexw, TCGCond cond,
Signature · 1 line
2.45.1
[PULL 35/45] hw/i386/sev: Add support to encrypt BIOS when SEV-SNP is enabled
In reply to Paolo BonziniFrom: Brijesh Singh <[email protected]>
As with SEV, an SNP guest requires that the BIOS be part of the initial encrypted/measured guest payload. Extend sev_encrypt_flash() to handle the SNP case and plumb through the GPA of the BIOS location since this is needed for SNP.
Message-ID: <[email protected]>
--- include/hw/i386/x86.h | 2 +- target/i386/sev.h | 2 +- hw/i386/pc_sysfw.c | 12 +++++++----- hw/i386/x86-common.c | 2 +- target/i386/sev-sysemu-stub.c | 2 +- target/i386/sev.c | 5 +++-- 6 files changed, 14 insertions(+), 11 deletions(-)
include/hw/i386/x86.h +1 -1
@@ -154,6 +154,6 @@ void ioapic_init_gsi(GSIState *gsi_state, Object *parent);DeviceState *ioapic_init_secondary (GSIState *gsi_state);/* pc_sysfw.c */ -void x86_firmware_configure (void *ptr,int size); +void x86_firmware_configure (hwaddr gpa,void *ptr,int size);#endif
target/i386/sev.h +1 -1
@@ -59,7 +59,7 @@ uint32_t sev_get_cbit_position(void);uint32_t sev_get_reduced_phys_bits (void );bool sev_add_kernel_loader_hashes (SevKernelLoaderContext *ctx,Error **errp); -int sev_encrypt_flash (uint8_t *ptr,uint64_t len,Error **errp); +int sev_encrypt_flash (hwaddr gpa,uint8_t *ptr,uint64_t len,Error **errp);int sev_inject_launch_secret (const char *hdr,const char *secret,uint64_t gpa,Error **errp);
hw/i386/pc_sysfw.c +7 -5
@@ -148,6 +148,8 @@ static void pc_system_flash_map(PCMachineState *pcms,assert (PC_MACHINE_GET_CLASS (pcms)->pci_enabled);for (i =0 ; i <ARRAY_SIZE (pcms->flash); i++) { +hwaddr gpa; + system_flash = pcms->flash[i]; blk =pflash_cfi01_get_blk (system_flash);if (!blk) {
@@ -177,11 +179,11 @@ static void pc_system_flash_map(PCMachineState *pcms, } total_size += size; + gpa =0x100000000ULL - total_size;/* where the flash is mapped */ qdev_prop_set_uint32 (DEVICE (system_flash),"num-blocks" , size /FLASH_SECTOR_SIZE );sysbus_realize_and_unref (SYS_BUS_DEVICE (system_flash), &error_fatal); -sysbus_mmio_map (SYS_BUS_DEVICE (system_flash),0 , -0x100000000ULL - total_size); +sysbus_mmio_map (SYS_BUS_DEVICE (system_flash),0 , gpa);if (i ==0 ) { flash_mem =pflash_cfi01_get_memory (system_flash);
@@ -196,7 +198,7 @@ static void pc_system_flash_map(PCMachineState *pcms,if (sev_enabled ()) { flash_ptr =memory_region_get_ram_ptr (flash_mem); flash_size =memory_region_size (flash_mem); -x86_firmware_configure (flash_ptr, flash_size); +x86_firmware_configure (gpa, flash_ptr, flash_size); } } }
@@ -249,7 +251,7 @@ void pc_system_firmware_init(PCMachineState *pcms,pc_system_flash_cleanup_unused (pcms); } -void x86_firmware_configure (void *ptr,int size) +void x86_firmware_configure (hwaddr gpa,void *ptr,int size) {int ret;
@@ -270,6 +272,6 @@ void x86_firmware_configure(void *ptr, int size)exit (1 ); } -sev_encrypt_flash (ptr, size, &error_fatal); +sev_encrypt_flash (gpa, ptr, size, &error_fatal); } }
hw/i386/x86-common.c +1 -1
@@ -1013,7 +1013,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,*/ void *ptr =memory_region_get_ram_ptr (&x86ms->bios);load_image_size (filename, ptr, bios_size); -x86_firmware_configure (ptr, bios_size); +x86_firmware_configure (0x100000000ULL - bios_size, ptr, bios_size); }else {memory_region_set_readonly (&x86ms->bios, !isapc_ram_fw); ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 );
target/i386/sev-sysemu-stub.c +1 -1
@@ -42,7 +42,7 @@ void qmp_sev_inject_launch_secret(const char *packet_header, const char *secret,error_setg (errp,"SEV is not available in this QEMU" ); } -int sev_encrypt_flash (uint8_t *ptr,uint64_t len,Error **errp) +int sev_encrypt_flash (hwaddr gpa,uint8_t *ptr,uint64_t len,Error **errp) {g_assert_not_reached (); }
target/i386/sev.c +3 -2
@@ -1484,7 +1484,7 @@ static int sev_snp_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) }int -sev_encrypt_flash (uint8_t *ptr,uint64_t len,Error **errp) +sev_encrypt_flash (hwaddr gpa,uint8_t *ptr,uint64_t len,Error **errp) {SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs);
@@ -1841,7 +1841,8 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)/* zero the excess data so the measurement can be reliably calculated */ memset (padded_ht->padding,0 ,sizeof (padded_ht->padding)); -if (sev_encrypt_flash ((uint8_t *)padded_ht,sizeof (*padded_ht), errp) <0 ) { +if (sev_encrypt_flash (area->base, (uint8_t *)padded_ht, +sizeof (*padded_ht), errp) <0 ) { ret = false; }
Signature · 1 line
2.45.1
[PULL 05/45] host/i386: assume presence of SSE2
In reply to Paolo BonziniQEMU now requires an x86-64-v2 host, which has SSE2. Use it freely in buffer_is_zero.
--- host/include/i386/host/cpuinfo.h | 1 - util/bufferiszero.c | 4 ++-- util/cpuinfo-i386.c | 1 - 3 files changed, 2 insertions(+), 4 deletions(-)
host/include/i386/host/cpuinfo.h +0 -1
@@ -14,7 +14,6 @@#define CPUINFO_POPCNT (1u << 4)#define CPUINFO_BMI1 (1u << 5)#define CPUINFO_BMI2 (1u << 6) -#define CPUINFO_SSE2 (1u << 7)#define CPUINFO_AVX1 (1u << 9)#define CPUINFO_AVX2 (1u << 10)#define CPUINFO_AVX512F (1u << 11)
util/bufferiszero.c +2 -2
@@ -188,14 +188,14 @@ static biz_accel_fn const accel_table[] = {static unsigned best_accel (void ) { +#ifdef CONFIG_AVX2_OPT unsigned info =cpuinfo_init (); -#ifdef CONFIG_AVX2_OPT if (info &CPUINFO_AVX2 ) {return 2 ; }#endif -return info &CPUINFO_SSE2 ?1 :0 ; +return 1 ; }#elif defined(__aarch64__) && defined(__ARM_NEON)
util/cpuinfo-i386.c +0 -1
@@ -34,7 +34,6 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)if (max >=1 ) {__cpuid (1 , a, b, c, d); - info |= (d & bit_SSE2 ?CPUINFO_SSE2 :0 ); info |= (c & bit_MOVBE ?CPUINFO_MOVBE :0 ); info |= (c & bit_POPCNT ?CPUINFO_POPCNT :0 ); info |= (c & bit_PCLMUL ?CPUINFO_PCLMUL :0 );
Signature · 1 line
2.45.1