qemu/hw-misc-support-vpsp.patch

191 lines
5.3 KiB
Diff
Raw Permalink Normal View History

QEMU update to version 8.2.0-18: - hw/loongarch/virt: Fix FDT memory node address width - hw/loongarch: Fix fdt memory node wrong 'reg' - load_elf: fix iterator's type for elf file processing - migration/colo: Fix bdrv_graph_rdlock_main_loop: Assertion `!qemu_in_… - target/i386: no single-step exception after MOV or POP SS - char-stdio: Restore blocking mode of stdout on exit - backends/cryptodev-builtin: Fix local_error leaks - target/loongarch: fix a wrong print in cpu dump - virtio-pci: fix use of a released vector - target/arm: Disable SVE extensions when SVE is disabled - hw/misc/bcm2835_property: Fix handling of FRAMEBUFFER_SET_PALETTE - target/i386: Introduce SapphireRapids-v3 to add missing features - virtio-net: Ensure queue index fits with RSS (CVE-2024-6505) - nbd/server: CVE-2024-7409: Avoid use-after-free when closing server - update io/trace-events. Parameters should remain consistent. - update docs/tools/virtfs-proxy-helper.rst. This place is spelled wrong. - kvm: Add support for CSV2 reboot - target/i386/kvm: Fix the resettable info when emulate Hygon CSV2 guest - target/i386: get/set/migrate GHCB state - target/i386: csv: Add support for migrate VMSA for CSV2 guest - migration/ram: Accelerate the loading of CSV guest's encrypted pages - migration/ram: Accelerate the transmission of CSV guest's encrypted pages - target/i386: csv: add support to load incoming encrypted pages queued in the CMD list - target/i386: csv: add support to queue the incoming page into a list - target/i386: csv: add support to encrypt the outgoing pages in the list queued before. - target/i386: csv: add support to queue the outgoing page into a list - target/i386: csv: Read cert chain from file when prepared for CSV live migration - target/i386: Introduce header file csv.h - migration/ram: Fix calculation of gfn correpond to a page in ramblock - target/i386: sev: Clear shared_regions_list when reboot CSV Guest - migration/ram: Force encrypted status for VGA vram - target/i386: sev: Return 0 if sev_send_get_packet_len() fails - kvm: Add support for userspace MSR filtering and handling of MSR_KVM_MIGRATION_CONTROL. - migration/ram: Force encrypted status for flash0 & flash1 devices. - migration/ram: add support to send encrypted pages - migration: add support to migrate shared regions list - kvm: Add support for SEV shared regions list and KVM_EXIT_HYPERCALL. - target/i386: sev: add support to load incoming encrypted page - target/i386: sev: add support to encrypt the outgoing page - target/i386: sev: do not create launch context for an incoming guest - target/i386: sev: provide callback to setup outgoing context - confidential guest support: introduce ConfidentialGuestMemoryEncryptionOps for encrypted VMs - migration.json: add AMD SEV specific migration parameters - doc: update AMD SEV to include Live migration flow - crypto/tlscredspsk: Free username on finalize - hw/nvme: fix leak of uninitialized memory in io_mgmt_recv - hw/display/vhost-user-gpu.c: fix vhost_user_gpu_chr_read() - cvm : Implement command blacklist for cvm security enhancement - crypto: Introduce SM3 hash hmac pbkdf algorithm - virtio-net: Use virtual time for RSC timers - vvfat: Fix bug in writing to middle of file - hw/core/ptimer: fix timer zero period condition for freq > 1GHz - hw/misc: support vpsp Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com>
2024-09-18 15:20:53 +08:00
From f74cee44cd57da213a790f7711a68da0f4de061a Mon Sep 17 00:00:00 2001
From: xiongmengbiao <xiongmengbiao@hygon.cn>
Date: Thu, 30 Nov 2023 13:47:21 +0800
Subject: [PATCH] hw/misc: support vpsp
simulate a psp misc device for support tkm's key isolation
Signed-off-by: xiongmengbiao <xiongmengbiao@hygon.cn>
---
hw/misc/Kconfig | 4 ++
hw/misc/meson.build | 1 +
hw/misc/psp.c | 141 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 146 insertions(+)
create mode 100644 hw/misc/psp.c
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index cc8a8c1418..2ea5c68eb5 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -200,4 +200,8 @@ config IOSB
config XLNX_VERSAL_TRNG
bool
+config PSP_DEV
+ bool
+ default y
+
source macio/Kconfig
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
index 36c20d5637..28cba0ac28 100644
--- a/hw/misc/meson.build
+++ b/hw/misc/meson.build
@@ -9,6 +9,7 @@ system_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c'))
system_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c'))
system_ss.add(when: 'CONFIG_LED', if_true: files('led.c'))
system_ss.add(when: 'CONFIG_PVPANIC_COMMON', if_true: files('pvpanic.c'))
+system_ss.add(when: 'CONFIG_PSP_DEV', if_true: files('psp.c'))
# ARM devices
system_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c'))
diff --git a/hw/misc/psp.c b/hw/misc/psp.c
new file mode 100644
index 0000000000..6ff2ceec10
--- /dev/null
+++ b/hw/misc/psp.c
@@ -0,0 +1,141 @@
+/*
+ * hygon psp device emulation
+ *
+ * Copyright 2024 HYGON Corp.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/compiler.h"
+#include "qemu/error-report.h"
+#include "qapi/error.h"
+#include "migration/vmstate.h"
+#include "hw/qdev-properties.h"
+#include "sysemu/runstate.h"
+#include <sys/ioctl.h>
+
+#define TYPE_PSP_DEV "psp"
+OBJECT_DECLARE_SIMPLE_TYPE(PSPDevState, PSP_DEV)
+
+struct PSPDevState {
+ /* Private */
+ DeviceState pdev;
+
+ /* Public */
+ Notifier shutdown_notifier;
+ int dev_fd;
+ bool enabled;
+
+ /**
+ * vid is used to identify a virtual machine in qemu.
+ * When a virtual machine accesses a tkm key,
+ * the TKM module uses different key spaces based on different vids.
+ */
+ uint32_t vid;
+};
+
+#define PSP_DEV_PATH "/dev/hygon_psp_config"
+#define HYGON_PSP_IOC_TYPE 'H'
+#define PSP_IOC_MUTEX_ENABLE _IOWR(HYGON_PSP_IOC_TYPE, 1, NULL)
+#define PSP_IOC_MUTEX_DISABLE _IOWR(HYGON_PSP_IOC_TYPE, 2, NULL)
+#define PSP_IOC_VPSP_OPT _IOWR(HYGON_PSP_IOC_TYPE, 3, NULL)
+
+enum VPSP_DEV_CTRL_OPCODE {
+ VPSP_OP_VID_ADD,
+ VPSP_OP_VID_DEL,
+};
+
+struct psp_dev_ctrl {
+ unsigned char op;
+ union {
+ unsigned int vid;
+ unsigned char reserved[128];
+ } data;
+};
+
+static void psp_dev_destroy(PSPDevState *state)
+{
+ struct psp_dev_ctrl ctrl = { 0 };
+ if (state && state->dev_fd) {
+ if (state->enabled) {
+ ctrl.op = VPSP_OP_VID_DEL;
+ if (ioctl(state->dev_fd, PSP_IOC_VPSP_OPT, &ctrl) < 0) {
+ error_report("VPSP_OP_VID_DEL: %d", -errno);
+ } else {
+ state->enabled = false;
+ }
+ }
+ qemu_close(state->dev_fd);
+ state->dev_fd = 0;
+ }
+}
+
+/**
+ * Guest OS performs shut down operations through 'shutdown' and 'powerdown' event.
+ * The 'powerdown' event will also trigger 'shutdown' in the end,
+ * so only attention to the 'shutdown' event.
+ *
+ * When Guest OS trigger 'reboot' or 'reset' event, to do nothing.
+*/
+static void psp_dev_shutdown_notify(Notifier *notifier, void *data)
+{
+ PSPDevState *state = container_of(notifier, PSPDevState, shutdown_notifier);
+ psp_dev_destroy(state);
+}
+
+static void psp_dev_realize(DeviceState *dev, Error **errp)
+{
+ struct psp_dev_ctrl ctrl = { 0 };
+ PSPDevState *state = PSP_DEV(dev);
+
+ state->dev_fd = qemu_open_old(PSP_DEV_PATH, O_RDWR);
+ if (state->dev_fd < 0) {
+ error_setg(errp, "fail to open %s, errno %d.", PSP_DEV_PATH, errno);
+ goto end;
+ }
+
+ ctrl.op = VPSP_OP_VID_ADD;
+ ctrl.data.vid = state->vid;
+ if (ioctl(state->dev_fd, PSP_IOC_VPSP_OPT, &ctrl) < 0) {
+ error_setg(errp, "psp_dev_realize VPSP_OP_VID_ADD vid %d, return %d", ctrl.data.vid, -errno);
+ goto end;
+ }
+
+ state->enabled = true;
+ state->shutdown_notifier.notify = psp_dev_shutdown_notify;
+ qemu_register_shutdown_notifier(&state->shutdown_notifier);
+end:
+ return;
+}
+
+static struct Property psp_dev_properties[] = {
+ DEFINE_PROP_UINT32("vid", PSPDevState, vid, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void psp_dev_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->desc = "PSP Device";
+ dc->realize = psp_dev_realize;
+ set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+ device_class_set_props(dc, psp_dev_properties);
+}
+
+static const TypeInfo psp_dev_info = {
+ .name = TYPE_PSP_DEV,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(PSPDevState),
+ .class_init = psp_dev_class_init,
+};
+
+static void psp_dev_register_types(void)
+{
+ type_register_static(&psp_dev_info);
+}
+
+type_init(psp_dev_register_types)
--
2.41.0.windows.1