From: Dave.Martin@arm.com (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v9 12/16] KVM: arm64: Save host SVE context as appropriate
Date: Mon, 21 May 2018 15:49:05 +0100 [thread overview]
Message-ID: <20180521144904.GD13470@e103592.cambridge.arm.com> (raw)
In-Reply-To: <eac5821b-c5e0-90c9-cdd6-73643662d68d@arm.com>
On Mon, May 21, 2018 at 03:40:02PM +0100, Marc Zyngier wrote:
> On 21/05/18 15:17, Dave Martin wrote:
> > This patch adds SVE context saving to the hyp FPSIMD context switch
> > path. This means that it is no longer necessary to save the host
> > SVE state in advance of entering the guest, when in use.
> >
> > In order to avoid adding pointless complexity to the code, VHE is
> > assumed if SVE is in use. VHE is an architectural prerequisite for
> > SVE, so there is no good reason to turn CONFIG_ARM64_VHE off in
> > kernels that support both SVE and KVM.
> >
> > Historically, software models exist that can expose the
> > architecturally invalid configuration of SVE without VHE, so if
> > this situation is detected at kvm_init() time then KVM will be
> > disabled.
> >
> > Signed-off-by: Dave Martin <Dave.Martin@arm.com>
> >
> > ---
> >
> > * Stripped the following tags, reviewers please reconfirm:
> >
> > Formerly-Reviewed-by: Christoffer Dall <christoffer.dall@arm.com>
> > Formerly-Acked-by: Marc Zyngier <marc.zyngier@arm.com>
> > Formerly-Acked-by: Catalin Marinas <catalin.marinas@arm.com>
> >
> > (Creation of a new file for this one change may be deemed undesirable,
> > but there didn't seem to be a correct place to put it. There may also
> > be a way around the circular include problem that I missed.)
> >
> > Changes since v8:
> >
> > * Add kvm_arch_check_supported() hook, and move arm64-specific check
> > for SVE-implies-VHE into arch/arm64/.
> >
> > Due to circular header dependency problems, it is difficult to get
> > the prototype for kvm_pr_*() functions in <asm/kvm_host.h>, so this
> > patch puts arm64's kvm_arch_check_supported() hook out of line.
> > This is not a hot function.
> > ---
> > arch/arm/include/asm/kvm_host.h | 1 +
> > arch/arm64/Kconfig | 7 +++++++
> > arch/arm64/include/asm/kvm_host.h | 1 +
> > arch/arm64/kvm/Makefile | 2 +-
> > arch/arm64/kvm/fpsimd.c | 1 -
> > arch/arm64/kvm/hyp/switch.c | 20 +++++++++++++++++++-
> > arch/arm64/kvm/init.c | 33 +++++++++++++++++++++++++++++++++
> > virt/kvm/arm/arm.c | 6 ++++++
> > 8 files changed, 68 insertions(+), 3 deletions(-)
> > create mode 100644 arch/arm64/kvm/init.c
> >
[...]
> > diff --git a/arch/arm64/kvm/init.c b/arch/arm64/kvm/init.c
> > new file mode 100644
> > index 0000000..3b6e730
> > --- /dev/null
> > +++ b/arch/arm64/kvm/init.c
> > @@ -0,0 +1,33 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * arch/arm64/kvm/init.c: KVM initialisation support
> > + *
> > + * Copyright 2018 Arm Limited
> > + * Author: Dave Martin <Dave.Martin@arm.com>
> > + */
> > +#include <linux/errno.h>
> > +#include <linux/kvm_host.h>
> > +#include <asm/cpufeature.h>
> > +#include <asm/kvm_host.h>
> > +
> > +/* Additional arch-dependent checks for KVM usability */
> > +int kvm_arch_check_supported(void)
> > +{
> > + /*
> > + * VHE is a prerequisite for SVE in the Arm architecture, and
> > + * Kconfig ensures that if system_supports_sve() here then
> > + * CONFIG_ARM64_VHE is enabled, so if VHE support wasn't already
> > + * detected and enabled, the CPU is architecturally
> > + * noncompliant.
> > + *
> > + * Just in case this mismatch is seen, detect it, warn and give
> > + * up. Supporting this forbidden configuration in Hyp would be
> > + * pointless.
> > + */
> > + if (system_supports_sve() && !has_vhe()) {
> > + kvm_pr_unimpl("SVE system without VHE unsupported. Broken cpu?");
> > + return -ENODEV;
> > + }
> > +
> > + return 0;
> > +}
>
> [entering bikeshedding territory]
>
> I'm not exactly keen on this. This feels overkill, and a departure from
> what we've been doing so far.
>
> Why don't you simply have a helper in kvm_host.h that does:
>
> static inline bool kvm_arm_check_sve_valid(void)
> {
> return !system_supports_sve() || has_vhe();
> }
>
> (and a canonical "return true;" implementation for 32bit)
>
> > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
> > index bee226c..8518df0 100644
> > --- a/virt/kvm/arm/arm.c
> > +++ b/virt/kvm/arm/arm.c
[...]
> > @@ -1574,6 +1576,10 @@ int kvm_arch_init(void *opaque)
> > return -ENODEV;
> > }
> >
> > + err = kvm_arch_check_supported();
> > + if (err)
> > + return err;
> > +
>
> And turn this into:
>
> if (!kvm_arm_check_sve_valid()) {
> kvm_pr_unimpl("SVE system without VHE unsupported. Broken cpu?");
> return -EINVAL;
> }
>
> It has the advantage of being obvious of what we check for, and doesn't
> add any extra file.
Making the call special-purpose makes it more natural to pull the printk
out of the call, solving the header issues.
This would be a bit gross in core code, but arm.c is supported to be
Arm-specific, so if you prefer this approach it doesn't look too bad
here.
I'm happy to rework along these lines.
Cheers
---Dave
next prev parent reply other threads:[~2018-05-21 14:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-21 14:17 [PATCH v9 00/16] KVM: arm64: Optimise FPSIMD context switching Dave Martin
2018-05-21 14:17 ` [PATCH v9 01/16] thread_info: Add update_thread_flag() helpers Dave Martin
2018-05-21 14:17 ` [PATCH v9 02/16] arm64: Use update{,_tsk}_thread_flag() Dave Martin
2018-05-21 14:17 ` [PATCH v9 03/16] KVM: arm/arm64: Introduce kvm_arch_vcpu_run_pid_change Dave Martin
2018-05-21 14:17 ` [PATCH v9 04/16] KVM: arm64: Convert lazy FPSIMD context switch trap to C Dave Martin
2018-05-21 14:17 ` [PATCH v9 05/16] arm64: fpsimd: Generalise context saving for non-task contexts Dave Martin
2018-05-21 14:17 ` [PATCH v9 06/16] arm64/sve: Refactor user SVE trap maintenance for external use Dave Martin
2018-05-21 14:17 ` [PATCH v9 07/16] KVM: arm64: Repurpose vcpu_arch.debug_flags for general-purpose flags Dave Martin
2018-05-21 14:17 ` [PATCH v9 08/16] KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing Dave Martin
2018-05-21 14:17 ` [PATCH v9 09/16] arm64/sve: Move read_zcr_features() out of cpufeature.h Dave Martin
2018-05-21 14:17 ` [PATCH v9 10/16] arm64/sve: Switch sve_pffr() argument from task to thread Dave Martin
2018-05-21 14:17 ` [PATCH v9 11/16] arm64/sve: Move sve_pffr() to fpsimd.h and make inline Dave Martin
2018-05-21 14:17 ` [PATCH v9 12/16] KVM: arm64: Save host SVE context as appropriate Dave Martin
2018-05-21 14:40 ` Marc Zyngier
2018-05-21 14:49 ` Dave Martin [this message]
2018-05-21 14:17 ` [PATCH v9 13/16] KVM: arm64: Remove eager host SVE state saving Dave Martin
2018-05-21 14:17 ` [PATCH v9 14/16] KVM: arm64: Remove redundant *exit_code changes in fpsimd_guest_exit() Dave Martin
2018-05-21 14:17 ` [PATCH v9 15/16] KVM: arm64: Fold redundant exit code checks out of fixup_guest_exit() Dave Martin
2018-05-21 14:17 ` [PATCH v9 16/16] KVM: arm64: Invoke FPSIMD context switch trap from C Dave Martin
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=20180521144904.GD13470@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).