From: Ricardo Koller <ricarkol@google.com>
To: Andrew Jones <drjones@redhat.com>
Cc: Marc Zyngier <maz@kernel.org>,
kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
pbonzini@redhat.com, alexandru.elisei@arm.com,
eric.auger@redhat.com
Subject: Re: [PATCH 1/3] KVM: selftests: Add exception handling support for aarch64
Date: Mon, 26 Apr 2021 11:58:13 -0700 [thread overview]
Message-ID: <YIcNRVEF7RXjqHuY@google.com> (raw)
In-Reply-To: <20210423110529.vivemdwnznhblhyf@gator>
On Fri, Apr 23, 2021 at 01:05:29PM +0200, Andrew Jones wrote:
> On Fri, Apr 23, 2021 at 09:58:24AM +0100, Marc Zyngier wrote:
> > Hi Ricardo,
> >
> > Thanks for starting this.
>
> Indeed! Thank you for contributing to AArch64 kvm selftests!
>
> > > +void vm_handle_exception(struct kvm_vm *vm, int vector, int ec,
> > > + void (*handler)(struct ex_regs *));
> > > +
> > > +#define SPSR_D (1 << 9)
> > > +#define SPSR_SS (1 << 21)
> > > +
> > > +#define write_sysreg(reg, val) \
> > > +({ \
> > > + asm volatile("msr "__stringify(reg)", %0" : : "r"(val)); \
> > > +})
>
> Linux does fancy stuff with the Z constraint to allow xzr. We might as
> well copy that.
>
> > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/handlers.S b/tools/testing/selftests/kvm/lib/aarch64/handlers.S
> > > new file mode 100644
> > > index 000000000000..c920679b87c0
> > > --- /dev/null
> > > +++ b/tools/testing/selftests/kvm/lib/aarch64/handlers.S
> > > @@ -0,0 +1,104 @@
> > > +/* SPDX-License-Identifier: GPL-2.0 */
> > > +.macro save_registers, el
> > > + stp x28, x29, [sp, #-16]!
> > > + stp x26, x27, [sp, #-16]!
> > > + stp x24, x25, [sp, #-16]!
> > > + stp x22, x23, [sp, #-16]!
> > > + stp x20, x21, [sp, #-16]!
> > > + stp x18, x19, [sp, #-16]!
> > > + stp x16, x17, [sp, #-16]!
> > > + stp x14, x15, [sp, #-16]!
> > > + stp x12, x13, [sp, #-16]!
> > > + stp x10, x11, [sp, #-16]!
> > > + stp x8, x9, [sp, #-16]!
> > > + stp x6, x7, [sp, #-16]!
> > > + stp x4, x5, [sp, #-16]!
> > > + stp x2, x3, [sp, #-16]!
> > > + stp x0, x1, [sp, #-16]!
> > > +
> > > + .if \el == 0
> > > + mrs x1, sp_el0
> > > + .else
> > > + mov x1, sp
> > > + .endif
> >
> > It there any point in saving SP_EL1, given that you already have
> > altered it significantly and will not be restoring it? I don't care
> > much, and maybe it is useful as debug information, but a comment would
> > certainly make the intent clearer.
>
> kvm-unit-tests takes some pains to save the original sp. We may be able to
> take some inspiration from there for this save and restore.
>
> > > +void kvm_exit_unexpected_vector(int vector, uint64_t ec)
> > > +{
> > > + ucall(UCALL_UNHANDLED, 2, vector, ec);
> > > +}
> > > +
> > > +#define HANDLERS_IDX(_vector, _ec) ((_vector * ESR_EC_NUM) + _ec)
> >
> > This is definitely odd. Not all the ECs are valid for all vector entry
> > points. Actually, ECs only make sense for synchronous exceptions, and
> > asynchronous events (IRQ, FIQ, SError) cannot populate ESR_ELx.
>
> For this, kvm-unit-tests provides a separate API for interrupt handler
> installation, which ensures ec is not used. Also, kvm-unit-tests uses
> a 2-D array [vector][ec] for the synchronous exceptions. I think we
> should be able to use a 2-D array here too, instead of the IDX macro.
>
> > > +void vm_handle_exception(struct kvm_vm *vm, int vector, int ec,
> > > + void (*handler)(struct ex_regs *))
> >
> > The name seems to be slightly ill defined. To me "handle exception" is
> > the action of handling the exception. Here, you are merely installing
> > an exception handler.
> >
>
> I agree. Please rename this for all of kvm selftests to something with
> 'install' in the name with the first patch of this series.
>
> Thanks,
> drew
>
Thank you Andrew and Marc for the reviews. Will send v2 with all the
feedback.
next prev parent reply other threads:[~2021-04-26 18:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 4:03 [PATCH 0/3] KVM: selftests: arm64 exception handling and debug test Ricardo Koller
2021-04-23 4:03 ` [PATCH 1/3] KVM: selftests: Add exception handling support for aarch64 Ricardo Koller
2021-04-23 8:58 ` Marc Zyngier
2021-04-23 11:05 ` Andrew Jones
2021-04-26 18:58 ` Ricardo Koller [this message]
2021-04-29 17:51 ` Ricardo Koller
2021-04-29 19:59 ` Marc Zyngier
2021-04-29 20:48 ` Ricardo Koller
2021-04-23 4:03 ` [PATCH 2/3] KVM: selftests: Add aarch64/debug-exceptions test Ricardo Koller
2021-04-23 11:22 ` Andrew Jones
2021-04-23 4:03 ` [PATCH 3/3] KVM: selftests: Use a ucall for x86 unhandled vector reporting Ricardo Koller
2021-04-23 10:45 ` Andrew Jones
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=YIcNRVEF7RXjqHuY@google.com \
--to=ricarkol@google.com \
--cc=alexandru.elisei@arm.com \
--cc=drjones@redhat.com \
--cc=eric.auger@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.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