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 02/13] KVM: arm64: Track host-unmapped MMIO regions in a static array
Date: Fri, 07 Aug 2026 17:00:50 +0000	[thread overview]
Message-ID: <20260807170051.0E27B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807164322.2970811-4-sebastianene@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The error rollback path incorrectly maps previously unmapped protected MMIO regions into the host stage-2 page tables, breaking isolation.
- [High] Invalid use of the linear map macro `__hyp_va()` for physical MMIO addresses causes hypervisor page table bounds checks to fail or collide with private VA regions.
--

--- Patch [2]: [PATCH v2 02/13] KVM: arm64: Track host-unmapped MMIO regions in a static array ---
commit 8dc1d17638f0ac1801faef9ffe3be3d70a9ddf5c
Author: Sebastian Ene <sebastianene@google.com>
Subject: KVM: arm64: Track host-unmapped MMIO regions in a static array

This commit introduces a registry to track protected MMIO regions that are
unmapped from the host stage-2 page tables. It stores these regions in a
fixed-size array and donates their ownership to the hypervisor during
initialization to ensure host-exclusion and persistent tracking.

> diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c
> index 75b00c3233102..64c0290da888f 100644
> --- a/arch/arm64/kvm/hyp/nvhe/setup.c
> +++ b/arch/arm64/kvm/hyp/nvhe/setup.c
[ ... ]
> @@ -284,6 +284,26 @@ static int fix_hyp_pgtable_refcnt(void)
> +static int donate_protected_mmio_regions(void)
> +{
> +	int ret;
> +	int i;
> +
> +	for (i = 0; i < num_protected_reg; i++) {
> +		ret = __pkvm_host_donate_hyp_mmio(hyp_pfn_to_phys(pkvm_protected_regs[i].pfn),
> +						  pkvm_protected_regs[i].nr_pages << PAGE_SHIFT);
[Severity: High]
This is a pre-existing issue, but does calling __pkvm_host_donate_hyp_mmio()
here work for physical MMIO addresses?

Looking at __pkvm_host_donate_hyp_mmio(), it uses __hyp_va() to compute the
virtual address:

__pkvm_host_donate_hyp_mmio() {
	...
	virt = __hyp_va(addr + offset);
	...
}

Since __hyp_va() applies the linear map offset, which is sized and aligned
specifically for RAM, applying it to physical MMIO addresses (which reside
outside RAM boundaries) yields an invalid virtual address. This causes the
subsequent hypervisor page table bounds checks to fail with -ERANGE, or
silently corrupts EL2 private memory structures, reliably forcing the failure
path to execute.

> +		if (ret)
> +			goto err_setup;
> +	}
> +
> +	return 0;
> +err_setup:
> +	while (--i >= 0)
> +		__pkvm_hyp_donate_host_mmio(hyp_pfn_to_phys(pkvm_protected_regs[i].pfn),
> +					    pkvm_protected_regs[i].nr_pages << PAGE_SHIFT);
[Severity: High]
This isn't a bug introduced by this patch, but could this error rollback path
inadvertently map previously unmapped regions into the host stage-2?

The regions tracked in pkvm_protected_regs are intended to remain unmapped
from the host stage-2 page tables. However, __pkvm_hyp_donate_host_mmio()
unconditionally idmaps the region to the host at the end of the function:

__pkvm_hyp_donate_host_mmio() {
	...
	WARN_ON(host_stage2_idmap_locked(addr, size, PKVM_HOST_MMIO_PROT));
	...
}

Since the failure path is triggered by the __hyp_va() issue mentioned above,
this rollback will execute and forcibly install a valid mapping in the host
stage-2 page tables for regions that were originally unmapped, breaking the
hypervisor-host isolation boundary.

> +	return ret;
> +}

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

  reply	other threads:[~2026-08-07 17:00 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 [this message]
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
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=20260807170051.0E27B1F000E9@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.