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>,
	kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH v2 05/13] irqchip/gic-v3-its: Add support for the ITS emulation setup
Date: Fri, 07 Aug 2026 17:00:44 +0000	[thread overview]
Message-ID: <20260807170044.B1B771F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807164322.2970811-7-sebastianene@google.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] The intended API design dictates calling `on_each_cpu()` while hardware interrupts are disabled, which triggers SMP deadlocks.
- [High] Page allocations are performed while holding raw spinlocks, violating PREEMPT_RT lock nesting rules and causing 'sleeping while atomic' panics.
- [High] Partial failure during ITS emulation setup leaves the system in a broken, partially-emulated state with no rollback.
- [Medium] Defensive check `WARN_ON(!flags)` in `its_emulate_release_locks` leads to a NULL pointer dereference and unbalanced unlocks on the error path.
- [Medium] Acquiring an unbounded number of identical locks triggers lockdep's same-lock-class tracking.
--

--- Patch [5]: [PATCH v2 05/13] irqchip/gic-v3-its: Add support for the ITS emulation setup ---
commit 96beb9b6951a65e060abceadeb7be17ef57b5218
Author: Sebastian Ene <sebastianene@google.com>

irqchip/gic-v3-its: Add support for the ITS emulation setup

This commit introduces helper functions to lock the ITS and duplicate its state
for pKVM emulation. It allows an emulation layer to hide original hardware
tables and command queues from the host.

> pkvm_drop_host_privileges()
>         its_emulate_acquire_locks(&flags);
>                 on_each_cpu(_kvm_host_prot_finalize, &ret, 1);
>         its_emulate_release_locks(ret, &flags, pkvm_its_emulate_setup);

[Severity: High]
Will this sequence trigger a deadlock? its_emulate_acquire_locks() uses
raw_spin_lock_irqsave(), disabling local interrupts. Calling on_each_cpu()
sends cross-CPU IPIs and waits for completion, which is strictly
prohibited while interrupts are disabled because the local CPU cannot
process incoming IPIs.

> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c

[ ... ]

> +static struct its_host_state *its_snapshot_host_state(struct its_node *its)
> +{
> +	void *page;
> +	struct its_host_state *snapshot;
> +	int i;
> +
> +	page = its_alloc_pages_node(its->numa_node, GFP_ATOMIC | __GFP_ZERO, 0);

[Severity: High]
Is it safe to call the page allocator here? This function is called from
its_emulate_switch_queues_locked() inside the its_emulate_release_locks()
loop, where both the global its_lock and the local its->lock raw spinlocks
are held.

Even with GFP_ATOMIC, the page allocator acquires zone->lock, which is a
sleeping rt_mutex on PREEMPT_RT kernels. Acquiring a sleepable lock while
holding a raw spinlock causes a sleeping while atomic panic.

[ ... ]

> +void its_emulate_acquire_locks(unsigned long *flags)
> +{
> +	struct its_node *its;
> +
> +	if (WARN_ON(!flags))
> +		return;
> +
> +	raw_spin_lock_irqsave(&its_lock, *flags);
> +
> +	list_for_each_entry(its, &its_nodes, entry)
> +		raw_spin_lock(&its->lock);
> +}

[Severity: Medium]
Does holding all these identical locks concurrently trigger lockdep? Since
all its->lock instances belong to the same lock class, acquiring an
unbounded number of them sequentially without unlocking or using nested
annotations will trigger lockdep's same-lock-class tracking and disable
further lockdep checks.

> +int its_emulate_release_locks(int ret_pkvm_finalize, unsigned long *flags, its_emulate_setup cb)
> +{
> +	struct its_node *its;
> +	int ret = 0;
> +
> +	if (WARN_ON(!flags || !cb))
> +		ret = -EINVAL;
> +
> +	list_for_each_entry(its, &its_nodes, entry) {
> +		if (!ret_pkvm_finalize && !ret)
> +			ret = its_emulate_switch_queues_locked(its, cb);
> +
> +		raw_spin_unlock(&its->lock);
> +	}
> +
> +	raw_spin_unlock_irqrestore(&its_lock, *flags);
> +
> +	return ret;
> +}

[Severity: Medium]
If flags is NULL, the WARN_ON triggers and sets ret = -EINVAL, but execution
continues. Doesn't this lead to a NULL pointer dereference in
raw_spin_unlock_irqrestore() at the end of the function, as well as
unbalanced unlocks for all its->lock instances (since the acquire
function returns early)?

[Severity: High]
If its_emulate_switch_queues_locked() fails for a node, ret is populated
and subsequent nodes are skipped. However, what happens to the nodes that
were already successfully switched? 

Without rolling back the hardware state for those previous nodes, the
system is left partially emulated, which would cause a loss of
synchronization between the driver and hardware and lead to IOMMU or
interrupt faults.

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

  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
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 [this message]
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=20260807170044.B1B771F000E9@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.