From nobody Mon Nov 17 09:53:02 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=1603716316; cv=none; d=zohomail.com; s=zohoarc; b=JPRwfHgZFzPHp2yyI9amNLzy238rvTVj5NSSYsklqQQdqmEO268u3ZK1bnhHajsEPBG52yy11DuBbL+cLo0QJQk3mh8dC7EEJcNs/efQMXaH9wMDmjM4uphZXMfcto9zni2hrD4ztDja3cWnOnRo+rjyROqStPyc/fPTyUslkFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603716316; 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=oZwzH1FRQABZakBVpkGKf6L7QrG6PxxHDHIgwP6Wpw4=; b=bm8Alg0xpyBHenuERmv2ybnLjrueMlQSCP++WbQPgk0N6KHHLoz8VgCl7AzbJAanxeYC9exJcmC9k6WbPDkm0BNE11rL9OmnsupB6PW+1v7ebn83c7sXSkNeq+QL2DoZAlz8sQ4k/RDHHWWAdTtVd+emfXdE7l+7aTzegTonMEQ= 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 1603716316910805.7826692899478; Mon, 26 Oct 2020 05:45:16 -0700 (PDT) Received: from localhost ([::1]:44992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kX1sB-0003NJ-BD for importer@patchew.org; Mon, 26 Oct 2020 08:45:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kX1o2-0007bC-Ry for qemu-devel@nongnu.org; Mon, 26 Oct 2020 08:40:59 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:43030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kX1nz-0007Sb-2p for qemu-devel@nongnu.org; Mon, 26 Oct 2020 08:40:58 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-RpLFQiOWOyuxOy1thYqQ_g-1; Mon, 26 Oct 2020 08:40:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 750D05AED2; Mon, 26 Oct 2020 12:40:49 +0000 (UTC) Received: from bahia.lan (ovpn-112-70.ams2.redhat.com [10.36.112.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F4185DC1B; Mon, 26 Oct 2020 12:40:47 +0000 (UTC) X-MC-Unique: RpLFQiOWOyuxOy1thYqQ_g-1 Subject: [PATCH 3/4] target/ppc: Fix kvmppc_load_htab_chunk() error reporting From: Greg Kurz To: David Gibson Date: Mon, 26 Oct 2020 13:40:47 +0100 Message-ID: <160371604713.305923.5264900354159029580.stgit@bahia.lan> In-Reply-To: <160371602625.305923.7832478283946753271.stgit@bahia.lan> References: <160371602625.305923.7832478283946753271.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/26 08:40:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 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: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 f51b663f7dcb..ff7de7da2875 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2341,8 +2341,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 d85ba8ffe00b..0223b93ea561 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 72e05f1cd2fc..73ce2bc95114 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(); }