]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Map hyp text as RO and dump instr on panic
authorMostafa Saleh <smostafa@google.com>
Tue, 9 Sep 2025 13:36:31 +0000 (13:36 +0000)
committerMarc Zyngier <maz@kernel.org>
Mon, 15 Sep 2025 12:04:23 +0000 (13:04 +0100)
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>
arch/arm64/kvm/handle_exit.c
arch/arm64/kvm/hyp/nvhe/setup.c

index 99a8205fc10425708062c62fb9faf293b81020a8..d449e15680e46dc7241cb2f8fbbeffd31be11264 100644 (file)
@@ -560,9 +560,7 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
        kvm_nvhe_dump_backtrace(hyp_offset);
 
        /* Dump the faulting instruction */
-       if (!is_protected_kvm_enabled() ||
-           IS_ENABLED(CONFIG_NVHE_EL2_DEBUG))
-               dump_kernel_instr(panic_addr + kaslr_offset());
+       dump_kernel_instr(panic_addr + kaslr_offset());
 
        /*
         * Hyp has panicked and we're going to handle that by panicking the
index a48d3f5a5afba7c5e4dbf1a6466c59910f80ce04..90bd014e952fbc57a104444800cf78afe4400683 100644 (file)
@@ -192,6 +192,7 @@ static int fix_host_ownership_walker(const struct kvm_pgtable_visit_ctx *ctx,
        enum pkvm_page_state state;
        struct hyp_page *page;
        phys_addr_t phys;
+       enum kvm_pgtable_prot prot;
 
        if (!kvm_pte_valid(ctx->old))
                return 0;
@@ -210,11 +211,18 @@ static int fix_host_ownership_walker(const struct kvm_pgtable_visit_ctx *ctx,
         * configured in the hypervisor stage-1, and make sure to propagate them
         * to the hyp_vmemmap state.
         */
-       state = pkvm_getstate(kvm_pgtable_hyp_pte_prot(ctx->old));
+       prot = kvm_pgtable_hyp_pte_prot(ctx->old);
+       state = pkvm_getstate(prot);
        switch (state) {
        case PKVM_PAGE_OWNED:
                set_hyp_state(page, PKVM_PAGE_OWNED);
-               return host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HYP);
+               /* hyp text is RO in the host stage-2 to be inspected on panic. */
+               if (prot == PAGE_HYP_EXEC) {
+                       set_host_state(page, PKVM_NOPAGE);
+                       return host_stage2_idmap_locked(phys, PAGE_SIZE, KVM_PGTABLE_PROT_R);
+               } else {
+                       return host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HYP);
+               }
        case PKVM_PAGE_SHARED_OWNED:
                set_hyp_state(page, PKVM_PAGE_SHARED_OWNED);
                set_host_state(page, PKVM_PAGE_SHARED_BORROWED);