public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Pierre Morel <pmorel@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	borntraeger@de.ibm.com, frankja@linux.ibm.com, cohuck@redhat.com,
	david@redhat.com, thuth@redhat.com, imbrenda@linux.ibm.com,
	hca@linux.ibm.com, gor@linux.ibm.com, pmorel@linux.ibm.com,
	wintera@linux.ibm.com, seiden@linux.ibm.com, nrb@linux.ibm.com
Subject: [PATCH v9 3/3] s390x: KVM: resetting the Topology-Change-Report
Date: Fri,  6 May 2022 11:24:03 +0200	[thread overview]
Message-ID: <20220506092403.47406-4-pmorel@linux.ibm.com> (raw)
In-Reply-To: <20220506092403.47406-1-pmorel@linux.ibm.com>

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 |  5 ++
 arch/s390/kvm/kvm-s390.c         | 79 ++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)

diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index 7a6b14874d65..abdcf4069343 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,10 @@ 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
+
 /* 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 c8bdce31464f..80a1244f0ead 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1731,6 +1731,76 @@ static void kvm_s390_sca_set_mtcr(struct kvm *kvm)
 	ipte_unlock(kvm);
 }
 
+/**
+ * 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 void kvm_s390_sca_clear_mtcr(struct kvm *kvm)
+{
+	struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */
+
+	ipte_lock(kvm);
+	sca->utility  &= ~SCA_UTILITY_MTCR;
+	ipte_unlock(kvm);
+}
+
+static int kvm_s390_set_topology(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	if (!test_kvm_facility(kvm, 11))
+		return -ENXIO;
+
+	switch (attr->attr) {
+	case KVM_S390_VM_CPU_TOPO_MTR_SET:
+		kvm_s390_sca_set_mtcr(kvm);
+		break;
+	case KVM_S390_VM_CPU_TOPO_MTR_CLEAR:
+		kvm_s390_sca_clear_mtcr(kvm);
+		break;
+	}
+	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; /* SCA version doesn't matter */
+	int val;
+
+	ipte_lock(kvm);
+	val = !!(sca->utility & SCA_UTILITY_MTCR);
+	ipte_unlock(kvm);
+
+	return val;
+}
+
+static int kvm_s390_get_topology(struct kvm *kvm, struct kvm_device_attr *attr)
+{
+	int mtcr;
+
+	if (!test_kvm_facility(kvm, 11))
+		return -ENXIO;
+
+	mtcr = kvm_s390_sca_get_mtcr(kvm);
+	if (copy_to_user((void __user *)attr->addr, &mtcr, sizeof(mtcr)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 {
 	int ret;
@@ -1751,6 +1821,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;
@@ -1776,6 +1849,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;
@@ -1849,6 +1925,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


  parent reply	other threads:[~2022-05-06  9:21 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  9:24 [PATCH v9 0/3] s390x: KVM: CPU Topology Pierre Morel
2022-05-06  9:24 ` [PATCH v9 1/3] s390x: KVM: ipte lock for SCA access should be contained in KVM Pierre Morel
2022-05-12  9:08   ` David Hildenbrand
2022-05-16 16:30     ` Pierre Morel
2022-05-12 11:32   ` Janosch Frank
2022-05-16 14:13     ` Pierre Morel
2022-05-06  9:24 ` [PATCH v9 2/3] s390x: KVM: guest support for topology function Pierre Morel
2022-05-12  9:24   ` David Hildenbrand
2022-05-16 14:13     ` Pierre Morel
2022-06-17 14:49       ` Pierre Morel
2022-05-12 11:41   ` Janosch Frank
2022-05-16 10:41     ` Pierre Morel
2022-05-19  9:01   ` Christian Borntraeger
2022-05-19  9:23     ` Pierre Morel
2022-05-19  9:36       ` Christian Borntraeger
2022-05-06  9:24 ` Pierre Morel [this message]
2022-05-12  9:31   ` [PATCH v9 3/3] s390x: KVM: resetting the Topology-Change-Report David Hildenbrand
2022-05-12  9:52     ` Claudio Imbrenda
2022-05-12 10:01       ` David Hildenbrand
2022-05-16 14:21         ` Pierre Morel
2022-05-18 14:33           ` David Hildenbrand
2022-05-18 16:55             ` Pierre Morel
2022-05-16 10:36     ` Pierre Morel
2022-05-18 10:51     ` Pierre Morel
2022-05-18 15:26 ` [PATCH v9 0/3] s390x: KVM: CPU Topology Christian Borntraeger
2022-05-18 16:41   ` Pierre Morel
2022-05-19  5:46   ` Heiko Carstens
2022-05-19  8:07     ` Christian Borntraeger
2022-05-19  9:02       ` Pierre Morel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220506092403.47406-4-pmorel@linux.ibm.com \
    --to=pmorel@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    --cc=seiden@linux.ibm.com \
    --cc=thuth@redhat.com \
    --cc=wintera@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox