Skip to contentSkip to conversation

hw/s390x: Add a more verbose comment about get_machine_class() and the wrappers

PATCH Applied Thomas Huth 3 participants 5 messages Jan 23, 2020 – Jan 24, 2020

lore
Share & tools
lore
#1 lore raw
In reply to Thomas Huth
Quoted 15 lines · On Thu, 23 Jan 2020 18:02:56 +0100 Thomas Huth <[email protected]> wrote:

While working on the "Enable adapter interruption suppression again" recently, I had to discover that the meaning of get_machine_class() and the related *_allowed() wrappers is not very obvious. Add a more verbose comment here to clarify how these should be used.

---
 hw/s390x/s390-virtio-ccw.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index e0e28139a2..7fb389f0e5 100644

hw/s390x/s390-virtio-ccw.c static inline void machine_set_dea_key_wrap(Object *obj, bool value, · line 514

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +7 -0
@@ -505,6 +505,18 @@ static inline void machine_set_dea_key_wrap(Object *obj, bool value,
 
 static S390CcwMachineClass *current_mc;
 
+/*
+ * Get the class of the s390-ccw-virtio machine that is currently in use.
+ * Note: libvirt is using the "none" machine to probe for the features of the
+ * host CPU, so in case this is called with the "none" machine, the function
+ * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
+ * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
+ * below return the correct default value for the "none" machine.

Maybe add a blank line here for readability? (Can do so while applying.)

Quoted 18 lines
hw/s390x/s390-virtio-ccw.c +5 -1
+ * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
+ * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
+ * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
+ * CPU initialization and s390_has_feat() later should be sufficient.
+ */
 static S390CcwMachineClass *get_machine_class(void)
 {
     if (unlikely(!current_mc)) {
@@ -521,19 +533,16 @@ static S390CcwMachineClass *get_machine_class(void)
 
 bool ri_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->ri_allowed;
 }
 
 bool cpu_model_allowed(void)
 {

hw/s390x/s390-virtio-ccw.c static S390CcwMachineClass *get_machine_class(void) · line 548

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +0 -2
-    /* for "none" machine this results in true */
     return get_machine_class()->cpu_model_allowed;
 }
 
 bool hpage_1m_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->hpage_1m_allowed;
 }
 

Looks good to me, but will wait for a review or two.

#0 lore raw

PATCH 1/1 hw/s390x: Add a more verbose comment about get_machine_class() and the wrappers

While working on the "Enable adapter interruption suppression again" recently, I had to discover that the meaning of get_machine_class() and the related *_allowed() wrappers is not very obvious. Add a more verbose comment here to clarify how these should be used.

---
 hw/s390x/s390-virtio-ccw.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -3
index e0e28139a2..7fb389f0e5 100644
@@ -505,6 +505,18 @@ static inline void machine_set_dea_key_wrap(Object *obj, bool value,
 
 static S390CcwMachineClass *current_mc;
 
+/*
+ * Get the class of the s390-ccw-virtio machine that is currently in use.
+ * Note: libvirt is using the "none" machine to probe for the features of the
+ * host CPU, so in case this is called with the "none" machine, the function
+ * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
+ * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
+ * below return the correct default value for the "none" machine.
+ * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
+ * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
+ * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
+ * CPU initialization and s390_has_feat() later should be sufficient.
+ */
 static S390CcwMachineClass *get_machine_class(void)
 {
     if (unlikely(!current_mc)) {
@@ -521,19 +533,16 @@ static S390CcwMachineClass *get_machine_class(void)
 
 bool ri_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->ri_allowed;
 }
 
 bool cpu_model_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->cpu_model_allowed;
 }
 
 bool hpage_1m_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->hpage_1m_allowed;
 }
 
Signature · 1 line
2.18.1
#2 lore raw
In reply to Cornelia Huck
Quoted 21 lines · Cornelia Huck
Quoted 18 lines · On Thu, 23 Jan 2020 18:02:56 +0100 Thomas Huth <[email protected]> wrote:

While working on the "Enable adapter interruption suppression again" recently, I had to discover that the meaning of get_machine_class() and the related *_allowed() wrappers is not very obvious. Add a more verbose comment here to clarify how these should be used.

---
 hw/s390x/s390-virtio-ccw.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index e0e28139a2..7fb389f0e5 100644
@@ -505,6 +505,18 @@ static inline void machine_set_dea_key_wrap(Object *obj, bool value,
 
 static S390CcwMachineClass *current_mc;
 
Quoted 9 lines

hw/s390x/s390-virtio-ccw.c static inline void machine_set_dea_key_wrap(Object *obj, bool value, · line 514

Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +7 -0
+/*
+ * Get the class of the s390-ccw-virtio machine that is currently in use.
+ * Note: libvirt is using the "none" machine to probe for the features of the
+ * host CPU, so in case this is called with the "none" machine, the function
+ * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
+ * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
+ * below return the correct default value for the "none" machine.

Maybe add a blank line here for readability? (Can do so while applying.)

Sure, fine for me!

Quoted 22 lines
Quoted 22 lines
hw/s390x/s390-virtio-ccw.c +5 -2
+ * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
+ * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
+ * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
+ * CPU initialization and s390_has_feat() later should be sufficient.
+ */
 static S390CcwMachineClass *get_machine_class(void)
 {
     if (unlikely(!current_mc)) {
@@ -521,19 +533,16 @@ static S390CcwMachineClass *get_machine_class(void)
 
 bool ri_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->ri_allowed;
 }
 
 bool cpu_model_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->cpu_model_allowed;
 }
 
Quoted 9 lines

hw/s390x/s390-virtio-ccw.c static S390CcwMachineClass *get_machine_class(void) · line 548

Quoted 6 lines
hw/s390x/s390-virtio-ccw.c +0 -1
 bool hpage_1m_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->hpage_1m_allowed;
 }
 

Looks good to me, but will wait for a review or two.

Thanks,
Thomas

Reviewed-by on v1 1/1
#3 lore raw
In reply to Thomas Huth
Quoted 44 lines · Thomas Huth

While working on the "Enable adapter interruption suppression again" recently, I had to discover that the meaning of get_machine_class() and the related *_allowed() wrappers is not very obvious. Add a more verbose comment here to clarify how these should be used.

---
 hw/s390x/s390-virtio-ccw.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -1
index e0e28139a2..7fb389f0e5 100644
@@ -505,6 +505,18 @@ static inline void machine_set_dea_key_wrap(Object *obj, bool value,
 
 static S390CcwMachineClass *current_mc;
 
+/*
+ * Get the class of the s390-ccw-virtio machine that is currently in use.
+ * Note: libvirt is using the "none" machine to probe for the features of the
+ * host CPU, so in case this is called with the "none" machine, the function
+ * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
+ * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
+ * below return the correct default value for the "none" machine.
+ * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
+ * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
+ * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
+ * CPU initialization and s390_has_feat() later should be sufficient.
+ */
 static S390CcwMachineClass *get_machine_class(void)
 {
     if (unlikely(!current_mc)) {
@@ -521,19 +533,16 @@ static S390CcwMachineClass *get_machine_class(void)
 
 bool ri_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->ri_allowed;
 }
 
 bool cpu_model_allowed(void)
 {

hw/s390x/s390-virtio-ccw.c static S390CcwMachineClass *get_machine_class(void) · line 548

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +0 -2
-    /* for "none" machine this results in true */
     return get_machine_class()->cpu_model_allowed;
 }
 
 bool hpage_1m_allowed(void)
 {
-    /* for "none" machine this results in true */
     return get_machine_class()->hpage_1m_allowed;
 }
 

Very helpful, thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
In reply to Thomas Huth
Quoted 9 lines · On Thu, 23 Jan 2020 18:02:56 +0100 Thomas Huth <[email protected]> wrote:

While working on the "Enable adapter interruption suppression again" recently, I had to discover that the meaning of get_machine_class() and the related *_allowed() wrappers is not very obvious. Add a more verbose comment here to clarify how these should be used.

---
 hw/s390x/s390-virtio-ccw.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Thanks, applied.