aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/virtual/kvm/api.txt10
-rw-r--r--arch/arm64/include/uapi/asm/kvm.h5
-rw-r--r--arch/arm64/kvm/guest.c7
3 files changed, 14 insertions, 8 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 68509dee23e8..03df379a02b0 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2171,13 +2171,15 @@ and KVM_ARM_VCPU_FINALIZE for more information about this procedure.
2171KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector 2171KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector
2172lengths supported by the vcpu to be discovered and configured by 2172lengths supported by the vcpu to be discovered and configured by
2173userspace. When transferred to or from user memory via KVM_GET_ONE_REG 2173userspace. When transferred to or from user memory via KVM_GET_ONE_REG
2174or KVM_SET_ONE_REG, the value of this register is of type __u64[8], and 2174or KVM_SET_ONE_REG, the value of this register is of type
2175encodes the set of vector lengths as follows: 2175__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as
2176follows:
2176 2177
2177__u64 vector_lengths[8]; 2178__u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS];
2178 2179
2179if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX && 2180if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX &&
2180 ((vector_lengths[(vq - 1) / 64] >> ((vq - 1) % 64)) & 1)) 2181 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >>
2182 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1))
2181 /* Vector length vq * 16 bytes supported */ 2183 /* Vector length vq * 16 bytes supported */
2182else 2184else
2183 /* Vector length vq * 16 bytes not supported */ 2185 /* Vector length vq * 16 bytes not supported */
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index 2a04ef015469..edd2db8e5160 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -258,9 +258,14 @@ struct kvm_vcpu_events {
258 KVM_REG_SIZE_U256 | \ 258 KVM_REG_SIZE_U256 | \
259 ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 259 ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1)))
260 260
261#define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN
262#define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX
263
261/* Vector lengths pseudo-register: */ 264/* Vector lengths pseudo-register: */
262#define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ 265#define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \
263 KVM_REG_SIZE_U512 | 0xffff) 266 KVM_REG_SIZE_U512 | 0xffff)
267#define KVM_ARM64_SVE_VLS_WORDS \
268 ((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1)
264 269
265/* Device Control API: ARM VGIC */ 270/* Device Control API: ARM VGIC */
266#define KVM_DEV_ARM_VGIC_GRP_ADDR 0 271#define KVM_DEV_ARM_VGIC_GRP_ADDR 0
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index 73044e3f8706..5bb909c3ff7c 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -23,7 +23,6 @@
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/nospec.h> 25#include <linux/nospec.h>
26#include <linux/kernel.h>
27#include <linux/kvm_host.h> 26#include <linux/kvm_host.h>
28#include <linux/module.h> 27#include <linux/module.h>
29#include <linux/stddef.h> 28#include <linux/stddef.h>
@@ -210,7 +209,7 @@ out:
210#define vq_mask(vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64) 209#define vq_mask(vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64)
211 210
212static bool vq_present( 211static bool vq_present(
213 const u64 (*const vqs)[DIV_ROUND_UP(SVE_VQ_MAX - SVE_VQ_MIN + 1, 64)], 212 const u64 (*const vqs)[KVM_ARM64_SVE_VLS_WORDS],
214 unsigned int vq) 213 unsigned int vq)
215{ 214{
216 return (*vqs)[vq_word(vq)] & vq_mask(vq); 215 return (*vqs)[vq_word(vq)] & vq_mask(vq);
@@ -219,7 +218,7 @@ static bool vq_present(
219static int get_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 218static int get_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
220{ 219{
221 unsigned int max_vq, vq; 220 unsigned int max_vq, vq;
222 u64 vqs[DIV_ROUND_UP(SVE_VQ_MAX - SVE_VQ_MIN + 1, 64)]; 221 u64 vqs[KVM_ARM64_SVE_VLS_WORDS];
223 222
224 if (!vcpu_has_sve(vcpu)) 223 if (!vcpu_has_sve(vcpu))
225 return -ENOENT; 224 return -ENOENT;
@@ -243,7 +242,7 @@ static int get_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
243static int set_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 242static int set_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
244{ 243{
245 unsigned int max_vq, vq; 244 unsigned int max_vq, vq;
246 u64 vqs[DIV_ROUND_UP(SVE_VQ_MAX - SVE_VQ_MIN + 1, 64)]; 245 u64 vqs[KVM_ARM64_SVE_VLS_WORDS];
247 246
248 if (!vcpu_has_sve(vcpu)) 247 if (!vcpu_has_sve(vcpu))
249 return -ENOENT; 248 return -ENOENT;