All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: David Gibson <david@gibson.dropbear.id.au>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org, groug@kaod.org
Subject: [PULL 17/18] spapr: Improve spapr_reallocate_hpt() error reporting
Date: Wed, 28 Oct 2020 01:17:34 +1100	[thread overview]
Message-ID: <20201027141735.728821-18-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20201027141735.728821-1-david@gibson.dropbear.id.au>

From: Greg Kurz <groug@kaod.org>

spapr_reallocate_hpt() has three users, two of which pass &error_fatal
and the third one, htab_load(), passes &local_err, uses it to detect
failures and simply propagates -EINVAL up to vmstate_load(), which will
cause QEMU to exit. It is thus confusing that spapr_reallocate_hpt()
doesn't return right away when an error is detected in some cases. Also,
the comment suggesting that the caller is welcome to try to carry on
seems like a remnant in this respect.

This can be improved:
- change spapr_reallocate_hpt() to always report a negative errno on
  failure, either as reported by KVM or -ENOSPC if the HPT is smaller
  than what was asked,
- use that to detect failures in htab_load() which is preferred over
  checking &local_err,
- propagate this negative errno to vmstate_load() because it is more
  accurate than propagating -EINVAL for all possible errors.

[dwg: Fix compile error due to omitted prelim patch]
Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <160371605460.305923.5890143959901241157.stgit@bahia.lan>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c         | 20 +++++++++++---------
 include/hw/ppc/spapr.h |  3 +--
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index ec2536dba1..227075103e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1483,8 +1483,7 @@ void spapr_free_hpt(SpaprMachineState *spapr)
     close_htab_fd(spapr);
 }
 
-void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
-                          Error **errp)
+int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp)
 {
     ERRP_GUARD();
     long rc;
@@ -1496,7 +1495,7 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
 
     if (rc == -EOPNOTSUPP) {
         error_setg(errp, "HPT not supported in nested guests");
-        return;
+        return -EOPNOTSUPP;
     }
 
     if (rc < 0) {
@@ -1504,8 +1503,7 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
         error_setg_errno(errp, errno, "Failed to allocate KVM HPT of order %d",
                          shift);
         error_append_hint(errp, "Try smaller maxmem?\n");
-        /* This is almost certainly fatal, but if the caller really
-         * wants to carry on with shift == 0, it's welcome to try */
+        return -errno;
     } else if (rc > 0) {
         /* kernel-side HPT allocated */
         if (rc != shift) {
@@ -1513,6 +1511,7 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
                        "Requested order %d HPT, but kernel allocated order %ld",
                        shift, rc);
             error_append_hint(errp, "Try smaller maxmem?\n");
+            return -ENOSPC;
         }
 
         spapr->htab_shift = shift;
@@ -1526,7 +1525,7 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
         if (!spapr->htab) {
             error_setg_errno(errp, errno,
                              "Could not allocate HPT of order %d", shift);
-            return;
+            return -ENOMEM;
         }
 
         memset(spapr->htab, 0, size);
@@ -1539,6 +1538,7 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
     /* We're setting up a hash table, so that means we're not radix */
     spapr->patb_entry = 0;
     spapr_set_all_lpcrs(0, LPCR_HR | LPCR_UPRT);
+    return 0;
 }
 
 void spapr_setup_hpt(SpaprMachineState *spapr)
@@ -2292,11 +2292,13 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id)
     }
 
     if (section_hdr) {
+        int ret;
+
         /* First section gives the htab size */
-        spapr_reallocate_hpt(spapr, section_hdr, &local_err);
-        if (local_err) {
+        ret = spapr_reallocate_hpt(spapr, section_hdr, &local_err);
+        if (ret < 0) {
             error_report_err(local_err);
-            return -EINVAL;
+            return ret;
         }
         return 0;
     }
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index bb47896f17..2e89e36cfb 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -846,8 +846,7 @@ void spapr_hotplug_req_add_by_count_indexed(SpaprDrcType drc_type,
 void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type,
                                                uint32_t count, uint32_t index);
 int spapr_hpt_shift_for_ramsize(uint64_t ramsize);
-void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
-                          Error **errp);
+int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp);
 void spapr_clear_pending_events(SpaprMachineState *spapr);
 void spapr_clear_pending_hotplug_events(SpaprMachineState *spapr);
 int spapr_max_server_number(SpaprMachineState *spapr);
-- 
2.26.2



  parent reply	other threads:[~2020-10-27 14:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27 14:17 [PULL 00/18] ppc-for-5.2 queue 20201028 David Gibson
2020-10-27 14:17 ` [PULL 01/18] spapr: Clarify why DR connectors aren't user creatable David Gibson
2020-10-27 14:17 ` [PULL 02/18] ppc/spapr: re-assert IRQs during event-scan if there are pending David Gibson
2020-10-27 14:17 ` [PULL 03/18] hw/net: move allocation to the heap due to very large stack frame David Gibson
2020-10-27 14:17 ` [PULL 04/18] spapr: Move spapr_create_nvdimm_dr_connectors() to core machine code David Gibson
2020-10-27 14:17 ` [PULL 05/18] spapr: Fix leak of CPU machine specific data David Gibson
2020-10-27 14:17 ` [PULL 06/18] spapr: Unrealize vCPUs with qdev_unrealize() David Gibson
2020-10-27 14:17 ` [PULL 07/18] spapr: Drop spapr_delete_vcpu() unused argument David Gibson
2020-10-27 14:17 ` [PULL 08/18] spapr: Make spapr_cpu_core_unrealize() idempotent David Gibson
2020-10-27 14:17 ` [PULL 09/18] spapr: Simplify spapr_cpu_core_realize() and spapr_cpu_core_unrealize() David Gibson
2020-10-27 14:17 ` [PULL 10/18] pc-dimm: Drop @errp argument of pc_dimm_plug() David Gibson
2020-10-27 14:17 ` [PULL 11/18] spapr: Use appropriate getter for PC_DIMM_ADDR_PROP David Gibson
2020-10-27 14:17 ` [PULL 12/18] spapr: Use appropriate getter for PC_DIMM_SLOT_PROP David Gibson
2020-10-27 14:17 ` [PULL 13/18] spapr: Pass &error_abort when getting some PC DIMM properties David Gibson
2020-10-27 14:17 ` [PULL 14/18] spapr: Simplify error handling in spapr_memory_plug() David Gibson
2020-10-27 14:17 ` [PULL 15/18] spapr: Use error_append_hint() in spapr_reallocate_hpt() David Gibson
2020-10-27 14:17 ` [PULL 16/18] target/ppc: Fix kvmppc_load_htab_chunk() error reporting David Gibson
2020-10-27 14:17 ` David Gibson [this message]
2020-10-27 14:17 ` [PULL 18/18] ppc/: fix some comment spelling errors David Gibson
2020-10-30 11:55 ` [PULL 00/18] ppc-for-5.2 queue 20201028 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201027141735.728821-18-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.