Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ce51210

Browse files
Quentin PerretWill Deacon
authored andcommitted
ANDROID: KVM: arm64: Allow skipping module page donation
__pkvm_map_module_page() currently goes through a full host-to-hyp donation for every module page being mapped. However, in order to allow mapping protected pages as modules, let's make this behaviour optional. Bug: 278749606 Bug: 264070847 Change-Id: Ic3b1b68f11283c215bc8c6e1352f91bcf52a3935 Signed-off-by: Quentin Perret <[email protected]>
1 parent 23f0263 commit ce51210

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

arch/arm64/include/asm/kvm_pkvm_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct pkvm_module_ops {
2020
enum kvm_pgtable_prot prot,
2121
unsigned long *haddr);
2222
void *(*alloc_module_va)(u64 nr_pages);
23-
int (*map_module_page)(u64 pfn, void *va, enum kvm_pgtable_prot prot);
23+
int (*map_module_page)(u64 pfn, void *va, enum kvm_pgtable_prot prot, bool is_protected);
2424
int (*register_serial_driver)(void (*hyp_putc_cb)(char));
2525
void (*putc)(char c);
2626
void (*puts)(const char *s);

arch/arm64/kvm/hyp/include/nvhe/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int pkvm_create_stack(phys_addr_t phys, unsigned long *haddr);
3232
int pkvm_alloc_private_va_range(size_t size, unsigned long *haddr);
3333
void pkvm_remove_mappings(void *from, void *to);
3434

35-
int __pkvm_map_module_page(u64 pfn, void *va, enum kvm_pgtable_prot prot);
35+
int __pkvm_map_module_page(u64 pfn, void *va, enum kvm_pgtable_prot prot, bool is_protected);
3636
void __pkvm_unmap_module_page(u64 pfn, void *va);
3737
void *__pkvm_alloc_module_va(u64 nr_pages);
3838
#ifdef CONFIG_NVHE_EL2_DEBUG

arch/arm64/kvm/hyp/nvhe/hyp-main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ static void handle___pkvm_map_module_page(struct kvm_cpu_context *host_ctxt)
12321232
DECLARE_REG(void *, va, host_ctxt, 2);
12331233
DECLARE_REG(enum kvm_pgtable_prot, prot, host_ctxt, 3);
12341234

1235-
cpu_reg(host_ctxt, 1) = (u64)__pkvm_map_module_page(pfn, va, prot);
1235+
cpu_reg(host_ctxt, 1) = (u64)__pkvm_map_module_page(pfn, va, prot, false);
12361236
}
12371237

12381238
static void handle___pkvm_unmap_module_page(struct kvm_cpu_context *host_ctxt)

arch/arm64/kvm/hyp/nvhe/mm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,24 @@ void *__pkvm_alloc_module_va(u64 nr_pages)
150150
return (void *)addr;
151151
}
152152

153-
int __pkvm_map_module_page(u64 pfn, void *va, enum kvm_pgtable_prot prot)
153+
int __pkvm_map_module_page(u64 pfn, void *va, enum kvm_pgtable_prot prot, bool is_protected)
154154
{
155155
unsigned long addr = (unsigned long)va;
156156
int ret;
157157

158158
assert_in_mod_range(addr);
159159

160-
ret = __pkvm_host_donate_hyp(pfn, 1);
161-
if (ret)
162-
return ret;
160+
if (!is_protected) {
161+
ret = __pkvm_host_donate_hyp(pfn, 1);
162+
if (ret)
163+
return ret;
164+
}
163165

164166
ret = __pkvm_create_mappings(addr, PAGE_SIZE, hyp_pfn_to_phys(pfn), prot);
165-
if (ret) {
167+
if (ret && !is_protected)
166168
WARN_ON(__pkvm_hyp_donate_host(pfn, 1));
167-
return ret;
168-
}
169169

170-
return 0;
170+
return ret;
171171
}
172172

173173
void __pkvm_unmap_module_page(u64 pfn, void *va)

0 commit comments

Comments
 (0)