加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
migration-ram-Fix-calculation-of-gfn-correpond-to-a-.patch 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
Jiabo Feng 提交于 2024-09-18 15:20 . QEMU update to version 8.2.0-18:
From ec2518709b8d461c3a165c1722ccd2e585cec161 Mon Sep 17 00:00:00 2001
From: hanliyang <hanliyang@hygon.cn>
Date: Sun, 16 Jan 2022 20:05:02 -0500
Subject: [PATCH] migration/ram: Fix calculation of gfn correpond to a page in
ramblock
A RAMBlock contains a host memory region which may consist of many
discontiguous MemoryRegion in AddressSpace of a Guest, so we cannot
get gpa by MemoryRegion.addr. Since KVM memslot records the relationship
between gpa and hva, so we can pass the hva of page in RAMBlock to
kvm_phisical_memory_addr_from_host() to get the expected gpa.
Signed-off-by: hanliyang <hanliyang@hygon.cn>
---
migration/ram.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/migration/ram.c b/migration/ram.c
index 66a36736ad..1abe8476f7 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -67,6 +67,7 @@
/* Defines RAM_SAVE_ENCRYPTED_PAGE and RAM_SAVE_SHARED_REGION_LIST */
#include "target/i386/sev.h"
+#include "sysemu/kvm.h"
#include "hw/boards.h" /* for machine_dump_guest_core() */
@@ -2145,6 +2146,8 @@ static bool encrypted_test_list(RAMState *rs, RAMBlock *block,
struct ConfidentialGuestMemoryEncryptionOps *ops =
cgs_class->memory_encryption_ops;
unsigned long gfn;
+ hwaddr paddr = 0;
+ int ret;
/* ROM devices contains the unencrypted data */
if (memory_region_is_rom(block->mr)) {
@@ -2167,7 +2170,14 @@ static bool encrypted_test_list(RAMState *rs, RAMBlock *block,
* Translate page in ram_addr_t address space to GPA address
* space using memory region.
*/
- gfn = page + (block->mr->addr >> TARGET_PAGE_BITS);
+ if (kvm_enabled()) {
+ ret = kvm_physical_memory_addr_from_host(kvm_state,
+ block->host + (page << TARGET_PAGE_BITS), &paddr);
+ if (ret == 0) {
+ return false;
+ }
+ }
+ gfn = paddr >> TARGET_PAGE_BITS;
return ops->is_gfn_in_unshared_region(gfn);
}
--
2.41.0.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化