cleanup error handling in kvmppc_read_int_cpu_dt()
cover cleanup error handling in kvmppc_read_int_cpu_dt()
Hi,
This series is a cleanup that fixes the issues observed by Markus Armbruster in the review of jianchunfu's patch:
https://lists.gnu.org/archive/html/qemu-devel/2022-06/msg05393.html
I've also included jianchunfu's patch, with the relevant bits, in the series.
Daniel Henrique Barboza (8):
target/ppc/kvm.c: do not return -1 on uint64_t return target/ppc: add errp to kvmppc_read_int_cpu_dt() target/ppc: use g_autofree in kvmppc_read_int_cpu_dt() target/ppc: use Error pointer in kvmppc_get_clockfreq() ppc440_bamboo.c: handle clock freq read error in load_device_tree sam460ex.c: use CPU_FREQ if unable to read DT clock e500.c: use PLATFORM_CLK_FREQ_HZ if unable to read clock freq from DT spapr.c: handle clock freq read errors in spapr_dt_cpu()
jianchunfu (1):
target/ppc: Add error reporting when opening file fails
hw/ppc/e500.c | 8 +++++++- hw/ppc/ppc440_bamboo.c | 17 ++++++++++++++--- hw/ppc/sam460ex.c | 8 +++++++- hw/ppc/spapr.c | 12 +++++++++++- include/hw/ppc/spapr.h | 1 + target/ppc/kvm.c | 33 +++++++++++++++++---------------- target/ppc/kvm_ppc.h | 2 +- 7 files changed, 58 insertions(+), 23 deletions(-)
Signature · 1 line
2.36.1
PATCH 1/9 target/ppc/kvm.c: do not return -1 on uint64_t return
kvmppc_read_int_dt() and kvmppc_read_int_cpu_dt() return an uint64_t, while returning -1 when an error occurs. kvmppc_read_int_cpu_dt() claims that it will return 0 if anything wrong happens, but it's returning -1 if kmvppc_find_cpu_dt() fails.
The elephant in the room is that returning -1 while claiming that the return is uint64_t, results in 18446744073709551615 for the callers. This reason alone is enough to not return -1 under these circunstances.
We'll still have the problem of having to deal with a '0' return that might, or might not be, an error. We'll make this distintion clear in the next patches.
--- target/ppc/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/ppc/kvm.c +2 -2
@@ -1907,7 +1907,7 @@ static uint64_t kvmppc_read_int_dt(const char *filename) f =fopen (filename,"rb" );if (!f) { -return -1 ; +return 0 ; } len =fread (&u,1 ,sizeof (u), f);
@@ -1934,7 +1934,7 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname)uint64_t val;if (kvmppc_find_cpu_dt (buf,sizeof (buf))) { -return -1 ; +return 0 ; } tmp =g_strdup_printf ("%s/%s" , buf, propname);
Signature · 1 line
2.36.1
PATCH 2/9 target/ppc: add errp to kvmppc_read_int_cpu_dt()
In reply to Daniel Henrique BarbozaThe function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to kvmppc_read_int_cpu_dt() that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.
--- target/ppc/kvm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
target/ppc/kvm.c +9 -7
@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename)/* * Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) {char buf[PATH_MAX ], *tmp;uint64_t val;if (kvmppc_find_cpu_dt (buf,sizeof (buf))) { +error_setg (errp,"Failed to read CPU property %s" , propname);return 0 ; }
@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname)uint64_t kvmppc_get_clockfreq (void ) { -return kvmppc_read_int_cpu_dt ("clock-frequency" ); +return kvmppc_read_int_cpu_dt ("clock-frequency" ,NULL ); }static int kvmppc_get_dec_bits (void ) { -int nr_bits =kvmppc_read_int_cpu_dt ("ibm,dec-bits" ); +int nr_bits =kvmppc_read_int_cpu_dt ("ibm,dec-bits" ,NULL );if (nr_bits >0 ) {return nr_bits;
@@ -2336,8 +2338,8 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on)static void kvmppc_host_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc); -uint32_t dcache_size =kvmppc_read_int_cpu_dt ("d-cache-size" ); -uint32_t icache_size =kvmppc_read_int_cpu_dt ("i-cache-size" ); +uint32_t dcache_size =kvmppc_read_int_cpu_dt ("d-cache-size" ,NULL ); +uint32_t icache_size =kvmppc_read_int_cpu_dt ("i-cache-size" ,NULL );/* Now fix up the class with information we can query from the host */ pcc->pvr =mfpvr ();
Signature · 1 line
2.36.1
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 39 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/ppc/kvm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename)/* * Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) {char buf[PATH_MAX ], *tmp;uint64_t val;if (kvmppc_find_cpu_dt (buf,sizeof (buf))) { +error_setg (errp,"Failed to read CPU property %s" , propname);return 0 ; }
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1951
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname)uint64_t kvmppc_get_clockfreq (void ) { -return kvmppc_read_int_cpu_dt ("clock-frequency" ); +return kvmppc_read_int_cpu_dt ("clock-frequency" ,NULL );
This should be fatal. no ?
C.
Quoted 20 lines
target/ppc/kvm.c +3
-3}static int kvmppc_get_dec_bits (void ) { -int nr_bits =kvmppc_read_int_cpu_dt ("ibm,dec-bits" ); +int nr_bits =kvmppc_read_int_cpu_dt ("ibm,dec-bits" ,NULL );if (nr_bits >0 ) {return nr_bits;@@ -2336,8 +2338,8 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on)static void kvmppc_host_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc); -uint32_t dcache_size =kvmppc_read_int_cpu_dt ("d-cache-size" ); -uint32_t icache_size =kvmppc_read_int_cpu_dt ("i-cache-size" ); +uint32_t dcache_size =kvmppc_read_int_cpu_dt ("d-cache-size" ,NULL ); +uint32_t icache_size =kvmppc_read_int_cpu_dt ("i-cache-size" ,NULL );/* Now fix up the class with information we can query from the host */ pcc->pvr =mfpvr ();
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }
Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
Thanks,
Daniel
Quoted 22 lines
C.
Quoted 17 lines
target/ppc/kvm.c +3
-3} static int kvmppc_get_dec_bits(void) { - int nr_bits = kvmppc_read_int_cpu_dt("ibm,dec-bits"); + int nr_bits = kvmppc_read_int_cpu_dt("ibm,dec-bits", NULL); if (nr_bits > 0) { return nr_bits;@@ -2336,8 +2338,8 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on) static void kvmppc_host_cpu_class_init(ObjectClass *oc, void *data) { PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc); - uint32_t dcache_size = kvmppc_read_int_cpu_dt("d-cache-size"); - uint32_t icache_size = kvmppc_read_int_cpu_dt("i-cache-size"); + uint32_t dcache_size = kvmppc_read_int_cpu_dt("d-cache-size", NULL); + uint32_t icache_size = kvmppc_read_int_cpu_dt("i-cache-size", NULL); /* Now fix up the class with information we can query from the host */ pcc->pvr = mfpvr();
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 49 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
Quoted 8 lines
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
C.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 54 lines · Cédric Le Goater
Quoted 53 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
Quoted 8 lines
Quoted 4 lines
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
I can assert that with pSeries we can safely error_fatal if the DT doesn't contain 'clock-frequency' since it's on PAPR under this section:
"C.6.2 OF Root Note
This section defines additional properties and methods associated with PAPR platforms that OSs expect to find in the root node."
I interpret this as "if there's no clock-frequency just bail out".
Thanks,
Daniel
Quoted 3 lines
C.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
In reply to Cédric Le GoaterQuoted 54 lines · Cédric Le Goater
Quoted 53 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
Quoted 8 lines
Quoted 4 lines
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 61 lines · Mark Cave-Ayland
Quoted 59 lines · Cédric Le Goater
Quoted 57 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
Quoted 5 lines
Quoted 3 lines
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
Oh. Sorry. and I still have access to a real G5 running the latest debian. I should give it a try one day.
Thanks
C.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 62 lines · Cédric Le Goater
Quoted 61 lines · Mark Cave-Ayland
Quoted 59 lines · Cédric Le Goater
Quoted 57 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
Oh. Sorry. and I still have access to a real G5 running the latest debian. I should give it a try one day.
I gave KVM a try on a :
cpu : PPC970MP, altivec supported
clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
processor : 1
cpu : PPC970MP, altivec supported
clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
timebase : 33333333
platform : PowerMac
model : PowerMac11,2
machine : PowerMac11,2
motherboard : PowerMac11,2 MacRISC4 Power Macintosh
detected as : 337 (PowerMac G5 Dual Core)
pmac flags : 00000000
L2 cache : 1024K unified
pmac-generation : NewWorldrunning debian with kernel 5.18.0-2-powerpc64. With the installed QEMU 7.0.0,
qemu-system-ppc64 -M mac99 -cpu host -accel kvm ...
doesn't go very far. Program exception is quickly reached and host says:
[56450.118422] Couldn't emulate instruction 0x00000000 (op 0 xop 0)
[56450.119060] kvmppc_exit_pr_progint: emulation at 100 failed (00000000)Anything special I should know ?
Thanks,
C.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 94 lines · Cédric Le Goater
Quoted 63 lines · Cédric Le Goater
Quoted 62 lines · Mark Cave-Ayland
Quoted 60 lines · Cédric Le Goater
Quoted 58 lines · Daniel Henrique Barboza
Quoted 37 lines · Cédric Le Goater
Quoted 36 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const charQuoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char · line 1951
Quoted 5 lines
target/ppc/kvm.c +1
-1*propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
Oh. Sorry. and I still have access to a real G5 running the latest debian. I should give it a try one day.
I gave KVM a try on a :
cpu : PPC970MP, altivec supported clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
processor : 1
cpu : PPC970MP, altivec supported clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
timebase : 33333333
platform : PowerMac
model : PowerMac11,2
machine : PowerMac11,2
motherboard : PowerMac11,2 MacRISC4 Power Macintosh detected as : 337 (PowerMac G5 Dual Core) pmac flags : 00000000
L2 cache : 1024K unified
pmac-generation : NewWorldrunning debian with kernel 5.18.0-2-powerpc64. With the installed QEMU 7.0.0,
Quoted 8 lines
qemu-system-ppc64 -M mac99 -cpu host -accel kvm ...
doesn't go very far. Program exception is quickly reached and host says:
[56450.118422] Couldn't emulate instruction 0x00000000 (op 0 xop 0) [56450.119060] kvmppc_exit_pr_progint: emulation at 100 failed (00000000)Anything special I should know ?
As I don't have access to a G5 I've never tried that, however the qemu-system-ppc64 mac99 is wired differently to the qemu-system-ppc mac99 machine so I wouldn't be surprised if something is broken there.
My normal test for MacOS is something like:
qemu-system-ppc -M mac99 -accel kvm -hda macos104.img
Can you try qemu-system-ppc and see if it is any better? If not then I can fire up the G4 and get the git hashes for my last known working configuration.
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 104 lines · Mark Cave-Ayland
Quoted 93 lines · Cédric Le Goater
Quoted 62 lines · Cédric Le Goater
Quoted 61 lines · Mark Cave-Ayland
Quoted 59 lines · Cédric Le Goater
Quoted 57 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
Oh. Sorry. and I still have access to a real G5 running the latest debian. I should give it a try one day.
I gave KVM a try on a :
cpu : PPC970MP, altivec supported clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
processor : 1
cpu : PPC970MP, altivec supported clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
timebase : 33333333
platform : PowerMac
model : PowerMac11,2
machine : PowerMac11,2
motherboard : PowerMac11,2 MacRISC4 Power Macintosh detected as : 337 (PowerMac G5 Dual Core) pmac flags : 00000000
L2 cache : 1024K unified
pmac-generation : NewWorldrunning debian with kernel 5.18.0-2-powerpc64. With the installed QEMU 7.0.0,
Quoted 8 lines
qemu-system-ppc64 -M mac99 -cpu host -accel kvm ...
doesn't go very far. Program exception is quickly reached and host says:
[56450.118422] Couldn't emulate instruction 0x00000000 (op 0 xop 0) [56450.119060] kvmppc_exit_pr_progint: emulation at 100 failed (00000000)Anything special I should know ?
Quoted 7 lines
As I don't have access to a G5 I've never tried that, however the qemu-system-ppc64 mac99 is wired differently to the qemu-system-ppc mac99 machine so I wouldn't be surprised if something is broken there.
My normal test for MacOS is something like:
qemu-system-ppc -M mac99 -accel kvm -hda macos104.img
Can you try qemu-system-ppc and see if it is any better? If not then I can fire up the G4 and get the git hashes for my last known working configuration.
Same issue with 32bit.
Thanks,
C.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 11 lines · Cédric Le Goater
Quoted 9 lines
Quoted 1 line
Anything special I should know ?
As I don't have access to a G5 I've never tried that, however the qemu-system-ppc64 mac99 is wired differently to the qemu-system-ppc mac99 machine so I wouldn't be surprised if something is broken there.
My normal test for MacOS is something like:
qemu-system-ppc -M mac99 -accel kvm -hda macos104.img
Can you try qemu-system-ppc and see if it is any better? If not then I can fire up the G4 and get the git hashes for my last known working configuration.
Same issue with 32bit.
I've just fired up my G4 to test this again, pulled the latest QEMU git master and confirmed that I have a working setup with the details below:
Host kernel: (5.1.0-rc2+)
commit a3ac7917b73070010c05b4485b8582a6c9cd69b6
Author: Linus Torvalds <[email protected]> Date: Mon Mar 25 14:49:00 2019 -0700
Guest kernel: (4.14.0-3-powerpc)
using Debian ports debian-9.0-powerpc-NETINST-1.iso
Command line:
./qemu-system-ppc [-M mac99] -accel kvm -cdrom /home/mca/images/debian-9.0-powerpc-NETINST-1.iso -boot d -nographic
However if I switch to using the latest Debian ports debian-10.0.0-powerpc-NETINST-1.iso then I get a failure:
[ 0.198565] BUG: Unable to handle kernel data access on read at 0xbb0030d4 [ 0.205152] Faulting instruction address: 0x0001b0c4 [ 0.210175] Oops: Kernel access of bad area, sig: 11 [#1] [ 0.214933] BE PAGE_SIZE=4K MMU=Hash PowerMac [ 0.218226] Modules linked in: [ 0.220746] CPU: 0 PID: 0 Comm: swapper Not tainted 5.6.0-2-powerpc #1 Debian 5.6.14-1 [ 0.226967] NIP: 0001b0c4 LR: 000030d4 CTR: 00000000 [ 0.230869] REGS: c7fb5908 TRAP: 0300 Not tainted (5.6.0-2-powerpc Debian 5.6.14-1) [ 0.236844] MSR: 00001012 <ME,DR,RI> CR: 24002820 XER: 20000000 [ 0.242096] DAR: bb0030d4 DSISR: 40000000 [ 0.242096] GPR00: c0044e70 c7fb59c0 c0b26510 c7fb5f48 bb0030d4 40000000 00000000 00000001 [ 0.242096] GPR08: ff340038 bb0030d4 00001032 c7fb59c0 00000000 00000000 00000000 00000004 [ 0.242096] GPR16: 029c61f0 029c5d68 07c5cd08 00000001 029dd844 fffffffd fff55d10 42000000 [ 0.242096] GPR24: c0af6704 c0b20d94 00000000 00000000 c0bd862c 00000000 00000000 0000000d [ 0.271138] NIP [0001b0c4] 0x1b0c4 [ 0.273978] LR [000030d4] 0x30d4 [ 0.276410] Call Trace: [ 0.278812] Instruction dump: [ 0.281219] 55290206 XXXXXXXX XXXXXXXX XXXXXXXX 4c00012c XXXXXXXX XXXXXXXX XXXXXXXX [ 0.287561] 419f0028 XXXXXXXX XXXXXXXX XXXXXXXX 81690000 XXXXXXXX XXXXXXXX XXXXXXXX [ 0.293922] ---[ end trace 3a9d775bab6f3340 ]--- [ 0.297491] [ 1.284408] Kernel panic - not syncing: Attempted to kill the idle task! [ 1.290027] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
Decompressing the initrd takes quite a long time, but I think this is the issue that was recently discussed on the mailing list?
I think the next step should be to move my host kernel forward to a more current version with the working debian-9.0-powerpc-NETINST-1.iso and see if it is able to boot without any problems.
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 23 lines · Mark Cave-Ayland
Quoted 11 lines · Cédric Le Goater
Quoted 9 lines
Quoted 1 line
Anything special I should know ?
As I don't have access to a G5 I've never tried that, however the qemu-system-ppc64 mac99 is wired differently to the qemu-system-ppc mac99 machine so I wouldn't be surprised if something is broken there.
My normal test for MacOS is something like:
qemu-system-ppc -M mac99 -accel kvm -hda macos104.img
Can you try qemu-system-ppc and see if it is any better? If not then I can fire up the G4 and get the git hashes for my last known working configuration.
Same issue with 32bit.
I've just fired up my G4 to test this again, pulled the latest QEMU git master and confirmed that I have a working setup with the details below:
Host kernel: (5.1.0-rc2+)
commita3ac7917b73070010c05b4485b8582a6c9cd69b6Author: Linus Torvalds <[email protected]> Date: Mon Mar 25 14:49:00 2019 -0700Guest kernel: (4.14.0-3-powerpc)
using Debian ports debian-9.0-powerpc-NETINST-1.iso
Quoted 6 lines
Command line:
./qemu-system-ppc [-M mac99] -accel kvm -cdrom/home/mca/images/debian-9.0-powerpc-NETINST-1.iso-boot d -nographicHowever if I switch to using the latest Debian ports debian-10.0.0-powerpc-NETINST-1.iso then I get a failure:
[ 0.198565] BUG: Unable to handle kernel data access on read at 0xbb0030d4
What is or should be at this address and why does the kernel access it? By default I see nothing mapped there. Do you need more RAM? Maybe the default 128 MB is not enough for newer kernels? I've seen such problem with other OSes before.
Regards,
BALATON Zoltan
Quoted 35 lines
[ 0.205152] Faulting instruction address: 0x0001b0c4 [ 0.210175] Oops: Kernel access of bad area, sig: 11 [#1] [ 0.214933] BE PAGE_SIZE=4K MMU=Hash PowerMac [ 0.218226] Modules linked in: [ 0.220746] CPU: 0 PID: 0 Comm: swapper Not tainted 5.6.0-2-powerpc #1 Debian 5.6.14-1 [ 0.226967] NIP: 0001b0c4 LR: 000030d4 CTR: 00000000 [ 0.230869] REGS: c7fb5908 TRAP: 0300 Not tainted (5.6.0-2-powerpc Debian 5.6.14-1) [ 0.236844] MSR: 00001012 <ME,DR,RI> CR: 24002820 XER: 20000000 [ 0.242096] DAR: bb0030d4 DSISR: 40000000 [ 0.242096] GPR00: c0044e70 c7fb59c0 c0b26510 c7fb5f48 bb0030d4 40000000 00000000 00000001 [ 0.242096] GPR08: ff340038 bb0030d4 00001032 c7fb59c0 00000000 00000000 00000000 00000004 [ 0.242096] GPR16: 029c61f0 029c5d68 07c5cd08 00000001 029dd844 fffffffd fff55d10 42000000 [ 0.242096] GPR24: c0af6704 c0b20d94 00000000 00000000 c0bd862c 00000000 00000000 0000000d [ 0.271138] NIP [0001b0c4] 0x1b0c4 [ 0.273978] LR [000030d4] 0x30d4 [ 0.276410] Call Trace: [ 0.278812] Instruction dump: [ 0.281219] 55290206 XXXXXXXX XXXXXXXX XXXXXXXX 4c00012c XXXXXXXX XXXXXXXX XXXXXXXX [ 0.287561] 419f0028 XXXXXXXX XXXXXXXX XXXXXXXX 81690000 XXXXXXXX XXXXXXXX XXXXXXXX [ 0.293922] ---[ end trace 3a9d775bab6f3340 ]--- [ 0.297491] [ 1.284408] Kernel panic - not syncing: Attempted to kill the idle task! [ 1.290027] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---Decompressing the initrd takes quite a long time, but I think this is the issue that was recently discussed on the mailing list?
I think the next step should be to move my host kernel forward to a more current version with the working debian-9.0-powerpc-NETINST-1.iso and see if it is able to boot without any problems.
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 24 lines · BALATON Zoltan
Quoted 23 lines · Mark Cave-Ayland
Quoted 11 lines · Cédric Le Goater
Quoted 9 lines
Quoted 1 line
Anything special I should know ?
As I don't have access to a G5 I've never tried that, however the qemu-system-ppc64 mac99 is wired differently to the qemu-system-ppc mac99 machine so I wouldn't be surprised if something is broken there.
My normal test for MacOS is something like:
qemu-system-ppc -M mac99 -accel kvm -hda macos104.img
Can you try qemu-system-ppc and see if it is any better? If not then I can fire up the G4 and get the git hashes for my last known working configuration.
Same issue with 32bit.
I've just fired up my G4 to test this again, pulled the latest QEMU git master and confirmed that I have a working setup with the details below:
Host kernel: (5.1.0-rc2+)
commita3ac7917b73070010c05b4485b8582a6c9cd69b6
Author: Linus Torvalds <[email protected]> Date: Mon Mar 25 14:49:00 2019 -0700Guest kernel: (4.14.0-3-powerpc)
using Debian ports debian-9.0-powerpc-NETINST-1.iso
Quoted 8 lines
Quoted 6 lines
Command line:
./qemu-system-ppc [-M mac99] -accel kvm -cdrom/home/mca/images/debian-9.0-powerpc-NETINST-1.iso-boot d -nographicHowever if I switch to using the latest Debian ports debian-10.0.0-powerpc-NETINST-1.iso then I get a failure:
[ 0.198565] BUG: Unable to handle kernel data access on read at
0xbb0030d4What is or should be at this address and why does the kernel access it? By default I see nothing mapped there. Do you need more RAM? Maybe the default 128 MB is not enough for newer kernels? I've seen such problem with other OSes before.
Yeah I've already tried increasing the RAM and it makes no difference. It wouldn't surprise me if it's a kernel issue since Christophe has done a lot of low-level work for 32-bit PPC including moving routines from asm to C and KASAN. I'm away for a few days but I will do a bisect when I get back, unless anyone beats me to it...
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
In reply to Mark Cave-AylandQuoted 22 lines · Mark Cave-Ayland
Quoted 21 lines · Cédric Le Goater
I gave KVM a try on a :
cpu : PPC970MP, altivec supported clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
processor : 1
cpu : PPC970MP, altivec supported clock : 2000.000000MHz
revision : 1.0 (pvr 0044 0100)
timebase : 33333333
platform : PowerMac
model : PowerMac11,2
machine : PowerMac11,2
motherboard : PowerMac11,2 MacRISC4 Power Macintosh detected as : 337 (PowerMac G5 Dual Core) pmac flags : 00000000
L2 cache : 1024K unified
pmac-generation : NewWorldrunning debian with kernel 5.18.0-2-powerpc64. With the installed QEMU 7.0.0,
Quoted 7 lines
Quoted 7 lines
qemu-system-ppc64 -M mac99 -cpu host -accel kvm ...
doesn't go very far. Program exception is quickly reached and host says:
[56450.118422] Couldn't emulate instruction 0x00000000 (op 0 xop 0) [56450.119060] kvmppc_exit_pr_progint: emulation at 100 failed(00000000)
Maybe try with -d unimp,guest_errors at least or some more debug options to find why it gets a 0 opcode. It probably takes a wrong exception somewhere? But with KVM maybe this does not give more info and you need to enable KVM tracing or run in a debgger instead?
In the past I've managed to run Linux on qemu-system-ppc64 -M mac99 with TCG and trace KVM-PR guest within that but I forgot the details. If I remember correctly I've found there's some problem with emulated KVM and nobody replied on the list so I could not go further. It's also quite slow that way so not the best way to test.
Quoted 3 lines
Quoted 1 line
Anything special I should know ?
As I don't have access to a G5 I've never tried that, however the qemu-system-ppc64 mac99 is wired differently to the qemu-system-ppc mac99 machine so I wouldn't be surprised if something is broken there.
I think you can get the 32 bit version with qemu-system-ppc64 by adding -cpu G4 as it decides based on CPU type what to emulate. By default -M mac99 with qemu-system-ppc64 is a G5 Mac but OpenBIOS still gives it the same device-tree as the G4 one so guests might be confused by this. Linux did not seem to care that much though.
Quoted 3 lines
My normal test for MacOS is something like:
qemu-system-ppc -M mac99 -accel kvm -hda macos104.img
This should really be -M mac99,via=pmu as that is the closest to real hardware currently.
This mac99 machine is quite confusing and maybe the only reason we need separate ppc and ppc64 qemu executables. What do you think about deprecating it and splitting it into something like powermac3_1 for mac99,via=pmu with G4 CPU, powermac7_2 for the G5 one and maybe some powerbookX_Y for the mac99 with CUDA instead of PMU but I don't know if that actually exists in real hardware? Also rename g3beige to the actual model name at the same time. This would clear this up and avoid the confusing options that we have now because of everything emulated by the single mac99 machine.
Regards,
BALATON Zoltan
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
In reply to Mark Cave-AylandQuoted 61 lines · Mark Cave-Ayland
Quoted 59 lines · Cédric Le Goater
Quoted 57 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
Quoted 5 lines
Quoted 3 lines
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
We can't just error_fatal by default then.
Each machine should be able to determine how to handle this missing DT element. If I want to error_fatal for pseries then I can do so in patch 9/9, but other than that I'll keep the existing behavior.
Thanks,
Daniel
Quoted 5 lines
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 67 lines · Daniel Henrique Barboza
Quoted 66 lines · Mark Cave-Ayland
Quoted 63 lines · Cédric Le Goater
Quoted 50 lines · Daniel Henrique Barboza
Quoted 37 lines · Cédric Le Goater
Quoted 36 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const charQuoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1951
Quoted 5 lines
target/ppc/kvm.c +1
-1*propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
Quoted 8 lines
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Quoted 8 lines
Quoted 1 line
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
We can't just
error_fatalby default then.Each machine should be able to determine how to handle this missing DT element. If I want to
error_fatalfor pseries then I can do so in patch 9/9, but other than that I'll keep the existing behavior.
This wouldn't be a problem for the Mac machines since they pass the clock frequency from QEMU to OpenBIOS using the fw_cfg interface which builds the tree itself rather than using FDT. So I think using error_fatal should still be fine.
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Quoted 71 lines · Mark Cave-Ayland
Quoted 69 lines · Daniel Henrique Barboza
Quoted 66 lines · Mark Cave-Ayland
Quoted 54 lines · Cédric Le Goater
Quoted 53 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
Quoted 8 lines
Quoted 4 lines
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
Quoted 7 lines
Quoted 5 lines
We can't just
error_fatalby default then.Each machine should be able to determine how to handle this missing DT element. If I want to
error_fatalfor pseries then I can do so in patch 9/9, but other than that I'll keep the existing behavior.This wouldn't be a problem for the Mac machines since they pass the clock frequency from QEMU to OpenBIOS using the
fw_cfginterface which builds the tree itself rather than using FDT. So I think usingerror_fatalshould still be fine.
One less board that would break if we error_fatal in that condition then :)
In theory, for boards that doesn't care/doesn't support KVM, this function shouldn't be even called. I guess I'll move the series into this direction instead.
Daniel
Quoted 5 lines
ATB,
Mark.
Re: [PATCH 2/9] target/ppc: add errp to kvmppc_read_int_cpu_dt()
In reply to Daniel Henrique BarbozaQuoted 68 lines · Daniel Henrique Barboza
Quoted 65 lines · Mark Cave-Ayland
Quoted 62 lines · Cédric Le Goater
Quoted 49 lines · Daniel Henrique Barboza
Quoted 36 lines · Cédric Le Goater
Quoted 35 lines · Daniel Henrique Barboza
The function can't just return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error.
Add an Error pointer to
kvmppc_read_int_cpu_dt()that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)target/ppc/kvm.c +5
-3@@ -1925,15 +1925,17 @@ static uint64_t kvmppc_read_int_dt(const char *filename) /** Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the format) +* integer (32-bit or 64-bit). Returns 0 and set errp if anything goes +* wrong (can't find or open the property, or doesn't understand the +* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { + error_setg(errp, "Failed to read CPU property %s", propname); return 0; }Quoted 8 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_cpu_dt(const char *propname) · line 1950
Quoted 5 lines
target/ppc/kvm.c +1
-1@@ -1946,12 +1948,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL);This should be fatal. no ?
Quoted 8 lines
I'm not sure. I went under the assumption that there might be some weird condition where 'clock-frequency' might be missing from the DT, and this is why we're not exiting out immediately.
That said, the advantage of turning this into fatal is that we won't need all the other patches that handles error on this function. We're going to assume that if 'clock-frequency' is missing then we can't boot. I'm okay with that.
I think so. Some machines behave badly when 'clock-frequency' is bogus, division by zero, no console, etc. We could check easily with pseries which is the only KVM PPC platform.
Quoted 8 lines
Quoted 1 line
Well not quite true ;) I haven't tested it during the last release cycle, but the Mac machines were still working fine to boot OS X with KVM-PR on my G4 Mac Mini last time I checked.
We can't just
error_fatalby default then.Each machine should be able to determine how to handle this missing DT element. If I want to
error_fatalfor pseries then I can do so in patch 9/9, but other than that I'll keep the existing behavior.
Or add an errp here :
hw/ppc/e500.c: clock_freq = kvmppc_get_clockfreq(); hw/ppc/sam460ex.c: clock_freq = kvmppc_get_clockfreq(); hw/ppc/ppc440_bamboo.c: clock_freq = kvmppc_get_clockfreq(); hw/ppc/spapr.c: uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000;
C.
PATCH 3/9 target/ppc: Add error reporting when opening file fails
In reply to Daniel Henrique BarbozaFrom: jianchunfu <[email protected]>
Add error reporting before return when opening file fails in kvmppc_read_int_dt().
--- target/ppc/kvm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/kvm.c +3 -2
@@ -1896,7 +1896,7 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)return 0 ; } -static uint64_t kvmppc_read_int_dt (const char *filename) +static uint64_t kvmppc_read_int_dt (const char *filename,Error **errp) {union {uint32_t v32;
@@ -1907,6 +1907,7 @@ static uint64_t kvmppc_read_int_dt(const char *filename) f =fopen (filename,"rb" );if (!f) { +error_setg (errp,"Error opening %s: %s" , filename,strerror (errno));return 0 ; }
@@ -1940,7 +1941,7 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) } tmp =g_strdup_printf ("%s/%s" , buf, propname); - val =kvmppc_read_int_dt (tmp); + val =kvmppc_read_int_dt (tmp, errp);g_free (tmp);return val;
Signature · 1 line
2.36.1
Re: [PATCH 3/9] target/ppc: Add error reporting when opening file fails
Quoted 8 lines · Daniel Henrique Barboza
From: jianchunfu <[email protected]>
Add error reporting before return when opening file fails in
kvmppc_read_int_dt().Signed-off-by jianchunfu <[email protected]>[danielhb: use error_setg() instead of fprintf]Signed-off-by Daniel Henrique Barboza <[email protected]>
Thanks,
C.
Quoted 34 lines
--- target/ppc/kvm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/ppc/kvm.c +3
-2@@ -1896,7 +1896,7 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)return 0 ; } -static uint64_t kvmppc_read_int_dt (const char *filename) +static uint64_t kvmppc_read_int_dt (const char *filename,Error **errp) {union {uint32_t v32;@@ -1907,6 +1907,7 @@ static uint64_t kvmppc_read_int_dt(const char *filename) f =fopen (filename,"rb" );if (!f) { +error_setg (errp,"Error opening %s: %s" , filename,strerror (errno));return 0 ; }@@ -1940,7 +1941,7 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) } tmp =g_strdup_printf ("%s/%s" , buf, propname); - val =kvmppc_read_int_dt (tmp); + val =kvmppc_read_int_dt (tmp, errp);g_free (tmp);return val;
PATCH 4/9 target/ppc: use g_autofree in kvmppc_read_int_cpu_dt()
In reply to Daniel Henrique BarbozaThis spares us a g_free() call. Let's also not use 'val' and return the value of kvmppc_read_int_dt() directly.
--- target/ppc/kvm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
target/ppc/kvm.c +3 -5
@@ -1932,8 +1932,8 @@ static uint64_t kvmppc_read_int_dt(const char *filename, Error **errp)*/ static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { -char buf[PATH_MAX ], *tmp; -uint64_t val; + g_autofree char *tmp = NULL; +char buf[PATH_MAX ];if (kvmppc_find_cpu_dt (buf,sizeof (buf))) {error_setg (errp,"Failed to read CPU property %s" , propname);
@@ -1941,10 +1941,8 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) } tmp =g_strdup_printf ("%s/%s" , buf, propname); - val =kvmppc_read_int_dt (tmp, errp); -g_free (tmp); -return val; +return kvmppc_read_int_dt (tmp, errp); }uint64_t kvmppc_get_clockfreq (void )
Signature · 1 line
2.36.1
Re: [PATCH 4/9] target/ppc: use g_autofree in kvmppc_read_int_cpu_dt()
Quoted 13 lines · Daniel Henrique Barboza
This spares us a
g_free()call. Let's also not use 'val' and return the value ofkvmppc_read_int_dt()directly.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/ppc/kvm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)target/ppc/kvm.c +0
-0
target/ppc/kvm.c static uint64_t kvmppc_read_int_dt(const char *filename, Error **errp) · line 1935
Quoted 6 lines
target/ppc/kvm.c +1
-2@@ -1932,8 +1932,8 @@ static uint64_t kvmppc_read_int_dt(const char *filename, Error **errp)*/ static uint64_t kvmppc_read_int_cpu_dt (const char *propname,Error **errp) { -char buf[PATH_MAX ], *tmp; -uint64_t val; + g_autofree char *tmp = NULL;
I think you need to assign g_autofree variables where they are declared.
C.
Quoted 16 lines
target/ppc/kvm.c +2
-3+char buf[PATH_MAX ];if (kvmppc_find_cpu_dt (buf,sizeof (buf))) {error_setg (errp,"Failed to read CPU property %s" , propname);@@ -1941,10 +1941,8 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) } tmp =g_strdup_printf ("%s/%s" , buf, propname); - val =kvmppc_read_int_dt (tmp, errp); -g_free (tmp); -return val; +return kvmppc_read_int_dt (tmp, errp); }uint64_t kvmppc_get_clockfreq (void )
Re: [PATCH 4/9] target/ppc: use g_autofree in kvmppc_read_int_cpu_dt()
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines · Daniel Henrique Barboza
This spares us a
g_free()call. Let's also not use 'val' and return the value ofkvmppc_read_int_dt()directly.Signed-off-by Daniel Henrique Barboza <[email protected]>---
target/ppc/kvm.c| 8 +++-----1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 13 lines
target/ppc/kvm.c static uint64_t kvmppc_read_int_dt(const char *filename, Error **errp) · line 1935
Quoted 11 lines
target/ppc/kvm.c +1
-2@@ -1932,8 +1932,8 @@ static uint64_t kvmppc_read_int_dt(const char *filename, Error **errp)*/ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) { - char buf[PATH_MAX], *tmp; - uint64_t val; + g_autofree char *tmp = NULL;I think you need to assign
g_autofreevariables where they are declared.
We need to initialize the var with something, not necessarily with the value we're going to use. Initializing with 'NULL' works.
Thanks,
Daniel
Quoted 16 lines
C.
Quoted 12 lines
target/ppc/kvm.c +2
-3+ char buf[PATH_MAX]; if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { error_setg(errp, "Failed to read CPU property %s", propname);@@ -1941,10 +1941,8 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) } tmp = g_strdup_printf("%s/%s", buf, propname); - val = kvmppc_read_int_dt(tmp, errp); - g_free(tmp); - return val; + return kvmppc_read_int_dt(tmp, errp); } uint64_t kvmppc_get_clockfreq(void)
PATCH 5/9 target/ppc: use Error pointer in kvmppc_get_clockfreq()
In reply to Daniel Henrique BarbozaCallers will then be able to handle any errors that might happen when reading the clock frequency.
--- hw/ppc/e500.c | 2 +- hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/sam460ex.c | 2 +- hw/ppc/spapr.c | 2 +- target/ppc/kvm.c | 4 ++-- target/ppc/kvm_ppc.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
hw/ppc/e500.c +1 -1
@@ -405,7 +405,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,if (kvm_enabled ()) {/* Read out host's frequencies */ - clock_freq =kvmppc_get_clockfreq (); + clock_freq =kvmppc_get_clockfreq (NULL ); tb_freq =kvmppc_get_tbfreq ();/* indicate KVM hypercall interface */
hw/ppc/ppc440_bamboo.c +1 -1
@@ -107,7 +107,7 @@ static int bamboo_load_device_tree(hwaddr addr,* the correct frequencies. */ if (kvm_enabled ()) { tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (); + clock_freq =kvmppc_get_clockfreq (NULL ); } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
hw/ppc/sam460ex.c +1 -1
@@ -179,7 +179,7 @@ static int sam460ex_load_device_tree(hwaddr addr,* the correct frequencies. */ if (kvm_enabled ()) { tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (); + clock_freq =kvmppc_get_clockfreq (NULL ); } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
hw/ppc/spapr.c +1 -1
@@ -654,7 +654,7 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, 0xffffffff, 0xffffffff};uint32_t tbfreq =kvm_enabled () ?kvmppc_get_tbfreq () :SPAPR_TIMEBASE_FREQ ; -uint32_t cpufreq =kvm_enabled () ?kvmppc_get_clockfreq () :1000000000 ; +uint32_t cpufreq =kvm_enabled () ?kvmppc_get_clockfreq (NULL ) :1000000000 ;uint32_t page_sizes_prop[64 ];size_t page_sizes_prop_size;unsigned int smp_threads = ms->smp.threads;
target/ppc/kvm.c +2 -2
@@ -1945,9 +1945,9 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp)return kvmppc_read_int_dt (tmp, errp); } -uint64_t kvmppc_get_clockfreq (void ) +uint64_t kvmppc_get_clockfreq (Error **errp) { -return kvmppc_read_int_cpu_dt ("clock-frequency" ,NULL ); +return kvmppc_read_int_cpu_dt ("clock-frequency" , errp); }static int kvmppc_get_dec_bits (void )
target/ppc/kvm_ppc.h +1 -1
@@ -14,7 +14,7 @@#ifdef CONFIG_KVM uint32_t kvmppc_get_tbfreq (void ); -uint64_t kvmppc_get_clockfreq (void ); +uint64_t kvmppc_get_clockfreq (Error **errp);bool kvmppc_get_host_model (char **buf);bool kvmppc_get_host_serial (char **buf);int kvmppc_get_hasidle (CPUPPCState *env);
Signature · 1 line
2.36.1
Re: [PATCH 5/9] target/ppc: use Error pointer in kvmppc_get_clockfreq()
Quoted 18 lines · Daniel Henrique Barboza
Callers will then be able to handle any errors that might happen when reading the clock frequency.
Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/ppc/e500.c | 2 +- hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/sam460ex.c | 2 +- hw/ppc/spapr.c | 2 +- target/ppc/kvm.c | 4 ++-- target/ppc/kvm_ppc.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)hw/ppc/e500.c +0
-0
hw/ppc/e500.c static int ppce500_load_device_tree(PPCE500MachineState *pms, · line 408
Quoted 5 lines
hw/ppc/e500.c +1
-1@@ -405,7 +405,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,if (kvm_enabled ()) {/* Read out host's frequencies */ - clock_freq =kvmppc_get_clockfreq (); + clock_freq =kvmppc_get_clockfreq (NULL );
Can't we use error_fatal instead of NULL ?
Thanks,
C.
Quoted 71 lines
hw/ppc/e500.c +0
-0tb_freq =kvmppc_get_tbfreq ();/* indicate KVM hypercall interface */ hw/ppc/ppc440_bamboo.c +1
-1@@ -107,7 +107,7 @@ static int bamboo_load_device_tree(hwaddr addr,* the correct frequencies. */ if (kvm_enabled ()) { tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (); + clock_freq =kvmppc_get_clockfreq (NULL ); } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",hw/ppc/sam460ex.c +1
-1@@ -179,7 +179,7 @@ static int sam460ex_load_device_tree(hwaddr addr,* the correct frequencies. */ if (kvm_enabled ()) { tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (); + clock_freq =kvmppc_get_clockfreq (NULL ); } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",hw/ppc/spapr.c +1
-1@@ -654,7 +654,7 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, 0xffffffff, 0xffffffff};uint32_t tbfreq =kvm_enabled () ?kvmppc_get_tbfreq () :SPAPR_TIMEBASE_FREQ ; -uint32_t cpufreq =kvm_enabled () ?kvmppc_get_clockfreq () :1000000000 ; +uint32_t cpufreq =kvm_enabled () ?kvmppc_get_clockfreq (NULL ) :1000000000 ;uint32_t page_sizes_prop[64 ];size_t page_sizes_prop_size;unsigned int smp_threads = ms->smp.threads;target/ppc/kvm.c +2
-2@@ -1945,9 +1945,9 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp)return kvmppc_read_int_dt (tmp, errp); } -uint64_t kvmppc_get_clockfreq (void ) +uint64_t kvmppc_get_clockfreq (Error **errp) { -return kvmppc_read_int_cpu_dt ("clock-frequency" ,NULL ); +return kvmppc_read_int_cpu_dt ("clock-frequency" , errp); }static int kvmppc_get_dec_bits (void )target/ppc/kvm_ppc.h +1
-1@@ -14,7 +14,7 @@#ifdef CONFIG_KVM uint32_t kvmppc_get_tbfreq (void ); -uint64_t kvmppc_get_clockfreq (void ); +uint64_t kvmppc_get_clockfreq (Error **errp);bool kvmppc_get_host_model (char **buf);bool kvmppc_get_host_serial (char **buf);int kvmppc_get_hasidle (CPUPPCState *env);
PATCH 6/9 ppc440_bamboo.c: handle clock freq read error in load_device_tree
In reply to Daniel Henrique BarbozaLet's put the default clock and timebase freq value in macros for better readability. Use PPC440EP_CLOCK_FREQ as the default value of 'clock_freq' if kvmppc_get_clockfreq() throws an error.
--- hw/ppc/ppc440_bamboo.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
hw/ppc/ppc440_bamboo.c +14 -3
@@ -50,6 +50,10 @@#define PPC440EP_SDRAM_NR_BANKS 4 +#define PPC440EP_TB_FREQ 400000000 +#define PPC440EP_CLOCK_FREQ 400000000 + +static const ram_addr_t ppc440ep_sdram_bank_sizes[] = {256 * MiB,128 * MiB,64 * MiB,32 * MiB,16 * MiB,8 * MiB,0 };
@@ -67,8 +71,8 @@ static int bamboo_load_device_tree(hwaddr addr,char *filename;int fdt_size;void *fdt; -uint32_t tb_freq =400000000 ; -uint32_t clock_freq =400000000 ; +uint32_t tb_freq =PPC440EP_TB_FREQ ; +uint32_t clock_freq =PPC440EP_CLOCK_FREQ ; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {
@@ -106,8 +110,15 @@ static int bamboo_load_device_tree(hwaddr addr,* directly access the timebase without host involvement, we must expose * the correct frequencies. */ if (kvm_enabled ()) { +Error *local_err =NULL ; + tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (NULL ); + clock_freq =kvmppc_get_clockfreq (&local_err); + +/* Use default clock if we're unable to read it from the DT */ +if (local_err) { + clock_freq =PPC440EP_CLOCK_FREQ ; + } } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
Signature · 1 line
2.36.1
Re: [PATCH 6/9] ppc440_bamboo.c: handle clock freq read error in load_device_tree
Quoted 37 lines · Daniel Henrique Barboza
Let's put the default clock and timebase freq value in macros for better readability. Use
PPC440EP_CLOCK_FREQas the default value of 'clock_freq' ifkvmppc_get_clockfreq()throws an error.Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/ppc/ppc440_bamboo.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)hw/ppc/ppc440_bamboo.c +6
-2@@ -50,6 +50,10 @@#define PPC440EP_SDRAM_NR_BANKS 4 +#define PPC440EP_TB_FREQ 400000000 +#define PPC440EP_CLOCK_FREQ 400000000 + +static const ram_addr_t ppc440ep_sdram_bank_sizes[] = {256 * MiB,128 * MiB,64 * MiB,32 * MiB,16 * MiB,8 * MiB,0 };@@ -67,8 +71,8 @@ static int bamboo_load_device_tree(hwaddr addr,char *filename;int fdt_size;void *fdt; -uint32_t tb_freq =400000000 ; -uint32_t clock_freq =400000000 ; +uint32_t tb_freq =PPC440EP_TB_FREQ ; +uint32_t clock_freq =PPC440EP_CLOCK_FREQ ; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE );if (!filename) {@@ -106,8 +110,15 @@ static int bamboo_load_device_tree(hwaddr addr,* directly access the timebase without host involvement, we must expose
hw/ppc/ppc440_bamboo.c static int bamboo_load_device_tree(hwaddr addr, · line 119
Quoted 10 lines
hw/ppc/ppc440_bamboo.c +6
-1* the correct frequencies. */ if (kvm_enabled ()) { +Error *local_err =NULL ; + tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (NULL ); + clock_freq =kvmppc_get_clockfreq (&local_err); + +/* Use default clock if we're unable to read it from the DT */ +if (local_err) {
may be report the error to the user ?
Quoted 5 lines
hw/ppc/ppc440_bamboo.c +2
-0+ clock_freq =PPC440EP_CLOCK_FREQ ; + } } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
PATCH 7/9 sam460ex.c: use CPU_FREQ if unable to read DT clock
In reply to Daniel Henrique BarbozaFallback 'clock_freq' to CPU_FREQ if kvmppc_get_clockfreq() fails to read the clock from the DT.
--- hw/ppc/sam460ex.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/ppc/sam460ex.c +7 -1
@@ -178,8 +178,14 @@ static int sam460ex_load_device_tree(hwaddr addr,* directly access the timebase without host involvement, we must expose * the correct frequencies. */ if (kvm_enabled ()) { +Error *local_err =NULL ; + tb_freq =kvmppc_get_tbfreq (); - clock_freq =kvmppc_get_clockfreq (NULL ); + clock_freq =kvmppc_get_clockfreq (&local_err); + +if (local_err) { + clock_freq =CPU_FREQ ; + } } qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
Signature · 1 line
2.36.1
PATCH 8/9 e500.c: use PLATFORM_CLK_FREQ_HZ if unable to read clock freq from DT
In reply to Daniel Henrique BarbozaDefault 'clock_freq' to PLATFORM_CLK_FREQ_HZ if kvmppc_get_clockfreq() fails to read the clock from the DT.
--- hw/ppc/e500.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/ppc/e500.c +7 -1
@@ -404,8 +404,14 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,fprintf (stderr,"couldn't set /chosen/bootargs\n" );if (kvm_enabled ()) { +Error *local_err =NULL ; +/* Read out host's frequencies */ - clock_freq =kvmppc_get_clockfreq (NULL ); + clock_freq =kvmppc_get_clockfreq (&local_err); +if (local_err) { + clock_freq =PLATFORM_CLK_FREQ_HZ ; + } + tb_freq =kvmppc_get_tbfreq ();/* indicate KVM hypercall interface */
Signature · 1 line
2.36.1
PATCH 9/9 spapr.c: handle clock freq read errors in spapr_dt_cpu()
In reply to Daniel Henrique BarbozaLet's put the default spapr clock value in a SPAPR_CLOCK_FREQ for better readability.
After that, make 'cpufreq' default to SPAPR_CLOCK_FREQ if kvmppc_get_clockfreq() fails to read the clock from the DT.
--- hw/ppc/spapr.c | 12 +++++++++++- include/hw/ppc/spapr.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +11 -1
@@ -654,7 +654,7 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, 0xffffffff, 0xffffffff};uint32_t tbfreq =kvm_enabled () ?kvmppc_get_tbfreq () :SPAPR_TIMEBASE_FREQ ; -uint32_t cpufreq =kvm_enabled () ?kvmppc_get_clockfreq (NULL ) :1000000000 ; +uint32_t cpufreq =SPAPR_CLOCK_FREQ ;uint32_t page_sizes_prop[64 ];size_t page_sizes_prop_size;unsigned int smp_threads = ms->smp.threads;
@@ -699,6 +699,16 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, }_FDT ((fdt_setprop_cell (fdt, offset,"timebase-frequency" , tbfreq))); + +if (kvm_enabled ()) { +Error *local_err =NULL ; + + cpufreq =kvmppc_get_clockfreq (&local_err); +if (local_err) { + cpufreq =SPAPR_CLOCK_FREQ ; + } + } +_FDT ((fdt_setprop_cell (fdt, offset,"clock-frequency" , cpufreq)));_FDT ((fdt_setprop_cell (fdt, offset,"slb-size" , cpu->hash64_opts->slb_size)));_FDT ((fdt_setprop_cell (fdt, offset,"ibm,slb-size" , cpu->hash64_opts->slb_size)));
include/hw/ppc/spapr.h +1 -0
@@ -26,6 +26,7 @@ typedef struct SpaprPendingHpt SpaprPendingHpt;#define SPAPR_ENTRY_POINT 0x100#define SPAPR_TIMEBASE_FREQ 512000000ULL +#define SPAPR_CLOCK_FREQ 1000000000ULL#define TYPE_SPAPR_RTC "spapr-rtc"
Signature · 1 line
2.36.1