All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Ene" <sebastianene@google.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev
Subject: Re: [PATCH v2 04/13] KVM: Parse the device tree and register the ITS region with pKVM
Date: Fri, 07 Aug 2026 17:09:11 +0000	[thread overview]
Message-ID: <20260807170911.B6EAF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807164322.2970811-6-sebastianene@google.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] The function pointer for the MMIO emulator passed to EL2 points to unmapped/NX memory, causing an Instruction Abort.
- [High] MMIO emulation in `its_emulate_forward_req` double-swaps on Big Endian kernels by using `readX_relaxed` and `writeX_relaxed`.
- [High] pKVM incorrectly maps and accesses MMIO devices using the hypervisor's linear map (`__hyp_va()`) rather than a private VA range.
- [High] handle_host_mmio_trap ignores the ESR_ELx_SSE (Sign Extend) bit for MMIO reads, returning zero-extended values for signed loads.
--

--- Patch [4]: [PATCH v2 04/13] KVM: Parse the device tree and register the ITS region with pKVM ---
commit 6f98f20a817e227941fab67881459ac609810480
Author: Sebastian Ene <sebastianene@google.com>

KVM: Parse the device tree and register the ITS region with pKVM

Identify the ITS base address from the device tree and store it in the
pkvm_protected_regs array so that it will be unmapped from the host
address space. Register a callback to forward all the MMIO requests to
the device to prevent breaking ITS functionality.

> diff --git a/arch/arm64/kvm/hyp/nvhe/its_emulate.c b/arch/arm64/kvm/hyp/nvhe/its_emulate.c
> new file mode 100644
> index 0000000000000..63a42f520ed25
> --- /dev/null
> +++ b/arch/arm64/kvm/hyp/nvhe/its_emulate.c
> @@ -0,0 +1,37 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <asm/kvm_pkvm.h>
> +#include <nvhe/mem_protect.h>
> +
> +void its_emulate_forward_req(struct pkvm_protected_reg *region, u64 offset, bool write, u64 *reg,
> +			     u8 reg_size)
> +{
> +	void __iomem *addr = __hyp_va(PFN_PHYS(region->pfn) + offset);

[Severity: High]
Does using __hyp_va() here work for MMIO addresses? The __hyp_va() macro
subtracts hyp_physvirt_offset, which is based on RAM physical addresses.
Since MMIO regions often reside at lower physical addresses than RAM,
wouldn't this underflow and produce a virtual address with the top bits set,
leading to a Translation Fault? This same issue seems to be present in
__pkvm_host_donate_hyp_mmio() where it populates the page tables.

> +
> +	switch (reg_size) {
> +	case 1:
> +		if (!write)
> +			*reg = readb_relaxed(addr);
> +		else
> +			writeb_relaxed(*reg, addr);

[Severity: High]
Will these relaxed accessors cause a double-swap on Big Endian kernels?
When the host traps to EL2 on an MMIO access, the CPU register already
contains the exact data the host intended to write (swapped to Little
Endian by the host driver's writel). Using writeb_relaxed and similar
helpers will apply cpu_to_le* again. Should this use the __raw_read*
and __raw_write* accessors to preserve the trapped register's exact bit
representation?

> +		break;

[ ... ]

> diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c
> index 053e4f733e4be..5e80da18f3120 100644
> --- a/arch/arm64/kvm/pkvm.c
> +++ b/arch/arm64/kvm/pkvm.c

[ ... ]

> @@ -39,6 +44,47 @@ static int __init register_memblock_regions(void)
>  
> +static int __init register_its_emulated_region(void)
> +{

[ ... ]

> +		kvm_nvhe_sym(pkvm_protected_regs)[i].pfn = PHYS_PFN(res.start);
> +		kvm_nvhe_sym(pkvm_protected_regs)[i].cb =
> +			lm_alias(&kvm_nvhe_sym(its_emulate_forward_req));

[Severity: Critical]
Can this function pointer be safely executed at EL2? The host initializes
the callback using lm_alias, producing a host linear-map address. When
the hypervisor later applies kern_hyp_va() to it in
donate_protected_mmio_regions(), it converts it to a hyp linear-map
address. However, .hyp.text physical pages are not part of the
dynamically allocated hyp memory pool, so they are unmapped in the hyp
linear map. Does jumping to this pointer in handle_host_mmio_trap()
trigger an Instruction Abort?

[Severity: High]
Regarding how this callback's result is handled in handle_host_mmio_trap(),
does the trap handler process sign extension for MMIO reads? When the host
traps to EL2 on a stage-2 data abort caused by a signed read access (like
LDRSB), the ESR_ELx_SSE bit indicates the destination register should be
sign-extended. If handle_host_mmio_trap() writes the zero-extended value
directly into the host context, could this alter functional behavior for
signed loads?

> +		kvm_nvhe_sym(pkvm_protected_regs)[i].nr_pages =
> +			PFN_DOWN(min_t(u64, resource_size(&res), PAGE_ALIGN_DOWN(GITS_TRANSLATER)));

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260807164322.2970811-2-sebastianene@google.com?part=4

  reply	other threads:[~2026-08-07 17:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 16:43 [PATCH v2 00/13] KVM: ITS hardening for pKVM Sebastian Ene
2026-08-07 16:43 ` [PATCH v2 01/13] KVM: arm64: Donate MMIO to the hypervisor Sebastian Ene
2026-08-07 16:58   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 02/13] KVM: arm64: Track host-unmapped MMIO regions in a static array Sebastian Ene
2026-08-07 17:00   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 03/13] KVM: arm64: Support host MMIO trap handlers for unmapped devices Sebastian Ene
2026-08-07 17:03   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 04/13] KVM: Parse the device tree and register the ITS region with pKVM Sebastian Ene
2026-08-07 17:09   ` sashiko-bot [this message]
2026-08-07 16:43 ` [PATCH v2 05/13] irqchip/gic-v3-its: Add support for the ITS emulation setup Sebastian Ene
2026-08-07 17:00   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 06/13] KVM: arm64: Shadow the ITS command queue and setup emulation Sebastian Ene
2026-08-07 16:57   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 07/13] KVM: arm64: Restrict host access to the private ITS tables Sebastian Ene
2026-08-07 17:02   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 08/13] KVM: arm64: Trap & emulate the ITS MAPD command Sebastian Ene
2026-08-07 16:57   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 09/13] KVM: arm64: Trap & emulate the ITS MAPC command Sebastian Ene
2026-08-07 17:04   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 10/13] KVM: arm64: Restrict host updates to GITS_CTLR Sebastian Ene
2026-08-07 17:02   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 11/13] KVM: arm64: Prevent the host from specifying a different command queue Sebastian Ene
2026-08-07 17:28   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 12/13] KVM: arm64: Prevent the host from programming new GITS_BASER tables Sebastian Ene
2026-08-07 17:11   ` sashiko-bot
2026-08-07 16:43 ` [PATCH v2 13/13] KVM: arm64: Implement HVC interface for ITS emulation setup Sebastian Ene
2026-08-07 17:17   ` sashiko-bot

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=20260807170911.B6EAF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastianene@google.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.