代码拉取完成,页面将自动刷新
同步操作将从 src-anolis-os/qemu-kvm 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From fda324e163898d543e215cfec1aa3d26ba816426 Mon Sep 17 00:00:00 2001
From: jiangxin <jiangxin@hygon.cn>
Date: Tue, 24 Aug 2021 14:57:28 +0800
Subject: [PATCH 1/8] anolis: csv/i386: add CSV context
CSV is the secure virtualization feature on Hygon CPU.
It is compatible with the AMD SEV/SEV-ES and extends out
specific funtionality by setting bit 6 of guest policy.
Add the context and the build option.
Change-Id: I02b48c779dd25ddda4546fe3e28c1fe0c8c2e4c6
Signed-off-by: Xin Jiang <jiangxin@hygon.cn>
---
configs/devices/i386-softmmu/default.mak | 1 +
.../x86_64-softmmu/x86_64-rh-devices.mak | 1 +
hw/i386/Kconfig | 5 ++
target/i386/csv-sysemu-stub.c | 16 ++++++
target/i386/csv.c | 51 +++++++++++++++++++
target/i386/csv.h | 35 +++++++++++++
target/i386/meson.build | 1 +
7 files changed, 110 insertions(+)
create mode 100644 target/i386/csv-sysemu-stub.c
create mode 100644 target/i386/csv.c
create mode 100644 target/i386/csv.h
diff --git a/configs/devices/i386-softmmu/default.mak b/configs/devices/i386-softmmu/default.mak
index 598c6646df..db83ffcab9 100644
--- a/configs/devices/i386-softmmu/default.mak
+++ b/configs/devices/i386-softmmu/default.mak
@@ -23,6 +23,7 @@
#CONFIG_TPM_TIS_ISA=n
#CONFIG_VTD=n
#CONFIG_SGX=n
+#CONFIG_CSV=n
# Boards:
#
diff --git a/configs/devices/x86_64-softmmu/x86_64-rh-devices.mak b/configs/devices/x86_64-softmmu/x86_64-rh-devices.mak
index 31ce08edab..ee1df7aa52 100644
--- a/configs/devices/x86_64-softmmu/x86_64-rh-devices.mak
+++ b/configs/devices/x86_64-softmmu/x86_64-rh-devices.mak
@@ -102,3 +102,4 @@ CONFIG_TPM_TIS_ISA=y
CONFIG_TPM_EMULATOR=y
CONFIG_TPM_PASSTHROUGH=y
CONFIG_SGX=y
+CONFIG_CSV=y
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index d22ac4a4b9..ed35d762b3 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -10,6 +10,10 @@ config SGX
bool
depends on KVM
+config CSV
+ bool
+ depends on SEV
+
config PC
bool
imply APPLESMC
@@ -26,6 +30,7 @@ config PC
imply QXL
imply SEV
imply SGX
+ imply CSV
imply SGA
imply TEST_DEVICES
imply TPM_CRB
diff --git a/target/i386/csv-sysemu-stub.c b/target/i386/csv-sysemu-stub.c
new file mode 100644
index 0000000000..a89b2600e7
--- /dev/null
+++ b/target/i386/csv-sysemu-stub.c
@@ -0,0 +1,16 @@
+/*
+ * QEMU CSV support
+ *
+ * Copyright: Hygon Info Technologies Ltd. 2022
+ *
+ * Author:
+ * Jiang Xin <jiangxin@hygon.cn>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "sev.h"
+#include "csv.h"
diff --git a/target/i386/csv.c b/target/i386/csv.c
new file mode 100644
index 0000000000..aac825d3f9
--- /dev/null
+++ b/target/i386/csv.c
@@ -0,0 +1,51 @@
+/*
+ * QEMU CSV support
+ *
+ * Copyright: Hygon Info Technologies Ltd. 2022
+ *
+ * Author:
+ * Jiang Xin <jiangxin@hygon.cn>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "cpu.h"
+#include "sev.h"
+#include "csv.h"
+
+CsvGuestState csv_guest = { 0 };
+
+#define CPUID_VENDOR_HYGON_EBX 0x6f677948 /* "Hygo" */
+#define CPUID_VENDOR_HYGON_ECX 0x656e6975 /* "uine" */
+#define CPUID_VENDOR_HYGON_EDX 0x6e65476e /* "nGen" */
+
+#define GUEST_POLICY_CSV_BIT (1 << 6)
+
+static bool is_hygon_cpu(void)
+{
+ uint32_t ebx = 0;
+ uint32_t ecx = 0;
+ uint32_t edx = 0;
+
+ host_cpuid(0, 0, NULL, &ebx, &ecx, &edx);
+
+ if (ebx == CPUID_VENDOR_HYGON_EBX &&
+ ecx == CPUID_VENDOR_HYGON_ECX &&
+ edx == CPUID_VENDOR_HYGON_EDX)
+ return true;
+ else
+ return false;
+}
+
+bool
+csv_enabled(void)
+{
+ if (!is_hygon_cpu())
+ return false;
+
+ return sev_es_enabled() && (csv_guest.policy & GUEST_POLICY_CSV_BIT);
+}
diff --git a/target/i386/csv.h b/target/i386/csv.h
new file mode 100644
index 0000000000..057d37d975
--- /dev/null
+++ b/target/i386/csv.h
@@ -0,0 +1,35 @@
+/*
+ * QEMU CSV support
+ *
+ * Copyright: Hygon Info Technologies Ltd. 2022
+ *
+ * Author:
+ * Jiang Xin <jiangxin@hygon.cn>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_CSV_H
+#define QEMU_CSV_H
+
+#include "qapi/qapi-commands-misc-target.h"
+
+#ifdef CONFIG_CSV
+bool csv_enabled(void);
+#else
+#define csv_enabled() 0
+#endif
+
+struct CsvGuestState {
+ uint32_t policy;
+ int sev_fd;
+ void *state;
+};
+
+typedef struct CsvGuestState CsvGuestState;
+
+extern struct CsvGuestState csv_guest;
+
+#endif
diff --git a/target/i386/meson.build b/target/i386/meson.build
index ae38dc9563..361dea9290 100644
--- a/target/i386/meson.build
+++ b/target/i386/meson.build
@@ -21,6 +21,7 @@ i386_softmmu_ss.add(files(
'cpu-sysemu.c',
))
i386_softmmu_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-sysemu-stub.c'))
+i386_softmmu_ss.add(when: 'CONFIG_CSV', if_true: files('csv.c'), if_false: files('csv-sysemu-stub.c'))
i386_user_ss = ss.source_set()
--
2.17.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。