From: Vincent Donnefort <vdonnefort@google.com>
To: Ben Horgan <ben.horgan@arm.com>
Cc: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org,
oliver.upton@linux.dev, joey.gouly@arm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
james.morse@arm.com, tabba@google.com,
Quentin Perret <qperret@google.com>,
Ryan Roberts <ryan.roberts@arm.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] KVM: arm64: Fix debug checking for np-guests using huge mappings
Date: Mon, 18 Aug 2025 14:03:57 +0100 [thread overview]
Message-ID: <aKMkvQEyeK1QH12X@google.com> (raw)
In-Reply-To: <20250815162655.121108-1-ben.horgan@arm.com>
Thanks for the fix!
On Fri, Aug 15, 2025 at 05:26:55PM +0100, Ben Horgan wrote:
> When running with transparent huge pages and CONFIG_NVHE_EL2_DEBUG then
> the debug checking in assert_host_shared_guest() fails on the launch of an
> np-guest. This WARN_ON() causes a panic and generates the stack below.
>
> In __pkvm_host_relax_perms_guest() the debug checking assumes the mapping
> is a single page but it may be a block map. Update the checking so that
> the size is not checked and just assumes the correct size.
>
> While we're here make the same fix in __pkvm_host_mkyoung_guest().
>
> Info: # lkvm run -k /share/arch/arm64/boot/Image -m 704 -c 8 --name guest-128
> Info: Removed ghost socket file "/.lkvm//guest-128.sock".
> [ 1406.521757] kvm [141]: nVHE hyp BUG at: arch/arm64/kvm/hyp/nvhe/mem_protect.c:1088!
> [ 1406.521804] kvm [141]: nVHE call trace:
> [ 1406.521828] kvm [141]: [<ffff8000811676b4>] __kvm_nvhe_hyp_panic+0xb4/0xe8
> [ 1406.521946] kvm [141]: [<ffff80008116d12c>] __kvm_nvhe_assert_host_shared_guest+0xb0/0x10c
> [ 1406.522049] kvm [141]: [<ffff80008116f068>] __kvm_nvhe___pkvm_host_relax_perms_guest+0x48/0x104
> [ 1406.522157] kvm [141]: [<ffff800081169df8>] __kvm_nvhe_handle___pkvm_host_relax_perms_guest+0x64/0x7c
> [ 1406.522250] kvm [141]: [<ffff800081169f0c>] __kvm_nvhe_handle_trap+0x8c/0x1a8
> [ 1406.522333] kvm [141]: [<ffff8000811680fc>] __kvm_nvhe___skip_pauth_save+0x4/0x4
> [ 1406.522454] kvm [141]: ---[ end nVHE call trace ]---
> [ 1406.522477] kvm [141]: Hyp Offset: 0xfffece8013600000
> [ 1406.522554] Kernel panic - not syncing: HYP panic:
> [ 1406.522554] PS:834003c9 PC:0000b1806db6d170 ESR:00000000f2000800
> [ 1406.522554] FAR:ffff8000804be420 HPFAR:0000000000804be0 PAR:0000000000000000
> [ 1406.522554] VCPU:0000000000000000
> [ 1406.523337] CPU: 3 UID: 0 PID: 141 Comm: kvm-vcpu-0 Not tainted 6.16.0-rc7 #97 PREEMPT
> [ 1406.523485] Hardware name: FVP Base RevC (DT)
> [ 1406.523566] Call trace:
> [ 1406.523629] show_stack+0x18/0x24 (C)
> [ 1406.523753] dump_stack_lvl+0xd4/0x108
> [ 1406.523899] dump_stack+0x18/0x24
> [ 1406.524040] panic+0x3d8/0x448
> [ 1406.524184] nvhe_hyp_panic_handler+0x10c/0x23c
> [ 1406.524325] kvm_handle_guest_abort+0x68c/0x109c
> [ 1406.524500] handle_exit+0x60/0x17c
> [ 1406.524630] kvm_arch_vcpu_ioctl_run+0x2e0/0x8c0
> [ 1406.524794] kvm_vcpu_ioctl+0x1a8/0x9cc
> [ 1406.524919] __arm64_sys_ioctl+0xac/0x104
> [ 1406.525067] invoke_syscall+0x48/0x10c
> [ 1406.525189] el0_svc_common.constprop.0+0x40/0xe0
> [ 1406.525322] do_el0_svc+0x1c/0x28
> [ 1406.525441] el0_svc+0x38/0x120
> [ 1406.525588] el0t_64_sync_handler+0x10c/0x138
> [ 1406.525750] el0t_64_sync+0x1ac/0x1b0
> [ 1406.525876] SMP: stopping secondary CPUs
> [ 1406.525965] Kernel Offset: disabled
> [ 1406.526032] CPU features: 0x0000,00000080,8e134ca1,9446773f
> [ 1406.526130] Memory Limit: none
> [ 1406.959099] ---[ end Kernel panic - not syncing: HYP panic:
> [ 1406.959099] PS:834003c9 PC:0000b1806db6d170 ESR:00000000f2000800
> [ 1406.959099] FAR:ffff8000804be420 HPFAR:0000000000804be0 PAR:0000000000000000
> [ 1406.959099] VCPU:0000000000000000 ]
>
> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
> Fixes: db14091d8f75 ("KVM: arm64: Stage-2 huge mappings for np-guests")
Not sure if it really matters but it's more about fixing f28f1d02f4ea (KVM: arm64: Add a range
to __pkvm_host_unshare_guest()) which introduced the check size !=
kvm_granule_size(). Even though this is noop until db14091d8f75
> Cc: Vincent Donnefort <vdonnefort@google.com>
> Cc: Quentin Perret <qperret@google.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: stable@vger.kernel.org
Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
>
> ---
>
> This addresses the bug I raised here:
> https://lore.kernel.org/linux-arm-kernel/17b526ff-b824-4c24-8ac0-6821e5cc8900@arm.com/
>
> ---
> arch/arm64/kvm/hyp/nvhe/mem_protect.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index 8957734d6183..ddc8beb55eee 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -1010,9 +1010,12 @@ static int __check_host_shared_guest(struct pkvm_hyp_vm *vm, u64 *__phys, u64 ip
> return ret;
> if (!kvm_pte_valid(pte))
> return -ENOENT;
> - if (kvm_granule_size(level) != size)
> + if (size && kvm_granule_size(level) != size)
> return -E2BIG;
>
> + if (!size)
> + size = kvm_granule_size(level);
> +
> state = guest_get_page_state(pte, ipa);
> if (state != PKVM_PAGE_SHARED_BORROWED)
> return -EPERM;
> @@ -1100,7 +1103,7 @@ int __pkvm_host_relax_perms_guest(u64 gfn, struct pkvm_hyp_vcpu *vcpu, enum kvm_
> if (prot & ~KVM_PGTABLE_PROT_RWX)
> return -EINVAL;
>
> - assert_host_shared_guest(vm, ipa, PAGE_SIZE);
> + assert_host_shared_guest(vm, ipa, 0);
> guest_lock_component(vm);
> ret = kvm_pgtable_stage2_relax_perms(&vm->pgt, ipa, prot, 0);
> guest_unlock_component(vm);
> @@ -1156,7 +1159,7 @@ int __pkvm_host_mkyoung_guest(u64 gfn, struct pkvm_hyp_vcpu *vcpu)
> if (pkvm_hyp_vm_is_protected(vm))
> return -EPERM;
>
> - assert_host_shared_guest(vm, ipa, PAGE_SIZE);
> + assert_host_shared_guest(vm, ipa, 0);
> guest_lock_component(vm);
> kvm_pgtable_stage2_mkyoung(&vm->pgt, ipa, 0);
> guest_unlock_component(vm);
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-08-18 13:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 16:26 [PATCH] KVM: arm64: Fix debug checking for np-guests using huge mappings Ben Horgan
2025-08-18 13:03 ` Vincent Donnefort [this message]
2025-09-15 9:13 ` Ben Horgan
2025-09-15 9:38 ` Marc Zyngier
2025-09-15 9:51 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aKMkvQEyeK1QH12X@google.com \
--to=vdonnefort@google.com \
--cc=ben.horgan@arm.com \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.