mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-05-14 11:13:54 +00:00
KVM: arm64: Factor out core register ID enumeration
In preparation for adding logic to filter out some KVM_REG_ARM_CORE registers from the KVM_GET_REG_LIST output, this patch factors out the core register enumeration into a separate function and rebuilds num_core_regs() on top of it. This may be a little more expensive (depending on how good a job the compiler does of specialising the code), but KVM_GET_REG_LIST is not a hot path. This will make it easier to consolidate ID filtering code in one place. No functional change. Signed-off-by: Dave Martin <Dave.Martin@arm.com> Reviewed-by: Julien Thierry <julien.thierry@arm.com> Tested-by: zhang.lei <zhang.lei@jp.fujitsu.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
This commit is contained in:
parent
dc52f31a92
commit
be25bbb392
1 changed files with 25 additions and 8 deletions
|
@ -23,6 +23,7 @@
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/kvm_host.h>
|
#include <linux/kvm_host.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/stddef.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/vmalloc.h>
|
#include <linux/vmalloc.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
@ -194,9 +195,28 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int kvm_arm_copy_core_reg_indices(u64 __user *uindices)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
int n = 0;
|
||||||
|
const u64 core_reg = KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(struct kvm_regs) / sizeof(__u32); i++) {
|
||||||
|
if (uindices) {
|
||||||
|
if (put_user(core_reg | i, uindices))
|
||||||
|
return -EFAULT;
|
||||||
|
uindices++;
|
||||||
|
}
|
||||||
|
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned long num_core_regs(void)
|
static unsigned long num_core_regs(void)
|
||||||
{
|
{
|
||||||
return sizeof(struct kvm_regs) / sizeof(__u32);
|
return kvm_arm_copy_core_reg_indices(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,15 +296,12 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu)
|
||||||
*/
|
*/
|
||||||
int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
|
int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
|
||||||
const u64 core_reg = KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(struct kvm_regs) / sizeof(__u32); i++) {
|
ret = kvm_arm_copy_core_reg_indices(uindices);
|
||||||
if (put_user(core_reg | i, uindices))
|
if (ret)
|
||||||
return -EFAULT;
|
return ret;
|
||||||
uindices++;
|
uindices += ret;
|
||||||
}
|
|
||||||
|
|
||||||
ret = kvm_arm_copy_fw_reg_indices(vcpu, uindices);
|
ret = kvm_arm_copy_fw_reg_indices(vcpu, uindices);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
Loading…
Add table
Reference in a new issue