1 Star 0 Fork 38

xisme/qemu-kvm_src-anolis

forked from src-anolis-os/qemu-kvm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-anolis-csv-i386-add-CSV-context.patch 5.19 KB
一键复制 编辑 原始数据 按行查看 历史
jiangxin00 提交于 2023-09-14 13:59 +08:00 . Support Hygon CSV3 feature
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xisme/qemu-kvm_src-anolis.git
git@gitee.com:xisme/qemu-kvm_src-anolis.git
xisme
qemu-kvm_src-anolis
qemu-kvm_src-anolis
vtkm_support_csv

搜索帮助

371d5123 14472233 46e8bd33 14472233