-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the COVH promote_to_tvm() ABI which causes a TVM to be create…
…d in a single-step. Preload VM pages into memory, fill the NACL shared memory with boot vcpu state, and reflect the promote_to_tvm() call to the TSM. Support CoVE implementations that do not support dynamic page conversion. A TSM that does not support dynamic page conversion does not require the donation of pages to store VCPU state in confidential memory. Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
- Loading branch information
1 parent
1910bf1
commit c9a3bf1
Showing
11 changed files
with
218 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (c) 2024 IBM. | ||
* | ||
* Authors: | ||
* Wojciech Ozga <woz@zurich.ibm.com> | ||
*/ | ||
|
||
#include <linux/errno.h> | ||
#include <linux/err.h> | ||
#include <linux/kvm_host.h> | ||
#include <linux/list.h> | ||
#include <linux/mm.h> | ||
#include <linux/spinlock.h> | ||
#include <asm/csr.h> | ||
#include <asm/sbi.h> | ||
#include <asm/kvm_vcpu_sbi.h> | ||
#include <asm/kvm_cove.h> | ||
#include <asm/kvm_cove_sbi.h> | ||
#include <asm/kvm_nacl.h> | ||
#include <linux/rbtree.h> | ||
#include <linux/pgtable.h> | ||
|
||
static int preload_pages(struct kvm_vcpu *vcpu) { | ||
unsigned long hva, fault_addr, page; | ||
struct kvm_memory_slot *memslot; | ||
bool writable; | ||
|
||
memslot = search_memslots(kvm_memslots(vcpu->kvm), | ||
kernel_map.phys_addr, true); | ||
if (memslot) { | ||
for (page = 0; page < memslot->npages; page++) { | ||
fault_addr = gfn_to_gpa(memslot->base_gfn) + | ||
page * PAGE_SIZE; | ||
hva = gfn_to_hva_memslot_prot(memslot, | ||
gpa_to_gfn(fault_addr), | ||
&writable); | ||
if (!kvm_is_error_hva(hva)) | ||
kvm_riscv_gstage_map(vcpu, memslot, fault_addr, | ||
hva, NULL); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int kvm_riscv_cove_promote_to_tvm(struct kvm_vcpu *vcpu, | ||
unsigned long fdt_address, | ||
unsigned long tap_addr) { | ||
int rc; | ||
|
||
preload_pages(vcpu); | ||
rc = kvm_riscv_cove_vm_single_step_init(vcpu, fdt_address, tap_addr); | ||
if (rc) | ||
goto done; | ||
|
||
vcpu->kvm->arch.vm_type = KVM_VM_TYPE_RISCV_COVE; | ||
done: | ||
return rc; | ||
} | ||
|
||
static int kvm_sbi_ext_covh_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, | ||
struct kvm_vcpu_sbi_return *retdata) | ||
{ | ||
struct kvm_cpu_context *cp = &vcpu->arch.guest_context; | ||
unsigned long funcid = cp->a6; | ||
int ret; | ||
|
||
switch (funcid) { | ||
case SBI_EXT_COVH_PROMOTE_TO_TVM: | ||
ret = kvm_riscv_cove_promote_to_tvm(vcpu, cp->a0, cp->a1); | ||
return 0; | ||
|
||
default: | ||
kvm_err("%s: Unsupported guest SBI %ld.\n", __func__, funcid); | ||
retdata->err_val = SBI_ERR_NOT_SUPPORTED; | ||
return -EOPNOTSUPP; | ||
} | ||
} | ||
|
||
const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_covh = { | ||
.extid_start = SBI_EXT_COVH, | ||
.extid_end = SBI_EXT_COVH, | ||
.handler = kvm_sbi_ext_covh_handler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters