From: Dave.Martin@arm.com (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 06/14] KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing
Date: Tue, 8 May 2018 11:14:07 +0100 [thread overview]
Message-ID: <20180508101404.GD7753@e103592.cambridge.arm.com> (raw)
In-Reply-To: <e87c6940-1c79-ccd4-c6ad-2d87790b2e00@arm.com>
On Tue, May 08, 2018 at 10:58:04AM +0100, Marc Zyngier wrote:
> On 04/05/18 17:05, Dave Martin wrote:
> > This patch refactors KVM to align the host and guest FPSIMD
> > save/restore logic with each other for arm64. This reduces the
> > number of redundant save/restore operations that must occur, and
> > reduces the common-case IRQ blackout time during guest exit storms
> > by saving the host state lazily and optimising away the need to
> > restore the host state before returning to the run loop.
> >
> > Four hooks are defined in order to enable this:
> >
> > * kvm_arch_vcpu_run_map_fp():
> > Called on PID change to map necessary bits of current to Hyp.
> >
> > * kvm_arch_vcpu_load_fp():
> > Set up FP/SIMD for entering the KVM run loop (parse as
> > "vcpu_load fp").
> >
> > * kvm_arch_vcpu_park_fp():
> > Get FP/SIMD into a safe state for re-enabling interrupts after a
> > guest exit back to the run loop.
> >
> > For arm64 specifically, this involves updating the host kernel's
> > FPSIMD context tracking metadata so that kernel-mode NEON use
> > will cause the vcpu's FPSIMD state to be saved back correctly
> > into the vcpu struct. This must be done before re-enabling
> > interrupts because kernel-mode NEON may be used my softirqs.
>
> s/my/by/
>
> I must admit being slightly confused by the word "park". I tend to read
> "park" as "stash away for later use", while it really is "update the
> kernel's view of who is actually in control of the FP registers".
I was thinking park as in parking disk heads, i.e., get things so we can
kick FPSIMD without doing damage.
(Or indeed, applying the handbrake so your car doesn't roll away
downhill while you're gone.)
But of a strained analogy though, I'll admit.
> No, I don't have a better name for it... ;-) But maybe something along
> the lines of "hwsync_fp", in order to be consistent with the rest of the
> code that deals with shared resources?
To me, "hw" carries too much of a suggestion that we would be flushing
the registers back to memory. In fact, we don't touch the hardware
here, only kernel bookkeeping data.
Trying to come up with an intuitive name for this may be futile; how
about
* _sync_ (which is suitably vague), or
* _ctxsync_ (which will avoid fooling people into thinking they know
what it does without looking at the code)
?
[...]
> > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> > index 469de8a..811097e 100644
> > --- a/arch/arm64/include/asm/kvm_host.h
> > +++ b/arch/arm64/include/asm/kvm_host.h
> > @@ -30,6 +30,7 @@
> > #include <asm/kvm.h>
> > #include <asm/kvm_asm.h>
> > #include <asm/kvm_mmio.h>
> > +#include <asm/thread_info.h>
> >
> > #define __KVM_HAVE_ARCH_INTC_INITIALIZED
> >
> > @@ -238,6 +239,12 @@ struct kvm_vcpu_arch {
> >
> > /* Pointer to host CPU context */
> > kvm_cpu_context_t *host_cpu_context;
> > +
> > + struct thread_info *host_thread_info; /* hyp VA */
> > + struct user_fpsimd_state *host_fpsimd_state; /* hyp VA */
> > + bool host_sve_in_use; /* backup for host TIF_SVE while in guest */
> > + bool fp_enabled;
>
> Could we consider merging these two fields together with debug_flags?
> Overall, they share a common purpose (tracking the use of a resource
> shared between host and guest). Not necessarily something to do
> immediately though.
I expect so. I added these as bools partly for simplicity and partly
because there was no general-purpose flags field already.
We could make debug_flags into a general-purpose flags field, though.
Once we've agreed about the park_fp renaming, I'll consider reworking
this also -- but I'll punt it to a separate patch if it turns out to be
non-trivial.
[...]
> Other than the couple of minor nits above,
>
> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Thanks
---Dave
next prev parent reply other threads:[~2018-05-08 10:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-04 16:05 [PATCH v5 00/14] KVM: arm64: Optimise FPSIMD context switching Dave Martin
2018-05-04 16:05 ` [PATCH v5 01/14] thread_info: Add update_thread_flag() helpers Dave Martin
2018-05-04 16:05 ` [PATCH v5 02/14] arm64: Use update{,_tsk}_thread_flag() Dave Martin
2018-05-04 16:05 ` [PATCH v5 03/14] KVM: arm/arm64: Introduce kvm_arch_vcpu_run_pid_change Dave Martin
2018-05-08 8:56 ` Marc Zyngier
2018-05-04 16:05 ` [PATCH v5 04/14] KVM: arm64: Convert lazy FPSIMD context switch trap to C Dave Martin
2018-05-08 9:10 ` Marc Zyngier
2018-05-04 16:05 ` [PATCH v5 05/14] arm64: fpsimd: Generalise context saving for non-task contexts Dave Martin
2018-05-08 9:20 ` Marc Zyngier
2018-05-04 16:05 ` [PATCH v5 06/14] KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing Dave Martin
2018-05-08 9:58 ` Marc Zyngier
2018-05-08 10:14 ` Dave Martin [this message]
2018-05-04 16:05 ` [PATCH v5 07/14] arm64/sve: Move read_zcr_features() out of cpufeature.h Dave Martin
2018-05-04 16:05 ` [PATCH v5 08/14] arm64/sve: Switch sve_pffr() argument from task to thread Dave Martin
2018-05-04 16:05 ` [PATCH v5 09/14] arm64/sve: Move sve_pffr() to fpsimd.h and make inline Dave Martin
2018-05-04 16:05 ` [PATCH v5 10/14] KVM: arm64: Save host SVE context as appropriate Dave Martin
2018-05-08 10:38 ` Marc Zyngier
2018-05-08 11:25 ` Dave Martin
2018-05-08 11:57 ` Marc Zyngier
2018-05-08 12:40 ` Dave Martin
2018-05-04 16:05 ` [PATCH v5 11/14] KVM: arm64: Remove eager host SVE state saving Dave Martin
2018-05-04 16:05 ` [PATCH v5 12/14] KVM: arm64: Remove redundant *exit_code changes in fpsimd_guest_exit() Dave Martin
2018-05-08 10:51 ` Marc Zyngier
2018-05-04 16:05 ` [PATCH v5 13/14] KVM: arm64: Fold redundant exit code checks out of fixup_guest_exit() Dave Martin
2018-05-08 10:59 ` Marc Zyngier
2018-05-08 11:30 ` Dave Martin
2018-05-08 11:59 ` Marc Zyngier
2018-05-08 12:30 ` Dave Martin
2018-05-04 16:05 ` [PATCH v5 14/14] KVM: arm64: Invoke FPSIMD context switch trap from C Dave Martin
2018-05-08 11:03 ` Marc Zyngier
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=20180508101404.GD7753@e103592.cambridge.arm.com \
--to=dave.martin@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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).