KVM: s390: mechanism to enable guest zPCI Interpretation
authorMatthew Rosato <mjrosato@linux.ibm.com>
Mon, 6 Jun 2022 20:33:18 +0000 (16:33 -0400)
committerChristian Borntraeger <borntraeger@linux.ibm.com>
Mon, 11 Jul 2022 07:54:31 +0000 (09:54 +0200)
The guest must have access to certain facilities in order to allow
interpretive execution of zPCI instructions and adapter event
notifications.  However, there are some cases where a guest might
disable interpretation -- provide a mechanism via which we can defer
enabling the associated zPCI interpretation facilities until the guest
indicates it wishes to use them.

Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Link: https://lore.kernel.org/r/20220606203325.110625-15-mjrosato@linux.ibm.com
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
arch/s390/include/asm/kvm_host.h
arch/s390/kvm/kvm-s390.c
arch/s390/kvm/kvm-s390.h

index c1518a505060011a920194d76a9e849c84013baa..8e381603b6a787fbe05d95d76e7154b1ebb9468f 100644 (file)
@@ -254,7 +254,10 @@ struct kvm_s390_sie_block {
 #define ECB2_IEP       0x20
 #define ECB2_PFMFI     0x08
 #define ECB2_ESCA      0x04
+#define ECB2_ZPCI_LSI  0x02
        __u8    ecb2;                   /* 0x0062 */
+#define ECB3_AISI      0x20
+#define ECB3_AISII     0x10
 #define ECB3_DEA 0x08
 #define ECB3_AES 0x04
 #define ECB3_RI  0x01
@@ -940,6 +943,7 @@ struct kvm_arch{
        int use_cmma;
        int use_pfmfi;
        int use_skf;
+       int use_zpci_interp;
        int user_cpu_state_ctrl;
        int user_sigp;
        int user_stsi;
index d96c9be0480bf88f47f61665b5de236def35d4c1..a66da3f661140273701f3680c834cdac08846fff 100644 (file)
@@ -1031,6 +1031,42 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
        return 0;
 }
 
+static void kvm_s390_vcpu_pci_setup(struct kvm_vcpu *vcpu)
+{
+       /* Only set the ECB bits after guest requests zPCI interpretation */
+       if (!vcpu->kvm->arch.use_zpci_interp)
+               return;
+
+       vcpu->arch.sie_block->ecb2 |= ECB2_ZPCI_LSI;
+       vcpu->arch.sie_block->ecb3 |= ECB3_AISII + ECB3_AISI;
+}
+
+void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm)
+{
+       struct kvm_vcpu *vcpu;
+       unsigned long i;
+
+       lockdep_assert_held(&kvm->lock);
+
+       if (!kvm_s390_pci_interp_allowed())
+               return;
+
+       /*
+        * If host is configured for PCI and the necessary facilities are
+        * available, turn on interpretation for the life of this guest
+        */
+       kvm->arch.use_zpci_interp = 1;
+
+       kvm_s390_vcpu_block_all(kvm);
+
+       kvm_for_each_vcpu(i, vcpu, kvm) {
+               kvm_s390_vcpu_pci_setup(vcpu);
+               kvm_s390_sync_request(KVM_REQ_VSIE_RESTART, vcpu);
+       }
+
+       kvm_s390_vcpu_unblock_all(kvm);
+}
+
 static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req)
 {
        unsigned long cx;
@@ -3336,6 +3372,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
 
        kvm_s390_vcpu_crypto_setup(vcpu);
 
+       kvm_s390_vcpu_pci_setup(vcpu);
+
        mutex_lock(&vcpu->kvm->lock);
        if (kvm_s390_pv_is_protected(vcpu->kvm)) {
                rc = kvm_s390_pv_create_cpu(vcpu, &uvrc, &uvrrc);
index 497d52a83c7827515c71cb4f4c29e3e5e3db8aac..975cffaf13de6786fc43eac8c9fec2cfae7c1c3a 100644 (file)
@@ -507,6 +507,16 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
  */
 void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm);
 
+/**
+ * kvm_s390_vcpu_pci_enable_interp
+ *
+ * Set the associated PCI attributes for each vcpu to allow for zPCI Load/Store
+ * interpretation as well as adapter interruption forwarding.
+ *
+ * @kvm: the KVM guest
+ */
+void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm);
+
 /**
  * diag9c_forwarding_hz
  *