powerpc: Check whether TM is available before running other tests
PATCH v2 1/1 powerpc: Check whether TM is available before running other tests
Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it is not available.
---
v2:
- Reworked the check for the "ibm,pa-features" and added a comment
- Use a dedicated variable "has_tm" instead of "i" in main()
Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for that!) from v1 here since I changed the code a little bit. So it would be great if you could have another quick look at this v2.
powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
powerpc/tm.c +42 -1
@@ -10,6 +10,41 @@#include <asm/processor.h> #include <asm/handlers.h> #include <asm/smp.h> +#include <asm/setup.h> +#include <devicetree.h> + +/* Check "ibm,pa-features" property of a CPU node for the TM flag */ +static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr) +{ +const struct fdt_property *prop; +int plen; + + prop =fdt_get_property (dt_fdt (), fdtnode,"ibm,pa-features" , &plen); +if (!prop)/* No features means TM is also not available */ +return ; +/* Sanity check for the property layout (first two bytes are header) */ +assert (plen >=8 && prop->data[1 ] =0 && prop->data[0 ] <= plen -2 ); + +/* +* The "Transactional Memory Category Support" flags are at byte +* offset 22 and 23 of the attribute type 0, so when adding the +* two bytes for the header, we've got to look at offset 24 for +* the TM support bit. +*/ +if (plen >=26 && prop->data[0 ] >=24 && (prop->data[24 ] &0x80 ) !=0 ) + *(int *)ptr +=1 ; +} + +/* Check whether all CPU nodes have the TM flag */ +static bool all_cpus_have_tm (void ) +{ +int ret; +int available =0 ; + + ret =dt_for_each_cpu_node (cpu_has_tm, &available); + +return ret =0 && available = nr_cpus; +}static int h_cede (void ) {
@@ -101,11 +136,17 @@ struct {int main (int argc,char **argv) { -bool all; +bool all, has_tm;int i;report_prefix_push ("tm" ); + has_tm =all_cpus_have_tm (); +report_xfail ("TM available in 'ibm,pa-features' property" , + !has_tm, has_tm); +if (!has_tm) +return report_summary (); + all = argc =1 || !strcmp (argv[1 ],"all" );for (i =0 ; hctests[i].name !=NULL ; i++) {
Signature · 1 line
1.8.3.1
Quoted 5 lines · Thomas Huth
Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it is not available.
Signed-off-by Thomas Huth <[email protected]>
Quoted 8 lines
---
v2:
- Reworked the check for the "ibm,pa-features" and added a comment
- Use a dedicated variable "has_tm" instead of "i" inmain()Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for that!) from v1 here since I changed the code a little bit. So it would be great if you could have another quick look at this v2.
Quoted 70 lines
powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)powerpc/tm.c +42
-1@@ -10,6 +10,41 @@#include <asm/processor.h> #include <asm/handlers.h> #include <asm/smp.h> +#include <asm/setup.h> +#include <devicetree.h> + +/* Check "ibm,pa-features" property of a CPU node for the TM flag */ +static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr) +{ +const struct fdt_property *prop; +int plen; + + prop =fdt_get_property (dt_fdt (), fdtnode,"ibm,pa-features" , &plen); +if (!prop)/* No features means TM is also not available */ +return ; +/* Sanity check for the property layout (first two bytes are header) */ +assert (plen >=8 && prop->data[1 ] =0 && prop->data[0 ] <= plen -2 ); + +/* +* The "Transactional Memory Category Support" flags are at byte +* offset 22 and 23 of the attribute type 0, so when adding the +* two bytes for the header, we've got to look at offset 24 for +* the TM support bit. +*/ +if (plen >=26 && prop->data[0 ] >=24 && (prop->data[24 ] &0x80 ) !=0 ) + *(int *)ptr +=1 ; +} + +/* Check whether all CPU nodes have the TM flag */ +static bool all_cpus_have_tm (void ) +{ +int ret; +int available =0 ; + + ret =dt_for_each_cpu_node (cpu_has_tm, &available); + +return ret =0 && available = nr_cpus; +}static int h_cede (void ) {@@ -101,11 +136,17 @@ struct {int main (int argc,char **argv) { -bool all; +bool all, has_tm;int i;report_prefix_push ("tm" ); + has_tm =all_cpus_have_tm (); +report_xfail ("TM available in 'ibm,pa-features' property" , + !has_tm, has_tm); +if (!has_tm) +return report_summary (); + all = argc =1 || !strcmp (argv[1 ],"all" );for (i =0 ; hctests[i].name !=NULL ; i++) {
Quoted 10 lines · Thomas Huth
Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it is not available.
Signed-off-by Thomas Huth <[email protected]>---
v2:
- Reworked the check for the "ibm,pa-features" and added a comment
- Use a dedicated variable "has_tm" instead of "i" inmain()
Quoted 7 lines
Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for that!) from v1 here since I changed the code a little bit. So it would be great if you could have another quick look at this v2.
powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
Quoted 5 lines · Thomas Huth
Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it is not available.
Signed-off-by Thomas Huth <[email protected]>
Quoted 8 lines
---
v2:
- Reworked the check for the "ibm,pa-features" and added a comment
- Use a dedicated variable "has_tm" instead of "i" inmain()Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for that!) from v1 here since I changed the code a little bit. So it would be great if you could have another quick look at this v2.
Comments below
Quoted 28 lines
powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)powerpc/tm.c +11
-0@@ -10,6 +10,41 @@ #include <asm/processor.h> #include <asm/handlers.h> #include <asm/smp.h> +#include <asm/setup.h> +#include <devicetree.h> + +/* Check "ibm,pa-features" property of a CPU node for the TM flag */ +static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr) +{ +const struct fdt_property *prop; +int plen; + + prop =fdt_get_property (dt_fdt (), fdtnode,"ibm,pa- features", &plen); +if (!prop)/* No features means TM is also not available */
powerpc/tm.c +2
-0+return ; +/* Sanity check for the property layout (first two bytes are header) */
powerpc/tm.c
Quoted 1 line
powerpc/tm.c +1
-0+ assert(plen >= 8 && prop->data[1] = 0 && prop->data[0] <> plen - 2);
Just curious as to why you're checking "prop->data[0] *<=* plen - 2" as isn't anything other than prop->data[0] *=* plen - 2 an error in the structure of ibm,pa-features and thus an error in the device-tree?
Quoted 11 lines
powerpc/tm.c +3
-0+ +/* +* The "Transactional Memory Category Support" flags are at byte
powerpc/tm.c +1
-0+ * offset 22 and 23 of the attribute type 0, so when addingthe
powerpc/tm.c +1
-0+ * two bytes for the header, we've got to look at offset 24for
powerpc/tm.c +3
-0+* the TM support bit. +*/ + if (plen >= 26 && prop->data[0] >= 24 && (prop->data[24] &
Quoted 1 line
0x80) != 0)
With the sanity checking you performed before isn't it sufficient to check "prop->data[0] >= 24" as this guarantees that "plen >= 26". If you were to change the above to "prop->data[0] = plen - 2" then either one of the two checks could be kept as sufficient to ensure the other.
Quoted 35 lines
powerpc/tm.c +13
-0+ *(int *)ptr +=1 ; +} + +/* Check whether all CPU nodes have the TM flag */ +static bool all_cpus_have_tm (void ) +{ +int ret; +int available =0 ; + + ret =dt_for_each_cpu_node (cpu_has_tm, &available); + +return ret =0 && available = nr_cpus; +}
static inth_cede(void)
{powerpc/tm.c +0
-0@@ -101,11 +136,17 @@ struct {
intmain(int argc, char **argv)
{powerpc/tm.c +1
-1-bool all; +bool all, has_tm;int i;
report_prefix_push("tm");powerpc/tm.c +6
-0+ has_tm =all_cpus_have_tm (); +report_xfail ("TM available in 'ibm,pa-features' property" , + !has_tm, has_tm); +if (!has_tm) +return report_summary (); +all = argc = 1 || !strcmp(argv[1], "all");
for (i = 0; hctests[i].name != NULL; i++) {
Quoted 40 lines · Suraj Jitindar Singh
Quoted 5 lines · Thomas Huth
Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it is not available.
Signed-off-by Thomas Huth <[email protected]>Quoted 8 lines
---
v2:
- Reworked the check for the "ibm,pa-features" and added a comment
- Use a dedicated variable "has_tm" instead of "i" inmain()Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for that!) from v1 here since I changed the code a little bit. So it would be great if you could have another quick look at this v2.
Comments below
Quoted 25 lines
powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)powerpc/tm.c +11
-0@@ -10,6 +10,41 @@#include <asm/processor.h> #include <asm/handlers.h> #include <asm/smp.h> +#include <asm/setup.h> +#include <devicetree.h> + +/* Check "ibm,pa-features" property of a CPU node for the TM flag */ +static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr) +{ +const struct fdt_property *prop; +int plen; + + prop =fdt_get_property (dt_fdt (), fdtnode,"ibm,pa- features", &plen); +if (!prop)/* No features means TM is also not available */
Quoted 8 lines
powerpc/tm.c
Quoted 4 lines
powerpc/tm.c +2
-0+return ; +/* Sanity check for the property layout (first two bytes are header) */
powerpc/tm.c +1
-0+ assert(plen >= 8 && prop->data[1] = 0 && prop->data[0] <>> plen - 2);Just curious as to why you're checking "prop->data[0] *<=* plen - 2" as isn't anything other than prop->data[0] *=* plen - 2 an error in the structure of ibm,pa-features and thus an error in the device-tree?
QEMU currently uses prop->data[0] = plen - 2 , but looking at the LoPAPR specification, it clearly defines this property as "prop-encoded-array: One or more attribute-descriptor(s)", so there could be two or more attributes encoded in this property. While there is currently only attribute type 0 defined in the LoPAPR specification, it could be extended with other types in the future. So with the "<=", the code is already prepared for this situation in the future.
Quoted 6 lines
Quoted 6 lines
powerpc/tm.c +3
-0+ +/* +* The "Transactional Memory Category Support" flags are at byte
powerpc/tm.c +1
-0+* offset 22 and 23 of the attribute type 0, so when adding the
Quoted 8 lines
Quoted 6 lines
powerpc/tm.c +1
-0+* two bytes for the header, we've got to look at offset 24 for
powerpc/tm.c +3
-0+* the TM support bit. +*/ + if (plen >= 26 && prop->data[0] >= 24 && (prop->data[24] &
0x80) != 0)With the sanity checking you performed before isn't it sufficient to check "prop->data[0] >= 24" as this guarantees that "plen >= 26".
You're right, since the assert() already checked that "data[0] <= plen - 2", and I also check that "data[0] >= 24", we can automatically assume that "24 <= plen - 2", i.e. "plen >= 26". I'll send a v3 with that check removed.
Thomas
Quoted 59 lines · Thomas Huth
Quoted 50 lines · Suraj Jitindar Singh
Quoted 12 lines · Thomas Huth
Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it is not available.
Signed-off-by Thomas Huth <[email protected]>---
v2:
- Reworked the check for the "ibm,pa-features" and added a comment
- Use a dedicated variable "has_tm" instead of "i" inmain()Quoted 4 lines
Laurent, Suraj, Andrew, I did not add your Reviewed-by (thanks for
that!) from v1 here since I changed the code a little bit. So it would be great if you could have another quick look at this v2.Comments below
Quoted 31 lines
powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)powerpc/tm.c +4
-0@@ -10,6 +10,41 @@ #include <asm/processor.h> #include <asm/handlers.h> #include <asm/smp.h> +#include <asm/setup.h> +#include <devicetree.h> + +/* Check "ibm,pa-features" property of a CPU node for the TM flag */
+static voidcpu_has_tm(int fdtnode, u32 regval __unused, void *ptr)powerpc/tm.c +5
-0+{ +const struct fdt_property *prop; +int plen; + + prop = fdt_get_property(dt_fdt(), fdtnode, "ibm,pa-features", &plen);
powerpc/tm.c +1
-0+if (!prop)/* No features means TM is also not available */
powerpc/tm.c +2
-0+return ; +/* Sanity check for the property layout (first two bytes are
Quoted 8 lines
Quoted 3 lines
header) */
powerpc/tm.c +1
-0+ assert(plen >= 8 && prop->data[1] = 0 && prop->data[0]<> > > plen - 2);
Just curious as to why you're checking "prop->data[0] *<=* plen - 2" as
isn't anything other than prop->data[0] *=* plen - 2 an error in the
structure of ibm,pa-features and thus an error in the device-tree?
Quoted 10 lines
QEMU currently uses prop->data[0] = plen - 2 , but looking at the LoPAPR specification, it clearly defines this property as "prop-encoded-array: One or more attribute-descriptor(s)", so there could be two or more attributes encoded in this property. While there is
currently only attribute type 0 defined in the LoPAPR specification, it
could be extended with other types in the future. So with the "<=", the
code is already prepared for this situation in the future.
Sorry I do see that now, my misunderstanding.
Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
powerpc/tm.c +3
-0+ +/* +* The "Transactional Memory Category Support" flags are at
bytepowerpc/tm.c +1
-0+ * offset 22 and 23 of the attribute type 0, so whenadding
thepowerpc/tm.c +1
-0+ * two bytes for the header, we've got to look at offset24
forQuoted 8 lines
Quoted 5 lines
powerpc/tm.c +3
-0+* the TM support bit. +*/ + if (plen >= 26 && prop->data[0] >= 24 && (prop->data[24]&
0x80) != 0)With the sanity checking you performed before isn't it sufficient to
check "prop->data[0] >= 24" as this guarantees that "plen >= 26".
Quoted 4 lines
You're right, since the
assert()already checked that "data[0] <= plen - 2", and I also check that "data[0] >= 24", we can automatically assume that "24 <= plen - 2", i.e. "plen >= 26". I'll send a v3 with that check removed.
Thanks
Quoted 3 lines
Thomas