lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 13 May 2024 09:12:35 +0800
From: Bibo Mao <maobibo@...ngson.cn>
To: Tianrui Zhao <zhaotianrui@...ngson.cn>,
	Huacai Chen <chenhuacai@...nel.org>
Cc: WANG Xuerui <kernel@...0n.name>,
	kvm@...r.kernel.org,
	loongarch@...ts.linux.dev,
	linux-kernel@...r.kernel.org
Subject: [PATCH 3/3] LoongArch: KVM: Add vm migration support for LBT feature

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@...ngson.cn>
---
 arch/loongarch/include/uapi/asm/kvm.h |   7 ++
 arch/loongarch/kvm/vcpu.c             | 103 ++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)

diff --git a/arch/loongarch/include/uapi/asm/kvm.h b/arch/loongarch/include/uapi/asm/kvm.h
index 286b5ce93a57..9c3de257fddf 100644
--- a/arch/loongarch/include/uapi/asm/kvm.h
+++ b/arch/loongarch/include/uapi/asm/kvm.h
@@ -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 {
 };
diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index b2856539368a..a84c9d527d9d 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -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;
 	}
-- 
2.39.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ