qemu/target-i386-csv-Add-command-to-initialize-CSV3-conte.patch

202 lines
5.5 KiB
Diff
Raw Normal View History

QEMU update to version 8.2.0-26: - vdpa-dev: Fix initialisation order to restore VDUSE compatibility - tcg: Allow top bit of SIMD_DATA_BITS to be set in simd_desc() - migration: fix-possible-int-overflow - target/m68k: Map FPU exceptions to FPSR register - qemu-options: Fix CXL Fixed Memory Window interleave-granularity typo - hvf: arm: Fix encodings for ID_AA64PFR1_EL1 and debug System registers - hw/intc/arm_gic: Fix handling of NS view of GICC_APR<n> - qio: Inherit follow_coroutine_ctx across TLS - target/riscv: Fix the element agnostic function problem - accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded - tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers - migration: Fix file migration with fdset - ui/vnc: don't return an empty SASL mechlist to the client - target/arm: Fix FJCVTZS vs flush-to-zero - hw/ppc/e500: Prefer QOM cast - sphinx/qapidoc: Fix to generate doc for explicit, unboxed arguments - hw/ppc/e500: Remove unused "irqs" parameter - hw/ppc/e500: Add missing device tree properties to i2c controller node - hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb() - hw/arm/mps2-tz.c: fix RX/TX interrupts order - target/i386: csv: Add support to migrate the incoming context for CSV3 guest - target/i386: csv: Add support to migrate the outgoing context for CSV3 guest - target/i386: csv: Add support to migrate the incoming page for CSV3 guest - target/i386: csv: Add support to migrate the outgoing page for CSV3 guest - linux-headers: update kernel headers to include CSV3 migration cmds - vfio: Only map shared region for CSV3 virtual machine - vga: Force full update for CSV3 guest - target/i386: csv: Load initial image to private memory for CSV3 guest - target/i386: csv: Do not register/unregister guest secure memory for CSV3 guest - target/i386: cpu: Populate CPUID 0x8000_001F when CSV3 is active - target/i386: csv: Add command to load vmcb to CSV3 guest memory - target/i386: csv: Add command to load data to CSV3 guest memory - target/i386: csv: Add command to initialize CSV3 context - target/i386: csv: Add CSV3 context - next-kbd: convert to use qemu_input_handler_register() - qemu/bswap: Undefine CPU_CONVERT() once done - exec/memop: Remove unused memop_big_endian() helper - hw/nvme: fix handling of over-committed queues - 9pfs: fix crash on 'Treaddir' request - hw/misc/psp: Pin the hugepage memory specified by mem2 during use for psp - hw/misc: support tkm use mem2 memory - hw/i386: add mem2 option for qemu - kvm: add support for guest physical bits - target/i386: add guest-phys-bits cpu property Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com> (cherry picked from commit f45f35e88509a4ffa9f62332ee9601e9fe1f8d09)
2024-12-12 17:01:35 +08:00
From 4ce59de673b1b190cde76c458ac9e92a6413172d Mon Sep 17 00:00:00 2001
From: jiangxin <jiangxin@hygon.cn>
Date: Wed, 25 Aug 2021 11:07:41 +0800
Subject: [PATCH] target/i386: csv: Add command to initialize CSV3 context
When CSV3 is enabled, KVM_CSV3_INIT command is used to initialize
the platform, which is implemented by reusing the SEV API framework
and extending the functionality.
The KVM_CSV3_INIT command should be performed earlier than
any other command.
Signed-off-by: Xin Jiang <jiangxin@hygon.cn>
Signed-off-by: hanliyang <hanliyang@hygon.cn>
---
linux-headers/linux/kvm.h | 11 +++++++++
target/i386/csv-sysemu-stub.c | 5 ++++
target/i386/csv.c | 45 +++++++++++++++++++++++++++++++++++
target/i386/csv.h | 4 ++++
target/i386/sev.c | 17 +++++++++++++
target/i386/sev.h | 7 ++++++
6 files changed, 89 insertions(+)
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 8dc00808ec..90869068c8 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -2108,6 +2108,17 @@ struct kvm_csv_init {
__u32 len;
};
+/* CSV3 command */
+enum csv3_cmd_id {
+ KVM_CSV3_NR_MIN = 0xc0,
+
+ KVM_CSV3_INIT = KVM_CSV3_NR_MIN,
+};
+
+struct kvm_csv3_init_data {
+ __u64 nodemask;
+};
+
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
diff --git a/target/i386/csv-sysemu-stub.c b/target/i386/csv-sysemu-stub.c
index 5874e4cc1d..72f0f5c772 100644
--- a/target/i386/csv-sysemu-stub.c
+++ b/target/i386/csv-sysemu-stub.c
@@ -14,3 +14,8 @@
#include "qemu/osdep.h"
#include "sev.h"
#include "csv.h"
+
+int csv3_init(uint32_t policy, int fd, void *state, struct sev_ops *ops)
+{
+ return 0;
+}
diff --git a/target/i386/csv.c b/target/i386/csv.c
index 9a1de04db7..fd3ea291ca 100644
--- a/target/i386/csv.c
+++ b/target/i386/csv.c
@@ -12,6 +12,13 @@
*/
#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+
+#include <linux/kvm.h>
+
+#ifdef CONFIG_NUMA
+#include <numaif.h>
+#endif
#include "cpu.h"
#include "sev.h"
@@ -21,6 +28,44 @@ bool csv_kvm_cpu_reset_inhibit;
Csv3GuestState csv3_guest = { 0 };
+int
+csv3_init(uint32_t policy, int fd, void *state, struct sev_ops *ops)
+{
+ int fw_error;
+ int ret;
+ struct kvm_csv3_init_data data = { 0 };
+
+#ifdef CONFIG_NUMA
+ int mode;
+ unsigned long nodemask;
+
+ /* Set flags as 0 to retrieve the default NUMA policy. */
+ ret = get_mempolicy(&mode, &nodemask, sizeof(nodemask) * 8, NULL, 0);
+ if (ret == 0 && mode == MPOL_BIND)
+ data.nodemask = nodemask;
+#endif
+
+ if (!ops || !ops->sev_ioctl || !ops->fw_error_to_str)
+ return -1;
+
+ csv3_guest.policy = policy;
+ if (csv3_enabled()) {
+ ret = ops->sev_ioctl(fd, KVM_CSV3_INIT, &data, &fw_error);
+ if (ret) {
+ csv3_guest.policy = 0;
+ error_report("%s: Fail to initialize ret=%d fw_error=%d '%s'",
+ __func__, ret, fw_error, ops->fw_error_to_str(fw_error));
+ return -1;
+ }
+
+ csv3_guest.sev_fd = fd;
+ csv3_guest.state = state;
+ csv3_guest.sev_ioctl = ops->sev_ioctl;
+ csv3_guest.fw_error_to_str = ops->fw_error_to_str;
+ }
+ return 0;
+}
+
bool
csv3_enabled(void)
{
diff --git a/target/i386/csv.h b/target/i386/csv.h
index ea87c1ba27..4096e8658b 100644
--- a/target/i386/csv.h
+++ b/target/i386/csv.h
@@ -15,6 +15,7 @@
#define I386_CSV_H
#include "qapi/qapi-commands-misc-target.h"
+#include "sev.h"
#define GUEST_POLICY_CSV3_BIT (1 << 6)
#define GUEST_POLICY_REUSE_ASID (1 << 7)
@@ -77,10 +78,13 @@ struct Csv3GuestState {
uint32_t policy;
int sev_fd;
void *state;
+ int (*sev_ioctl)(int fd, int cmd, void *data, int *error);
+ const char *(*fw_error_to_str)(int code);
};
typedef struct Csv3GuestState Csv3GuestState;
extern struct Csv3GuestState csv3_guest;
+extern int csv3_init(uint32_t policy, int fd, void *state, struct sev_ops *ops);
#endif
diff --git a/target/i386/sev.c b/target/i386/sev.c
index af61ca5ba8..1c453b3148 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -1225,6 +1225,18 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
goto err;
}
+ /* Support CSV3 */
+ if (!ret && cmd == KVM_SEV_ES_INIT) {
+ ret = csv3_init(sev_guest->policy, sev->sev_fd, (void *)&sev->state, &sev_ops);
+ if (ret) {
+ error_setg(errp, "%s: failed to init csv3 context", __func__);
+ goto err;
+ }
+ /* The CSV3 guest is not resettable */
+ if (csv3_enabled())
+ csv_kvm_cpu_reset_inhibit = true;
+ }
+
/*
* The LAUNCH context is used for new guest, if its an incoming guest
* then RECEIVE context will be created after the connection is established.
@@ -2635,6 +2647,11 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)
return ret;
}
+struct sev_ops sev_ops = {
+ .sev_ioctl = sev_ioctl,
+ .fw_error_to_str = fw_error_to_str,
+};
+
static void
sev_register_types(void)
{
diff --git a/target/i386/sev.h b/target/i386/sev.h
index 0bfe3879ef..e91431e0f7 100644
--- a/target/i386/sev.h
+++ b/target/i386/sev.h
@@ -80,4 +80,11 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
extern bool sev_kvm_has_msr_ghcb;
+struct sev_ops {
+ int (*sev_ioctl)(int fd, int cmd, void *data, int *error);
+ const char *(*fw_error_to_str)(int code);
+};
+
+extern struct sev_ops sev_ops;
+
#endif
--
2.41.0.windows.1