@@ -85,6 +85,13 @@ struct kvm_fpu {
#define KVM_LOONGARCH_VCPU_CPUCFG 0
#define KVM_LOONGARCH_VCPU_PVTIME_CTRL 1
#define KVM_LOONGARCH_VCPU_PVTIME_GPA 0
+#define KVM_LOONGARCH_VCPU_LBT 2
+#define KVM_LOONGARCH_VCPU_LBT_SCR0 0
+#define KVM_LOONGARCH_VCPU_LBT_SCR1 1
+#define KVM_LOONGARCH_VCPU_LBT_SCR2 2
+#define KVM_LOONGARCH_VCPU_LBT_SCR3 3
+#define KVM_LOONGARCH_VCPU_LBT_FLAGS 4
+#define KVM_LOONGARCH_VCPU_LBT_FTOP 5
struct kvm_debug_exit_arch {
};
@@ -765,6 +765,100 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
return -EINVAL;
}
+static int kvm_loongarch_lbt_has_attr(struct kvm_vcpu *vcpu,
+ struct kvm_device_attr *attr)
+{
+ if (!kvm_guest_has_lbt(&vcpu->arch))
+ return -ENXIO;
+
+ switch (attr->attr) {
+ case KVM_LOONGARCH_VCPU_LBT_SCR0:
+ case KVM_LOONGARCH_VCPU_LBT_SCR1:
+ case KVM_LOONGARCH_VCPU_LBT_SCR2:
+ case KVM_LOONGARCH_VCPU_LBT_SCR3:
+ case KVM_LOONGARCH_VCPU_LBT_FLAGS:
+ case KVM_LOONGARCH_VCPU_LBT_FTOP:
+ return 0;
+ default:
+ return -ENXIO;
+ }
+
+ return -ENXIO;
+}
+
+static int kvm_loongarch_lbt_get_attr(struct kvm_vcpu *vcpu,
+ struct kvm_device_attr *attr)
+{
+ uint64_t val;
+
+ if (!kvm_guest_has_lbt(&vcpu->arch))
+ return -ENXIO;
+
+ switch (attr->attr) {
+ case KVM_LOONGARCH_VCPU_LBT_SCR0:
+ val = vcpu->arch.lbt.scr0;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_SCR1:
+ val = vcpu->arch.lbt.scr1;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_SCR2:
+ val = vcpu->arch.lbt.scr2;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_SCR3:
+ val = vcpu->arch.lbt.scr3;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_FLAGS:
+ val = vcpu->arch.lbt.eflags;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_FTOP:
+ val = vcpu->arch.fpu.ftop;
+ break;
+ default:
+ return -ENXIO;
+ }
+
+ if (put_user(val, (uint64_t __user *)attr->addr))
+ return -EFAULT;
+ return 0;
+}
+
+static int kvm_loongarch_lbt_set_attr(struct kvm_vcpu *vcpu,
+ struct kvm_device_attr *attr)
+{
+ u64 val;
+
+ if (!kvm_guest_has_lbt(&vcpu->arch))
+ return -ENXIO;
+
+ if (get_user(val, (u64 __user *)attr->addr))
+ return -EFAULT;
+
+ switch (attr->attr) {
+ case KVM_LOONGARCH_VCPU_LBT_SCR0:
+ vcpu->arch.lbt.scr0 = val;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_SCR1:
+ vcpu->arch.lbt.scr1 = val;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_SCR2:
+ vcpu->arch.lbt.scr2 = val;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_SCR3:
+ vcpu->arch.lbt.scr3 = val;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_FLAGS:
+ vcpu->arch.lbt.eflags = val;
+ break;
+ case KVM_LOONGARCH_VCPU_LBT_FTOP:
+ vcpu->arch.fpu.ftop = val;
+ break;
+ default:
+ return -ENXIO;
+ }
+
+ return 0;
+}
+
static int kvm_loongarch_cpucfg_has_attr(struct kvm_vcpu *vcpu,
struct kvm_device_attr *attr)
{
@@ -790,6 +884,9 @@ static int kvm_loongarch_vcpu_has_attr(struct kvm_vcpu *vcpu,
case KVM_LOONGARCH_VCPU_PVTIME_CTRL:
ret = kvm_loongarch_pvtime_has_attr(vcpu, attr);
break;
+ case KVM_LOONGARCH_VCPU_LBT:
+ ret = kvm_loongarch_lbt_has_attr(vcpu, attr);
+ break;
default:
break;
}
@@ -825,6 +922,9 @@ static int kvm_loongarch_vcpu_get_attr(struct kvm_vcpu *vcpu,
case KVM_LOONGARCH_VCPU_PVTIME_CTRL:
ret = kvm_loongarch_pvtime_get_attr(vcpu, attr);
break;
+ case KVM_LOONGARCH_VCPU_LBT:
+ ret = kvm_loongarch_lbt_get_attr(vcpu, attr);
+ break;
default:
break;
}
@@ -850,6 +950,9 @@ static int kvm_loongarch_vcpu_set_attr(struct kvm_vcpu *vcpu,
case KVM_LOONGARCH_VCPU_PVTIME_CTRL:
ret = kvm_loongarch_pvtime_set_attr(vcpu, attr);
break;
+ case KVM_LOONGARCH_VCPU_LBT:
+ ret = kvm_loongarch_lbt_set_attr(vcpu, attr);
+ break;
default:
break;
}
Every vcpu has separate LBT registers. And there are four scr registers, one flags and ftop register for LBT extension. When VM migrates, VMM needs to get LBT registers for every vcpu. Here macro KVM_LOONGARCH_VCPU_LBT is added for vcpu attr control info, the following macro is added to get/put LBT registers. KVM_LOONGARCH_VCPU_LBT_SCR0 KVM_LOONGARCH_VCPU_LBT_SCR1 KVM_LOONGARCH_VCPU_LBT_SCR2 KVM_LOONGARCH_VCPU_LBT_SCR3 KVM_LOONGARCH_VCPU_LBT_FLAGS KVM_LOONGARCH_VCPU_LBT_FTOP Signed-off-by: Bibo Mao <maobibo@loongson.cn> --- arch/loongarch/include/uapi/asm/kvm.h | 7 ++ arch/loongarch/kvm/vcpu.c | 103 ++++++++++++++++++++++++++ 2 files changed, 110 insertions(+)