[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/18] target/ppc: Fix kvmppc_load_htab_chunk() error reporting
From: |
David Gibson |
Subject: |
[PULL 16/18] target/ppc: Fix kvmppc_load_htab_chunk() error reporting |
Date: |
Wed, 28 Oct 2020 01:17:33 +1100 |
From: Greg Kurz <groug@kaod.org>
If kvmppc_load_htab_chunk() fails, its return value is propagated up
to vmstate_load(). It should thus be a negative errno, not -1 (which
maps to EPERM and would lure the user into thinking that the problem
is necessarily related to a lack of privilege).
Return the error reported by KVM or ENOSPC in case of short write.
While here, propagate the error message through an @errp argument
and have the caller to print it with error_report_err() instead
of relying on fprintf().
Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <160371604713.305923.5264900354159029580.stgit@bahia.lan>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
hw/ppc/spapr.c | 4 +++-
target/ppc/kvm.c | 11 +++++------
target/ppc/kvm_ppc.h | 5 +++--
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index ba0894e73a..ec2536dba1 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2347,8 +2347,10 @@ static int htab_load(QEMUFile *f, void *opaque, int
version_id)
assert(fd >= 0);
- rc = kvmppc_load_htab_chunk(f, fd, index, n_valid, n_invalid);
+ rc = kvmppc_load_htab_chunk(f, fd, index, n_valid, n_invalid,
+ &local_err);
if (rc < 0) {
+ error_report_err(local_err);
return rc;
}
}
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index d85ba8ffe0..0223b93ea5 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2683,7 +2683,7 @@ int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
int64_t max_ns)
}
int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
- uint16_t n_valid, uint16_t n_invalid)
+ uint16_t n_valid, uint16_t n_invalid, Error **errp)
{
struct kvm_get_htab_header *buf;
size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
@@ -2698,14 +2698,13 @@ int kvmppc_load_htab_chunk(QEMUFile *f, int fd,
uint32_t index,
rc = write(fd, buf, chunksize);
if (rc < 0) {
- fprintf(stderr, "Error writing KVM hash table: %s\n",
- strerror(errno));
- return rc;
+ error_setg_errno(errp, errno, "Error writing the KVM hash table");
+ return -errno;
}
if (rc != chunksize) {
/* We should never get a short write on a single chunk */
- fprintf(stderr, "Short write, restoring KVM hash table\n");
- return -1;
+ error_setg(errp, "Short write while restoring the KVM hash table");
+ return -ENOSPC;
}
return 0;
}
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
index 72e05f1cd2..73ce2bc951 100644
--- a/target/ppc/kvm_ppc.h
+++ b/target/ppc/kvm_ppc.h
@@ -56,7 +56,7 @@ int kvmppc_define_rtas_kernel_token(uint32_t token, const
char *function);
int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp);
int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns);
int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
- uint16_t n_valid, uint16_t n_invalid);
+ uint16_t n_valid, uint16_t n_invalid, Error **errp);
void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n);
void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1);
bool kvmppc_has_cap_fixup_hcalls(void);
@@ -316,7 +316,8 @@ static inline int kvmppc_save_htab(QEMUFile *f, int fd,
size_t bufsize,
}
static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
- uint16_t n_valid, uint16_t n_invalid)
+ uint16_t n_valid, uint16_t n_invalid,
+ Error **errp)
{
abort();
}
--
2.26.2
- [PULL 06/18] spapr: Unrealize vCPUs with qdev_unrealize(), (continued)
- [PULL 06/18] spapr: Unrealize vCPUs with qdev_unrealize(), David Gibson, 2020/10/27
- [PULL 08/18] spapr: Make spapr_cpu_core_unrealize() idempotent, David Gibson, 2020/10/27
- [PULL 13/18] spapr: Pass &error_abort when getting some PC DIMM properties, David Gibson, 2020/10/27
- [PULL 09/18] spapr: Simplify spapr_cpu_core_realize() and spapr_cpu_core_unrealize(), David Gibson, 2020/10/27
- [PULL 11/18] spapr: Use appropriate getter for PC_DIMM_ADDR_PROP, David Gibson, 2020/10/27
- [PULL 14/18] spapr: Simplify error handling in spapr_memory_plug(), David Gibson, 2020/10/27
- [PULL 05/18] spapr: Fix leak of CPU machine specific data, David Gibson, 2020/10/27
- [PULL 12/18] spapr: Use appropriate getter for PC_DIMM_SLOT_PROP, David Gibson, 2020/10/27
- [PULL 10/18] pc-dimm: Drop @errp argument of pc_dimm_plug(), David Gibson, 2020/10/27
- [PULL 15/18] spapr: Use error_append_hint() in spapr_reallocate_hpt(), David Gibson, 2020/10/27
- [PULL 16/18] target/ppc: Fix kvmppc_load_htab_chunk() error reporting,
David Gibson <=
- [PULL 17/18] spapr: Improve spapr_reallocate_hpt() error reporting, David Gibson, 2020/10/27
- [PULL 18/18] ppc/: fix some comment spelling errors, David Gibson, 2020/10/27
- Re: [PULL 00/18] ppc-for-5.2 queue 20201028, Peter Maydell, 2020/10/30