Skip to contentSkip to conversation

s390x: pv: Diag318 fixes

PATCH Superseded Janosch Frank 5 participants 17 messages Oct 21, 2020 – Oct 22, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover s390x: pv: Diag318 fixes

Here are two fixes for the diag318 support that fix crashes when booting PV guests.

We're working on extending our testing to catch problems like these earlier.

Branch:
https://gitlab.com/frankja/qemu/-/commits/bb/frankja/diag318_fixes

CI:
https://gitlab.com/frankja/qemu/-/pipelines/205771933

Janosch Frank (2):
s390x: pv: Remove sclp boundary checks
s390x: pv: Fix diag318 PV fencing

 hw/s390x/sclp.c    | 15 ++++++++++-----
 target/s390x/kvm.c |  3 +--
 2 files changed, 11 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 s390x: pv: Remove sclp boundary checks

The SCLP boundary cross check is done by the Ultravisor for a protected guest, hence we don't need to do it. As QEMU doesn't get a valid SCCB address in protected mode this is even problematic and can lead to QEMU reporting a false boundary cross error.

Fixes db13387ca0 ("s390/sclp: rework sclp boundary checks")
---
 hw/s390x/sclp.c | 5 -----
 1 file changed, 5 deletions(-)
hw/s390x/sclp.c +0 -5
index 00f1e4648d..0cf2290826 100644
@@ -285,11 +285,6 @@ int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
         goto out_write;
     }
 
-    if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb->h.length), code)) {
-        work_sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
-        goto out_write;
-    }
-
     sclp_c->execute(sclp, work_sccb, code);
 out_write:
     s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb,
Signature · 1 line
2.25.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] s390x: pv: Remove sclp boundary checks

Quoted 21 lines · Janosch Frank

The SCLP boundary cross check is done by the Ultravisor for a protected guest, hence we don't need to do it. As QEMU doesn't get a valid SCCB address in protected mode this is even problematic and can lead to QEMU reporting a false boundary cross error.

Fixes db13387ca0 ("s390/sclp: rework sclp boundary checks")
---
 hw/s390x/sclp.c | 5 -----
 1 file changed, 5 deletions(-)
hw/s390x/sclp.c +0 -0
index 00f1e4648d..0cf2290826 100644
@@ -285,11 +285,6 @@ int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
         goto out_write;

hw/s390x/sclp.c int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb, · line 290

Quoted 10 lines
hw/s390x/sclp.c +0 -5
     }
 
-    if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb->h.length), code)) {
-        work_sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
-        goto out_write;
-    }
-
     sclp_c->execute(sclp, work_sccb, code);
 out_write:
     s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb,
Signature · 3 lines
Thanks,

David / dhildenb
Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] s390x: pv: Remove sclp boundary checks

In reply to Janosch Frank
Quoted 10 lines · On Wed, 21 Oct 2020 09:43:44 -0400 Janosch Frank <[email protected]> wrote:

The SCLP boundary cross check is done by the Ultravisor for a protected guest, hence we don't need to do it. As QEMU doesn't get a valid SCCB address in protected mode this is even problematic and can lead to QEMU reporting a false boundary cross error.

Fixes db13387ca0 ("s390/sclp: rework sclp boundary checks")
Quoted 20 lines
---
 hw/s390x/sclp.c | 5 -----
 1 file changed, 5 deletions(-)
hw/s390x/sclp.c +0 -5
index 00f1e4648d..0cf2290826 100644
@@ -285,11 +285,6 @@ int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
         goto out_write;
     }
 
-    if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb->h.length), code)) {
-        work_sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
-        goto out_write;
-    }
-
     sclp_c->execute(sclp, work_sccb, code);
 out_write:
     s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb,
Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] s390x: pv: Remove sclp boundary checks

In reply to Janosch Frank
Quoted 21 lines · Janosch Frank

The SCLP boundary cross check is done by the Ultravisor for a protected guest, hence we don't need to do it. As QEMU doesn't get a valid SCCB address in protected mode this is even problematic and can lead to QEMU reporting a false boundary cross error.

Fixes db13387ca0 ("s390/sclp: rework sclp boundary checks")
---
 hw/s390x/sclp.c | 5 -----
 1 file changed, 5 deletions(-)
hw/s390x/sclp.c +0 -0
index 00f1e4648d..0cf2290826 100644
@@ -285,11 +285,6 @@ int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
         goto out_write;

hw/s390x/sclp.c int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb, · line 290

Quoted 10 lines
hw/s390x/sclp.c +0 -5
     }
 
-    if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb->h.length), code)) {
-        work_sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
-        goto out_write;
-    }
-
     sclp_c->execute(sclp, work_sccb, code);
 out_write:
     s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb,
#5 lore raw

PATCH 2/2 s390x: pv: Fix diag318 PV fencing

In reply to Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")
---
 hw/s390x/sclp.c    | 10 ++++++++++
 target/s390x/kvm.c |  3 +--
 2 files changed, 11 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +10 -0
index 0cf2290826..69aba402d3 100644
@@ -22,6 +22,7 @@
 #include "hw/s390x/event-facility.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "hw/s390x/pv.h"
 
 static inline SCLPDevice *get_sclp_device(void)
 {
@@ -142,6 +143,15 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
         s390_get_feat_block(S390_FEAT_TYPE_SCLP_FAC134,
                             &read_info->fac134);
+        /*
+         * Diag318 is not available in protected mode and will result
+         * in an operation exception. As we can dynamically move in
+         * and out of protected mode, we need to fence the feature
+         * here rather than when creating the CPU model.
+         */
+        if (s390_is_pv()) {
+            read_info->fac134 &= ~0x80;
+        }
     }
 
     read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
target/s390x/kvm.c +1 -2
index f13eff688c..baa070fdf7 100644
@@ -2498,8 +2498,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
      */
     set_bit(S390_FEAT_EXTENDED_LENGTH_SCCB, model->features);
 
-    /* DIAGNOSE 0x318 is not supported under protected virtualization */
-    if (!s390_is_pv() && kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
+    if (kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
         set_bit(S390_FEAT_DIAG_318, model->features);
     }
 
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH 2/2] s390x: pv: Fix diag318 PV fencing

Quoted 28 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")
---
 hw/s390x/sclp.c    | 10 ++++++++++
 target/s390x/kvm.c |  3 +--
 2 files changed, 11 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +1 -0
index 0cf2290826..69aba402d3 100644
@@ -22,6 +22,7 @@
 #include "hw/s390x/event-facility.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "hw/s390x/pv.h"
 
 static inline SCLPDevice *get_sclp_device(void)
 {
@@ -142,6 +143,15 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
         s390_get_feat_block(S390_FEAT_TYPE_SCLP_FAC134,

hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 154

Quoted 10 lines
hw/s390x/sclp.c +9 -0
                             &read_info->fac134);
+        /*
+         * Diag318 is not available in protected mode and will result
+         * in an operation exception. As we can dynamically move in
+         * and out of protected mode, we need to fence the feature
+         * here rather than when creating the CPU model.
+         */
+        if (s390_is_pv()) {
+            read_info->fac134 &= ~0x80;
+        }

Hmm, I thought firmware would handle exposing cpu features and similar, so we can't temper with it ....

Can we move that into s390_get_feat_block instead and check against the feature bit instead?

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH 2/2] s390x: pv: Fix diag318 PV fencing

Quoted 34 lines · David Hildenbrand
Quoted 33 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")
---
 hw/s390x/sclp.c    | 10 ++++++++++
 target/s390x/kvm.c |  3 +--
 2 files changed, 11 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +5 -0
index 0cf2290826..69aba402d3 100644
@@ -22,6 +22,7 @@
 #include "hw/s390x/event-facility.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "hw/s390x/pv.h"
 
 static inline SCLPDevice *get_sclp_device(void)
 {
@@ -142,6 +143,15 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
         s390_get_feat_block(S390_FEAT_TYPE_SCLP_FAC134,
                             &read_info->fac134);
+        /*
+         * Diag318 is not available in protected mode and will result
+         * in an operation exception. As we can dynamically move in
+         * and out of protected mode, we need to fence the feature
Quoted 8 lines

hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 154

Quoted 5 lines
hw/s390x/sclp.c +5 -0
+         * here rather than when creating the CPU model.
+         */
+        if (s390_is_pv()) {
+            read_info->fac134 &= ~0x80;
+        }

Hmm, I thought firmware would handle exposing cpu features and similar, so we can't temper with it ....

Only the stfle bits.

Quoted 3 lines

Can we move that into s390_get_feat_block instead and check against the feature bit instead?

No because we want to have this active for !pv and disabled for pv but we switch this multiple times when doing boot/reboot.

#8 lore raw

Re: [PATCH 2/2] s390x: pv: Fix diag318 PV fencing

Quoted 46 lines · Christian Borntraeger
Quoted 34 lines · David Hildenbrand
Quoted 33 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")
---
 hw/s390x/sclp.c    | 10 ++++++++++
 target/s390x/kvm.c |  3 +--
 2 files changed, 11 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +5 -0
index 0cf2290826..69aba402d3 100644
@@ -22,6 +22,7 @@
 #include "hw/s390x/event-facility.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "hw/s390x/pv.h"
 
 static inline SCLPDevice *get_sclp_device(void)
 {
@@ -142,6 +143,15 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
         s390_get_feat_block(S390_FEAT_TYPE_SCLP_FAC134,
                             &read_info->fac134);
+        /*
+         * Diag318 is not available in protected mode and will result
+         * in an operation exception. As we can dynamically move in
+         * and out of protected mode, we need to fence the feature
Quoted 8 lines

hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 154

Quoted 5 lines
hw/s390x/sclp.c +5 -0
+         * here rather than when creating the CPU model.
+         */
+        if (s390_is_pv()) {
+            read_info->fac134 &= ~0x80;
+        }

Hmm, I thought firmware would handle exposing cpu features and similar, so we can't temper with it ....

Quoted 7 lines

Only the stfle bits.

Quoted 3 lines

Can we move that into s390_get_feat_block instead and check against the feature bit instead?

No because we want to have this active for !pv and disabled for pv but we switch this multiple times when doing boot/reboot.

Keeping the s390_is_pv() condition of course.

Signature · 3 lines
Thanks,

David / dhildenb
#9 lore raw

Re: [PATCH 2/2] s390x: pv: Fix diag318 PV fencing

In reply to David Hildenbrand
Quoted 34 lines · David Hildenbrand
Quoted 33 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")
---
 hw/s390x/sclp.c    | 10 ++++++++++
 target/s390x/kvm.c |  3 +--
 2 files changed, 11 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +5 -0
index 0cf2290826..69aba402d3 100644
@@ -22,6 +22,7 @@
 #include "hw/s390x/event-facility.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "hw/s390x/pv.h"
 
 static inline SCLPDevice *get_sclp_device(void)
 {
@@ -142,6 +143,15 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
         s390_get_feat_block(S390_FEAT_TYPE_SCLP_FAC134,
                             &read_info->fac134);
+        /*
+         * Diag318 is not available in protected mode and will result
+         * in an operation exception. As we can dynamically move in
+         * and out of protected mode, we need to fence the feature
Quoted 8 lines

hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 154

Quoted 5 lines
hw/s390x/sclp.c +5 -0
+         * here rather than when creating the CPU model.
+         */
+        if (s390_is_pv()) {
+            read_info->fac134 &= ~0x80;
+        }

Hmm, I thought firmware would handle exposing cpu features and similar, so we can't temper with it ....

STFLE data is indeed provided by the Ultravisor, but SCLP is still done by QEMU as that data is often not machine specific as visible in this case

Quoted 4 lines

Can we move that into s390_get_feat_block instead and check against the feature bit instead?

You mean fence inside the s390_get_feat_block() function?

#10 lore raw

Re: [PATCH 2/2] s390x: pv: Fix diag318 PV fencing

Quoted 5 lines
Quoted 4 lines

Can we move that into s390_get_feat_block instead and check against the feature bit instead?

You mean fence inside the s390_get_feat_block() function?

Yes, in

s390_fill_feat_block()

and to make it clean even in

s390_has_feat()

based on s390_is_pv().

Signature · 3 lines
Thanks,

David / dhildenb
#11 lore raw

PATCH 1/1 s390x: pv: Fix diag318 PV fencing

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")

---

If you're sure that this is what you want, then I'll send a v2 of the patch set.

---
 target/s390x/cpu_features.c | 5 +++++
 target/s390x/cpu_features.h | 4 ++++
 target/s390x/cpu_models.c   | 4 ++++
 target/s390x/kvm.c          | 3 +--
 4 files changed, 14 insertions(+), 2 deletions(-)
target/s390x/cpu_features.c +5 -0
index 31ea8df246..42fe0bf4ca 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "cpu_features.h"
+#include "hw/s390x/pv.h"
 
 #define DEF_FEAT(_FEAT, _NAME, _TYPE, _BIT, _DESC) \
     [S390_FEAT_##_FEAT] = {                        \
@@ -105,6 +106,10 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
         }
         feat = find_next_bit(features, S390_FEAT_MAX, feat + 1);
     }
+
+    if (type == S390_FEAT_TYPE_SCLP_FAC134 && s390_is_pv()) {
+        clear_be_bit(s390_feat_def(S390_FEAT_DIAG_318)->bit, data);
+    }
 }
 
 void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
target/s390x/cpu_features.h +4 -0
index ef52ffce83..87463f064d 100644
@@ -81,6 +81,10 @@ const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group);
 
 #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1))
 
+static inline void clear_be_bit(unsigned int bit_nr, uint8_t *array)
+{
+    array[bit_nr / 8] &= ~(0x80 >> (bit_nr % 8));
+}
 static inline void set_be_bit(unsigned int bit_nr, uint8_t *array)
 {
     array[bit_nr / 8] |= 0x80 >> (bit_nr % 8);
target/s390x/cpu_models.c +4 -0
index ca484bfda7..461e0b8f4a 100644
@@ -29,6 +29,7 @@
 #include "hw/pci/pci.h"
 #endif
 #include "qapi/qapi-commands-machine-target.h"
+#include "hw/s390x/pv.h"
 
 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
     {                                                                    \
@@ -238,6 +239,9 @@ bool s390_has_feat(S390Feat feat)
         }
         return 0;
     }
+    if (feat == S390_FEAT_DIAG_318 && s390_is_pv()) {
+        return false;
+    }
     return test_bit(feat, cpu->model->features);
 }
 
target/s390x/kvm.c +1 -2
index f13eff688c..baa070fdf7 100644
@@ -2498,8 +2498,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
      */
     set_bit(S390_FEAT_EXTENDED_LENGTH_SCCB, model->features);
 
-    /* DIAGNOSE 0x318 is not supported under protected virtualization */
-    if (!s390_is_pv() && kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
+    if (kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
         set_bit(S390_FEAT_DIAG_318, model->features);
     }
 
Signature · 1 line
2.25.1
#12 lore raw

Re: [PATCH] s390x: pv: Fix diag318 PV fencing

Quoted 11 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")

---

If you're sure that this is what you want, then I'll send a v2 of the patch set.

So that's going to be the first CPU feature that gets suppressed in PC mode - which seems to be what we want.

diag318_needed() will return false, resulting in vmstate_diag318() not being included in the migration stream (I know, we don't support migration yet for PV).

I don't see where diag318 would get reset during a reipl - is it expected to be persistent when switching in/out of PV, or when reipling etc..?

Quoted 83 lines
---
 target/s390x/cpu_features.c | 5 +++++
 target/s390x/cpu_features.h | 4 ++++
 target/s390x/cpu_models.c   | 4 ++++
 target/s390x/kvm.c          | 3 +--
 4 files changed, 14 insertions(+), 2 deletions(-)
target/s390x/cpu_features.c +5 -0
index 31ea8df246..42fe0bf4ca 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "cpu_features.h"
+#include "hw/s390x/pv.h"
 
 #define DEF_FEAT(_FEAT, _NAME, _TYPE, _BIT, _DESC) \
     [S390_FEAT_##_FEAT] = {                        \
@@ -105,6 +106,10 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
         }
         feat = find_next_bit(features, S390_FEAT_MAX, feat + 1);
     }
+
+    if (type == S390_FEAT_TYPE_SCLP_FAC134 && s390_is_pv()) {
+        clear_be_bit(s390_feat_def(S390_FEAT_DIAG_318)->bit, data);
+    }
 }
 
 void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
target/s390x/cpu_features.h +4 -0
index ef52ffce83..87463f064d 100644
@@ -81,6 +81,10 @@ const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group);
 
 #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1))
 
+static inline void clear_be_bit(unsigned int bit_nr, uint8_t *array)
+{
+    array[bit_nr / 8] &= ~(0x80 >> (bit_nr % 8));
+}
 static inline void set_be_bit(unsigned int bit_nr, uint8_t *array)
 {
     array[bit_nr / 8] |= 0x80 >> (bit_nr % 8);
target/s390x/cpu_models.c +4 -0
index ca484bfda7..461e0b8f4a 100644
@@ -29,6 +29,7 @@
 #include "hw/pci/pci.h"
 #endif
 #include "qapi/qapi-commands-machine-target.h"
+#include "hw/s390x/pv.h"
 
 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
     {                                                                    \
@@ -238,6 +239,9 @@ bool s390_has_feat(S390Feat feat)
         }
         return 0;
     }
+    if (feat == S390_FEAT_DIAG_318 && s390_is_pv()) {
+        return false;
+    }
     return test_bit(feat, cpu->model->features);
 }
 
target/s390x/kvm.c +1 -2
index f13eff688c..baa070fdf7 100644
@@ -2498,8 +2498,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
      */
     set_bit(S390_FEAT_EXTENDED_LENGTH_SCCB, model->features);
 
-    /* DIAGNOSE 0x318 is not supported under protected virtualization */
-    if (!s390_is_pv() && kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
+    if (kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
         set_bit(S390_FEAT_DIAG_318, model->features);
     }
 
Signature · 3 lines
Thanks,

David / dhildenb
#13 lore raw

Re: [PATCH] s390x: pv: Fix diag318 PV fencing

Quoted 13 lines · David Hildenbrand
Quoted 11 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")

---

If you're sure that this is what you want, then I'll send a v2 of the patch set.

Quoted 6 lines

So that's going to be the first CPU feature that gets suppressed in PC mode - which seems to be what we want.

diag318_needed() will return false, resulting in vmstate_diag318() not being included in the migration stream (I know, we don't support migration yet for PV).

Well either you have it and need to migrate it or you don't. As it doesn't persist over IPLs, that should not be a problem, no?

Quoted 4 lines

I don't see where diag318 would get reset during a reipl - is it expected to be persistent when switching in/out of PV, or when reipling etc..?

That's actually another bug we need to address. Diag318 will need to be reset on a diag308 reset instead of when doing the cpu resets...

Quoted 86 lines
Quoted 84 lines

---
 target/s390x/cpu_features.c | 5 +++++
 target/s390x/cpu_features.h | 4 ++++
 target/s390x/cpu_models.c   | 4 ++++
 target/s390x/kvm.c          | 3 +--
 4 files changed, 14 insertions(+), 2 deletions(-)
target/s390x/cpu_features.c +5 -0
index 31ea8df246..42fe0bf4ca 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "cpu_features.h"
+#include "hw/s390x/pv.h"
 
 #define DEF_FEAT(_FEAT, _NAME, _TYPE, _BIT, _DESC) \
     [S390_FEAT_##_FEAT] = {                        \
@@ -105,6 +106,10 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
         }
         feat = find_next_bit(features, S390_FEAT_MAX, feat + 1);
     }
+
+    if (type == S390_FEAT_TYPE_SCLP_FAC134 && s390_is_pv()) {
+        clear_be_bit(s390_feat_def(S390_FEAT_DIAG_318)->bit, data);
+    }
 }
 
 void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
target/s390x/cpu_features.h +4 -0
index ef52ffce83..87463f064d 100644
@@ -81,6 +81,10 @@ const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group);
 
 #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1))
 
+static inline void clear_be_bit(unsigned int bit_nr, uint8_t *array)
+{
+    array[bit_nr / 8] &= ~(0x80 >> (bit_nr % 8));
+}
 static inline void set_be_bit(unsigned int bit_nr, uint8_t *array)
 {
     array[bit_nr / 8] |= 0x80 >> (bit_nr % 8);
target/s390x/cpu_models.c +4 -0
index ca484bfda7..461e0b8f4a 100644
@@ -29,6 +29,7 @@
 #include "hw/pci/pci.h"
 #endif
 #include "qapi/qapi-commands-machine-target.h"
+#include "hw/s390x/pv.h"
 
 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
     {                                                                    \
@@ -238,6 +239,9 @@ bool s390_has_feat(S390Feat feat)
         }
         return 0;
     }
+    if (feat == S390_FEAT_DIAG_318 && s390_is_pv()) {
+        return false;
+    }
     return test_bit(feat, cpu->model->features);
 }
 
target/s390x/kvm.c +1 -2
index f13eff688c..baa070fdf7 100644
@@ -2498,8 +2498,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
      */
     set_bit(S390_FEAT_EXTENDED_LENGTH_SCCB, model->features);
 
-    /* DIAGNOSE 0x318 is not supported under protected virtualization */
-    if (!s390_is_pv() && kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
+    if (kvm_check_extension(kvm_state, KVM_CAP_S390_DIAG318)) {
         set_bit(S390_FEAT_DIAG_318, model->features);
     }
 
#14 lore raw

Re: [PATCH] s390x: pv: Fix diag318 PV fencing

Quoted 17 lines · Janosch Frank
Quoted 16 lines · David Hildenbrand
Quoted 11 lines · Janosch Frank

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")

---

If you're sure that this is what you want, then I'll send a v2 of the patch set.

So that's going to be the first CPU feature that gets suppressed in PC mode - which seems to be what we want.

Quoted 6 lines
Quoted 3 lines

diag318_needed() will return false, resulting in vmstate_diag318() not being included in the migration stream (I know, we don't support migration yet for PV).

Well either you have it and need to migrate it or you don't. As it doesn't persist over IPLs, that should not be a problem, no?

Okay, was confused by no finding a proper reset from our central reset handler. So this feels like the right thing to do.

Signature · 3 lines
Thanks,

David / dhildenb
#15 lore raw

Re: [PATCH] s390x: pv: Fix diag318 PV fencing

In reply to Janosch Frank
Quoted 32 lines · On Thu, 22 Oct 2020 04:23:12 -0400 Janosch Frank <[email protected]> wrote:

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")

---

If you're sure that this is what you want, then I'll send a v2 of the patch set.

---
 target/s390x/cpu_features.c | 5 +++++
 target/s390x/cpu_features.h | 4 ++++
 target/s390x/cpu_models.c   | 4 ++++
 target/s390x/kvm.c          | 3 +--
 4 files changed, 14 insertions(+), 2 deletions(-)
target/s390x/cpu_features.c +1 -0
index 31ea8df246..42fe0bf4ca 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "cpu_features.h"
+#include "hw/s390x/pv.h"
 
 #define DEF_FEAT(_FEAT, _NAME, _TYPE, _BIT, _DESC) \
     [S390_FEAT_##_FEAT] = {                        \

target/s390x/cpu_features.c void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type, · line 113

Quoted 8 lines
target/s390x/cpu_features.c +4 -0
@@ -105,6 +106,10 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
         }
         feat = find_next_bit(features, S390_FEAT_MAX, feat + 1);
     }
+
+    if (type == S390_FEAT_TYPE_SCLP_FAC134 && s390_is_pv()) {
+        clear_be_bit(s390_feat_def(S390_FEAT_DIAG_318)->bit, data);
+    }
 }

Sorry, I'm a little rusty with cpu models. Does this affect the outcome of the corresponding QMP commands?

I would guess it does...

Regards,
Halil

#16 lore raw

Re: [PATCH] s390x: pv: Fix diag318 PV fencing

Quoted 47 lines · Halil Pasic
Quoted 32 lines · On Thu, 22 Oct 2020 04:23:12 -0400 Janosch Frank <[email protected]> wrote:

Diag318 fencing needs to be determined on the current VM PV state and not on the state that the VM has when we create the CPU model.

Fixes fabdada935 ("s390: guest support for diagnose 0x318")

---

If you're sure that this is what you want, then I'll send a v2 of the patch set.

---
 target/s390x/cpu_features.c | 5 +++++
 target/s390x/cpu_features.h | 4 ++++
 target/s390x/cpu_models.c   | 4 ++++
 target/s390x/kvm.c          | 3 +--
 4 files changed, 14 insertions(+), 2 deletions(-)
target/s390x/cpu_features.c +1 -0
index 31ea8df246..42fe0bf4ca 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "cpu_features.h"
+#include "hw/s390x/pv.h"
 
 #define DEF_FEAT(_FEAT, _NAME, _TYPE, _BIT, _DESC) \
     [S390_FEAT_##_FEAT] = {                        \

target/s390x/cpu_features.c void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type, · line 113

Quoted 8 lines
target/s390x/cpu_features.c +4 -0
@@ -105,6 +106,10 @@ void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
         }
         feat = find_next_bit(features, S390_FEAT_MAX, feat + 1);
     }
+
+    if (type == S390_FEAT_TYPE_SCLP_FAC134 && s390_is_pv()) {
+        clear_be_bit(s390_feat_def(S390_FEAT_DIAG_318)->bit, data);
+    }
 }

Sorry, I'm a little rusty with cpu models. Does this affect the outcome of the corresponding QMP commands?

Quoted 1 line

I would guess it does...

No, it shouldn't.

Signature · 3 lines
Thanks,

David / dhildenb