ppc: Fixes for fadump feature
v2 cover ppc: Fixes for fadump feature
Hi,
This patch series fixes the coverity issues on the Fadump feature patch series by Aditya [1].
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Changelog
=========
v2:
+ addressed review comments from Philippe
Shivang Upadhyay (2):
hw/ppc: Fix missing return on allocation failure hw/ppc: Fix memory leak in get_cpu_state_data()
hw/ppc/spapr_fadump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
PATCH v2 1/2 hw/ppc: Fix missing return on allocation failure
Fixes coverity (CID 1642026)
--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/spapr_fadump.c +1 -0
@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region)qemu_log_mask (LOG_GUEST_ERROR ,"FADump: Failed allocating memory (size: %zu) for copying" " reserved memory regions\n" ,FADUMP_CHUNK_SIZE ); +return false; } num_chunks =ceil ((src_len *1.0f ) /FADUMP_CHUNK_SIZE );
Signature · 1 line
2.51.0
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 17 lines · Shivang Upadhyay
Fixes coverity (CID 1642026)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA-SPmsnU1wzsWxBcFC=ZM_DDhPEg1N4iX9Q4bL1xOnwBg@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)hw/ppc/spapr_fadump.c +0
-0
hw/ppc/spapr_fadump.c static bool do_preserve_region(FadumpSection *region) · line 234
Quoted 1 line
hw/ppc/spapr_fadump.c +0
-0@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region) qemu_log_mask(LOG_GUEST_ERROR,
FWIW host heap exhaustion is not really a *guest* error, because the guest can not control it.
Quoted 6 lines
hw/ppc/spapr_fadump.c +1
-0"FADump: Failed allocating memory (size: %zu) for copying" " reserved memory regions\n", FADUMP_CHUNK_SIZE); +return false; } num_chunks =ceil ((src_len *1.0f ) /FADUMP_CHUNK_SIZE );
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Shivang Upadhyay
Fixes coverity (CID 1642026)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA-SPmsnU1wzsWxBcFC=ZM_DDhPEg1N4iX9Q4bL1xOnwBg@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)
Quoted 9 lines
hw/ppc/spapr_fadump.c static bool do_preserve_region(FadumpSection *region) · line 234
Quoted 6 lines
hw/ppc/spapr_fadump.c +0
-0@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region) qemu_log_mask(LOG_GUEST_ERROR,FWIW host heap exhaustion is not really a *guest* error, because the guest can not control it.
Hi, Philippe
Thanks for the review. There are following log level defined in log.h
.... #define CPU_LOG_TB_OUT_ASM (1u << 0) #define CPU_LOG_TB_IN_ASM (1u << 1) #define CPU_LOG_TB_OP (1u << 2) #define CPU_LOG_TB_OP_OPT (1u << 3) #define CPU_LOG_INT (1u << 4) #define CPU_LOG_EXEC (1u << 5) #define CPU_LOG_PCALL (1u << 6) #define CPU_LOG_TB_CPU (1u << 8) #define CPU_LOG_RESET (1u << 9) #define LOG_UNIMP (1u << 10) #define LOG_GUEST_ERROR (1u << 11) #define CPU_LOG_MMU (1u << 12) #define CPU_LOG_TB_NOCHAIN (1u << 13) #define CPU_LOG_PAGE (1u << 14) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1u << 16) #define CPU_LOG_TB_FPU (1u << 17) #define CPU_LOG_PLUGIN (1u << 18) /* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1u << 19) #define LOG_PER_THREAD (1u << 20) #define CPU_LOG_TB_VPU (1u << 21) #define LOG_TB_OP_PLUGIN (1u << 22) #define LOG_INVALID_MEM (1u << 23) ....
Which one do you recommend we use? or May we introduce a LOG_HOST_ERROR, if that's more appropriate.
Thanks
~Shivang.
Quoted 7 lines
Quoted 6 lines
hw/ppc/spapr_fadump.c +1
-0"FADump: Failed allocating memory (size: %zu) for copying" " reserved memory regions\n", FADUMP_CHUNK_SIZE); +return false; } num_chunks =ceil ((src_len *1.0f ) /FADUMP_CHUNK_SIZE );
Harsh Prateek Bora
Reviewed-byRe: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 57 lines · Shivang Upadhyay
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Shivang Upadhyay
Fixes coverity (CID 1642026)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA-SPmsnU1wzsWxBcFC=ZM_DDhPEg1N4iX9Q4bL1xOnwBg@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)Quoted 9 lines
hw/ppc/spapr_fadump.c static bool do_preserve_region(FadumpSection *region) · line 234
Quoted 6 lines
hw/ppc/spapr_fadump.c +0
-0@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region) qemu_log_mask(LOG_GUEST_ERROR,FWIW host heap exhaustion is not really a *guest* error, because the guest can not control it.
Hi, Philippe
Thanks for the review. There are following log level defined in
log.h.... #define CPU_LOG_TB_OUT_ASM (1u << 0) #define CPU_LOG_TB_IN_ASM (1u << 1) #define CPU_LOG_TB_OP (1u << 2) #define CPU_LOG_TB_OP_OPT (1u << 3) #define CPU_LOG_INT (1u << 4) #define CPU_LOG_EXEC (1u << 5) #define CPU_LOG_PCALL (1u << 6) #define CPU_LOG_TB_CPU (1u << 8) #define CPU_LOG_RESET (1u << 9) #define LOG_UNIMP (1u << 10) #define LOG_GUEST_ERROR (1u << 11) #define CPU_LOG_MMU (1u << 12) #define CPU_LOG_TB_NOCHAIN (1u << 13) #define CPU_LOG_PAGE (1u << 14) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1u << 16) #define CPU_LOG_TB_FPU (1u << 17) #define CPU_LOG_PLUGIN (1u << 18) /* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1u << 19) #define LOG_PER_THREAD (1u << 20) #define CPU_LOG_TB_VPU (1u << 21) #define LOG_TB_OP_PLUGIN (1u << 22) #define LOG_INVALID_MEM (1u << 23) ....
Quoted 2 lines
Which one do you recommend we use? or May we introduce a
LOG_HOST_ERROR, if that's more appropriate.
I think it would be better to have LOG_INSUFF_MEM for this case, but let's hear from Philippe and others for suggestions.
Since it's unlreated to the coverity fix and can be taken separately, so:
Quoted 10 lines
Thanks
~Shivang.Quoted 7 lines
Quoted 6 lines
hw/ppc/spapr_fadump.c +1
-0"FADump: Failed allocating memory (size: %zu) for copying" " reserved memory regions\n", FADUMP_CHUNK_SIZE); +return false; } num_chunks =ceil ((src_len *1.0f ) /FADUMP_CHUNK_SIZE );
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 63 lines · Harsh Prateek Bora
Quoted 57 lines · Shivang Upadhyay
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Shivang Upadhyay
Fixes coverity (CID 1642026)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA-SPmsnU1wzsWxBcFC=ZM_DDhPEg1N4iX9Q4bL1xOnwBg@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)Quoted 9 lines
hw/ppc/spapr_fadump.c static bool do_preserve_region(FadumpSection *region) · line 234
Quoted 6 lines
hw/ppc/spapr_fadump.c +0
-0@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region) qemu_log_mask(LOG_GUEST_ERROR,FWIW host heap exhaustion is not really a *guest* error, because the guest can not control it.
Hi, Philippe
Thanks for the review. There are following log level defined in
log.h.... #define CPU_LOG_TB_OUT_ASM (1u << 0) #define CPU_LOG_TB_IN_ASM (1u << 1) #define CPU_LOG_TB_OP (1u << 2) #define CPU_LOG_TB_OP_OPT (1u << 3) #define CPU_LOG_INT (1u << 4) #define CPU_LOG_EXEC (1u << 5) #define CPU_LOG_PCALL (1u << 6) #define CPU_LOG_TB_CPU (1u << 8) #define CPU_LOG_RESET (1u << 9) #define LOG_UNIMP (1u << 10) #define LOG_GUEST_ERROR (1u << 11) #define CPU_LOG_MMU (1u << 12) #define CPU_LOG_TB_NOCHAIN (1u << 13) #define CPU_LOG_PAGE (1u << 14) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1u << 16) #define CPU_LOG_TB_FPU (1u << 17) #define CPU_LOG_PLUGIN (1u << 18) /* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1u << 19) #define LOG_PER_THREAD (1u << 20) #define CPU_LOG_TB_VPU (1u << 21) #define LOG_TB_OP_PLUGIN (1u << 22) #define LOG_INVALID_MEM (1u << 23) ....Quoted 2 lines
Which one do you recommend we use? or May we introduce a
LOG_HOST_ERROR, if that's more appropriate.
Quoted 6 lines
I think it would be better to have
LOG_INSUFF_MEMfor this case, but let's hear from Philippe and others for suggestions.Since it's unlreated to the coverity fix and can be taken separately, so:
Reviewed-by Harsh Prateek Bora <[email protected]>
Thanks Harsh.
~Shivang.
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
In reply to Harsh Prateek BoraQuoted 56 lines · Harsh Prateek Bora
Quoted 55 lines · Shivang Upadhyay
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Shivang Upadhyay
Fixes coverity (CID 1642026)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA-SPmsnU1wzsWxBcFC=ZM_DDhPEg1N4iX9Q4bL1xOnwBg@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)Quoted 9 lines
hw/ppc/spapr_fadump.c static bool do_preserve_region(FadumpSection *region) · line 234
Quoted 6 lines
hw/ppc/spapr_fadump.c +0
-0@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region) qemu_log_mask(LOG_GUEST_ERROR,FWIW host heap exhaustion is not really a *guest* error, because the guest can not control it.
Hi, Philippe
Thanks for the review. There are following log level defined in
log.h.... #define CPU_LOG_TB_OUT_ASM (1u << 0) #define CPU_LOG_TB_IN_ASM (1u << 1) #define CPU_LOG_TB_OP (1u << 2) #define CPU_LOG_TB_OP_OPT (1u << 3) #define CPU_LOG_INT (1u << 4) #define CPU_LOG_EXEC (1u << 5) #define CPU_LOG_PCALL (1u << 6) #define CPU_LOG_TB_CPU (1u << 8) #define CPU_LOG_RESET (1u << 9) #define LOG_UNIMP (1u << 10) #define LOG_GUEST_ERROR (1u << 11) #define CPU_LOG_MMU (1u << 12) #define CPU_LOG_TB_NOCHAIN (1u << 13) #define CPU_LOG_PAGE (1u << 14) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1u << 16) #define CPU_LOG_TB_FPU (1u << 17) #define CPU_LOG_PLUGIN (1u << 18) /* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1u << 19) #define LOG_PER_THREAD (1u << 20) #define CPU_LOG_TB_VPU (1u << 21) #define LOG_TB_OP_PLUGIN (1u << 22) #define LOG_INVALID_MEM (1u << 23)
Quoted 6 lines
Quoted 4 lines
....Which one do you recommend we use? or May we introduce a
LOG_HOST_ERROR, if that's more appropriate.I think it would be better to have
LOG_INSUFF_MEMfor this case, but let's hear from Philippe and others for suggestions.
If it's not a guest error but an error in QEMU then maybe error_report (or warn_report if it's recoverable)?
Regards,
BALATON Zoltan
Quoted 16 lines
Since it's unlreated to the coverity fix and can be taken separately, so:
Reviewed-by Harsh Prateek Bora <[email protected]>Quoted 10 lines
Thanks
~Shivang.Quoted 7 lines
Quoted 6 lines
hw/ppc/spapr_fadump.c +1
-0"FADump: Failed allocating memory (size: %zu) for copying" " reserved memory regions\n", FADUMP_CHUNK_SIZE); +return false; } num_chunks =ceil ((src_len *1.0f ) /FADUMP_CHUNK_SIZE );
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 62 lines · BALATON Zoltan
Quoted 61 lines · Harsh Prateek Bora
Quoted 59 lines · Shivang Upadhyay
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Shivang Upadhyay
Fixes coverity (CID 1642026)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA-SPmsnU1wzsWxBcFC=ZM_DDhPEg1N4iX9Q4bL1xOnwBg@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 1 + 1 file changed, 1 insertion(+)Quoted 9 lines
hw/ppc/spapr_fadump.c static bool do_preserve_region(FadumpSection *region) · line 234
Quoted 6 lines
hw/ppc/spapr_fadump.c +0
-0@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region) qemu_log_mask(LOG_GUEST_ERROR,FWIW host heap exhaustion is not really a *guest* error, because the guest can not control it.
Hi, Philippe
Thanks for the review. There are following log level defined in
log.h.... #define CPU_LOG_TB_OUT_ASM (1u << 0) #define CPU_LOG_TB_IN_ASM (1u << 1) #define CPU_LOG_TB_OP (1u << 2) #define CPU_LOG_TB_OP_OPT (1u << 3) #define CPU_LOG_INT (1u << 4) #define CPU_LOG_EXEC (1u << 5) #define CPU_LOG_PCALL (1u << 6) #define CPU_LOG_TB_CPU (1u << 8) #define CPU_LOG_RESET (1u << 9) #define LOG_UNIMP (1u << 10) #define LOG_GUEST_ERROR (1u << 11) #define CPU_LOG_MMU (1u << 12) #define CPU_LOG_TB_NOCHAIN (1u << 13) #define CPU_LOG_PAGE (1u << 14) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1u << 16) #define CPU_LOG_TB_FPU (1u << 17) #define CPU_LOG_PLUGIN (1u << 18) /* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1u << 19) #define LOG_PER_THREAD (1u << 20) #define CPU_LOG_TB_VPU (1u << 21) #define LOG_TB_OP_PLUGIN (1u << 22) #define LOG_INVALID_MEM (1u << 23) ....Which one do you recommend we use? or May we introduce a
LOG_HOST_ERROR, if that's more appropriate.
Quoted 8 lines
Quoted 2 lines
I think it would be better to have
LOG_INSUFF_MEMfor this case, but let's hear from Philippe and others for suggestions.If it's not a guest error but an error in QEMU then maybe
error_report(orwarn_reportif it's recoverable)?Regards,
BALATON Zoltan
Hi
This allocation failure does not seem recoverable. Maybe Aditya can be more right about this.
Also I noticed a pattern to use g_malloc for critical things instead of g_try_malloc. But it will kill the full application if failure happens. So maybe just error_report is fine here(?).
~Shivang.
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 3 lines · Shivang Upadhyay
Also I noticed a pattern to use
g_mallocfor critical things instead ofg_try_malloc. But it will kill the full application if failure happens. So maybe justerror_reportis fine here(?).
docs/devel/style.rst has some notes on malloc choices, including this:
# Care should be taken to avoid introducing places where the guest could
# trigger an exit by causing a large allocation. For small allocations, # of the order of 4k, a failure to allocate is likely indicative of an # overloaded host and allowing ``g_malloc`` to ``exit`` is a reasonable # approach. However for larger allocations where we could realistically # fall-back to a smaller one if need be we should use functions like # ``g_try_new`` and check the result. For example this is valid approach # for a time/space trade-off like ``tlb_mmu_resize_locked`` in the # SoftMMU TLB code.
Since we're trying to allocate 32MB at once and this is during the guest run rather than at startup, this is probably a reasonable place to use g_try_malloc().
There are other places in this code that use LOG_GUEST_ERROR for things that aren't exactly guest errors, so my suggestion is that we take this patch as-is to fix the logic error. We can consider whether we want to try to improve the error reporting of this group of functions as a separate patch.
thanks
-- PMM
Re: [PATCH v2 1/2] hw/ppc: Fix missing return on allocation failure
Quoted 11 lines · Peter Maydell
docs/devel/style.rsthas some notes on malloc choices, including this:# Care should be taken to avoid introducing places where the guest could
# trigger an exit by causing a large allocation. For small allocations, # of the order of 4k, a failure to allocate is likely indicative of an # overloaded host and allowing ``g_malloc`` to ``exit`` is a reasonable # approach. However for larger allocations where we could realistically # fall-back to a smaller one if need be we should use functions like # ``g_try_new`` and check the result. For example this is valid approach # for a time/space trade-off like ``tlb_mmu_resize_locked`` in the # SoftMMU TLB code.
Hi Peter,
Thanks for clearing it up.
Quoted 10 lines
Since we're trying to allocate 32MB at once and this is during the guest run rather than at startup, this is probably a reasonable place to use
g_try_malloc().There are other places in this code that use
LOG_GUEST_ERRORfor things that aren't exactly guest errors, so my suggestion is that we take this patch as-is to fix the logic error. We can consider whether we want to try to improve the error reporting of this group of functions as a separate patch.
Sure.
~Shivang.
PATCH v2 2/2 hw/ppc: Fix memory leak in get_cpu_state_data()
In reply to Shivang UpadhyayFixes coverity (CID 1642024)
--- hw/ppc/spapr_fadump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_fadump.c +1 -1
@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu,static void *get_cpu_state_data (uint64_t *cpu_state_len) {FadumpRegSaveAreaHeader reg_save_hdr; -FadumpRegEntry *reg_entries; + g_autofree FadumpRegEntry *reg_entries = NULL;FadumpRegEntry *curr_reg_entry;CPUState *cpu;
Signature · 1 line
2.51.0
Re: [PATCH v2 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()
Quoted 11 lines · Shivang Upadhyay
Fixes coverity (CID 1642024)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH v2 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Shivang Upadhyay
Fixes coverity (CID 1642024)
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Link https://lore.kernel.org/qemu-devel/CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/ open hereReported-by Peter Maydell <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Shivang Upadhyay <[email protected]>--- hw/ppc/spapr_fadump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks
~Shivang