26ba25
From 89c813343ab05381d7def3b67120a4480490add7 Mon Sep 17 00:00:00 2001
26ba25
From: Thomas Huth <thuth@redhat.com>
26ba25
Date: Mon, 15 Oct 2018 10:19:28 +0100
26ba25
Subject: [PATCH 3/6] s390x/kvm: enable AP instruction interpretation for guest
26ba25
26ba25
RH-Author: Thomas Huth <thuth@redhat.com>
26ba25
Message-id: <1539598771-16223-4-git-send-email-thuth@redhat.com>
26ba25
Patchwork-id: 82697
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 3/6] s390x/kvm: enable AP instruction interpretation for guest
26ba25
Bugzilla: 1508142
26ba25
RH-Acked-by: David Hildenbrand <david@redhat.com>
26ba25
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
26ba25
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
26ba25
26ba25
From: Tony Krowiak <akrowiak@linux.ibm.com>
26ba25
26ba25
Let's use the KVM_SET_DEVICE_ATTR ioctl to enable hardware
26ba25
interpretation of AP instructions executed on the guest.
26ba25
If the S390_FEAT_AP feature is switched on for the guest,
26ba25
AP instructions must be interpreted by default; otherwise,
26ba25
they will be intercepted.
26ba25
26ba25
This attribute setting may be overridden by a device. For example,
26ba25
a device may want to provide AP instructions to the guest (i.e.,
26ba25
S390_FEAT_AP turned on), but it may want to emulate them. In this
26ba25
case, the AP instructions executed on the guest must be
26ba25
intercepted; so when the device is realized, it must disable
26ba25
interpretation.
26ba25
26ba25
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
26ba25
Tested-by: Pierre Morel <pmorel@linux.ibm.com>
26ba25
Reviewed-by: David Hildenbrand <david@redhat.com>
26ba25
Reviewed-by: Thomas Huth <thuth@redhat.com>
26ba25
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
26ba25
Acked-by: Halil Pasic <pasic@linux.ibm.com>
26ba25
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
26ba25
Message-Id: <20181010170309.12045-4-akrowiak@linux.ibm.com>
26ba25
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
26ba25
(cherry picked from commit 1d7db85b61cb9888b8ed8c8923343b468405b7a0)
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 target/s390x/kvm.c | 19 +++++++++++++++++++
26ba25
 1 file changed, 19 insertions(+)
26ba25
26ba25
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
26ba25
index 2a63499..4cb3499 100644
26ba25
--- a/target/s390x/kvm.c
26ba25
+++ b/target/s390x/kvm.c
26ba25
@@ -2298,11 +2298,26 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
26ba25
         error_setg(errp, "KVM: host CPU model could not be identified");
26ba25
         return;
26ba25
     }
26ba25
+    /* for now, we can only provide the AP feature with HW support */
26ba25
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
26ba25
+        KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
26ba25
+        set_bit(S390_FEAT_AP, model->features);
26ba25
+    }
26ba25
     /* strip of features that are not part of the maximum model */
26ba25
     bitmap_and(model->features, model->features, model->def->full_feat,
26ba25
                S390_FEAT_MAX);
26ba25
 }
26ba25
 
26ba25
+static void kvm_s390_configure_apie(bool interpret)
26ba25
+{
26ba25
+    uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
26ba25
+                                KVM_S390_VM_CRYPTO_DISABLE_APIE;
26ba25
+
26ba25
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
26ba25
+        kvm_s390_set_attr(attr);
26ba25
+    }
26ba25
+}
26ba25
+
26ba25
 void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
26ba25
 {
26ba25
     struct kvm_s390_vm_cpu_processor prop  = {
26ba25
@@ -2360,6 +2375,10 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
26ba25
     if (test_bit(S390_FEAT_CMM, model->features)) {
26ba25
         kvm_s390_enable_cmma();
26ba25
     }
26ba25
+
26ba25
+    if (test_bit(S390_FEAT_AP, model->features)) {
26ba25
+        kvm_s390_configure_apie(true);
26ba25
+    }
26ba25
 }
26ba25
 
26ba25
 void kvm_s390_restart_interrupt(S390CPU *cpu)
26ba25
-- 
26ba25
1.8.3.1
26ba25