From: Zenghui Yu <yuzenghui@huawei.com>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: <kvmarm@lists.linux.dev>, Marc Zyngier <maz@kernel.org>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Eric Auger <eric.auger@redhat.com>
Subject: Re: [PATCH] KVM: arm64: vgic-v3: Don't load pending state when enabling LPIs on RD
Date: Thu, 7 Mar 2024 17:00:42 +0800 [thread overview]
Message-ID: <db2920fd-9fe8-1ff4-3f00-34dc4afdcdd5@huawei.com> (raw)
In-Reply-To: <20240228000117.2297982-1-oliver.upton@linux.dev>
Hi Oliver,
On 2024/2/28 8:01, Oliver Upton wrote:
> Reality check: KVM's GIC/ITS emulation does not handle pending LPI state
> to the letter of the architecture!
>
> Although the GIC spec defines LPI pending state on a per-redistributor
> basis, KVM's view of the LPIs in a VM are global by design. This is
> intentional, as it is a massive simplification to the way KVM organizes
> interrupts and deals with the interactions between the vCPUs and ITSes.
>
> So, with that in mind, the KVM emulation of PENDBASE is completely wrong,
> as unmapped INTIDs (i.e. not mapped in any ITS) are silently ignored,
> even though the expecatation is that IRQs would be generated in real
> hardware. Even more hilarious things can happen for the LPIs that are
> actually mapped, as an update to global LPI state can pend an interrupt
> on a different vCPU.
I don't fully understand this "hilarious" part. Could you please
elaborate a bit more on it?
> vgic_add_lpi() fetches pending state when creating the global
> representation of an LPI. Both VM save/restore and guest interactions
> with the ITS find their way here, so the pending state will get loaded
> into KVM one way or another. That flow is slightly more correct, as it
> consults the pending table of the targeted redistributor.
This looks reasonable. I remember I had looked several times at this
code path (vgic_enable_lpis()/its_sync_lpi_pending_table()) but hadn't
made any improvements or progress.
E.g., it purely does *nothing* on the guest restore path, as
redistributors are restored before ITS, so there is no LPI mapping at
all when we're at its_sync_lpi_pending_table().
It's just been a long time. I'll take another look and think about it.
> Anyway, it is clear that this code can never be correct and doesn't
> serve a purpose. If bisection led you here you've probably got a *very*
> funky guest, and should bring it up on the list...
So I've tested it with kvm-unit-tests and got failure with the
its-pending-migration case:
INFO: gicv3: its-pending-migration: Migration complete
INFO: gicv3: its-pending-migration: expected 128 LPIs on PE #30, 0 observed
FAIL: gicv3: its-pending-migration: 128 LPIs on both PE0 and PE1 after
migration
SUMMARY: 1 tests, 1 unexpected failures
where the guest SW directly writes to the pending table when
GICR_CTLR.EnableLPIs == 0. I seriously doubt there is any use case like
that in real world. But not sure whether it is a funky behaviour from
the architectural perspective.
Thanks,
Zenghui
next prev parent reply other threads:[~2024-03-07 9:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 0:01 [PATCH] KVM: arm64: vgic-v3: Don't load pending state when enabling LPIs on RD Oliver Upton
2024-03-07 9:00 ` Zenghui Yu [this message]
2024-03-07 10:09 ` Marc Zyngier
2024-03-07 12:13 ` Zenghui Yu
2024-03-07 12:33 ` Zenghui Yu
2024-03-07 13:50 ` Marc Zyngier
2024-03-10 15:27 ` Zenghui Yu
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=db2920fd-9fe8-1ff4-3f00-34dc4afdcdd5@huawei.com \
--to=yuzenghui@huawei.com \
--cc=eric.auger@redhat.com \
--cc=james.morse@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox