KVM: arm64: Restore type-checking across the host/hyp hypercall boundary
Fuad Tabba
reviewercover KVM: arm64: Restore type-checking across the host/hyp hypercall boundary
Hi folks,
For a change, I thought I'd send a series that's neither a bunch of Sashiko bug fixes nor pKVM-specific.
The SMCCC conversion of the host/hyp interface reduced every hypercall to a function number and a pile of registers: kvm_call_hyp_nvhe() never shows the compiler a callable, so the caller's arguments and the handler's DECLARE_REG() casts can disagree in type, count or order without a diagnostic. Reviewing a fix for exactly that class of bug, Marc wrote [1]:
"we lost all form of type-checking when everything was hastily
converted to SMCCC to avoid function pointers. Somehow, I feel that the cure was worse than the disease.
I wish we'd reintroduce some form of compile-time checks, maybe by having generated stubs?"
and sketched the shape he preferred [2]: a generated nvhe_hvc_##f() stub that does the type-checking, driven by "some form of declarative IDL", with "both the caller and callee stubs ... totally generated".
This series implements that, in plain preprocessor macros rather than an external generator, in the mold of the syscall wrappers. Each hypercall's signature is declared once, in kvm_hcall.h:kvm_call_hyp_nvhe() resolves to a typed nvhe_hvc_##f() stub generated from the declaration, and the hyp-main.c handlers unmarshal their arguments through glue that is type-checked against the same declaration. A mistyped or stale call, or a handler that drifts from its caller, now fails to compile. On top of that shared declaration, host-VA parameters gain a __hostva sparse address space, so dereferencing one at EL2 without kern_hyp_va_host() translation is flagged by sparse. The address space is KVM-private and lives with the interface it annotates rather than in compiler_types.h, like x86's __seg_gs in asm/percpu.h. The deeper instances of that bug class, host VAs reached through struct fields after the boundary, are follow-up work.
The declarations do not also generate the function-number enum or the dispatch table. The enum carries the availability-band markers that decide when each hypercall becomes reachable, and its base entry is consumed from assembly, so generating it would hide the banding. The remaining duplication cannot drift silently: a name mismatch between declaration, caller and handler fails to compile, and a missing dispatch-table entry is rejected at run time as SMCCC_RET_NOT_SUPPORTED.
Along the way it turned out "make C=2" has never checked the nVHE objects at all: the custom %.nvhe.o rule reuses rule_cc_o_c, which only hooks the checker for C=1, and that only on a rebuild. Patches 2-5 fix the hook and the handful of pre-existing sparse warnings it flushes out, so the checker lands clean. The libfdt objects under arch/arm64/kernel/pi/ have the same gap through the same rule, so patch 6 gives them the same one-line fix; it touches arm64 core rather than KVM, so it can go through either tree. Patch 1 is
adjacent: trace_remote_event.h is not self-contained (it uses bool without including linux/types.h), which the nVHE include order had been silently working around; it can go through the tracing tree instead if preferred.
The first six patches do not depend on the type-checking work (the tracing-header fix, the sparse cleanups, and the two C=2 hook fixes), so they could be taken on their own, ahead of the rest of the series if that is easier.
The series is structured as follows:
01: Make trace_remote_event.h self-contained. 02-04: Fix the pre-existing sparse warnings in the nVHE code. 05: Run the source checker on nVHE objects under C=2. 06: Same for the libfdt objects under arch/arm64/kernel/pi/. 07: Pass the host-VA hypercall arguments as pointers at EL2. 08: Move the dispatch macros to a new kvm_hcall.h. 09: Declare the hypercall signatures, type-check the callers. 10: Generate the handler unmarshalling, type-check the handlers. 11: Tag host-VA parameters __hostva for sparse.
The generated code is unchanged, checked by comparing the disassembly of every KVM object, function by function, against the base: the callers are identical apart from hypercall returns now being tested at their declared width and the stage-2 TLB-flush level argument now being sign-extended as it is loaded (an s8 passed as an int), and the handlers are instruction-for-instruction identical apart from flush_hyp_vcpu()/sync_hyp_vcpu() being inlined into their only caller. The extra argument that prompted the thread, a mistyped or reordered argument, and a handler that disagrees with its declaration all now fail to compile. checkpatch complains about the __KVM_HCALL_MAP() machinery, the (type, name) pair syntax and the generated signature typedefs, as it does about __MAP() in the syscall wrappers; the idiom cannot be parenthesized, and the typedef is what checks the handler against the declaration. Enforcing the __hostva tag needs sparse v0.6.5-rc1 or later for __typeof_unqual__, as all sparse checking on current kernels does; no stable sparse release has it yet, so build from sparse.git (checker-valid.sh skips the check, with a warning, on anything older).
Based on Linux 7.2-rc4 (1590cf0329716).
Cheers,
/fuad
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (11):
tracing: Include linux/types.h in trace_remote_event.h
KVM: arm64: nVHE: Share the stacktrace per-CPU declarations with EL2
KVM: arm64: nVHE: Declare the hyp event IDs before defining them
KVM: arm64: nVHE: Use NULL to reset the trace buffer backing pointer
KVM: arm64: nVHE: Run the source checker under C=2
arm64: pi: Run the source checker on the libfdt objects under C=2
KVM: arm64: nVHE: Pass host VA arguments as pointers
KVM: arm64: Move the host hypercall interface to its own header
KVM: arm64: Type-check hypercall arguments at the caller
KVM: arm64: nVHE: Check hypercall handlers against the declared ABI
KVM: arm64: Tag host-VA hypercall parameters __hostva
arch/arm64/include/asm/kvm_hcall.h | 255 +++++++++++++ arch/arm64/include/asm/kvm_host.h | 48 +-- arch/arm64/include/asm/kvm_mmu.h | 10 + arch/arm64/include/asm/stacktrace/nvhe.h | 10 +- arch/arm64/kernel/pi/Makefile | 1 + arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 7 +- arch/arm64/kvm/hyp/include/nvhe/trace.h | 5 +- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/kvm/hyp/nvhe/events.c | 2 + arch/arm64/kvm/hyp/nvhe/hyp-main.c | 443 +++++++++++------------ arch/arm64/kvm/hyp/nvhe/pkvm.c | 12 +- arch/arm64/kvm/hyp/nvhe/stacktrace.c | 3 +- arch/arm64/kvm/hyp/nvhe/trace.c | 6 +- arch/arm64/kvm/hyp_trace.c | 2 +- arch/arm64/kvm/stacktrace.c | 3 - include/linux/trace_remote_event.h | 2 + 16 files changed, 508 insertions(+), 302 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_hcall.h
base-commit: 1590cf0329716306e948a8fc29f1d3ee87d3989f
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 1/11 tracing: Include linux/types.h in trace_remote_event.h
trace_remote_event.h uses bool without including linux/types.h, so a translation unit that includes it ahead of anything else that pulls types.h in fails to build, as with nvhe/trace.h at EL2.
--- include/linux/trace_remote_event.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/trace_remote_event.h +2 -0
@@ -3,6 +3,8 @@#ifndef _LINUX_TRACE_REMOTE_EVENTS_H#define _LINUX_TRACE_REMOTE_EVENTS_H +#include <linux/types.h> +struct trace_remote ;struct trace_event_fields ;struct trace_seq ;
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 2/11 KVM: arm64: nVHE: Share the stacktrace per-CPU declarations with EL2
In reply to Fuad TabbaThe declarations for overflow_stack, kvm_stacktrace_info and pkvm_stacktrace are only visible to the host (the first two sit in the host-only section of stacktrace/nvhe.h, the last is private to kvm/stacktrace.c), so the definitions in nvhe/stacktrace.c compile with no declaration in sight and sparse suggests making them static. DECLARE_KVM_NVHE_PER_CPU() resolves to the right symbol name on both sides of the build: move the declarations where both can see them and include the header from the EL2 side unconditionally.
No functional change intended.
--- arch/arm64/include/asm/stacktrace/nvhe.h | 10 ++++++++-- arch/arm64/kvm/hyp/nvhe/stacktrace.c | 3 +-- arch/arm64/kvm/stacktrace.c | 3 --- 3 files changed, 9 insertions(+), 7 deletions(-)
arch/arm64/include/asm/stacktrace/nvhe.h +8 -2
@@ -37,6 +37,14 @@ static inline void kvm_nvhe_unwind_init(struct unwind_state *state, state->pc = pc; } +DECLARE_KVM_NVHE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack); +DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_stacktrace_info, kvm_stacktrace_info); + +#ifdef CONFIG_PKVM_STACKTRACE +DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], + pkvm_stacktrace); +#endif +#ifndef __KVM_NVHE_HYPERVISOR__/* * Conventional (non-protected) nVHE HYP stack unwinder
@@ -45,8 +53,6 @@ static inline void kvm_nvhe_unwind_init(struct unwind_state *state,* (by the host in EL1). */ -DECLARE_KVM_NVHE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack); -DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_stacktrace_info, kvm_stacktrace_info); DECLARE_PER_CPU(unsigned long, kvm_arm_hyp_stack_base);void kvm_nvhe_dump_backtrace (unsigned long hyp_offset);
arch/arm64/kvm/hyp/nvhe/stacktrace.c +1 -2
@@ -8,6 +8,7 @@#include <asm/kvm_hyp.h> #include <asm/memory.h> #include <asm/percpu.h> +#include <asm/stacktrace/nvhe.h> DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack)__aligned(16) ;
@@ -35,8 +36,6 @@ static void hyp_prepare_backtrace(unsigned long fp, unsigned long pc) }#ifdef CONFIG_PKVM_STACKTRACE -#include <asm/stacktrace/nvhe.h> - DEFINE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], pkvm_stacktrace);static struct stack_info stackinfo_get_overflow (void )
arch/arm64/kvm/stacktrace.c +0 -3
@@ -198,9 +198,6 @@ static void hyp_dump_backtrace(unsigned long hyp_offset) }#ifdef CONFIG_PKVM_STACKTRACE -DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], - pkvm_stacktrace); -/* * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace. *
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 3/11 KVM: arm64: nVHE: Declare the hyp event IDs before defining them
In reply to Fuad TabbaThe defining expansion of HYP_EVENT() in events.c is the first time its translation unit meets hyp_event_id_<name>, so sparse suggests making the symbols static. Include kvm_hypevents.h ahead of define_events.h so the extern declarations come first, as with the tracepoint headers.
No functional change intended.
--- arch/arm64/kvm/hyp/nvhe/events.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kvm/hyp/nvhe/events.c +2 -0
@@ -7,6 +7,8 @@#include <nvhe/mm.h> #include <nvhe/trace.h> +#include <asm/kvm_hypevents.h> +#include <nvhe/define_events.h> int __tracing_enable_event (unsigned short id,bool enable)
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 4/11 KVM: arm64: nVHE: Use NULL to reset the trace buffer backing pointer
In reply to Fuad Tabbabpages_backing_start is a pointer; resetting it to plain 0 triggers a sparse warning.
No functional change intended.
--- arch/arm64/kvm/hyp/nvhe/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/trace.c +1 -1
@@ -93,7 +93,7 @@ static void hyp_trace_buffer_unload_bpage_backing(struct hyp_trace_buffer *trace__release_host_mem (start, size); - trace_buffer->bpages_backing_start =0 ; + trace_buffer->bpages_backing_start =NULL ; trace_buffer->bpages_backing_size =0 ; }
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 5/11 KVM: arm64: nVHE: Run the source checker under C=2
In reply to Fuad TabbaThe custom %.nvhe.o rule reuses rule_cc_o_c, which hooks the source checker only for C=1, and that only when the object is rebuilt. The C=2 hook, cmd_force_checksrc, hangs off the standard %.o rule that nVHE objects do not use, so "make C=2" silently skips every nVHE source file. Call cmd_force_checksrc after the compile rule, as the standard rule does.
--- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kvm/hyp/nvhe/Makefile +1 -0
@@ -49,6 +49,7 @@ targets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-relo # avoids file name clashes for files shared with VHE. $(obj)/%.nvhe.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) + $(call cmd,force_checksrc) $(obj)/%.nvhe.o: $(src)/%.S FORCE $(call if_changed_rule,as_o_S)
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 6/11 arm64: pi: Run the source checker on the libfdt objects under C=2
In reply to Fuad TabbaThe custom lib-%.o rule reuses rule_cc_o_c, which hooks the source checker only for C=1, and that only when the object is rebuilt. The C=2 hook, cmd_force_checksrc, hangs off the standard %.o rule, so "make C=2" silently skips the two libfdt objects. Call cmd_force_checksrc after the compile rule, as the standard rule does.
--- arch/arm64/kernel/pi/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kernel/pi/Makefile +1 -0
@@ -34,6 +34,7 @@ $(obj)/lib-%.pi.o: OBJCOPYFLAGS += --prefix-alloc-sections=.init $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE $(call if_changed_rule,cc_o_c) + $(call cmd,force_checksrc) obj-y := idreg-override.pi.o \ map_kernel.pi.o map_range.pi.o \
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 7/11 KVM: arm64: nVHE: Pass host VA arguments as pointers
In reply to Fuad TabbaFour hypercalls take host VAs as unsigned long: the donated vm, pgd and vcpu regions, and the tracing descriptor. Retype the arguments and their EL2 consumers as void *, so that the typed hypercall declarations introduced later in the series can attach a sparse address space to them; an address space attaches only to pointers.
No functional change intended.
--- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 5 ++--- arch/arm64/kvm/hyp/include/nvhe/trace.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 ++++---- arch/arm64/kvm/hyp/nvhe/pkvm.c | 11 +++++------ arch/arm64/kvm/hyp/nvhe/trace.c | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-)
arch/arm64/kvm/hyp/include/nvhe/pkvm.h +2 -3
@@ -69,10 +69,9 @@ void pkvm_hyp_vm_table_init(void *tbl);int __pkvm_reserve_vm (void );void __pkvm_unreserve_vm (pkvm_handle_t handle); -int __pkvm_init_vm (struct kvm *host_kvm,unsigned long vm_hva, -unsigned long pgd_hva); +int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva);int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -unsigned long vcpu_hva); +void *vcpu_hva);int __pkvm_reclaim_dying_guest_page (pkvm_handle_t handle,u64 gfn);int __pkvm_start_teardown_vm (pkvm_handle_t handle);
arch/arm64/kvm/hyp/include/nvhe/trace.h +2 -2
@@ -46,7 +46,7 @@ static inline pid_t __tracing_get_vcpu_pid(struct kvm_cpu_context *host_ctxt)void *tracing_reserve_entry (unsigned long length);void tracing_commit_entry (void ); -int __tracing_load (unsigned long desc_va,size_t desc_size); +int __tracing_load (void *desc_va,size_t desc_size);void __tracing_unload (void );int __tracing_enable (bool enable);int __tracing_swap_reader (unsigned int cpu);
@@ -59,7 +59,7 @@ static inline void tracing_commit_entry(void) { }#define HYP_EVENT (__name, __proto, __struct, __assign, __printk) \ static inline void trace_##__name(__proto) {} -static inline int __tracing_load (unsigned long desc_va,size_t desc_size) {return -ENODEV ; } +static inline int __tracing_load (void *desc_va,size_t desc_size) {return -ENODEV ; }static inline void __tracing_unload (void ) { }static inline int __tracing_enable (bool enable) {return -ENODEV ; }static inline int __tracing_swap_reader (unsigned int cpu) {return -ENODEV ; }
arch/arm64/kvm/hyp/nvhe/hyp-main.c +4 -4
@@ -577,8 +577,8 @@ static void handle___pkvm_unreserve_vm(struct kvm_cpu_context *host_ctxt)static void handle___pkvm_init_vm (struct kvm_cpu_context *host_ctxt) { DECLARE_REG(struct kvm *, host_kvm, host_ctxt, 1); - DECLARE_REG(unsigned long, vm_hva, host_ctxt, 2); - DECLARE_REG(unsigned long, pgd_hva, host_ctxt, 3); + DECLARE_REG(void *, vm_hva, host_ctxt, 2); + DECLARE_REG(void *, pgd_hva, host_ctxt, 3); host_kvm =kern_hyp_va (host_kvm);cpu_reg (host_ctxt,1 ) =__pkvm_init_vm (host_kvm, vm_hva, pgd_hva);
@@ -588,7 +588,7 @@ static void handle___pkvm_init_vcpu(struct kvm_cpu_context *host_ctxt) {DECLARE_REG (pkvm_handle_t, handle, host_ctxt,1 ); DECLARE_REG(struct kvm_vcpu *, host_vcpu, host_ctxt, 2); - DECLARE_REG(unsigned long, vcpu_hva, host_ctxt, 3); + DECLARE_REG(void *, vcpu_hva, host_ctxt, 3); host_vcpu =kern_hyp_va (host_vcpu);cpu_reg (host_ctxt,1 ) =__pkvm_init_vcpu (handle, host_vcpu, vcpu_hva);
@@ -634,7 +634,7 @@ static void handle___pkvm_finalize_teardown_vm(struct kvm_cpu_context *host_ctxtstatic void handle___tracing_load (struct kvm_cpu_context *host_ctxt) { - DECLARE_REG(unsigned long, desc_hva, host_ctxt, 1); + DECLARE_REG(void *, desc_hva, host_ctxt, 1);DECLARE_REG (size_t, desc_size, host_ctxt,2 );cpu_reg (host_ctxt,1 ) =__tracing_load (desc_hva, desc_size);
arch/arm64/kvm/hyp/nvhe/pkvm.c +5 -6
@@ -644,9 +644,9 @@ static size_t pkvm_get_hyp_vm_size(unsigned int nr_vcpus) size_mul(sizeof(struct pkvm_hyp_vcpu *), nr_vcpus)); } -static void *map_donated_memory_noclear (unsigned long host_va,size_t size) +static void *map_donated_memory_noclear (void *host_va,size_t size) { -void *va = (void *)kern_hyp_va (host_va); +void *va =kern_hyp_va (host_va);if (!PAGE_ALIGNED (va))return NULL ;
@@ -658,7 +658,7 @@ static void *map_donated_memory_noclear(unsigned long host_va, size_t size)return va; } -static void *map_donated_memory (unsigned long host_va,size_t size) +static void *map_donated_memory (void *host_va,size_t size) {void *va =map_donated_memory_noclear (host_va, size);
@@ -805,8 +805,7 @@ void teardown_selftest_vm(void)* * Return 0 success, negative error code on failure. */ -int __pkvm_init_vm (struct kvm *host_kvm,unsigned long vm_hva, -unsigned long pgd_hva) +int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva) {struct pkvm_hyp_vm *hyp_vm =NULL ;size_t vm_size, pgd_size;
@@ -897,7 +896,7 @@ static int register_hyp_vcpu(struct pkvm_hyp_vm *hyp_vm, }int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -unsigned long vcpu_hva) +void *vcpu_hva) {struct pkvm_hyp_vcpu *hyp_vcpu;struct pkvm_hyp_vm *hyp_vm;
arch/arm64/kvm/hyp/nvhe/trace.c +2 -2
@@ -206,9 +206,9 @@ static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_sizreturn true; } -int __tracing_load (unsigned long desc_hva,size_t desc_size) +int __tracing_load (void *desc_hva,size_t desc_size) { -struct hyp_trace_desc *desc = (struct hyp_trace_desc *)kern_hyp_va (desc_hva); +struct hyp_trace_desc *desc =kern_hyp_va (desc_hva);int ret; ret =__admit_host_mem (desc, desc_size);
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 8/11 KVM: arm64: Move the host hypercall interface to its own header
In reply to Fuad TabbaMove the kvm_call_hyp() dispatch macros and pkvm_handle_t out of kvm_host.h into a new kvm_hcall.h, giving the host<->hyp hypercall interface a single home that subsequent patches build on to restore type-checking across the boundary. The only adjustment to the moved code is the checkpatch-mandated space in "while (0)".
No functional change intended.
--- arch/arm64/include/asm/kvm_hcall.h | 68 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 48 +-------------------- 2 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_hcall.h
arch/arm64/include/asm/kvm_hcall.h new file +68 -0
@@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* The host<->hyp hypercall interface. +* +* Copyright (C) 2026 Google LLC +* Author: Fuad Tabba <[email protected]> +*/ + +#ifndef __ARM64_KVM_HCALL_H__ +#define __ARM64_KVM_HCALL_H__ + +#include <linux/arm-smccc.h> +#include <linux/bug.h> +#include <linux/errno.h> +#include <linux/types.h> + +#include <asm/barrier.h> +#include <asm/kvm_asm.h> +#include <asm/virt.h> + +typedef u16 pkvm_handle_t ; + +#ifndef __KVM_NVHE_HYPERVISOR__ +#define kvm_call_hyp_nvhe (f, ...) \ + ({ \ + struct arm_smccc_res res; \ + \ + arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(f), \ + ##__VA_ARGS__, &res); \ + if (WARN_ON(res.a0 != SMCCC_RET_SUCCESS)) \ + res.a1 = -EOPNOTSUPP; \ + \ + res.a1; \ + }) + +/* +* The isb() below is there to guarantee the same behaviour on VHE as on !VHE, +* where the eret to EL1 acts as a context synchronization event. +*/ +#define kvm_call_hyp (f, ...) \ + do { \ + if (has_vhe()) { \ + f(__VA_ARGS__); \ + isb(); \ + } else { \ + kvm_call_hyp_nvhe(f, ##__VA_ARGS__); \ + } \ + } while (0) + +#define kvm_call_hyp_ret (f, ...) \ + ({ \ + typeof(f(__VA_ARGS__)) ret; \ + \ + if (has_vhe()) { \ + ret = f(__VA_ARGS__); \ + } else { \ + ret = kvm_call_hyp_nvhe(f, ##__VA_ARGS__); \ + } \ + \ + ret; \ + }) +#else /* __KVM_NVHE_HYPERVISOR__ */ +#define kvm_call_hyp (f, ...) f(__VA_ARGS__) +#define kvm_call_hyp_ret (f, ...) f(__VA_ARGS__) +#define kvm_call_hyp_nvhe (f, ...) f(__VA_ARGS__) +#endif /* __KVM_NVHE_HYPERVISOR__ */ + +#endif /* __ARM64_KVM_HCALL_H__ */
arch/arm64/include/asm/kvm_host.h +1 -47
66 lines not on this page · raw message
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 9/11 KVM: arm64: Type-check hypercall arguments at the caller
In reply to Fuad Tabbakvm_call_hyp_nvhe() reduces its target to an SMCCC function number, so the compiler never sees a callable: arguments that are wrong in number, type or order are silently marshalled into registers. The kvm_call_hyp() wrappers only catch this on the VHE branch, and the pKVM-only hypercalls have no such branch.
Declare each hypercall's signature once in kvm_hcall.h and generate a typed stub from it, in the mold of the syscall wrappers. Make kvm_call_hyp_nvhe() resolve to the stub so every caller is checked against the declared signature; a stale or mistyped call now fails to compile. The stubs inline to the same SMCCC call the untyped macro used to make: the compiled callers are unchanged, apart from hypercall returns now being tested at their declared width.
The stage-2 protection arguments are declared u64 rather than enum kvm_pgtable_prot, as kvm_pgtable.h includes linux/kvm_host.h and the enum cannot be completed here.
--- arch/arm64/include/asm/kvm_hcall.h | 165 ++++++++++++++++++++++++++++- arch/arm64/kvm/hyp_trace.c | 2 +- 2 files changed, 165 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_hcall.h +164 -1
@@ -16,12 +16,35 @@#include <asm/barrier.h> #include <asm/kvm_asm.h> +#include <asm/spectre.h> #include <asm/virt.h> typedef u16 pkvm_handle_t ; +struct kvm ; +struct kvm_s2_mmu ; +struct kvm_vcpu ; +struct vgic_v3_cpu_if ; +struct vgic_v5_cpu_if ; + +/* +* Hypercall signatures are declared as (type, name) argument pairs. +* __KVM_HCALL_MAP() applies a macro to each pair, in the mold of __MAP() +* in <linux/syscalls.h>. +*/ +#define __KVM_HCALL_MAP1 (m, t, a, ...) m(t, a) +#define __KVM_HCALL_MAP2 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP1(m, __VA_ARGS__) +#define __KVM_HCALL_MAP3 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP2(m, __VA_ARGS__) +#define __KVM_HCALL_MAP4 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP3(m, __VA_ARGS__) +#define __KVM_HCALL_MAP5 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP4(m, __VA_ARGS__) +#define __KVM_HCALL_MAP6 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP5(m, __VA_ARGS__) +#define __KVM_HCALL_MAP (n, ...) __KVM_HCALL_MAP##n(__VA_ARGS__) + +#define __KVM_HCALL_DECL (t, a) t a +#define __KVM_HCALL_ARGS (t, a) a +#ifndef __KVM_NVHE_HYPERVISOR__ -#define kvm_call_hyp_nvhe (f, ...) \ +#define __kvm_call_hyp_nvhe (f, ...) \ ({ \ struct arm_smccc_res res; \ \
@@ -33,6 +56,43 @@ typedef u16 pkvm_handle_t; res.a1; \ }) +/* +* Generate a typed stub for each declared hypercall. kvm_call_hyp_nvhe() +* resolves to the stub, so a call with the wrong argument count or types +* fails to compile instead of being silently truncated to an SMCCC function +* number and a pile of registers. The stub inlines to the same SMCCC call +* the untyped macro used to make. +*/ +#define DECLARE_KVM_HOST_HCALL (ret, name, x, ...) \ + static __always_inline \ + ret nvhe_hvc_##name(__KVM_HCALL_MAP(x, __KVM_HCALL_DECL, __VA_ARGS__)) \ + { \ + return (ret)__kvm_call_hyp_nvhe(name, \ + __KVM_HCALL_MAP(x, __KVM_HCALL_ARGS, __VA_ARGS__)); \ + } + +#define DECLARE_KVM_HOST_HCALL_VOID (name, x, ...) \ + static __always_inline \ + void nvhe_hvc_##name(__KVM_HCALL_MAP(x, __KVM_HCALL_DECL, __VA_ARGS__)) \ + { \ + __kvm_call_hyp_nvhe(name, \ + __KVM_HCALL_MAP(x, __KVM_HCALL_ARGS, __VA_ARGS__)); \ + } + +#define DECLARE_KVM_HOST_HCALL0 (ret, name) \ + static __always_inline ret nvhe_hvc_##name(void) \ + { \ + return (ret)__kvm_call_hyp_nvhe(name); \ + } + +#define DECLARE_KVM_HOST_HCALL0_VOID (name) \ + static __always_inline void nvhe_hvc_##name(void) \ + { \ + __kvm_call_hyp_nvhe(name); \ + } + +#define kvm_call_hyp_nvhe (f, ...) nvhe_hvc_##f(__VA_ARGS__) +/* * The isb() below is there to guarantee the same behaviour on VHE as on !VHE, * where the eret to EL1 acts as a context synchronization event.
@@ -63,6 +123,109 @@ typedef u16 pkvm_handle_t;#define kvm_call_hyp (f, ...) f(__VA_ARGS__)#define kvm_call_hyp_ret (f, ...) f(__VA_ARGS__)#define kvm_call_hyp_nvhe (f, ...) f(__VA_ARGS__) + +#define DECLARE_KVM_HOST_HCALL (ret, name, x, ...) +#define DECLARE_KVM_HOST_HCALL_VOID (name, x, ...) +#define DECLARE_KVM_HOST_HCALL0 (ret, name) +#define DECLARE_KVM_HOST_HCALL0_VOID (name)#endif /* __KVM_NVHE_HYPERVISOR__ */ +/* Hypercalls that are unavailable once pKVM has finalised. */ +DECLARE_KVM_HOST_HCALL (int, __pkvm_init,4 , + phys_addr_t, phys, unsigned long, size, + unsigned long *, per_cpu_base, u32, hyp_va_bits) +DECLARE_KVM_HOST_HCALL(unsigned long, __pkvm_create_private_mapping, 3, + phys_addr_t, phys, size_t, size, u64, prot) +DECLARE_KVM_HOST_HCALL (int, __pkvm_cpu_set_vector,1 , + enum arm64_hyp_spectre_vector, slot) +DECLARE_KVM_HOST_HCALL0_VOID(__kvm_enable_ssbs) +DECLARE_KVM_HOST_HCALL0_VOID(__vgic_v3_init_lrs) +DECLARE_KVM_HOST_HCALL0(u64, __vgic_v3_get_gic_config) + +DECLARE_KVM_HOST_HCALL0(int, __pkvm_prot_finalize) + +/* Hypercalls that are always available and common to [nh]VHE/pKVM. */ +DECLARE_KVM_HOST_HCALL_VOID(__kvm_adjust_pc, 1, + struct kvm_vcpu *, vcpu) +DECLARE_KVM_HOST_HCALL(int, __kvm_vcpu_run, 1, + struct kvm_vcpu *, vcpu) +DECLARE_KVM_HOST_HCALL0_VOID(__kvm_flush_vm_context) +DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa, 3, + struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) +DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa_nsh, 3, + struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) +DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid, 1, + struct kvm_s2_mmu *, mmu) +DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_range, 3, + struct kvm_s2_mmu *, mmu, phys_addr_t, start, unsigned long, pages) +DECLARE_KVM_HOST_HCALL_VOID(__kvm_flush_cpu_context, 1, + struct kvm_s2_mmu *, mmu) +DECLARE_KVM_HOST_HCALL_VOID(__kvm_timer_set_cntvoff, 1, + u64, cntvoff) +DECLARE_KVM_HOST_HCALL(int, __tracing_load, 2, + void *, desc_hva, size_t, desc_size) +DECLARE_KVM_HOST_HCALL0_VOID(__tracing_unload) +DECLARE_KVM_HOST_HCALL(int, __tracing_enable, 1, + bool, enable) +DECLARE_KVM_HOST_HCALL(int, __tracing_swap_reader, 1, + unsigned int, cpu) +DECLARE_KVM_HOST_HCALL_VOID(__tracing_update_clock, 4, + u32, mult, u32, shift, u64, epoch_ns, u64, epoch_cyc) +DECLARE_KVM_HOST_HCALL(int, __tracing_reset, 1, + unsigned int, cpu) +DECLARE_KVM_HOST_HCALL(int, __tracing_enable_event, 2, + unsigned short, id, bool, enable) +DECLARE_KVM_HOST_HCALL_VOID(__tracing_write_event, 1, + u64, id) +DECLARE_KVM_HOST_HCALL_VOID(__vgic_v3_save_aprs, 1, + struct vgic_v3_cpu_if *, cpu_if) +DECLARE_KVM_HOST_HCALL_VOID(__vgic_v3_restore_vmcr_aprs, 1, + struct vgic_v3_cpu_if *, cpu_if) +DECLARE_KVM_HOST_HCALL_VOID(__vgic_v5_save_apr, 1, + struct vgic_v5_cpu_if *, cpu_if) +DECLARE_KVM_HOST_HCALL_VOID(__vgic_v5_restore_vmcr_apr, 1, + struct vgic_v5_cpu_if *, cpu_if) + +/* Hypercalls that are available only when pKVM has finalised. */ +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_share_hyp, 1, + u64, pfn) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_unshare_hyp, 1, + u64, pfn) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_donate_guest, 2, + u64, pfn, u64, gfn) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_share_guest, 4, + u64, pfn, u64, gfn, u64, nr_pages, u64, prot) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_unshare_guest, 3, + pkvm_handle_t, handle, u64, gfn, u64, nr_pages) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_relax_perms_guest, 2, + u64, gfn, u64, prot) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_wrprotect_guest, 3, + pkvm_handle_t, handle, u64, gfn, u64, nr_pages) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_test_clear_young_guest, 4, + pkvm_handle_t, handle, u64, gfn, u64, nr_pages, bool, mkold) +DECLARE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, + u64, gfn) +DECLARE_KVM_HOST_HCALL0(int, __pkvm_reserve_vm) +DECLARE_KVM_HOST_HCALL_VOID(__pkvm_unreserve_vm, 1, + pkvm_handle_t, handle) +DECLARE_KVM_HOST_HCALL(int, __pkvm_init_vm, 3, + struct kvm *, host_kvm, void *, vm_hva, void *, pgd_hva) +DECLARE_KVM_HOST_HCALL(int, __pkvm_init_vcpu, 3, + pkvm_handle_t, handle, struct kvm_vcpu *, host_vcpu, + void *, vcpu_hva) +DECLARE_KVM_HOST_HCALL0(int, __pkvm_vcpu_in_poison_fault) +DECLARE_KVM_HOST_HCALL(int, __pkvm_force_reclaim_guest_page, 1, + phys_addr_t, phys) +DECLARE_KVM_HOST_HCALL(int, __pkvm_reclaim_dying_guest_page, 2, + pkvm_handle_t, handle, u64, gfn) +DECLARE_KVM_HOST_HCALL(int, __pkvm_start_teardown_vm, 1, + pkvm_handle_t, handle) +DECLARE_KVM_HOST_HCALL(int, __pkvm_finalize_teardown_vm, 1, + pkvm_handle_t, handle) +DECLARE_KVM_HOST_HCALL_VOID(__pkvm_vcpu_load, 3, + pkvm_handle_t, handle, unsigned int, vcpu_idx, u64, hcr_el2) +DECLARE_KVM_HOST_HCALL0_VOID(__pkvm_vcpu_put) +DECLARE_KVM_HOST_HCALL_VOID(__pkvm_tlb_flush_vmid, 1, + pkvm_handle_t, handle) +#endif /* __ARM64_KVM_HCALL_H__ */
arch/arm64/kvm/hyp_trace.c +1 -1
@@ -264,7 +264,7 @@ static struct trace_buffer_desc *hyp_trace_load(unsigned long size, void *priv)if (ret) goto err_free_buffer; - ret =kvm_call_hyp_nvhe (__tracing_load, (unsigned long )desc, desc_size); + ret =kvm_call_hyp_nvhe (__tracing_load, desc, desc_size);if (ret) goto err_unload_pages;
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 10/11 KVM: arm64: nVHE: Check hypercall handlers against the declared ABI
In reply to Fuad TabbaEach hypercall handler unmarshals its arguments from the host context with hand-written DECLARE_REG() casts that nothing ties to what the caller passed: a handler can disagree with its caller in argument type, count or register index without a diagnostic.
Generate the unmarshalling instead. DEFINE_KVM_HOST_HCALL() expands to the handle_<name>() glue, modelled on the syscall wrappers, and checks the handler's parameter list against the signature declared in kvm_hcall.h, so both ends of every hypercall are now compiled against the same declaration. Handler bodies keep their logic and lose the DECLARE_REG() and return-register boilerplate. The compiled handlers are instruction-for-instruction identical, apart from flush_hyp_vcpu() and sync_hyp_vcpu() now being inlined into their only caller.
--- arch/arm64/include/asm/kvm_hcall.h | 19 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 420 ++++++++++++++--------------- 2 files changed, 213 insertions(+), 226 deletions(-)
arch/arm64/include/asm/kvm_hcall.h +15 -4
@@ -41,6 +41,8 @@ struct vgic_v5_cpu_if;#define __KVM_HCALL_MAP (n, ...) __KVM_HCALL_MAP##n(__VA_ARGS__)#define __KVM_HCALL_DECL (t, a) t a +#define __KVM_HCALL_LONG (t, a) unsigned long a +#define __KVM_HCALL_CAST (t, a) (__force t) a#define __KVM_HCALL_ARGS (t, a) a#ifndef __KVM_NVHE_HYPERVISOR__
@@ -124,10 +126,19 @@ struct vgic_v5_cpu_if;#define kvm_call_hyp_ret (f, ...) f(__VA_ARGS__)#define kvm_call_hyp_nvhe (f, ...) f(__VA_ARGS__) -#define DECLARE_KVM_HOST_HCALL (ret, name, x, ...) -#define DECLARE_KVM_HOST_HCALL_VOID (name, x, ...) -#define DECLARE_KVM_HOST_HCALL0 (ret, name) -#define DECLARE_KVM_HOST_HCALL0_VOID (name) +/* +* At EL2 each declaration emits the canonical signature of the hypercall, +* which DEFINE_KVM_HOST_HCALL() in hyp-main.c checks the handler +* definition against. +*/ +#define DECLARE_KVM_HOST_HCALL (ret, name, x, ...) \ + typedef ret kvm_host_hcall_sig_##name(__KVM_HCALL_MAP(x, __KVM_HCALL_DECL, __VA_ARGS__)); +#define DECLARE_KVM_HOST_HCALL_VOID (name, x, ...) \ + typedef void kvm_host_hcall_sig_##name(__KVM_HCALL_MAP(x, __KVM_HCALL_DECL, __VA_ARGS__)); +#define DECLARE_KVM_HOST_HCALL0 (ret, name) \ + typedef ret kvm_host_hcall_sig_##name(void); +#define DECLARE_KVM_HOST_HCALL0_VOID (name) \ + typedef void kvm_host_hcall_sig_##name(void);#endif /* __KVM_NVHE_HYPERVISOR__ */ /* Hypercalls that are unavailable once pKVM has finalised. */
arch/arm64/kvm/hyp/nvhe/hyp-main.c +198 -222
683 lines not on this page · raw message
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH 11/11 KVM: arm64: Tag host-VA hypercall parameters __hostva
The nVHE hypervisor takes host virtual addresses as hypercall arguments and translates each with kern_hyp_va() before use. Nothing marks them as host-owned, so dereferencing one untranslated at EL2 - a recurring bug class - is invisible to the compiler.
Add a __hostva sparse address space, active only for EL2 code, and tag the host-VA parameters in the hypercall declarations. kern_hyp_va_host() is the only sanctioned unwrap: it translates the address, preserves the pointee type (stripped of qualifiers, as with the percpu accessors) and drops the tag with a __force cast, so an untranslated host VA fails sparse. The tag flows from the shared declaration into the generated handler and on into the donated-memory and tracing-descriptor helpers, so a handler cannot extract a host VA without it. Host code sees plain pointers, and the tag is checker-only: no code is generated.
--- arch/arm64/include/asm/kvm_hcall.h | 43 ++++++++++++------- arch/arm64/include/asm/kvm_mmu.h | 10 +++++ arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 6 ++- arch/arm64/kvm/hyp/include/nvhe/trace.h | 5 ++- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 57 +++++++++++++------------ arch/arm64/kvm/hyp/nvhe/pkvm.c | 11 ++--- arch/arm64/kvm/hyp/nvhe/trace.c | 4 +- 7 files changed, 82 insertions(+), 54 deletions(-)
arch/arm64/include/asm/kvm_hcall.h +28 -15
@@ -27,6 +27,18 @@ struct kvm_vcpu;struct vgic_v3_cpu_if ;struct vgic_v5_cpu_if ; +/* +* A host VA carried by a hypercall argument. At EL2 such a pointer must not +* be dereferenced until it is translated with kern_hyp_va_host(); sparse +* flags any use that skips the translation. The tag describes the EL2 view +* only: the host dereferences its own VAs freely. +*/ +#if defined(__KVM_NVHE_HYPERVISOR__) && defined(__CHECKER__) +#define __hostva __attribute__((noderef, address_space(__hostva))) +#else +#define __hostva +#endif +/* * Hypercall signatures are declared as (type, name) argument pairs. * __KVM_HCALL_MAP() applies a macro to each pair, in the mold of __MAP()
@@ -157,24 +169,24 @@ DECLARE_KVM_HOST_HCALL0(int, __pkvm_prot_finalize)/* Hypercalls that are always available and common to [nh]VHE/pKVM. */ DECLARE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu)DECLARE_KVM_HOST_HCALL (int, __kvm_vcpu_run,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) DECLARE_KVM_HOST_HCALL0_VOID(__kvm_flush_vm_context) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa_nsh, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid, 1, - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_range, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, start, unsigned long, pages) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, start, unsigned long, pages) DECLARE_KVM_HOST_HCALL_VOID(__kvm_flush_cpu_context, 1, - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) DECLARE_KVM_HOST_HCALL_VOID(__kvm_timer_set_cntvoff, 1, u64, cntvoff) DECLARE_KVM_HOST_HCALL(int, __tracing_load, 2, - void *, desc_hva, size_t, desc_size) + void __hostva *, desc_hva, size_t, desc_size) DECLARE_KVM_HOST_HCALL0_VOID(__tracing_unload) DECLARE_KVM_HOST_HCALL(int, __tracing_enable, 1, bool, enable)
@@ -189,13 +201,13 @@ DECLARE_KVM_HOST_HCALL(int, __tracing_enable_event, 2,DECLARE_KVM_HOST_HCALL_VOID (__tracing_write_event,1 , u64, id)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v3_save_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v3_restore_vmcr_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v5_save_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v5_restore_vmcr_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) /* Hypercalls that are available only when pKVM has finalised. */ DECLARE_KVM_HOST_HCALL(int, __pkvm_host_share_hyp, 1,
@@ -220,10 +232,11 @@ DECLARE_KVM_HOST_HCALL0(int, __pkvm_reserve_vm)DECLARE_KVM_HOST_HCALL_VOID (__pkvm_unreserve_vm,1 , pkvm_handle_t, handle)DECLARE_KVM_HOST_HCALL (int, __pkvm_init_vm,3 , - struct kvm *, host_kvm, void *, vm_hva, void *, pgd_hva) + struct kvm __hostva *, host_kvm, void __hostva *, vm_hva, + void __hostva *, pgd_hva)DECLARE_KVM_HOST_HCALL (int, __pkvm_init_vcpu,3 , - pkvm_handle_t, handle, struct kvm_vcpu *, host_vcpu, - void *, vcpu_hva) + pkvm_handle_t, handle, struct kvm_vcpu __hostva *, host_vcpu, + void __hostva *, vcpu_hva) DECLARE_KVM_HOST_HCALL0(int, __pkvm_vcpu_in_poison_fault)DECLARE_KVM_HOST_HCALL (int, __pkvm_force_reclaim_guest_page,1 , phys_addr_t, phys)
arch/arm64/include/asm/kvm_mmu.h +10 -0
@@ -7,6 +7,8 @@#ifndef __ARM64_KVM_MMU_H__#define __ARM64_KVM_MMU_H__ +#include <linux/compiler.h> +#include <asm/page.h> #include <asm/memory.h> #include <asm/mmu.h>
@@ -140,6 +142,14 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)#define kern_hyp_va (v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) +/* +* Translate a __hostva-tagged host VA, dropping the tag: the only sanctioned +* unwrap. Translation only, no ownership or bounds validation; the result +* carries the pointee type stripped of the tag and of any cv-qualifiers. +*/ +#define kern_hyp_va_host (v) \ + ((TYPEOF_UNQUAL(*(v)) *)__kern_hyp_va((unsigned long)(__force void *)(v))) +extern u32 __hyp_va_bits;/*
arch/arm64/kvm/hyp/include/nvhe/pkvm.h +4 -2
@@ -7,6 +7,7 @@#ifndef __ARM64_KVM_NVHE_PKVM_H__#define __ARM64_KVM_NVHE_PKVM_H__ +#include <asm/kvm_hcall.h> #include <asm/kvm_pkvm.h> #include <nvhe/gfp.h>
@@ -69,9 +70,10 @@ void pkvm_hyp_vm_table_init(void *tbl);int __pkvm_reserve_vm (void );void __pkvm_unreserve_vm (pkvm_handle_t handle); -int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva); +int __pkvm_init_vm(struct kvm *host_kvm, void __hostva *vm_hva, + void __hostva *pgd_hva);int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -void *vcpu_hva); + void __hostva *vcpu_hva);int __pkvm_reclaim_dying_guest_page (pkvm_handle_t handle,u64 gfn);int __pkvm_start_teardown_vm (pkvm_handle_t handle);
arch/arm64/kvm/hyp/include/nvhe/trace.h +3 -2
@@ -4,6 +4,7 @@#include <linux/trace_remote_event.h> +#include <asm/kvm_hcall.h> #include <asm/kvm_hyptrace.h> static inline pid_t __tracing_get_vcpu_pid (struct kvm_cpu_context *host_ctxt)
@@ -46,7 +47,7 @@ static inline pid_t __tracing_get_vcpu_pid(struct kvm_cpu_context *host_ctxt)void *tracing_reserve_entry (unsigned long length);void tracing_commit_entry (void ); -int __tracing_load (void *desc_va,size_t desc_size); +int __tracing_load(void __hostva *desc_va, size_t desc_size);void __tracing_unload (void );int __tracing_enable (bool enable);int __tracing_swap_reader (unsigned int cpu);
@@ -59,7 +60,7 @@ static inline void tracing_commit_entry(void) { }#define HYP_EVENT (__name, __proto, __struct, __assign, __printk) \ static inline void trace_##__name(__proto) {} -static inline int __tracing_load (void *desc_va,size_t desc_size) {return -ENODEV ; } +static inline int __tracing_load(void __hostva *desc_va, size_t desc_size) { return -ENODEV; }static inline void __tracing_unload (void ) { }static inline int __tracing_enable (bool enable) {return -ENODEV ; }static inline int __tracing_swap_reader (unsigned int cpu) {return -ENODEV ; }
arch/arm64/kvm/hyp/nvhe/hyp-main.c +29 -28
141 lines not on this page · raw message
arch/arm64/kvm/hyp/nvhe/pkvm.c +6 -5
@@ -644,9 +644,9 @@ static size_t pkvm_get_hyp_vm_size(unsigned int nr_vcpus) size_mul(sizeof(struct pkvm_hyp_vcpu *), nr_vcpus)); } -static void *map_donated_memory_noclear (void *host_va,size_t size) +static void *map_donated_memory_noclear(void __hostva *host_va, size_t size) { -void *va =kern_hyp_va (host_va); +void *va =kern_hyp_va_host (host_va);if (!PAGE_ALIGNED (va))return NULL ;
@@ -658,7 +658,7 @@ static void *map_donated_memory_noclear(void *host_va, size_t size)return va; } -static void *map_donated_memory (void *host_va,size_t size) +static void *map_donated_memory(void __hostva *host_va, size_t size) {void *va =map_donated_memory_noclear (host_va, size);
@@ -805,7 +805,8 @@ void teardown_selftest_vm(void)* * Return 0 success, negative error code on failure. */ -int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva) +int __pkvm_init_vm(struct kvm *host_kvm, void __hostva *vm_hva, + void __hostva *pgd_hva) {struct pkvm_hyp_vm *hyp_vm =NULL ;size_t vm_size, pgd_size;
@@ -896,7 +897,7 @@ static int register_hyp_vcpu(struct pkvm_hyp_vm *hyp_vm, }int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -void *vcpu_hva) + void __hostva *vcpu_hva) {struct pkvm_hyp_vcpu *hyp_vcpu;struct pkvm_hyp_vm *hyp_vm;
arch/arm64/kvm/hyp/nvhe/trace.c +2 -2
@@ -206,9 +206,9 @@ static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_sizreturn true; } -int __tracing_load (void *desc_hva,size_t desc_size) +int __tracing_load(void __hostva *desc_hva, size_t desc_size) { -struct hyp_trace_desc *desc =kern_hyp_va (desc_hva); +struct hyp_trace_desc *desc =kern_hyp_va_host (desc_hva);int ret; ret =__admit_host_mem (desc, desc_size);
Signature · 1 line
2.39.5
[email protected]
AI reviewRe: [PATCH v1 09/11] KVM: arm64: Type-check hypercall arguments at the caller
In reply to Fuad TabbaThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Disabling the hypervisor trace clock fails to stop the background clock synchronization worker. --
--- Patch [9]: [PATCH v1 09/11] KVM: arm64: Type-check hypercall arguments at the caller --- commit 171ebbffa4142a86e7fab981732cd83df6923869
Author: Fuad Tabba <[email protected]>
KVM: arm64: Type-check hypercall arguments at the caller
This commit replaces the untyped kvm_call_hyp_nvhe macro with typed stubs generated for each declared hypercall. This ensures that hypercall arguments are checked for correct number and types at compile time.
arch/arm64/kvm/hyp_trace.c
Quoted 4 lines
arch/arm64/kvm/hyp_trace.c +0
-0
[ ... ]
[Severity: High]
This is a pre-existing issue, but I noticed a logic error in this same file in hyp_trace_clock_enable() when tracing is disabled:
arch/arm64/kvm/hyp_trace.c:hyp_trace_clock_enable() {
...
if (!enable) {
cancel_delayed_work_sync(&hyp_clock->work);
hyp_clock->running = false;
}...
Does this accidentally restart the background clock synchronization worker instead of stopping it?
Without a return statement inside the if (!enable) block, execution appears to continue down the function. This would cause the worker to be inadvertently re-initialized and restarted, leaving the background task running and making periodic __tracing_update_clock hypercalls indefinitely after tracing has been disabled.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
[email protected]
AI reviewRe: [PATCH v1 10/11] KVM: arm64: nVHE: Check hypercall handlers against the declared ABI
In reply to Fuad TabbaThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The MDCR_EL2 trap configuration register is unconditionally copied from the untrusted host VCPU on every guest entry, violating pKVM isolation guarantees for protected VMs.
- [Critical] The protected VM's register context (ctxt) is copied back to the untrusted host VCPU on every exit, leaking confidential guest state.
--
--- Patch [10]: [PATCH v1 10/11] KVM: arm64: nVHE: Check hypercall handlers against the declared ABI --- commit 3f8ed457b3a7f1b8aabe10f15d93afe4df7e93a2
Author: Fuad Tabba <[email protected]>
KVM: arm64: nVHE: Check hypercall handlers against the declared ABI
This commit generates the unmarshalling of hypercall handlers using DEFINE_KVM_HOST_HCALL. It checks the handler's parameter list against the signature declared in kvm_hcall.h to prevent caller/handler disagreements. Manual DECLARE_REG casts are removed from the handler bodies.
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0
[ ... ]
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +1
-4@@ -228,15 +282,11 @@ static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt)* loading a vcpu. Therefore, if SME features enabled the host * is misbehaving. */ -if (unlikely (system_supports_sme () &&read_sysreg_s (SYS_SVCR ))) { - ret = -EINVAL ; - goto out; - } +if (unlikely (system_supports_sme () &&read_sysreg_s (SYS_SVCR )))
arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt) · line 291
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +3
-4+return -EINVAL ; -if (!hyp_vcpu) { - ret = -EINVAL ; - goto out; - } +if (!hyp_vcpu) +return -EINVAL ;flush_hyp_vcpu (hyp_vcpu);
[Severity: Critical]
This is a pre-existing issue, but does this function allow the untrusted host to bypass pKVM isolation guarantees?
Looking at flush_hyp_vcpu() in arch/arm64/kvm/hyp/nvhe/hyp-main.c, the MDCR_EL2 trap configuration is copied unconditionally from the untrusted host vCPU on every guest entry:
hyp_vcpu->vcpu.arch.mdcr_el2 = host_vcpu->arch.mdcr_el2;
For a protected VM, the MDCR_EL2 trap configuration should be strictly EL2-private and initialized internally. By syncing this from the host on every entry, could the host maliciously reconfigure the guest's debug traps?
[Severity: Critical]
This is also a pre-existing issue, but does the exit path leak confidential guest execution state to the host?
In the corresponding sync_hyp_vcpu() function called after the guest run, the protected VM's register context is copied back to the host vCPU:
host_vcpu->arch.ctxt = hyp_vcpu->vcpu.arch.ctxt;
Since this copies the hypervisor's private copy of the guest's context back into the host-controlled structure, won't this allow the host EL1 to directly inspect highly confidential execution state (including general purpose registers and system registers) after the hypercall returns?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH v1 11/11] KVM: arm64: Tag host-VA hypercall parameters __hostva
In reply to Fuad TabbaThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] kern_hyp_va_host() macro fails to strip the __hostva address space tag for Sparse.
Pre-existing issues:
- [Critical] Missing host pointer ownership validation in always-on hypercalls allows a malicious host to corrupt EL2-private memory (Confused Deputy). --
--- Patch [11]: [PATCH v1 11/11] KVM: arm64: Tag host-VA hypercall parameters __hostva --- commit 4acf0dff6116caffddce5517211ac9136d9b0ee1
Author: Fuad Tabba <[email protected]>
KVM: arm64: Tag host-VA hypercall parameters __hostva
This commit introduces the __hostva sparse address space to tag host virtual addresses passed as hypercall arguments in the nVHE hypervisor. It adds kern_hyp_va_host() to explicitly unwrap and translate these tagged pointers, ensuring that untranslated host VAs are caught by sparse checks.
Quoted 3 lines
arch/arm64/include/asm/kvm_mmu.h +0
-0
[ ... ]
arch/arm64/include/asm/kvm_mmu.h static __always_inline unsigned long __kern_hyp_va(unsigned long v) · line 151
Quoted 11 lines
arch/arm64/include/asm/kvm_mmu.h +7
-0@@ -140,6 +142,14 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)#define kern_hyp_va (v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) +/* +* Translate a __hostva-tagged host VA, dropping the tag: the only sanctioned +* unwrap. Translation only, no ownership or bounds validation; the result +* carries the pointee type stripped of the tag and of any cv-qualifiers. +*/ +#define kern_hyp_va_host (v) \ + ((TYPEOF_UNQUAL(*(v)) *)__kern_hyp_va((unsigned long)(__force void *)(v)))
[Severity: Medium]
Does TYPEOF_UNQUAL() actually strip the address space tag in Sparse?
Sparse treats address spaces as type qualifiers that typeof_unqual (and by extension TYPEOF_UNQUAL) does not remove, unlike const or volatile. Consequently, this cast evaluates to a pointer that still carries the __hostva tag.
When assigned to a regular kernel pointer, this will trigger incorrect type in assignment (different address spaces) false positive warnings across the codebase when running make C=2.
Should this use an explicit cast to __kernel (address_space(0)) to correctly strip the tag, similar to how per_cpu_ptr handles __percpu?
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0
[ ... ]
arch/arm64/kvm/hyp/nvhe/hyp-main.c DEFINE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, · line 427
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2
-2@@ -421,9 +421,9 @@ DEFINE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, }DEFINE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) { -__kvm_adjust_pc (kern_hyp_va (vcpu)); +__kvm_adjust_pc (kern_hyp_va_host (vcpu)); }
[Severity: Critical]
This is a pre-existing issue, but does this lack of ownership validation allow the host to corrupt EL2-private memory?
Under pKVM, the host is treated as an adversary. If the host provides a TTBR1 virtual address that maps to an EL2-private physical address, kern_hyp_va_host() will translate it into a valid EL2 linear map pointer without verifying ownership.
The hypervisor will then write into EL2-private memory when modifying flags in __kvm_adjust_pc() or hardware register state in __vgic_v3_save_aprs(), corrupting its own state or the state of protected guests.
Should there be an explicit ownership check before dereferencing pointers from these always-on hypercalls?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Fuad Tabba
reviewerRe: [PATCH v1 09/11] KVM: arm64: Type-check hypercall arguments at the caller
In reply to [email protected]Quoted 30 lines · On Mon, 20 Jul 2026 at 18:29, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Disabling the hypervisor trace clock fails to stop the background clock synchronization worker. ----- Patch [9]: [PATCH v1 09/11] KVM: arm64: Type-check hypercall arguments at the caller --- commit
171ebbffa4142a86e7fab981732cd83df6923869
Author: Fuad Tabba <[email protected]>KVM: arm64: Type-check hypercall arguments at the caller
This commit replaces the untyped
kvm_call_hyp_nvhemacro with typed stubs generated for each declared hypercall. This ensures that hypercall arguments are checked for correct number and types at compile time.arch/arm64/kvm/hyp_trace.c
Quoted 4 lines
arch/arm64/kvm/hyp_trace.c +0
-0[ ... ]
[Severity: High]
This is a pre-existing issue, but I noticed a logic error in this same file inhyp_trace_clock_enable()when tracing is disabled:arch/arm64/kvm/hyp_trace.c:hyp_trace_clock_enable() {
...
Quoted 8 lines
if (!enable) { cancel_delayed_work_sync(&hyp_clock->work); hyp_clock->running = false; }...
Does this accidentally restart the background clock synchronization worker instead of stopping it?
Yes. I will send a separate patch to fix this, as you noted, it's not introduced by this series.
/fuad
Quoted 9 lines
Without a return statement inside the if (!enable) block, execution appears to continue down the function. This would cause the worker to be inadvertently re-initialized and restarted, leaving the background task running and making periodic
__tracing_update_clockhypercalls indefinitely after tracing has been disabled.--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Fuad Tabba
reviewerRe: [PATCH v1 10/11] KVM: arm64: nVHE: Check hypercall handlers against the declared ABI
In reply to [email protected]Quoted 6 lines · On Mon, 20 Jul 2026 at 18:42, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] TheMDCR_EL2trap configuration register is unconditionally copied from the untrusted host VCPU on every guest entry, violating pKVM isolation guarantees for protected VMs.
- [Critical] The protected VM's register context (ctxt) is copied back to the untrusted host VCPU on every exit, leaking confidential guest state.
I'm working on it [1]. This is part of upstreaming pKVM. We'll get there eventually...
/fuad
https://lore.kernel.org/all/[email protected]/
Quoted 72 lines
--
--- Patch [10]: [PATCH v1 10/11] KVM: arm64: nVHE: Check hypercall handlers against the declared ABI --- commit
3f8ed457b3a7f1b8aabe10f15d93afe4df7e93a2
Author: Fuad Tabba <[email protected]>KVM: arm64: nVHE: Check hypercall handlers against the declared ABI
This commit generates the unmarshalling of hypercall handlers using
DEFINE_KVM_HOST_HCALL. It checks the handler's parameter list against the signature declared inkvm_hcall.hto prevent caller/handler disagreements. ManualDECLARE_REGcasts are removed from the handler bodies.Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0[ ... ]
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +1
-4@@ -228,15 +282,11 @@ static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt)* loading a vcpu. Therefore, if SME features enabled the host * is misbehaving. */ -if (unlikely (system_supports_sme () &&read_sysreg_s (SYS_SVCR ))) { - ret = -EINVAL ; - goto out; - } +if (unlikely (system_supports_sme () &&read_sysreg_s (SYS_SVCR )))arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt) · line 291
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +3
-4+return -EINVAL ; -if (!hyp_vcpu) { - ret = -EINVAL ; - goto out; - } +if (!hyp_vcpu) +return -EINVAL ;flush_hyp_vcpu (hyp_vcpu);[Severity: Critical]
This is a pre-existing issue, but does this function allow the untrusted host to bypass pKVM isolation guarantees?Looking at
flush_hyp_vcpu()inarch/arm64/kvm/hyp/nvhe/hyp-main.c, theMDCR_EL2trap configuration is copied unconditionally from the untrusted host vCPU on every guest entry:
hyp_vcpu->vcpu.arch.mdcr_el2=host_vcpu->arch.mdcr_el2;For a protected VM, the
MDCR_EL2trap configuration should be strictly EL2-private and initialized internally. By syncing this from the host on every entry, could the host maliciously reconfigure the guest's debug traps?[Severity: Critical]
This is also a pre-existing issue, but does the exit path leak confidential guest execution state to the host?In the corresponding
sync_hyp_vcpu()function called after the guest run, the protected VM's register context is copied back to the host vCPU:
host_vcpu->arch.ctxt=hyp_vcpu->vcpu.arch.ctxt;Since this copies the hypervisor's private copy of the guest's context back into the host-controlled structure, won't this allow the host EL1 to directly inspect highly confidential execution state (including general purpose registers and system registers) after the hypercall returns?
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Fuad Tabba
reviewerRe: [PATCH v1 11/11] KVM: arm64: Tag host-VA hypercall parameters __hostva
In reply to [email protected]Quoted 47 lines · On Mon, 20 Jul 2026 at 18:55, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium]kern_hyp_va_host()macro fails to strip the__hostvaaddress space tag for Sparse.Pre-existing issues:
- [Critical] Missing host pointer ownership validation in always-on hypercalls allows a malicious host to corrupt EL2-private memory (Confused Deputy). ----- Patch [11]: [PATCH v1 11/11] KVM: arm64: Tag host-VA hypercall parameters
__hostva--- commit4acf0dff6116caffddce5517211ac9136d9b0ee1
Author: Fuad Tabba <[email protected]>KVM: arm64: Tag host-VA hypercall parameters
__hostvaThis commit introduces the
__hostvasparse address space to tag host virtual addresses passed as hypercall arguments in the nVHE hypervisor. It addskern_hyp_va_host()to explicitly unwrap and translate these tagged pointers, ensuring that untranslated host VAs are caught by sparse checks.Quoted 3 lines
arch/arm64/include/asm/kvm_mmu.h +0
-0[ ... ]
arch/arm64/include/asm/kvm_mmu.h static __always_inline unsigned long __kern_hyp_va(unsigned long v) · line 151
Quoted 11 lines
arch/arm64/include/asm/kvm_mmu.h +7
-0@@ -140,6 +142,14 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)#define kern_hyp_va (v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) +/* +* Translate a __hostva-tagged host VA, dropping the tag: the only sanctioned +* unwrap. Translation only, no ownership or bounds validation; the result +* carries the pointee type stripped of the tag and of any cv-qualifiers. +*/ +#define kern_hyp_va_host (v) \ + ((TYPEOF_UNQUAL(*(v)) *)__kern_hyp_va((unsigned long)(__force void *)(v)))[Severity: Medium]
DoesTYPEOF_UNQUAL()actually strip the address space tag in Sparse?Sparse treats address spaces as type qualifiers that
typeof_unqual(and by extensionTYPEOF_UNQUAL) does not remove, unlike const or volatile. Consequently, this cast evaluates to a pointer that still carries the__hostvatag.
Quoted 6 lines
When assigned to a regular kernel pointer, this will trigger incorrect type in assignment (different address spaces) false positive warnings across the codebase when running make C=2.
Should this use an explicit cast to
__kernel(address_space(0)) to correctly strip the tag, similar to howper_cpu_ptrhandles__percpu?
The __hostva tag is stripped, so these warnings don't occur. Under sparse TYPEOF_UNQUAL() is __typeof_unqual__(), which in sparse >= v0.6.5-rc1 removes the address_space qualifier, so kern_hyp_va_host() returns a plain kernel pointer. Verified: C=2 over the nvhe objects is warning-free, while a control doing an implicit __hostva -> plain conversion does warn. Older sparse lacks __typeof_unqual__, so scripts/checker-valid.sh disables checking with a warning rather than emitting false positives.
Quoted 10 lines
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0[ ... ]
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0@@ -421,9 +421,9 @@ DEFINE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, }
Quoted 11 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c DEFINE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, · line 427
Quoted 7 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2
-2DEFINE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) { -__kvm_adjust_pc (kern_hyp_va (vcpu)); +__kvm_adjust_pc (kern_hyp_va_host (vcpu)); }[Severity: Critical]
This is a pre-existing issue, but does this lack of ownership validation allow the host to corrupt EL2-private memory?
Working on it :) Different series group [1].
/fuad
[1] https://lore.kernel.org/all/[email protected]/
Quoted 16 lines
Under pKVM, the host is treated as an adversary. If the host provides a TTBR1 virtual address that maps to an EL2-private physical address,
kern_hyp_va_host()will translate it into a valid EL2 linear map pointer without verifying ownership.The hypervisor will then write into EL2-private memory when modifying flags in
__kvm_adjust_pc()or hardware register state in__vgic_v3_save_aprs(), corrupting its own state or the state of protected guests.Should there be an explicit ownership check before dereferencing pointers from these always-on hypercalls?
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Re: [PATCH v1 01/11] tracing: Include linux/types.h in trace_remote_event.h
In reply to Fuad Tabbainclude/linux/trace_remote_event.h line 10
Quoted 13 lines · On Mon, 20 Jul 2026 17:13:33 +0100 Fuad Tabba <[email protected]> wrote:
include/linux/trace_remote_event.h +2
-0@@ -3,6 +3,8 @@#ifndef _LINUX_TRACE_REMOTE_EVENTS_H#define _LINUX_TRACE_REMOTE_EVENTS_H +#include <linux/types.h> +struct trace_remote ;struct trace_event_fields ;struct trace_seq ;
I don't know if this is correct or not, but here's my ack so others can decide and take it through their trees.
-- Steve
Marc Zyngier
maintainerRe: [PATCH v1 09/11] KVM: arm64: Type-check hypercall arguments at the caller
In reply to Fuad TabbaQuoted 75 lines · Fuad Tabba
kvm_call_hyp_nvhe()reduces its target to an SMCCC function number, so the compiler never sees a callable: arguments that are wrong in number, type or order are silently marshalled into registers. Thekvm_call_hyp()wrappers only catch this on the VHE branch, and the pKVM-only hypercalls have no such branch.Declare each hypercall's signature once in
kvm_hcall.hand generate a typed stub from it, in the mold of the syscall wrappers. Makekvm_call_hyp_nvhe()resolve to the stub so every caller is checked against the declared signature; a stale or mistyped call now fails to compile. The stubs inline to the same SMCCC call the untyped macro used to make: the compiled callers are unchanged, apart from hypercall returns now being tested at their declared width.The stage-2 protection arguments are declared u64 rather than enum
kvm_pgtable_prot, askvm_pgtable.hincludeslinux/kvm_host.hand the enum cannot be completed here.Assisted-by Antigravity:gemini-3.1-proSigned-off-by Fuad Tabba <[email protected]>--- arch/arm64/include/asm/kvm_hcall.h | 165 ++++++++++++++++++++++++++++- arch/arm64/kvm/hyp_trace.c | 2 +- 2 files changed, 165 insertions(+), 2 deletions(-)arch/arm64/include/asm/kvm_hcall.h +28
-1@@ -16,12 +16,35 @@#include <asm/barrier.h> #include <asm/kvm_asm.h> +#include <asm/spectre.h> #include <asm/virt.h> typedef u16 pkvm_handle_t ; +struct kvm ; +struct kvm_s2_mmu ; +struct kvm_vcpu ; +struct vgic_v3_cpu_if ; +struct vgic_v5_cpu_if ; + +/* +* Hypercall signatures are declared as (type, name) argument pairs. +* __KVM_HCALL_MAP() applies a macro to each pair, in the mold of __MAP() +* in <linux/syscalls.h>. +*/ +#define __KVM_HCALL_MAP1 (m, t, a, ...) m(t, a) +#define __KVM_HCALL_MAP2 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP1(m, __VA_ARGS__) +#define __KVM_HCALL_MAP3 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP2(m, __VA_ARGS__) +#define __KVM_HCALL_MAP4 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP3(m, __VA_ARGS__) +#define __KVM_HCALL_MAP5 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP4(m, __VA_ARGS__) +#define __KVM_HCALL_MAP6 (m, t, a, ...) m(t, a), __KVM_HCALL_MAP5(m, __VA_ARGS__) +#define __KVM_HCALL_MAP (n, ...) __KVM_HCALL_MAP##n(__VA_ARGS__) + +#define __KVM_HCALL_DECL (t, a) t a +#define __KVM_HCALL_ARGS (t, a) a +#ifndef __KVM_NVHE_HYPERVISOR__ -#define kvm_call_hyp_nvhe (f, ...) \ +#define __kvm_call_hyp_nvhe (f, ...) \ ({ \ struct arm_smccc_res res; \ \@@ -33,6 +56,43 @@ typedef u16 pkvm_handle_t; res.a1; \ }) +/* +* Generate a typed stub for each declared hypercall. kvm_call_hyp_nvhe() +* resolves to the stub, so a call with the wrong argument count or types +* fails to compile instead of being silently truncated to an SMCCC function
arch/arm64/include/asm/kvm_hcall.h typedef u16 pkvm_handle_t; · line 72
Quoted 10 lines
arch/arm64/include/asm/kvm_hcall.h +10
-0+* number and a pile of registers. The stub inlines to the same SMCCC call +* the untyped macro used to make. +*/ +#define DECLARE_KVM_HOST_HCALL (ret, name, x, ...) \ + static __always_inline \ + ret nvhe_hvc_##name(__KVM_HCALL_MAP(x, __KVM_HCALL_DECL, __VA_ARGS__)) \ + { \ + return (ret)__kvm_call_hyp_nvhe(name, \ + __KVM_HCALL_MAP(x, __KVM_HCALL_ARGS, __VA_ARGS__)); \ + }
One thing I find absolutely horrible is to have to specify the number of parameters here. It is already bad to have to comma-separate everything, but having to count them is too hard for me ;-).
We already have facilities to count the number of parameters to a macro (see the COUNT_ARGS macro). You could make use of it all over the place.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Fuad Tabba
reviewerRe: [PATCH v1 09/11] KVM: arm64: Type-check hypercall arguments at the caller
Hi Marc,
On Thu, 30 Jul 2026 at 13:37, Marc Zyngier <[email protected]> wrote:
...
Quoted 19 lines
Quoted 4 lines
arch/arm64/include/asm/kvm_hcall.h +4
-0+/* +* Generate a typed stub for each declared hypercall. kvm_call_hyp_nvhe() +* resolves to the stub, so a call with the wrong argument count or types +* fails to compile instead of being silently truncated to an SMCCC function arch/arm64/include/asm/kvm_hcall.h typedef u16 pkvm_handle_t; · line 72
Quoted 10 lines
arch/arm64/include/asm/kvm_hcall.h +10
-0+* number and a pile of registers. The stub inlines to the same SMCCC call +* the untyped macro used to make. +*/ +#define DECLARE_KVM_HOST_HCALL (ret, name, x, ...) \ + static __always_inline \ + ret nvhe_hvc_##name(__KVM_HCALL_MAP(x, __KVM_HCALL_DECL, __VA_ARGS__)) \ + { \ + return (ret)__kvm_call_hyp_nvhe(name, \ + __KVM_HCALL_MAP(x, __KVM_HCALL_ARGS, __VA_ARGS__)); \ + }One thing I find absolutely horrible is to have to specify the number of parameters here. It is already bad to have to comma-separate everything, but having to count them is too hard for me ;-).
Quoted 3 lines
We already have facilities to count the number of parameters to a macro (see the
COUNT_ARGSmacro). You could make use of it all over the place.
Will Deacon mentioned the same thing yesterday (offline). I'll drop it in v2. The count was only there because the macro that walks the pair list is a copy of __MAP() in <linux/syscalls.h>, which gets its arity from the SYSCALL_DEFINEn name. No better reason than that.
COUNT_ARGS() does work here. The list is (type, name) pairs, so it counts twice the arguments, which the ladder absorbs by being indexed on list entries:
#define __KVM_HCALL_MAP2(m, t, a, ...) m(t, a)
#define __KVM_HCALL_MAP4(m, t, a, ...) m(t, a), __KVM_HCALL_MAP2(m, __VA_ARGS__) [...]
#define __KVM_HCALL_MAP12(m, t, a, ...) m(t, a), __KVM_HCALL_MAP10(m, __VA_ARGS__)
#define __KVM_HCALL_MAP_N(n, m, ...) CONCATENATE(__KVM_HCALL_MAP, n)(m, __VA_ARGS__)
#define __KVM_HCALL_MAP(m, ...) __KVM_HCALL_MAP_N(COUNT_ARGS(__VA_ARGS__), m, __VA_ARGS__)
DECLARE_KVM_HOST_HCALL(int, __pkvm_init,
phys_addr_t, phys, unsigned long, size, unsigned long *, per_cpu_base, u32, hyp_va_bits)
That drops 40 hand-written counts from the declarations and 40 from the handler definitions. __KVM_HCALL_MAP_N() is for the handler side, which truncates a fixed list of six argument registers, and takes its count from COUNT_ARGS() as well.
I diffed the preprocessed output before and after: token-identical apart from the __LINE__ values that shift with the declarations.
Cheers,
/fuad
Quoted 7 lines
Thanks,
M.--
Without deviation from the norm, progress is not possible.
Re: [PATCH v1 03/11] KVM: arm64: nVHE: Declare the hyp event IDs before defining them
In reply to Fuad TabbaQuoted 9 lines · Fuad Tabba
The defining expansion of
HYP_EVENT()inevents.cis the first time its translation unit meets hyp_event_id_<name>, so sparse suggests making the symbols static. Includekvm_hypevents.hahead ofdefine_events.hso the extern declarations come first, as with the tracepoint headers.No functional change intended.
Signed-off-by Fuad Tabba <[email protected]>
Quoted 20 lines
--- arch/arm64/kvm/hyp/nvhe/events.c | 2 ++ 1 file changed, 2 insertions(+)arch/arm64/kvm/hyp/nvhe/events.c +2
-0@@ -7,6 +7,8 @@#include <nvhe/mm.h> #include <nvhe/trace.h> +#include <asm/kvm_hypevents.h> +#include <nvhe/define_events.h> int __tracing_enable_event (unsigned short id,bool enable)Signature · 1 line
2.39.5
Signature · 1 line
Vincent
Re: [PATCH v1 04/11] KVM: arm64: nVHE: Use NULL to reset the trace buffer backing pointer
In reply to Fuad TabbaQuoted 6 lines · Fuad Tabba
bpages_backing_startis a pointer; resetting it to plain 0 triggers a sparse warning.No functional change intended.
Signed-off-by Fuad Tabba <[email protected]>
Probably missed this when modifying the type for bpages_backing_start.
Quoted 20 lines
--- arch/arm64/kvm/hyp/nvhe/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/hyp/nvhe/trace.c +1
-1@@ -93,7 +93,7 @@ static void hyp_trace_buffer_unload_bpage_backing(struct hyp_trace_buffer *trace__release_host_mem (start, size); - trace_buffer->bpages_backing_start =0 ; + trace_buffer->bpages_backing_start =NULL ; trace_buffer->bpages_backing_size =0 ; }Signature · 1 line
2.39.5
Signature · 1 line
Vincent
Re: [PATCH v1 05/11] KVM: arm64: nVHE: Run the source checker under C=2
In reply to Fuad TabbaQuoted 9 lines · Fuad Tabba
The custom %.nvhe.o rule reuses
rule_cc_o_c, which hooks the source checker only for C=1, and that only when the object is rebuilt. The C=2 hook,cmd_force_checksrc, hangs off the standard %.o rule that nVHE objects do not use, so "make C=2" silently skips every nVHE source file. Callcmd_force_checksrcafter the compile rule, as the standard rule does.Fixes 7621712918ad4 ("KVM: arm64: Add build rules for separate VHE/nVHE object files")Signed-off-by Fuad Tabba <[email protected]>
Nice, I have wanted to fix this annoying issue for a while now!
Quoted 19 lines
--- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + 1 file changed, 1 insertion(+)arch/arm64/kvm/hyp/nvhe/Makefile +1
-0@@ -49,6 +49,7 @@ targets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-relo # avoids file name clashes for files shared with VHE. $(obj)/%.nvhe.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) + $(call cmd,force_checksrc) $(obj)/%.nvhe.o: $(src)/%.S FORCE $(call if_changed_rule,as_o_S)Signature · 1 line
2.39.5
Signature · 1 line
Vincent
Re: [PATCH v1 11/11] KVM: arm64: Tag host-VA hypercall parameters __hostva
In reply to Fuad TabbaQuoted 35 lines · Fuad Tabba
The nVHE hypervisor takes host virtual addresses as hypercall arguments and translates each with
kern_hyp_va()before use. Nothing marks them as host-owned, so dereferencing one untranslated at EL2 - a recurring bug class - is invisible to the compiler.Add a
__hostvasparse address space, active only for EL2 code, and tag the host-VA parameters in the hypercall declarations.kern_hyp_va_host()is the only sanctioned unwrap: it translates the address, preserves the pointee type (stripped of qualifiers, as with the percpu accessors) and drops the tag with a__forcecast, so an untranslated host VA fails sparse. The tag flows from the shared declaration into the generated handler and on into the donated-memory and tracing-descriptor helpers, so a handler cannot extract a host VA without it. Host code sees plain pointers, and the tag is checker-only: no code is generated.Signed-off-by Fuad Tabba <[email protected]>--- arch/arm64/include/asm/kvm_hcall.h | 43 ++++++++++++------- arch/arm64/include/asm/kvm_mmu.h | 10 +++++ arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 6 ++- arch/arm64/kvm/hyp/include/nvhe/trace.h | 5 ++- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 57 +++++++++++++------------ arch/arm64/kvm/hyp/nvhe/pkvm.c | 11 ++--- arch/arm64/kvm/hyp/nvhe/trace.c | 4 +- 7 files changed, 82 insertions(+), 54 deletions(-)arch/arm64/include/asm/kvm_hcall.h +1
-0@@ -27,6 +27,18 @@ struct kvm_vcpu;struct vgic_v3_cpu_if ;struct vgic_v5_cpu_if ; +/*
arch/arm64/include/asm/kvm_hcall.h struct kvm_vcpu; · line 40
Quoted 10 lines
arch/arm64/include/asm/kvm_hcall.h +10
-0+* A host VA carried by a hypercall argument. At EL2 such a pointer must not +* be dereferenced until it is translated with kern_hyp_va_host(); sparse +* flags any use that skips the translation. The tag describes the EL2 view +* only: the host dereferences its own VAs freely. +*/ +#if defined(__KVM_NVHE_HYPERVISOR__) && defined(__CHECKER__) +#define __hostva __attribute__((noderef, address_space(__hostva))) +#else +#define __hostva +#endif
Could we have __kern, just like we have __user.
Ideally this could be used later to mark the values we don't trust, so not only VAs but also nr_pages. In mem_protect.c e.g.
size_t pfn_range_is_valid(u64 __kern pfn, u64 __kern nr_pages)
so that size is only trusted once pfn_range_is_valid() has run.
And beside, that matches "kern_hyp_va"
Quoted 370 lines
arch/arm64/include/asm/kvm_hcall.h +17
-15+/* * Hypercall signatures are declared as (type, name) argument pairs. * __KVM_HCALL_MAP() applies a macro to each pair, in the mold of __MAP() @@ -157,24 +169,24 @@ DECLARE_KVM_HOST_HCALL0(int, __pkvm_prot_finalize)/* Hypercalls that are always available and common to [nh]VHE/pKVM. */ DECLARE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu)DECLARE_KVM_HOST_HCALL (int, __kvm_vcpu_run,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) DECLARE_KVM_HOST_HCALL0_VOID(__kvm_flush_vm_context) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa_nsh, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid, 1, - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_range, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, start, unsigned long, pages) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, start, unsigned long, pages) DECLARE_KVM_HOST_HCALL_VOID(__kvm_flush_cpu_context, 1, - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) DECLARE_KVM_HOST_HCALL_VOID(__kvm_timer_set_cntvoff, 1, u64, cntvoff) DECLARE_KVM_HOST_HCALL(int, __tracing_load, 2, - void *, desc_hva, size_t, desc_size) + void __hostva *, desc_hva, size_t, desc_size) DECLARE_KVM_HOST_HCALL0_VOID(__tracing_unload) DECLARE_KVM_HOST_HCALL(int, __tracing_enable, 1, bool, enable)@@ -189,13 +201,13 @@ DECLARE_KVM_HOST_HCALL(int, __tracing_enable_event, 2,DECLARE_KVM_HOST_HCALL_VOID (__tracing_write_event,1 , u64, id)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v3_save_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v3_restore_vmcr_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v5_save_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v5_restore_vmcr_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) /* Hypercalls that are available only when pKVM has finalised. */ DECLARE_KVM_HOST_HCALL(int, __pkvm_host_share_hyp, 1,@@ -220,10 +232,11 @@ DECLARE_KVM_HOST_HCALL0(int, __pkvm_reserve_vm)DECLARE_KVM_HOST_HCALL_VOID (__pkvm_unreserve_vm,1 , pkvm_handle_t, handle)DECLARE_KVM_HOST_HCALL (int, __pkvm_init_vm,3 , - struct kvm *, host_kvm, void *, vm_hva, void *, pgd_hva) + struct kvm __hostva *, host_kvm, void __hostva *, vm_hva, + void __hostva *, pgd_hva)DECLARE_KVM_HOST_HCALL (int, __pkvm_init_vcpu,3 , - pkvm_handle_t, handle, struct kvm_vcpu *, host_vcpu, - void *, vcpu_hva) + pkvm_handle_t, handle, struct kvm_vcpu __hostva *, host_vcpu, + void __hostva *, vcpu_hva) DECLARE_KVM_HOST_HCALL0(int, __pkvm_vcpu_in_poison_fault)DECLARE_KVM_HOST_HCALL (int, __pkvm_force_reclaim_guest_page,1 , phys_addr_t, phys)arch/arm64/include/asm/kvm_mmu.h +10
-0@@ -7,6 +7,8 @@#ifndef __ARM64_KVM_MMU_H__#define __ARM64_KVM_MMU_H__ +#include <linux/compiler.h> +#include <asm/page.h> #include <asm/memory.h> #include <asm/mmu.h> @@ -140,6 +142,14 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)#define kern_hyp_va (v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) +/* +* Translate a __hostva-tagged host VA, dropping the tag: the only sanctioned +* unwrap. Translation only, no ownership or bounds validation; the result +* carries the pointee type stripped of the tag and of any cv-qualifiers. +*/ +#define kern_hyp_va_host (v) \ + ((TYPEOF_UNQUAL(*(v)) *)__kern_hyp_va((unsigned long)(__force void *)(v))) +extern u32 __hyp_va_bits;/* arch/arm64/kvm/hyp/include/nvhe/pkvm.h +4
-2@@ -7,6 +7,7 @@#ifndef __ARM64_KVM_NVHE_PKVM_H__#define __ARM64_KVM_NVHE_PKVM_H__ +#include <asm/kvm_hcall.h> #include <asm/kvm_pkvm.h> #include <nvhe/gfp.h> @@ -69,9 +70,10 @@ void pkvm_hyp_vm_table_init(void *tbl);int __pkvm_reserve_vm (void );void __pkvm_unreserve_vm (pkvm_handle_t handle); -int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva); +int __pkvm_init_vm(struct kvm *host_kvm, void __hostva *vm_hva, + void __hostva *pgd_hva);int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -void *vcpu_hva); + void __hostva *vcpu_hva);int __pkvm_reclaim_dying_guest_page (pkvm_handle_t handle,u64 gfn);int __pkvm_start_teardown_vm (pkvm_handle_t handle);arch/arm64/kvm/hyp/include/nvhe/trace.h +3
-2@@ -4,6 +4,7 @@#include <linux/trace_remote_event.h> +#include <asm/kvm_hcall.h> #include <asm/kvm_hyptrace.h> static inline pid_t __tracing_get_vcpu_pid (struct kvm_cpu_context *host_ctxt)@@ -46,7 +47,7 @@ static inline pid_t __tracing_get_vcpu_pid(struct kvm_cpu_context *host_ctxt)void *tracing_reserve_entry (unsigned long length);void tracing_commit_entry (void ); -int __tracing_load (void *desc_va,size_t desc_size); +int __tracing_load(void __hostva *desc_va, size_t desc_size);void __tracing_unload (void );int __tracing_enable (bool enable);int __tracing_swap_reader (unsigned int cpu);@@ -59,7 +60,7 @@ static inline void tracing_commit_entry(void) { }#define HYP_EVENT (__name, __proto, __struct, __assign, __printk) \ static inline void trace_##__name(__proto) {} -static inline int __tracing_load (void *desc_va,size_t desc_size) {return -ENODEV ; } +static inline int __tracing_load(void __hostva *desc_va, size_t desc_size) { return -ENODEV; }static inline void __tracing_unload (void ) { }static inline int __tracing_enable (bool enable) {return -ENODEV ; }static inline int __tracing_swap_reader (unsigned int cpu) {return -ENODEV ; }arch/arm64/kvm/hyp/nvhe/hyp-main.c +29
-28@@ -269,7 +269,7 @@ DEFINE_KVM_HOST_HCALL0_VOID(__pkvm_vcpu_put) }DEFINE_KVM_HOST_HCALL (int, __kvm_vcpu_run,1 , - struct kvm_vcpu *, host_vcpu) + struct kvm_vcpu __hostva *, host_vcpu) {int ret;@@ -294,7 +294,7 @@ DEFINE_KVM_HOST_HCALL(int, __kvm_vcpu_run, 1,sync_hyp_vcpu (hyp_vcpu); }else { -struct kvm_vcpu *vcpu =kern_hyp_va (host_vcpu); +struct kvm_vcpu *vcpu =kern_hyp_va_host (host_vcpu);/* The host is fully trusted, run its vCPU directly. */ fpsimd_lazy_switch_to_guest (vcpu);@@ -421,9 +421,9 @@ DEFINE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, }DEFINE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) { -__kvm_adjust_pc (kern_hyp_va (vcpu)); +__kvm_adjust_pc (kern_hyp_va_host (vcpu)); }DEFINE_KVM_HOST_HCALL0_VOID (__kvm_flush_vm_context)@@ -432,27 +432,27 @@ DEFINE_KVM_HOST_HCALL0_VOID(__kvm_flush_vm_context) }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid_ipa,3 , - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) { -__kvm_tlb_flush_vmid_ipa (kern_hyp_va (mmu), ipa, level); +__kvm_tlb_flush_vmid_ipa (kern_hyp_va_host (mmu), ipa, level); }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid_ipa_nsh,3 , - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) { -__kvm_tlb_flush_vmid_ipa_nsh (kern_hyp_va (mmu), ipa, level); +__kvm_tlb_flush_vmid_ipa_nsh (kern_hyp_va_host (mmu), ipa, level); }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid_range,3 , - struct kvm_s2_mmu *, mmu, phys_addr_t, start, unsigned long, pages) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, start, unsigned long, pages) { -__kvm_tlb_flush_vmid_range (kern_hyp_va (mmu), start, pages); +__kvm_tlb_flush_vmid_range (kern_hyp_va_host (mmu), start, pages); }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid,1 , - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) { -__kvm_tlb_flush_vmid (kern_hyp_va (mmu)); +__kvm_tlb_flush_vmid (kern_hyp_va_host (mmu)); } DEFINE_KVM_HOST_HCALL_VOID(__pkvm_tlb_flush_vmid, 1,@@ -468,9 +468,9 @@ DEFINE_KVM_HOST_HCALL_VOID(__pkvm_tlb_flush_vmid, 1, }DEFINE_KVM_HOST_HCALL_VOID (__kvm_flush_cpu_context,1 , - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) { -__kvm_flush_cpu_context (kern_hyp_va (mmu)); +__kvm_flush_cpu_context (kern_hyp_va_host (mmu)); } DEFINE_KVM_HOST_HCALL_VOID(__kvm_timer_set_cntvoff, 1,@@ -499,15 +499,15 @@ DEFINE_KVM_HOST_HCALL0_VOID(__vgic_v3_init_lrs) }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v3_save_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if) { -__vgic_v3_save_aprs (kern_hyp_va (cpu_if)); +__vgic_v3_save_aprs (kern_hyp_va_host (cpu_if)); }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v3_restore_vmcr_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if) { -__vgic_v3_restore_vmcr_aprs (kern_hyp_va (cpu_if)); +__vgic_v3_restore_vmcr_aprs (kern_hyp_va_host (cpu_if)); } DEFINE_KVM_HOST_HCALL(int, __pkvm_init, 4,@@ -579,16 +579,17 @@ DEFINE_KVM_HOST_HCALL_VOID(__pkvm_unreserve_vm, 1, }DEFINE_KVM_HOST_HCALL (int, __pkvm_init_vm,3 , - struct kvm *, host_kvm, void *, vm_hva, void *, pgd_hva) + struct kvm __hostva *, host_kvm, void __hostva *, vm_hva, + void __hostva *, pgd_hva) { -return __pkvm_init_vm (kern_hyp_va (host_kvm), vm_hva, pgd_hva); +return __pkvm_init_vm (kern_hyp_va_host (host_kvm), vm_hva, pgd_hva); }DEFINE_KVM_HOST_HCALL (int, __pkvm_init_vcpu,3 , - pkvm_handle_t, handle, struct kvm_vcpu *, host_vcpu, - void *, vcpu_hva) + pkvm_handle_t, handle, struct kvm_vcpu __hostva *, host_vcpu, + void __hostva *, vcpu_hva) { -return __pkvm_init_vcpu (handle,kern_hyp_va (host_vcpu), vcpu_hva); +return __pkvm_init_vcpu (handle,kern_hyp_va_host (host_vcpu), vcpu_hva); }DEFINE_KVM_HOST_HCALL0 (int, __pkvm_vcpu_in_poison_fault)@@ -623,7 +624,7 @@ DEFINE_KVM_HOST_HCALL(int, __pkvm_finalize_teardown_vm, 1, }DEFINE_KVM_HOST_HCALL (int, __tracing_load,2 , - void *, desc_hva, size_t, desc_size) + void __hostva *, desc_hva, size_t, desc_size) {return __tracing_load (desc_hva, desc_size); }@@ -670,15 +671,15 @@ DEFINE_KVM_HOST_HCALL_VOID(__tracing_write_event, 1, }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v5_save_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) { -__vgic_v5_save_apr (kern_hyp_va (cpu_if)); +__vgic_v5_save_apr (kern_hyp_va_host (cpu_if)); }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v5_restore_vmcr_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) { -__vgic_v5_restore_vmcr_apr (kern_hyp_va (cpu_if)); +__vgic_v5_restore_vmcr_apr (kern_hyp_va_host (cpu_if)); }typedef void (*hcall_t )(struct kvm_cpu_context *);arch/arm64/kvm/hyp/nvhe/pkvm.c +6
-5@@ -644,9 +644,9 @@ static size_t pkvm_get_hyp_vm_size(unsigned int nr_vcpus) size_mul(sizeof(struct pkvm_hyp_vcpu *), nr_vcpus)); } -static void *map_donated_memory_noclear (void *host_va,size_t size) +static void *map_donated_memory_noclear(void __hostva *host_va, size_t size) { -void *va =kern_hyp_va (host_va); +void *va =kern_hyp_va_host (host_va);if (!PAGE_ALIGNED (va))return NULL ;@@ -658,7 +658,7 @@ static void *map_donated_memory_noclear(void *host_va, size_t size)return va; } -static void *map_donated_memory (void *host_va,size_t size) +static void *map_donated_memory(void __hostva *host_va, size_t size) {void *va =map_donated_memory_noclear (host_va, size);@@ -805,7 +805,8 @@ void teardown_selftest_vm(void)* * Return 0 success, negative error code on failure. */ -int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva) +int __pkvm_init_vm(struct kvm *host_kvm, void __hostva *vm_hva, + void __hostva *pgd_hva) {struct pkvm_hyp_vm *hyp_vm =NULL ;size_t vm_size, pgd_size;@@ -896,7 +897,7 @@ static int register_hyp_vcpu(struct pkvm_hyp_vm *hyp_vm, }int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -void *vcpu_hva) + void __hostva *vcpu_hva) {struct pkvm_hyp_vcpu *hyp_vcpu;struct pkvm_hyp_vm *hyp_vm;arch/arm64/kvm/hyp/nvhe/trace.c +2
-2@@ -206,9 +206,9 @@ static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_sizreturn true; } -int __tracing_load (void *desc_hva,size_t desc_size) +int __tracing_load(void __hostva *desc_hva, size_t desc_size) { -struct hyp_trace_desc *desc =kern_hyp_va (desc_hva); +struct hyp_trace_desc *desc =kern_hyp_va_host (desc_hva);int ret; ret =__admit_host_mem (desc, desc_size);Signature · 1 line
2.39.5
Signature · 1 line
Vincent
Fuad Tabba
reviewerRe: [PATCH v1 11/11] KVM: arm64: Tag host-VA hypercall parameters __hostva
On Mon, 3 Aug 2026 at 11:50, Vincent Donnefort <[email protected]> wrote:
...
Quoted 22 lines
Quoted 9 lines
arch/arm64/include/asm/kvm_hcall.h +1
-0@@ -27,6 +27,18 @@ struct kvm_vcpu;struct vgic_v3_cpu_if ;struct vgic_v5_cpu_if ; +/* arch/arm64/include/asm/kvm_hcall.h struct kvm_vcpu; · line 40
Quoted 10 lines
arch/arm64/include/asm/kvm_hcall.h +10
-0+* A host VA carried by a hypercall argument. At EL2 such a pointer must not +* be dereferenced until it is translated with kern_hyp_va_host(); sparse +* flags any use that skips the translation. The tag describes the EL2 view +* only: the host dereferences its own VAs freely. +*/ +#if defined(__KVM_NVHE_HYPERVISOR__) && defined(__CHECKER__) +#define __hostva __attribute__((noderef, address_space(__hostva))) +#else +#define __hostva +#endif Could we have
__kern, just like we have__user.
Quoted 8 lines
Ideally this could be used later to mark the values we don't trust, so not only VAs but also
nr_pages. Inmem_protect.ce.g.
size_tpfn_range_is_valid(u64 __kern pfn, u64 __kern nr_pages)so that size is only trusted once
pfn_range_is_valid()has run.And beside, that matches "
kern_hyp_va"
Makes sense, I'll do it in the respin.
Thanks for the reviews!
/fuad
Quoted 374 lines
Quoted 369 lines
arch/arm64/include/asm/kvm_hcall.h +17
-15+/* * Hypercall signatures are declared as (type, name) argument pairs. * __KVM_HCALL_MAP() applies a macro to each pair, in the mold of __MAP() @@ -157,24 +169,24 @@ DECLARE_KVM_HOST_HCALL0(int, __pkvm_prot_finalize)/* Hypercalls that are always available and common to [nh]VHE/pKVM. */ DECLARE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu)DECLARE_KVM_HOST_HCALL (int, __kvm_vcpu_run,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) DECLARE_KVM_HOST_HCALL0_VOID(__kvm_flush_vm_context) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_ipa_nsh, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid, 1, - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) DECLARE_KVM_HOST_HCALL_VOID(__kvm_tlb_flush_vmid_range, 3, - struct kvm_s2_mmu *, mmu, phys_addr_t, start, unsigned long, pages) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, start, unsigned long, pages) DECLARE_KVM_HOST_HCALL_VOID(__kvm_flush_cpu_context, 1, - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) DECLARE_KVM_HOST_HCALL_VOID(__kvm_timer_set_cntvoff, 1, u64, cntvoff) DECLARE_KVM_HOST_HCALL(int, __tracing_load, 2, - void *, desc_hva, size_t, desc_size) + void __hostva *, desc_hva, size_t, desc_size) DECLARE_KVM_HOST_HCALL0_VOID(__tracing_unload) DECLARE_KVM_HOST_HCALL(int, __tracing_enable, 1, bool, enable)@@ -189,13 +201,13 @@ DECLARE_KVM_HOST_HCALL(int, __tracing_enable_event, 2,DECLARE_KVM_HOST_HCALL_VOID (__tracing_write_event,1 , u64, id)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v3_save_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v3_restore_vmcr_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v5_save_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if)DECLARE_KVM_HOST_HCALL_VOID (__vgic_v5_restore_vmcr_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) /* Hypercalls that are available only when pKVM has finalised. */ DECLARE_KVM_HOST_HCALL(int, __pkvm_host_share_hyp, 1,@@ -220,10 +232,11 @@ DECLARE_KVM_HOST_HCALL0(int, __pkvm_reserve_vm)DECLARE_KVM_HOST_HCALL_VOID (__pkvm_unreserve_vm,1 , pkvm_handle_t, handle)DECLARE_KVM_HOST_HCALL (int, __pkvm_init_vm,3 , - struct kvm *, host_kvm, void *, vm_hva, void *, pgd_hva) + struct kvm __hostva *, host_kvm, void __hostva *, vm_hva, + void __hostva *, pgd_hva)DECLARE_KVM_HOST_HCALL (int, __pkvm_init_vcpu,3 , - pkvm_handle_t, handle, struct kvm_vcpu *, host_vcpu, - void *, vcpu_hva) + pkvm_handle_t, handle, struct kvm_vcpu __hostva *, host_vcpu, + void __hostva *, vcpu_hva) DECLARE_KVM_HOST_HCALL0(int, __pkvm_vcpu_in_poison_fault)DECLARE_KVM_HOST_HCALL (int, __pkvm_force_reclaim_guest_page,1 , phys_addr_t, phys)arch/arm64/include/asm/kvm_mmu.h +10
-0@@ -7,6 +7,8 @@#ifndef __ARM64_KVM_MMU_H__#define __ARM64_KVM_MMU_H__ +#include <linux/compiler.h> +#include <asm/page.h> #include <asm/memory.h> #include <asm/mmu.h> @@ -140,6 +142,14 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)#define kern_hyp_va (v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) +/* +* Translate a __hostva-tagged host VA, dropping the tag: the only sanctioned +* unwrap. Translation only, no ownership or bounds validation; the result +* carries the pointee type stripped of the tag and of any cv-qualifiers. +*/ +#define kern_hyp_va_host (v) \ + ((TYPEOF_UNQUAL(*(v)) *)__kern_hyp_va((unsigned long)(__force void *)(v))) +extern u32 __hyp_va_bits;/* arch/arm64/kvm/hyp/include/nvhe/pkvm.h +4
-2@@ -7,6 +7,7 @@#ifndef __ARM64_KVM_NVHE_PKVM_H__#define __ARM64_KVM_NVHE_PKVM_H__ +#include <asm/kvm_hcall.h> #include <asm/kvm_pkvm.h> #include <nvhe/gfp.h> @@ -69,9 +70,10 @@ void pkvm_hyp_vm_table_init(void *tbl);int __pkvm_reserve_vm (void );void __pkvm_unreserve_vm (pkvm_handle_t handle); -int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva); +int __pkvm_init_vm(struct kvm *host_kvm, void __hostva *vm_hva, + void __hostva *pgd_hva);int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -void *vcpu_hva); + void __hostva *vcpu_hva);int __pkvm_reclaim_dying_guest_page (pkvm_handle_t handle,u64 gfn);int __pkvm_start_teardown_vm (pkvm_handle_t handle);arch/arm64/kvm/hyp/include/nvhe/trace.h +3
-2@@ -4,6 +4,7 @@#include <linux/trace_remote_event.h> +#include <asm/kvm_hcall.h> #include <asm/kvm_hyptrace.h> static inline pid_t __tracing_get_vcpu_pid (struct kvm_cpu_context *host_ctxt)@@ -46,7 +47,7 @@ static inline pid_t __tracing_get_vcpu_pid(struct kvm_cpu_context *host_ctxt)void *tracing_reserve_entry (unsigned long length);void tracing_commit_entry (void ); -int __tracing_load (void *desc_va,size_t desc_size); +int __tracing_load(void __hostva *desc_va, size_t desc_size);void __tracing_unload (void );int __tracing_enable (bool enable);int __tracing_swap_reader (unsigned int cpu);@@ -59,7 +60,7 @@ static inline void tracing_commit_entry(void) { }#define HYP_EVENT (__name, __proto, __struct, __assign, __printk) \ static inline void trace_##__name(__proto) {} -static inline int __tracing_load (void *desc_va,size_t desc_size) {return -ENODEV ; } +static inline int __tracing_load(void __hostva *desc_va, size_t desc_size) { return -ENODEV; }static inline void __tracing_unload (void ) { }static inline int __tracing_enable (bool enable) {return -ENODEV ; }static inline int __tracing_swap_reader (unsigned int cpu) {return -ENODEV ; }arch/arm64/kvm/hyp/nvhe/hyp-main.c +29
-28@@ -269,7 +269,7 @@ DEFINE_KVM_HOST_HCALL0_VOID(__pkvm_vcpu_put) }DEFINE_KVM_HOST_HCALL (int, __kvm_vcpu_run,1 , - struct kvm_vcpu *, host_vcpu) + struct kvm_vcpu __hostva *, host_vcpu) {int ret;@@ -294,7 +294,7 @@ DEFINE_KVM_HOST_HCALL(int, __kvm_vcpu_run, 1,sync_hyp_vcpu (hyp_vcpu); }else { -struct kvm_vcpu *vcpu =kern_hyp_va (host_vcpu); +struct kvm_vcpu *vcpu =kern_hyp_va_host (host_vcpu);/* The host is fully trusted, run its vCPU directly. */ fpsimd_lazy_switch_to_guest (vcpu);@@ -421,9 +421,9 @@ DEFINE_KVM_HOST_HCALL(int, __pkvm_host_mkyoung_guest, 1, }DEFINE_KVM_HOST_HCALL_VOID (__kvm_adjust_pc,1 , - struct kvm_vcpu *, vcpu) + struct kvm_vcpu __hostva *, vcpu) { -__kvm_adjust_pc (kern_hyp_va (vcpu)); +__kvm_adjust_pc (kern_hyp_va_host (vcpu)); }DEFINE_KVM_HOST_HCALL0_VOID (__kvm_flush_vm_context)@@ -432,27 +432,27 @@ DEFINE_KVM_HOST_HCALL0_VOID(__kvm_flush_vm_context) }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid_ipa,3 , - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) { -__kvm_tlb_flush_vmid_ipa (kern_hyp_va (mmu), ipa, level); +__kvm_tlb_flush_vmid_ipa (kern_hyp_va_host (mmu), ipa, level); }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid_ipa_nsh,3 , - struct kvm_s2_mmu *, mmu, phys_addr_t, ipa, int, level) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, ipa, int, level) { -__kvm_tlb_flush_vmid_ipa_nsh (kern_hyp_va (mmu), ipa, level); +__kvm_tlb_flush_vmid_ipa_nsh (kern_hyp_va_host (mmu), ipa, level); }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid_range,3 , - struct kvm_s2_mmu *, mmu, phys_addr_t, start, unsigned long, pages) + struct kvm_s2_mmu __hostva *, mmu, phys_addr_t, start, unsigned long, pages) { -__kvm_tlb_flush_vmid_range (kern_hyp_va (mmu), start, pages); +__kvm_tlb_flush_vmid_range (kern_hyp_va_host (mmu), start, pages); }DEFINE_KVM_HOST_HCALL_VOID (__kvm_tlb_flush_vmid,1 , - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) { -__kvm_tlb_flush_vmid (kern_hyp_va (mmu)); +__kvm_tlb_flush_vmid (kern_hyp_va_host (mmu)); } DEFINE_KVM_HOST_HCALL_VOID(__pkvm_tlb_flush_vmid, 1,@@ -468,9 +468,9 @@ DEFINE_KVM_HOST_HCALL_VOID(__pkvm_tlb_flush_vmid, 1, }DEFINE_KVM_HOST_HCALL_VOID (__kvm_flush_cpu_context,1 , - struct kvm_s2_mmu *, mmu) + struct kvm_s2_mmu __hostva *, mmu) { -__kvm_flush_cpu_context (kern_hyp_va (mmu)); +__kvm_flush_cpu_context (kern_hyp_va_host (mmu)); } DEFINE_KVM_HOST_HCALL_VOID(__kvm_timer_set_cntvoff, 1,@@ -499,15 +499,15 @@ DEFINE_KVM_HOST_HCALL0_VOID(__vgic_v3_init_lrs) }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v3_save_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if) { -__vgic_v3_save_aprs (kern_hyp_va (cpu_if)); +__vgic_v3_save_aprs (kern_hyp_va_host (cpu_if)); }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v3_restore_vmcr_aprs,1 , - struct vgic_v3_cpu_if *, cpu_if) + struct vgic_v3_cpu_if __hostva *, cpu_if) { -__vgic_v3_restore_vmcr_aprs (kern_hyp_va (cpu_if)); +__vgic_v3_restore_vmcr_aprs (kern_hyp_va_host (cpu_if)); } DEFINE_KVM_HOST_HCALL(int, __pkvm_init, 4,@@ -579,16 +579,17 @@ DEFINE_KVM_HOST_HCALL_VOID(__pkvm_unreserve_vm, 1, }DEFINE_KVM_HOST_HCALL (int, __pkvm_init_vm,3 , - struct kvm *, host_kvm, void *, vm_hva, void *, pgd_hva) + struct kvm __hostva *, host_kvm, void __hostva *, vm_hva, + void __hostva *, pgd_hva) { -return __pkvm_init_vm (kern_hyp_va (host_kvm), vm_hva, pgd_hva); +return __pkvm_init_vm (kern_hyp_va_host (host_kvm), vm_hva, pgd_hva); }DEFINE_KVM_HOST_HCALL (int, __pkvm_init_vcpu,3 , - pkvm_handle_t, handle, struct kvm_vcpu *, host_vcpu, - void *, vcpu_hva) + pkvm_handle_t, handle, struct kvm_vcpu __hostva *, host_vcpu, + void __hostva *, vcpu_hva) { -return __pkvm_init_vcpu (handle,kern_hyp_va (host_vcpu), vcpu_hva); +return __pkvm_init_vcpu (handle,kern_hyp_va_host (host_vcpu), vcpu_hva); }DEFINE_KVM_HOST_HCALL0 (int, __pkvm_vcpu_in_poison_fault)@@ -623,7 +624,7 @@ DEFINE_KVM_HOST_HCALL(int, __pkvm_finalize_teardown_vm, 1, }DEFINE_KVM_HOST_HCALL (int, __tracing_load,2 , - void *, desc_hva, size_t, desc_size) + void __hostva *, desc_hva, size_t, desc_size) {return __tracing_load (desc_hva, desc_size); }@@ -670,15 +671,15 @@ DEFINE_KVM_HOST_HCALL_VOID(__tracing_write_event, 1, }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v5_save_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) { -__vgic_v5_save_apr (kern_hyp_va (cpu_if)); +__vgic_v5_save_apr (kern_hyp_va_host (cpu_if)); }DEFINE_KVM_HOST_HCALL_VOID (__vgic_v5_restore_vmcr_apr,1 , - struct vgic_v5_cpu_if *, cpu_if) + struct vgic_v5_cpu_if __hostva *, cpu_if) { -__vgic_v5_restore_vmcr_apr (kern_hyp_va (cpu_if)); +__vgic_v5_restore_vmcr_apr (kern_hyp_va_host (cpu_if)); }typedef void (*hcall_t )(struct kvm_cpu_context *);arch/arm64/kvm/hyp/nvhe/pkvm.c +6
-5@@ -644,9 +644,9 @@ static size_t pkvm_get_hyp_vm_size(unsigned int nr_vcpus) size_mul(sizeof(struct pkvm_hyp_vcpu *), nr_vcpus)); } -static void *map_donated_memory_noclear (void *host_va,size_t size) +static void *map_donated_memory_noclear(void __hostva *host_va, size_t size) { -void *va =kern_hyp_va (host_va); +void *va =kern_hyp_va_host (host_va);if (!PAGE_ALIGNED (va))return NULL ;@@ -658,7 +658,7 @@ static void *map_donated_memory_noclear(void *host_va, size_t size)return va; } -static void *map_donated_memory (void *host_va,size_t size) +static void *map_donated_memory(void __hostva *host_va, size_t size) {void *va =map_donated_memory_noclear (host_va, size);@@ -805,7 +805,8 @@ void teardown_selftest_vm(void)* * Return 0 success, negative error code on failure. */ -int __pkvm_init_vm (struct kvm *host_kvm,void *vm_hva,void *pgd_hva) +int __pkvm_init_vm(struct kvm *host_kvm, void __hostva *vm_hva, + void __hostva *pgd_hva) {struct pkvm_hyp_vm *hyp_vm =NULL ;size_t vm_size, pgd_size;@@ -896,7 +897,7 @@ static int register_hyp_vcpu(struct pkvm_hyp_vm *hyp_vm, }int __pkvm_init_vcpu (pkvm_handle_t handle,struct kvm_vcpu *host_vcpu, -void *vcpu_hva) + void __hostva *vcpu_hva) {struct pkvm_hyp_vcpu *hyp_vcpu;struct pkvm_hyp_vm *hyp_vm;arch/arm64/kvm/hyp/nvhe/trace.c +2
-3@@ -206,9 +206,9 @@ static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_sizreturn true; } -int __tracing_load (void *desc_hva,size_t desc_size) +int __tracing_load(void __hostva *desc_hva, size_t desc_size) { -struct hyp_trace_desc *desc =kern_hyp_va (desc_hva); +struct hyp_trace_desc *desc =kern_hyp_va_host (desc_hva);int ret; ret =__admit_host_mem (desc, desc_size); --Quoted 2 lines
2.39.5
--
Vincent