1 Star 0 Fork 38

xisme/qemu-kvm_src-anolis

forked from src-anolis-os/qemu-kvm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1121-target-i386-kvm-Support-to-get-and-enable-extensions.patch 3.82 KB
一键复制 编辑 原始数据 按行查看 历史
Xuchun Shang 提交于 2025-01-09 14:02 +08:00 . [Feature] Sync Patch form source repo
From 576b6a5d6f90b7628b2ce977bb77f3589f8636c5 Mon Sep 17 00:00:00 2001
From: hanliyang <hanliyang@hygon.cn>
Date: Sat, 28 Sep 2024 14:46:28 +0800
Subject: [PATCH 2/5] target/i386: kvm: Support to get and enable extensions
for Hygon CoCo guest
To enable advanced Hygon CoCo features, we should detect these features
during the initialization of VMs in the KVM accelerator. It is
suggested to enable these features if they are detected, allowing the
guest VM to run with additional functionalities.
Signed-off-by: hanliyang <hanliyang@hygon.cn>
---
linux-headers/linux/kvm.h | 7 +++++++
target/i386/csv-sysemu-stub.c | 3 +++
target/i386/csv.c | 3 +++
target/i386/csv.h | 3 +++
target/i386/kvm/kvm.c | 17 +++++++++++++++++
5 files changed, 33 insertions(+)
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 3875127a37..dca6b48476 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1155,6 +1155,13 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_S390_ZPCI_OP 221
#define KVM_CAP_S390_CPU_TOPOLOGY 222
#define KVM_CAP_SEV_ES_GHCB 500
+#define KVM_CAP_HYGON_COCO_EXT 501
+/* support userspace to request firmware to build CSV3 guest's memory space */
+#define KVM_CAP_HYGON_COCO_EXT_CSV3_SET_PRIV_MEM (1 << 0)
+/* support request to update CSV3 guest's memory region multiple times */
+#define KVM_CAP_HYGON_COCO_EXT_CSV3_MULT_LUP_DATA (1 << 1)
+/* support request to inject secret to CSV3 guest */
+#define KVM_CAP_HYGON_COCO_EXT_CSV3_INJ_SECRET (1 << 2)
#define KVM_EXIT_HYPERCALL_VALID_MASK (1 << KVM_HC_MAP_GPA_RANGE)
diff --git a/target/i386/csv-sysemu-stub.c b/target/i386/csv-sysemu-stub.c
index 96ca055270..cf2c0c1a31 100644
--- a/target/i386/csv-sysemu-stub.c
+++ b/target/i386/csv-sysemu-stub.c
@@ -15,6 +15,9 @@
#include "sev.h"
#include "csv.h"
+uint32_t kvm_hygon_coco_ext;
+uint32_t kvm_hygon_coco_ext_inuse;
+
int csv_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 0e48982964..f00385d809 100644
--- a/target/i386/csv.c
+++ b/target/i386/csv.c
@@ -33,6 +33,9 @@
#include "csv.h"
#include "exec/address-spaces.h"
+uint32_t kvm_hygon_coco_ext;
+uint32_t kvm_hygon_coco_ext_inuse;
+
struct ConfidentialGuestMemoryEncryptionOps csv_memory_encryption_ops = {
.save_setup = sev_save_setup,
.save_outgoing_page = NULL,
diff --git a/target/i386/csv.h b/target/i386/csv.h
index 86f46d30c2..03537a5728 100644
--- a/target/i386/csv.h
+++ b/target/i386/csv.h
@@ -67,6 +67,9 @@ struct dma_map_region {
#define CSV3_OUTGOING_PAGE_WINDOW_SIZE (512 * TARGET_PAGE_SIZE)
+extern uint32_t kvm_hygon_coco_ext;
+extern uint32_t kvm_hygon_coco_ext_inuse;
+
struct guest_addr_entry {
uint64_t share: 1;
uint64_t reserved: 11;
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index cecc3d035d..469349420c 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2455,6 +2455,23 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
}
}
+ if (is_hygon_cpu()) {
+ /* check and enable Hygon coco extensions */
+ kvm_hygon_coco_ext = (uint32_t)kvm_vm_check_extension(s,
+ KVM_CAP_HYGON_COCO_EXT);
+ if (kvm_hygon_coco_ext) {
+ ret = kvm_vm_enable_cap(s, KVM_CAP_HYGON_COCO_EXT, 0,
+ (uint64_t)kvm_hygon_coco_ext);
+ if (ret == -EINVAL) {
+ error_report("kvm: Failed to enable KVM_CAP_HYGON_COCO_EXT cap: %s",
+ strerror(-ret));
+ kvm_hygon_coco_ext_inuse = 0;
+ } else {
+ kvm_hygon_coco_ext_inuse = (uint32_t)ret;
+ }
+ }
+ }
+
ret = kvm_get_supported_msrs(s);
if (ret < 0) {
return ret;
--
2.39.3
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