s390x: pv: Diag318 fixes
v2 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/206174979
V2:
* Moved fencing nto cpu model functions
* Added rev-by and acks
Janosch Frank (2):
s390x: pv: Remove sclp boundary checks
s390x: pv: Fix diag318 PV fencing
hw/s390x/sclp.c | 5 ----- target/s390x/cpu_features.c | 5 +++++ target/s390x/cpu_features.h | 4 ++++ target/s390x/cpu_models.c | 4 ++++ target/s390x/kvm.c | 3 +-- 5 files changed, 14 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 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.
--- hw/s390x/sclp.c | 5 ----- 1 file changed, 5 deletions(-)
hw/s390x/sclp.c +0 -5
@@ -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
PATCH v2 2/2 s390x: pv: Fix diag318 PV fencing
In reply to Janosch FrankDiag318 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH v2 2/2] s390x: pv: Fix diag318 PV fencing
Quoted 79 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.
Signed-off-by Janosch Frank <[email protected]>Reported-by Marc Hartmayer <[email protected]>Fixes fabdada935 ("s390: guest support for diagnose 0x318")--- 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@@ -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@@ -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@@ -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 +0
-0
target/s390x/kvm.c void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) · line 2504
Quoted 9 lines
target/s390x/kvm.c +1
-2@@ -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
Re: [PATCH v2 2/2] s390x: pv: Fix diag318 PV fencing
In reply to Janosch FrankQuoted 6 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.
Signed-off-by Janosch Frank <[email protected]>Reported-by Marc Hartmayer <[email protected]>Fixes fabdada935 ("s390: guest support for diagnose 0x318")
I prefer v1 as it is more obvious what happens, but this looks fine as well and as David prefers this let us go with this one.
Quoted 82 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@@ -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@@ -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@@ -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@@ -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); }
Re: [PATCH v2 2/2] s390x: pv: Fix diag318 PV fencing
In reply to Janosch FrankQuoted 89 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.
Signed-off-by Janosch Frank <[email protected]>Reported-by Marc Hartmayer <[email protected]>Fixes fabdada935 ("s390: guest support for diagnose 0x318")--- 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@@ -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@@ -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@@ -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@@ -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
Quoted 23 lines · Janosch Frank
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_fixesCI:
https://gitlab.com/frankja/qemu/-/pipelines/206174979V2:
* Moved fencing nto cpu model functions
* Added rev-by and acksJanosch Frank (2):
s390x: pv: Remove sclp boundary checks
s390x: pv: Fix diag318 PV fencing
Quoted 7 lines
hw/s390x/sclp.c | 5 ----- target/s390x/cpu_features.c | 5 +++++ target/s390x/cpu_features.h | 4 ++++ target/s390x/cpu_models.c | 4 ++++ target/s390x/kvm.c | 3 +-- 5 files changed, 14 insertions(+), 7 deletions(-)
Thanks for correcting this. You've certainly received plenty of reviews and ack's, but since this touches code I worked on:
Signature · 4 lines
Regards, Collin Stay safe and stay healthy
Cornelia Huck
AppliedQuoted 23 lines · On Thu, 22 Oct 2020 06:31:33 -0400 Janosch Frank <[email protected]> wrote:
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_fixesCI:
https://gitlab.com/frankja/qemu/-/pipelines/206174979V2:
* Moved fencing nto cpu model functions
* Added rev-by and acksJanosch Frank (2):
s390x: pv: Remove sclp boundary checks
s390x: pv: Fix diag318 PV fencing
Quoted 7 lines
hw/s390x/sclp.c | 5 ----- target/s390x/cpu_features.c | 5 +++++ target/s390x/cpu_features.h | 4 ++++ target/s390x/cpu_models.c | 4 ++++ target/s390x/kvm.c | 3 +-- 5 files changed, 14 insertions(+), 7 deletions(-)
Thanks, applied.