From: Dave Martin <Dave.Martin@arm.com>
To: kvmarm@lists.cs.columbia.edu
Cc: "Christoffer Dall" <cdall@kernel.org>,
"Marc Zyngier" <marc.zyngier@arm.com>,
"Andre Przywara" <andre.przywara@arm.com>,
"Will Deacon" <will.deacon@arm.com>,
"Kristina Martsenko" <kristina.martsenko@arm.com>,
"Zhang Lei" <zhang.lei@jp.fujitsu.com>,
"Amit Daniel Kachhap" <amit.kachhap@arm.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH kvmtool v3 9/9] arm64: Select SVE vector lengths via the command line
Date: Thu, 30 May 2019 16:13:14 +0100 [thread overview]
Message-ID: <1559229194-3036-10-git-send-email-Dave.Martin@arm.com> (raw)
In-Reply-To: <1559229194-3036-1-git-send-email-Dave.Martin@arm.com>
In order to support use cases such as migration, it may be
important in some situations to restrict the set of SVE vector
lengths available to the guest. It can also be useful to observe
the behaviour of guest OSes with different vector lengths.
To enable testing and experimentation for such configurations, this
patch adds a command-line option to allow setting of the set of
vector lengths to be made available to the guest.
For now, the setting is global: no means is offered to configure
individual guest vcpus independently of each other.
By default all vector lengths that the host can support are given
to the guest, as before.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
arm/aarch64/include/kvm/kvm-config-arch.h | 8 +++-
arm/aarch64/kvm-cpu.c | 80 ++++++++++++++++++++++++++++++-
arm/include/arm-common/kvm-config-arch.h | 1 +
3 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h
index 41e9d05..a996612 100644
--- a/arm/aarch64/include/kvm/kvm-config-arch.h
+++ b/arm/aarch64/include/kvm/kvm-config-arch.h
@@ -1,6 +1,8 @@
#ifndef KVM__KVM_CONFIG_ARCH_H
#define KVM__KVM_CONFIG_ARCH_H
+int sve_vls_parser(const struct option *opt, const char *arg, int unset);
+
#define ARM_OPT_ARCH_RUN(cfg) \
OPT_BOOLEAN('\0', "aarch32", &(cfg)->aarch32_guest, \
"Run AArch32 guest"), \
@@ -16,7 +18,11 @@
OPT_BOOLEAN('\0', "enable-sve", &(cfg)->enable_sve, \
"Enable SVE for the guest"), \
OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \
- "Disable SVE for the guest"),
+ "Disable SVE for the guest"), \
+ OPT_CALLBACK('\0', "sve-vls", &(cfg)->sve_vqs, \
+ "comma-separated list of vector lengths, in 128-bit units", \
+ "Set of vector lengths to enable for the guest", \
+ sve_vls_parser, NULL),
#include "arm-common/kvm-config-arch.h"
diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c
index cdfb22e..2c624c3 100644
--- a/arm/aarch64/kvm-cpu.c
+++ b/arm/aarch64/kvm-cpu.c
@@ -1,8 +1,13 @@
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
#include "kvm/kvm-cpu.h"
#include "kvm/kvm.h"
#include "kvm/virtio.h"
#include <asm/ptrace.h>
+#include <asm/sigcontext.h>
#define COMPAT_PSR_F_BIT 0x00000040
#define COMPAT_PSR_I_BIT 0x00000080
@@ -12,6 +17,65 @@
#define SCTLR_EL1_E0E_MASK (1 << 24)
#define SCTLR_EL1_EE_MASK (1 << 25)
+/*
+ * Work around old kernel headers that lack these definitions in
+ * <asm/sigcontext.h>:
+ */
+#ifndef SVE_VQ_MIN
+#define SVE_VQ_MIN 1
+#endif
+
+#ifndef SVE_VQ_MAX
+#define SVE_VQ_MAX 512
+#endif
+
+int sve_vls_parser(const struct option *opt, const char *arg, int unset)
+{
+ size_t offset = 0;
+ int vq, n, t;
+ u64 (*vqs)[(SVE_VQ_MAX + 1 - SVE_VQ_MIN + 63) / 64];
+ u64 **cfg_vqs = opt->value;
+
+ if (*cfg_vqs) {
+ pr_err("sve-vls: SVE vector lengths set may only be specified once");
+ return -1;
+ }
+
+ vqs = calloc(1, sizeof *vqs);
+ if (!vqs)
+ die("%s", strerror(ENOMEM));
+
+ offset = 0;
+ while (arg[offset]) {
+ n = -1;
+
+ t = sscanf(arg + offset,
+ offset == 0 ? "%i%n" : ",%i%n",
+ &vq, &n);
+ if (t == EOF || t < 1 || n <= 0) {
+ pr_err("sve-vls: Comma-separated list of vector lengths required");
+ goto error;
+ }
+
+ if (vq < SVE_VQ_MIN || vq > SVE_VQ_MAX) {
+ pr_err("sve-vls: Invalid vector length %d", vq);
+ goto error;
+ }
+
+ vq -= SVE_VQ_MIN;
+ (*vqs)[vq / 64] |= (u64)1 << (vq % 64);
+
+ offset += n;
+ }
+
+ *cfg_vqs = *vqs;
+ return 0;
+
+error:
+ free(vqs);
+ return -1;
+}
+
static __u64 __core_reg_id(__u64 offset)
{
__u64 id = KVM_REG_ARM64 | KVM_REG_ARM_CORE | offset;
@@ -180,6 +244,16 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init)
static int configure_sve(struct kvm_cpu *vcpu)
{
int feature = KVM_ARM_VCPU_SVE;
+ struct kvm_one_reg r = {
+ .id = KVM_REG_ARM64_SVE_VLS,
+ .addr = (u64)vcpu->kvm->cfg.arch.sve_vqs,
+ };
+
+ if (vcpu->kvm->cfg.arch.sve_vqs)
+ if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, &r)) {
+ pr_err("Cannot set requested SVE vector lengths");
+ return -1;
+ }
if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature)) {
pr_err("KVM_ARM_VCPU_FINALIZE: %s", strerror(errno));
@@ -191,9 +265,13 @@ static int configure_sve(struct kvm_cpu *vcpu)
int kvm_cpu__configure_features(struct kvm_cpu *vcpu)
{
- if (vcpu->kvm->cfg.arch.enable_sve)
+ if (vcpu->kvm->cfg.arch.enable_sve) {
if (configure_sve(vcpu))
return -1;
+ } else {
+ if (vcpu->kvm->cfg.arch.sve_vqs)
+ pr_warning("SVE vector lengths ignored");
+ }
return 0;
}
diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h
index 40e3d1f..b45201f 100644
--- a/arm/include/arm-common/kvm-config-arch.h
+++ b/arm/include/arm-common/kvm-config-arch.h
@@ -12,6 +12,7 @@ struct kvm_config_arch {
u64 kaslr_seed;
bool enable_sve;
bool disable_sve;
+ u64 *sve_vqs;
bool enable_ptrauth;
bool disable_ptrauth;
enum irqchip_type irqchip;
--
2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
prev parent reply other threads:[~2019-05-30 15:16 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-30 15:13 [PATCH kvmtool v3 0/9] arm64: Pointer Authentication and SVE support Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 1/9] update_headers.sh: Add missing shell quoting Dave Martin
2019-05-31 17:02 ` Andre Przywara
2019-06-03 10:40 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 2/9] update_headers.sh: Cleanly report failure on error Dave Martin
2019-05-31 17:03 ` Andre Przywara
2019-06-03 10:41 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 3/9] update_headers.sh: arm64: Copy sve_context.h if available Dave Martin
2019-05-31 17:03 ` Andre Przywara
2019-06-03 11:08 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 4/9] update_headers: Sync kvm UAPI headers with linux v5.1-rc1 Dave Martin
2019-05-31 17:03 ` Andre Przywara
2019-06-03 11:10 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 5/9] KVM: arm/arm64: Add a vcpu feature for pointer authentication Dave Martin
2019-05-31 17:04 ` Andre Przywara
2019-06-03 11:23 ` Dave Martin
2019-06-03 14:03 ` Andre Przywara
2019-06-03 14:18 ` Dave Martin
2019-06-03 14:07 ` Will Deacon
2019-06-03 14:17 ` Dave Martin
2019-06-03 13:48 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 6/9] arm/arm64: Factor out ptrauth vcpu feature setup Dave Martin
2019-05-31 17:04 ` Andre Przywara
2019-06-03 11:12 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 7/9] arm64: Make ptrauth enable/disable diagnostics more user-friendly Dave Martin
2019-05-31 17:05 ` Andre Przywara
2019-06-03 11:14 ` Dave Martin
2019-05-30 15:13 ` [PATCH kvmtool v3 8/9] arm64: Add SVE support Dave Martin
2019-05-31 17:13 ` Andre Przywara
2019-06-03 11:15 ` Dave Martin
2019-05-30 15:13 ` Dave Martin [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=1559229194-3036-10-git-send-email-Dave.Martin@arm.com \
--to=dave.martin@arm.com \
--cc=alex.bennee@linaro.org \
--cc=amit.kachhap@arm.com \
--cc=andre.przywara@arm.com \
--cc=cdall@kernel.org \
--cc=kristina.martsenko@arm.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marc.zyngier@arm.com \
--cc=will.deacon@arm.com \
--cc=zhang.lei@jp.fujitsu.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).