From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvm@vger.kernel.org,
"open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)"
<kvmarm@lists.cs.columbia.edu>,
"moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)"
<linux-arm-kernel@lists.infradead.org>,
Zenghui Yu <yuzenghui@huawei.com>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
kernel-team@android.com, stable@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: arm64: Commit pending PC adjustemnts before returning to userspace
Date: Tue, 11 May 2021 09:45:01 +0100 [thread overview]
Message-ID: <87lf8loe0i.wl-maz@kernel.org> (raw)
In-Reply-To: <CA+EHjTzoWYhgVjURzi9V8nGQO5DOimgGKv7gQcfrRgd-Gf2j2Q@mail.gmail.com>
On Tue, 11 May 2021 09:22:37 +0100,
Fuad Tabba <tabba@google.com> wrote:
>
> Hi Marc,
>
>
> On Tue, May 11, 2021 at 9:14 AM Marc Zyngier <maz@kernel.org> wrote:
> >
> > Hi Fuad,
> >
> > On Tue, 11 May 2021 09:03:40 +0100,
> > Fuad Tabba <tabba@google.com> wrote:
> > >
> > > Hi Marc,
> > >
> > > > KVM: arm64: Commit pending PC adjustemnts before returning to userspace
> > >
> > > s/adjustments/adjustments
> >
> > Looks like Gmail refuses to let you mimic my spelling mistakes! :D
> >
> > >
> > > On Mon, May 10, 2021 at 10:49 AM Marc Zyngier <maz@kernel.org> wrote:
> > > >
> > > > KVM currently updates PC (and the corresponding exception state)
> > > > using a two phase approach: first by setting a set of flags,
> > > > then by converting these flags into a state update when the vcpu
> > > > is about to enter the guest.
> > > >
> > > > However, this creates a disconnect with userspace if the vcpu thread
> > > > returns there with any exception/PC flag set. In this case, the exposed
> > > > context is wrong, as userpsace doesn't have access to these flags
> > > > (they aren't architectural). It also means that these flags are
> > > > preserved across a reset, which isn't expected.
> > > >
> > > > To solve this problem, force an explicit synchronisation of the
> > > > exception state on vcpu exit to userspace. As an optimisation
> > > > for nVHE systems, only perform this when there is something pending.
> > >
> > > I've tested this with a few nvhe and vhe tests that exercise both
> > > __kvm_adjust_pc call paths (__kvm_vcpu_run and
> > > kvm_arch_vcpu_ioctl_run), and the tests ran as expected. I'll do the
> > > same for v2 when you send it out.
> >
> > Ah, that's interesting. Do you have tests that actually fail when
> > hitting this bug? Given that this is pretty subtle, it'd be good to
> > have a way to make sure it doesn't crop up again.
>
> Nothing that fails, just code that generates exceptions or emulates
> instructions at various points. That said, I think it should be
> straightforward to write a selftest for this. I'll give it a go.
PC adjustment is easy-ish: have a vcpu to hit WFI with no interrupt
pending, send the thread a signal to make it exit to userspace, update
the PC to another address, and check that the instruction at that
address is actually executed.
Exception injection is a lot more difficult: you need to force a vcpu
exit to userspace right after having caused an exception to be
injected by KVM. I can't think of an easy way to do that other than
repeatedly executing an instruction that generates an exception while
signalling the thread to force the exit. Ugly.
M.
--
Without deviation from the norm, progress is not possible.
prev parent reply other threads:[~2021-05-11 8:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-10 9:49 [PATCH 0/2] KVM: arm64: Fixup PC updates on exit to userspace Marc Zyngier
2021-05-10 9:49 ` [PATCH 1/2] KVM: arm64: Move __adjust_pc out of line Marc Zyngier
2021-05-10 14:55 ` Alexandru Elisei
2021-05-10 15:08 ` Marc Zyngier
2021-05-10 9:49 ` [PATCH 2/2] KVM: arm64: Commit pending PC adjustemnts before returning to userspace Marc Zyngier
2021-05-10 14:55 ` Alexandru Elisei
2021-05-10 15:04 ` Marc Zyngier
2021-05-10 15:14 ` Alexandru Elisei
2021-05-11 7:44 ` Marc Zyngier
2021-05-11 16:50 ` Alexandru Elisei
2021-05-11 8:03 ` Fuad Tabba
2021-05-11 8:14 ` Marc Zyngier
2021-05-11 8:22 ` Fuad Tabba
2021-05-11 8:45 ` Marc Zyngier [this message]
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=87lf8loe0i.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=alexandru.elisei@arm.com \
--cc=james.morse@arm.com \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).