Skip to contentSkip to conversation

s390/kvm: handle diagnose 318 instruction call

PATCH New Collin Walling 1 participant 1 message Aug 31, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 s390/kvm: handle diagnose 318 instruction call

The diagnose 318 instruction is a privileged instruction that must be interpreted by SIE and handled via KVM.

The control program name and version codes (CPNC and CPVC) set by this instruction are saved to the kvm->arch struct. The CPNC is also set in the SIE control block of all VCPUs. The new kvm_s390_set_misc interface is introduced for migration.

---
 arch/s390/include/asm/kvm_host.h       |  6 ++-
 arch/s390/include/uapi/asm/kvm.h       |  5 ++
 arch/s390/kvm/diag.c                   | 16 ++++++
 arch/s390/kvm/kvm-s390.c               | 90 ++++++++++++++++++++++++++++++++++
 arch/s390/kvm/kvm-s390.h               |  1 +
 tools/arch/s390/include/uapi/asm/kvm.h |  1 +
 6 files changed, 118 insertions(+), 1 deletion(-)
arch/s390/include/asm/kvm_host.h +5 -1
index 29c940b..fabeb32 100644
@@ -227,7 +227,8 @@ struct kvm_s390_sie_block {
 	__u32	scaol;			/* 0x0064 */
 	__u8	reserved68;		/* 0x0068 */
 	__u8    epdx;			/* 0x0069 */
-	__u8    reserved6a[2];		/* 0x006a */
+	__u8    cpnc;			/* 0x006a */
+	__u8	reserved6b;		/* 0x006b */
 	__u32	todpr;			/* 0x006c */
 #define GISA_FORMAT1 0x00000001
 	__u32	gd;			/* 0x0070 */
@@ -383,6 +384,7 @@ struct kvm_vcpu_stat {
 	u64 diagnose_9c;
 	u64 diagnose_258;
 	u64 diagnose_308;
+	u64 diagnose_318;
 	u64 diagnose_500;
 	u64 diagnose_other;
 };
@@ -829,6 +831,8 @@ struct kvm_arch{
 	/* subset of available cpu features enabled by user space */
 	DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
 	struct kvm_s390_gisa *gisa;
+	u8 cpnc;
+	u64 cpvc;
 };
 
 #define KVM_HVA_ERR_BAD		(-1UL)
arch/s390/include/uapi/asm/kvm.h +5 -0
index 9a50f02..e66b409 100644
@@ -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_MISC		5
 
 /* kvm attributes for mem_ctrl */
 #define KVM_S390_VM_MEM_ENABLE_CMMA	0
@@ -130,6 +131,7 @@ struct kvm_s390_vm_cpu_machine {
 #define KVM_S390_VM_CPU_FEAT_PFMFI	11
 #define KVM_S390_VM_CPU_FEAT_SIGPIF	12
 #define KVM_S390_VM_CPU_FEAT_KSS	13
+#define KVM_S390_VM_CPU_FEAT_DIAG318	14
 struct kvm_s390_vm_cpu_feat {
 	__u64 feat[16];
 };
@@ -166,6 +168,9 @@ struct kvm_s390_vm_cpu_subfunc {
 #define KVM_S390_VM_MIGRATION_START	1
 #define KVM_S390_VM_MIGRATION_STATUS	2
 
+/* kvm attributes for KVM_S390_VM_MISC */
+#define KVM_S390_VM_MISC_CPC		0
+
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
 	/* general purpose regs for s390 */
arch/s390/kvm/diag.c +16 -0
index 45634b3d..4f013e9 100644
@@ -235,6 +235,20 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
 	return ret < 0 ? ret : 0;
 }
 
+static int __diag_set_control_prog_name(struct kvm_vcpu *vcpu)
+{
+	unsigned int reg = (vcpu->arch.sie_block->ipa & 0xf0) >> 4;
+	unsigned long cpc = vcpu->run->s.regs.gprs[reg];
+
+	vcpu->stat.diagnose_318++;
+	kvm_s390_set_cpc(vcpu->kvm, cpc);
+
+	VCPU_EVENT(vcpu, 3, "diag 0x318 name code: %x version code: %llx",
+		   vcpu->kvm->arch.cpnc, vcpu->kvm->arch.cpvc);
+
+	return 0;
+}
+
 int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
 {
 	int code = kvm_s390_get_base_disp_rs(vcpu, NULL) & 0xffff;
@@ -254,6 +268,8 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
 		return __diag_page_ref_service(vcpu);
 	case 0x308:
 		return __diag_ipl_functions(vcpu);
+	case 0x318:
+		return __diag_set_control_prog_name(vcpu);
 	case 0x500:
 		return __diag_virtio_hypercall(vcpu);
 	default:
arch/s390/kvm/kvm-s390.c +90 -0

132 lines not on this page · raw message

arch/s390/kvm/kvm-s390.h +1 -0
index 981e3ba..d1f65dd 100644
@@ -281,6 +281,7 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
 int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
 
 /* implemented in kvm-s390.c */
+void kvm_s390_set_cpc(struct kvm *kvm, u64 cpc);
 void kvm_s390_set_tod_clock(struct kvm *kvm,
 			    const struct kvm_s390_vm_tod_clock *gtod);
 long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);
tools/arch/s390/include/uapi/asm/kvm.h +1 -0
index 4cdaa55..caa5858 100644
@@ -130,6 +130,7 @@ struct kvm_s390_vm_cpu_machine {
 #define KVM_S390_VM_CPU_FEAT_PFMFI	11
 #define KVM_S390_VM_CPU_FEAT_SIGPIF	12
 #define KVM_S390_VM_CPU_FEAT_KSS	13
+#define KVM_S390_VM_CPU_FEAT_DIAG318	14
 struct kvm_s390_vm_cpu_feat {
 	__u64 feat[16];
 };
Signature · 1 line
2.7.4