Skip to content

Commit 6f1ece1

Browse files
misalehMarc Zyngier
authored andcommitted
KVM: arm64: Map hyp text as RO and dump instr on panic
Map the hyp text section as RO, there are no secrets there and that allows the kernel extract info for debugging. As in case of panic we can now dump the faulting instructions similar to the kernel. Signed-off-by: Mostafa Saleh <smostafa@google.com> Acked-by: Will Deacon <will@kernel.org> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 92b7624 commit 6f1ece1

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

arch/arm64/kvm/handle_exit.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,7 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
560560
kvm_nvhe_dump_backtrace(hyp_offset);
561561

562562
/* Dump the faulting instruction */
563-
if (!is_protected_kvm_enabled() ||
564-
IS_ENABLED(CONFIG_NVHE_EL2_DEBUG))
565-
dump_kernel_instr(panic_addr + kaslr_offset());
563+
dump_kernel_instr(panic_addr + kaslr_offset());
566564

567565
/*
568566
* Hyp has panicked and we're going to handle that by panicking the

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static int fix_host_ownership_walker(const struct kvm_pgtable_visit_ctx *ctx,
192192
enum pkvm_page_state state;
193193
struct hyp_page *page;
194194
phys_addr_t phys;
195+
enum kvm_pgtable_prot prot;
195196

196197
if (!kvm_pte_valid(ctx->old))
197198
return 0;
@@ -210,11 +211,18 @@ static int fix_host_ownership_walker(const struct kvm_pgtable_visit_ctx *ctx,
210211
* configured in the hypervisor stage-1, and make sure to propagate them
211212
* to the hyp_vmemmap state.
212213
*/
213-
state = pkvm_getstate(kvm_pgtable_hyp_pte_prot(ctx->old));
214+
prot = kvm_pgtable_hyp_pte_prot(ctx->old);
215+
state = pkvm_getstate(prot);
214216
switch (state) {
215217
case PKVM_PAGE_OWNED:
216218
set_hyp_state(page, PKVM_PAGE_OWNED);
217-
return host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HYP);
219+
/* hyp text is RO in the host stage-2 to be inspected on panic. */
220+
if (prot == PAGE_HYP_EXEC) {
221+
set_host_state(page, PKVM_NOPAGE);
222+
return host_stage2_idmap_locked(phys, PAGE_SIZE, KVM_PGTABLE_PROT_R);
223+
} else {
224+
return host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HYP);
225+
}
218226
case PKVM_PAGE_SHARED_OWNED:
219227
set_hyp_state(page, PKVM_PAGE_SHARED_OWNED);
220228
set_host_state(page, PKVM_PAGE_SHARED_BORROWED);

0 commit comments

Comments
 (0)