From nobody Mon Nov 17 12:08:26 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603810289; cv=none; d=zohomail.com; s=zohoarc; b=BAPx6lMncNcieJXKvmwkODBs+OR+LnS2+wyHAAFEAtNux/gUFsDrLJmdh7svmdIS0YI8wWf7dc86URybio6fHs41gfxuanW6VXmYMNRRwdP0sOIff38bymAxVyBvVpps0vPNRqiZYaLiDt8XHf0OZgc8TfT1jPxMfgQRxGnLvFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603810289; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ebuWYMAW/eUiLL6rZRq8VO4MKGn1b0EgRlLkR+ngOyc=; b=nSDl13M0qTCaMbC6x+Fd0b954f8pkQ5dD8DlxqCH3VO5nqB5k2if2+13esK7c8oioqPTrKbWZUnDNyz9Bs6GnLB/Q1d6fe28qN7PvE0hgnviUKRrg32Sc6zJfXkNlkJHpeE1bVtiP8pGlKEN4h89uP6Eluyg1B5xvOu2bWau1K0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603810288115895.7751121126422; Tue, 27 Oct 2020 07:51:28 -0700 (PDT) Received: from localhost ([::1]:59680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXQJr-0000vE-7g for importer@patchew.org; Tue, 27 Oct 2020 10:51:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXPnj-0002J8-SI; Tue, 27 Oct 2020 10:18:17 -0400 Received: from ozlabs.org ([203.11.71.1]:40093) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXPnh-0007d7-0v; Tue, 27 Oct 2020 10:18:15 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4CLDLt1Qt0z9sj3; Wed, 28 Oct 2020 01:17:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1603808278; bh=iYQRi/tNG112bmgF4xqQ7eKKIeFdgRePVgkns9RLLKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ErQp/ru1Of/fHE4PD6Xv4YL2DI33SJhLg7Jc2WQsqNnnaMDKp1QfdNRGxw9lNzU7O LaB+8gob81bBNVqjmQFIOVVwkCkfPilbnsvx8Nb+0L36LDtHrV7RiS8U5b46Ovfu3r kHAx3VBIL+RGbcYrof6b0VmdNIjuvoUKJM/RENEU= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 16/18] target/ppc: Fix kvmppc_load_htab_chunk() error reporting Date: Wed, 28 Oct 2020 01:17:33 +1100 Message-Id: <20201027141735.728821-17-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201027141735.728821-1-david@gibson.dropbear.id.au> References: <20201027141735.728821-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 10:17:43 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Gibson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz 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 Message-Id: <160371604713.305923.5264900354159029580.stgit@bahia.lan> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Gibson --- 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) =20 assert(fd >=3D 0); =20 - rc =3D kvmppc_load_htab_chunk(f, fd, index, n_valid, n_invalid= ); + rc =3D 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 bufs= ize, int64_t max_ns) } =20 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 **e= rrp) { struct kvm_get_htab_header *buf; size_t chunksize =3D sizeof(*buf) + n_valid * HASH_PTE_SIZE_64; @@ -2698,14 +2698,13 @@ int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uin= t32_t index, =20 rc =3D 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 !=3D 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 **e= rrp); 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, } =20 static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t ind= ex, - uint16_t n_valid, uint16_t n_inva= lid) + uint16_t n_valid, uint16_t n_inva= lid, + Error **errp) { abort(); } --=20 2.26.2