lkml.org 
[lkml]   [2022]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v8 2/2] s390x: KVM: resetting the Topology-Change-Report
Date
During a subsystem reset the Topology-Change-Report is cleared.
Let's give userland the possibility to clear the MTCR in the case
of a subsystem reset.

To migrate the MTCR, let's give userland the possibility to
query the MTCR state.

Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
arch/s390/include/uapi/asm/kvm.h | 9 +++
arch/s390/kvm/kvm-s390.c | 103 +++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+)

diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index 7a6b14874d65..bb3df6d49f27 100644
--- a/arch/s390/include/uapi/asm/kvm.h
+++ b/arch/s390/include/uapi/asm/kvm.h
@@ -74,6 +74,7 @@ struct kvm_s390_io_adapter_req {
#define KVM_S390_VM_CRYPTO 2
#define KVM_S390_VM_CPU_MODEL 3
#define KVM_S390_VM_MIGRATION 4
+#define KVM_S390_VM_CPU_TOPOLOGY 5

/* kvm attributes for mem_ctrl */
#define KVM_S390_VM_MEM_ENABLE_CMMA 0
@@ -171,6 +172,14 @@ struct kvm_s390_vm_cpu_subfunc {
#define KVM_S390_VM_MIGRATION_START 1
#define KVM_S390_VM_MIGRATION_STATUS 2

+/* kvm attributes for cpu topology */
+#define KVM_S390_VM_CPU_TOPO_MTR_CLEAR 0
+#define KVM_S390_VM_CPU_TOPO_MTR_SET 1
+
+struct kvm_s390_cpu_topology {
+ __u16 mtcr;
+};
+
/* for KVM_GET_REGS and KVM_SET_REGS */
struct kvm_regs {
/* general purpose regs for s390 */
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 925ccc59f283..755f325c9e70 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1756,6 +1756,100 @@ static int kvm_s390_sca_set_mtcr(struct kvm *kvm)
return 0;
}

+/**
+ * kvm_s390_sca_clear_mtcr
+ * @kvm: guest KVM description
+ *
+ * Is only relevant if the topology facility is present,
+ * the caller should check KVM facility 11
+ *
+ * Updates the Multiprocessor Topology-Change-Report to signal
+ * the guest with a topology change.
+ */
+static int kvm_s390_sca_clear_mtcr(struct kvm *kvm)
+{
+ struct bsca_block *sca = kvm->arch.sca;
+ struct kvm_vcpu *vcpu;
+ int val;
+
+ vcpu = kvm_s390_get_first_vcpu(kvm);
+ if (!vcpu)
+ return -ENODEV;
+
+ ipte_lock(vcpu);
+ val = READ_ONCE(sca->utility);
+ WRITE_ONCE(sca->utility, sca->utility & ~SCA_UTILITY_MTCR);
+ ipte_unlock(vcpu);
+
+ return 0;
+}
+
+/**
+ * kvm_s390_sca_get_mtcr
+ * @kvm: guest KVM description
+ *
+ * Is only relevant if the topology facility is present,
+ * the caller should check KVM facility 11
+ *
+ * reports to QEMU the Multiprocessor Topology-Change-Report.
+ */
+static int kvm_s390_sca_get_mtcr(struct kvm *kvm)
+{
+ struct bsca_block *sca = kvm->arch.sca;
+ struct kvm_vcpu *vcpu;
+ int val;
+
+ vcpu = kvm_s390_get_first_vcpu(kvm);
+ if (!vcpu)
+ return -ENODEV;
+
+ ipte_lock(vcpu);
+ val = READ_ONCE(sca->utility);
+ ipte_unlock(vcpu);
+
+ return val;
+}
+
+static int kvm_s390_set_topology(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+ int ret = -EFAULT;
+
+ if (!test_kvm_facility(kvm, 11))
+ return -ENXIO;
+
+ switch (attr->attr) {
+ case KVM_S390_VM_CPU_TOPO_MTR_SET:
+ ret = kvm_s390_sca_set_mtcr(kvm);
+ break;
+ case KVM_S390_VM_CPU_TOPO_MTR_CLEAR:
+ ret = kvm_s390_sca_clear_mtcr(kvm);
+ break;
+ }
+
+ return ret;
+}
+
+static int kvm_s390_get_topology(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+ struct kvm_s390_cpu_topology *topology;
+ int ret = 0;
+
+ if (!test_kvm_facility(kvm, 11))
+ return -ENXIO;
+
+ topology = kzalloc(sizeof(*topology), GFP_KERNEL);
+ if (!topology)
+ return -ENOMEM;
+
+ topology->mtcr = kvm_s390_sca_get_mtcr(kvm);
+ if (copy_to_user((void __user *)attr->addr, topology,
+ sizeof(struct kvm_s390_cpu_topology)))
+ ret = -EFAULT;
+
+ kfree(topology);
+ return ret;
+}
+
static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
{
int ret;
@@ -1776,6 +1870,9 @@ static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
case KVM_S390_VM_MIGRATION:
ret = kvm_s390_vm_set_migration(kvm, attr);
break;
+ case KVM_S390_VM_CPU_TOPOLOGY:
+ ret = kvm_s390_set_topology(kvm, attr);
+ break;
default:
ret = -ENXIO;
break;
@@ -1801,6 +1898,9 @@ static int kvm_s390_vm_get_attr(struct kvm *kvm, struct kvm_device_attr *attr)
case KVM_S390_VM_MIGRATION:
ret = kvm_s390_vm_get_migration(kvm, attr);
break;
+ case KVM_S390_VM_CPU_TOPOLOGY:
+ ret = kvm_s390_get_topology(kvm, attr);
+ break;
default:
ret = -ENXIO;
break;
@@ -1874,6 +1974,9 @@ static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
case KVM_S390_VM_MIGRATION:
ret = 0;
break;
+ case KVM_S390_VM_CPU_TOPOLOGY:
+ ret = test_kvm_facility(kvm, 11) ? 0 : -ENXIO;
+ break;
default:
ret = -ENXIO;
break;
--
2.27.0
\
 
 \ /
  Last update: 2022-04-20 13:32    [W:0.351 / U:1.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site