From nobody Sun Apr 28 07:50:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505481441455781.6401418570418; Fri, 15 Sep 2017 06:17:21 -0700 (PDT) Received: from localhost ([::1]:53355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqUi-000434-Kv for importer@patchew.org; Fri, 15 Sep 2017 09:17:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqTO-0002W6-7W for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:15:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsqTN-0003qK-Bv for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:15:58 -0400 Received: from 2.mo2.mail-out.ovh.net ([188.165.53.149]:41416) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsqTN-0003q5-5R for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:15:57 -0400 Received: from player770.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 1A6D4A3035 for ; Fri, 15 Sep 2017 15:15:56 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player770.ha.ovh.net (Postfix) with ESMTPA id C7A463C007F; Fri, 15 Sep 2017 15:15:51 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 15:15:51 +0200 Message-ID: <150548135159.5945.17545667206379508322.stgit@bahia.lan> In-Reply-To: <150548133297.5945.7401220081077343726.stgit@bahia.lan> References: <150548133297.5945.7401220081077343726.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 15171501245440825845 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrgeekgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.53.149 Subject: [Qemu-devel] [PATCH 1/4] ppc/kvm: drop kvmppc_has_cap_htab_fd() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Thomas Huth , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 It never got used since its introduction (commit 7c43bca004af). Signed-off-by: Greg Kurz Reviewed-by: Thomas Huth --- target/ppc/kvm.c | 5 ----- target/ppc/kvm_ppc.h | 6 ------ 2 files changed, 11 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 1deaf106d2b9..00d7029b8d7a 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2448,11 +2448,6 @@ bool kvmppc_has_cap_epr(void) return cap_epr; } =20 -bool kvmppc_has_cap_htab_fd(void) -{ - return cap_htab_fd; -} - bool kvmppc_has_cap_fixup_hcalls(void) { return cap_fixup_hcalls; diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index f780e6ec7b72..08aab46c5a56 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -51,7 +51,6 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsigned = int hash_shift); #endif /* !CONFIG_USER_ONLY */ bool kvmppc_has_cap_epr(void); int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function); -bool kvmppc_has_cap_htab_fd(void); int kvmppc_get_htab_fd(bool write); 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, @@ -246,11 +245,6 @@ static inline int kvmppc_define_rtas_kernel_token(uint= 32_t token, return -1; } =20 -static inline bool kvmppc_has_cap_htab_fd(void) -{ - return false; -} - static inline int kvmppc_get_htab_fd(bool write) { return -1; From nobody Sun Apr 28 07:50:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505481540047475.67632642217677; Fri, 15 Sep 2017 06:19:00 -0700 (PDT) Received: from localhost ([::1]:53364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqWI-0005Ug-N2 for importer@patchew.org; Fri, 15 Sep 2017 09:18:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqTc-0002gn-KF for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsqTY-0003sW-K4 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:12 -0400 Received: from 7.mo2.mail-out.ovh.net ([188.165.48.182]:37196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsqTY-0003sG-D0 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:08 -0400 Received: from player770.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id AB816A9AE1 for ; Fri, 15 Sep 2017 15:16:05 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player770.ha.ovh.net (Postfix) with ESMTPA id 55A1B3C008B; Fri, 15 Sep 2017 15:16:01 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 15:16:01 +0200 Message-ID: <150548136111.5945.6437882724141726495.stgit@bahia.lan> In-Reply-To: <150548133297.5945.7401220081077343726.stgit@bahia.lan> References: <150548133297.5945.7401220081077343726.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 15174034520613755381 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrgeekgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.48.182 Subject: [Qemu-devel] [PATCH 2/4] spapr: introduce helpers to migrate HPT chunks and the end marker X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Thomas Huth , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This consolidates some duplicated code in a single helper. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f680f28a15ea..841117f6d185 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1708,6 +1708,23 @@ static int htab_save_setup(QEMUFile *f, void *opaque) return 0; } =20 +static void htab_save_chunk(QEMUFile *f, sPAPRMachineState *spapr, + int chunkstart, int n_valid, int n_invalid) +{ + qemu_put_be32(f, chunkstart); + qemu_put_be16(f, n_valid); + qemu_put_be16(f, n_invalid); + if (spapr) { + qemu_put_buffer(f, HPTE(spapr->htab, chunkstart), + HASH_PTE_SIZE_64 * n_valid); + } +} + +static void htab_save_end_marker(QEMUFile *f) +{ + htab_save_chunk(f, NULL, 0, 0, 0); +} + static void htab_save_first_pass(QEMUFile *f, sPAPRMachineState *spapr, int64_t max_ns) { @@ -1739,11 +1756,7 @@ static void htab_save_first_pass(QEMUFile *f, sPAPRM= achineState *spapr, if (index > chunkstart) { int n_valid =3D index - chunkstart; =20 - qemu_put_be32(f, chunkstart); - qemu_put_be16(f, n_valid); - qemu_put_be16(f, 0); - qemu_put_buffer(f, HPTE(spapr->htab, chunkstart), - HASH_PTE_SIZE_64 * n_valid); + htab_save_chunk(f, spapr, chunkstart, n_valid, 0); =20 if (has_timeout && (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - starttime) > max= _ns) { @@ -1805,11 +1818,7 @@ static int htab_save_later_pass(QEMUFile *f, sPAPRMa= chineState *spapr, int n_valid =3D invalidstart - chunkstart; int n_invalid =3D index - invalidstart; =20 - qemu_put_be32(f, chunkstart); - qemu_put_be16(f, n_valid); - qemu_put_be16(f, n_invalid); - qemu_put_buffer(f, HPTE(spapr->htab, chunkstart), - HASH_PTE_SIZE_64 * n_valid); + htab_save_chunk(f, spapr, chunkstart, n_valid, n_invalid); sent +=3D index - chunkstart; =20 if (!final && (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - startt= ime) > max_ns) { @@ -1872,10 +1881,7 @@ static int htab_save_iterate(QEMUFile *f, void *opaq= ue) rc =3D htab_save_later_pass(f, spapr, MAX_ITERATION_NS); } =20 - /* End marker */ - qemu_put_be32(f, 0); - qemu_put_be16(f, 0); - qemu_put_be16(f, 0); + htab_save_end_marker(f); =20 return rc; } @@ -1915,9 +1921,7 @@ static int htab_save_complete(QEMUFile *f, void *opaq= ue) } =20 /* End marker */ - qemu_put_be32(f, 0); - qemu_put_be16(f, 0); - qemu_put_be16(f, 0); + htab_save_end_marker(f); =20 return 0; } From nobody Sun Apr 28 07:50:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505481571760351.552165138821; Fri, 15 Sep 2017 06:19:31 -0700 (PDT) Received: from localhost ([::1]:53365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqWo-0005pk-Rg for importer@patchew.org; Fri, 15 Sep 2017 09:19:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqTk-0002ni-Du for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsqTg-0003vx-CH for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:20 -0400 Received: from 8.mo2.mail-out.ovh.net ([188.165.52.147]:45929) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsqTg-0003ve-61 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:16 -0400 Received: from player770.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 3174BA9D56 for ; Fri, 15 Sep 2017 15:16:15 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player770.ha.ovh.net (Postfix) with ESMTPA id DD3F63C006B; Fri, 15 Sep 2017 15:16:10 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 15:16:10 +0200 Message-ID: <150548137066.5945.3950849052176752689.stgit@bahia.lan> In-Reply-To: <150548133297.5945.7401220081077343726.stgit@bahia.lan> References: <150548133297.5945.7401220081077343726.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 15176849273411705333 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrgeekgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.52.147 Subject: [Qemu-devel] [PATCH 3/4] ppc/kvm: change kvmppc_get_htab_fd() to return -errno on error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Thomas Huth , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When kvmppc_get_htab_fd() fails, its return value is propagated up to qemu_savevm_state_iterate() or to qemu_savevm_state_complete_precopy(). All savevm handlers expect to receive a negative errno on error. Let's patch kvmppc_get_htab_fd() accordingly. While here, let's change htab_load() in the spapr code to also propagate the error, since it doesn't make sense to abort() if we couldn't get the htab fd from KVM. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 5 +++-- target/ppc/kvm.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 841117f6d185..1ae79326d1ac 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1218,7 +1218,7 @@ static int get_htab_fd(sPAPRMachineState *spapr) spapr->htab_fd =3D kvmppc_get_htab_fd(false); if (spapr->htab_fd < 0) { error_report("Unable to open fd for reading hash table from KVM: %= s", - strerror(errno)); + strerror(spapr->htab_fd)); } =20 return spapr->htab_fd; @@ -1962,7 +1962,8 @@ static int htab_load(QEMUFile *f, void *opaque, int v= ersion_id) fd =3D kvmppc_get_htab_fd(true); if (fd < 0) { error_report("Unable to open fd to restore KVM hash table: %s", - strerror(errno)); + strerror(fd)); + return fd; } } =20 diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 00d7029b8d7a..09d7dea79e2d 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2556,13 +2556,19 @@ int kvmppc_get_htab_fd(bool write) .flags =3D write ? KVM_GET_HTAB_WRITE : 0, .start_index =3D 0, }; + int ret; =20 if (!cap_htab_fd) { fprintf(stderr, "KVM version doesn't support saving the hash table= \n"); - return -1; + return -ENOTSUP; + } + + ret =3D kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &s); + if (ret < 0) { + return -errno; } =20 - return kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &s); + return ret; } =20 int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns) From nobody Sun Apr 28 07:50:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505481674881892.1885935174907; Fri, 15 Sep 2017 06:21:14 -0700 (PDT) Received: from localhost ([::1]:53381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqYT-00075O-N6 for importer@patchew.org; Fri, 15 Sep 2017 09:21:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsqTu-0002uv-5Y for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsqTq-0003zc-2b for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:30 -0400 Received: from 3.mo2.mail-out.ovh.net ([46.105.58.226]:54022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsqTp-0003zJ-PV for qemu-devel@nongnu.org; Fri, 15 Sep 2017 09:16:25 -0400 Received: from player770.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id D2BE0AA04F for ; Fri, 15 Sep 2017 15:16:24 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player770.ha.ovh.net (Postfix) with ESMTPA id 6E4BD3C008B; Fri, 15 Sep 2017 15:16:20 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 15:16:20 +0200 Message-ID: <150548138021.5945.4408791416827487125.stgit@bahia.lan> In-Reply-To: <150548133297.5945.7401220081077343726.stgit@bahia.lan> References: <150548133297.5945.7401220081077343726.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 15179382547778345461 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrgeekgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.58.226 Subject: [Qemu-devel] [PATCH 4/4] ppc/kvm: generalize the use of kvmppc_get_htab_fd() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Thomas Huth , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The use of KVM_PPC_GET_HTAB_FD is open-coded in kvmppc_read_hptes() and kvmppc_write_hpte(). This patch modifies kvmppc_get_htab_fd() so that it can be used everywhere we need to access the in-kernel htab: - add an index argument =3D> only kvmppc_read_hptes() passes an actual index, all other users pass 0 - add an errp argument to propagate error messages to the caller. =3D> spapr migration code prints the error =3D> hpte helpers pass &error_abort to keep the current behavior of hw_error() While here, this also fixes a bug in kvmppc_write_hpte() so that it opens the htab fd for writing instead of reading as it currently does. This never broke anything because we currently never call this code, as explained in the changelog of commit c1385933804bb: "This support updating htab managed by the hypervisor. Currently we don't have any user for this feature. This actually bring the store_hpte interface in-line with the load_hpte one. We may want to use this when we want to emulate henter hcall in qemu for HV kvm." The above is still true today. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 15 +++++++-------- target/ppc/kvm.c | 27 +++++++++------------------ target/ppc/kvm_ppc.h | 4 ++-- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 1ae79326d1ac..eeef549fbc15 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1211,14 +1211,15 @@ static uint64_t spapr_get_patbe(PPCVirtualHyperviso= r *vhyp) */ static int get_htab_fd(sPAPRMachineState *spapr) { + Error *local_err =3D NULL; + if (spapr->htab_fd >=3D 0) { return spapr->htab_fd; } =20 - spapr->htab_fd =3D kvmppc_get_htab_fd(false); + spapr->htab_fd =3D kvmppc_get_htab_fd(false, 0, &local_err); if (spapr->htab_fd < 0) { - error_report("Unable to open fd for reading hash table from KVM: %= s", - strerror(spapr->htab_fd)); + error_report_err(local_err); } =20 return spapr->htab_fd; @@ -1931,6 +1932,7 @@ static int htab_load(QEMUFile *f, void *opaque, int v= ersion_id) sPAPRMachineState *spapr =3D opaque; uint32_t section_hdr; int fd =3D -1; + Error *local_err =3D NULL; =20 if (version_id < 1 || version_id > 1) { error_report("htab_load() bad version"); @@ -1945,8 +1947,6 @@ static int htab_load(QEMUFile *f, void *opaque, int v= ersion_id) } =20 if (section_hdr) { - Error *local_err =3D NULL; - /* First section gives the htab size */ spapr_reallocate_hpt(spapr, section_hdr, &local_err); if (local_err) { @@ -1959,10 +1959,9 @@ static int htab_load(QEMUFile *f, void *opaque, int = version_id) if (!spapr->htab) { assert(kvm_enabled()); =20 - fd =3D kvmppc_get_htab_fd(true); + fd =3D kvmppc_get_htab_fd(true, 0, &local_err); if (fd < 0) { - error_report("Unable to open fd to restore KVM hash table: %s", - strerror(fd)); + error_report_err(local_err); return fd; } } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 09d7dea79e2d..c37d74941085 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2550,21 +2550,25 @@ int kvmppc_define_rtas_kernel_token(uint32_t token,= const char *function) return kvm_vm_ioctl(kvm_state, KVM_PPC_RTAS_DEFINE_TOKEN, &args); } =20 -int kvmppc_get_htab_fd(bool write) +int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp) { struct kvm_get_htab_fd s =3D { .flags =3D write ? KVM_GET_HTAB_WRITE : 0, - .start_index =3D 0, + .start_index =3D index, }; int ret; =20 if (!cap_htab_fd) { - fprintf(stderr, "KVM version doesn't support saving the hash table= \n"); + error_setg(errp, "KVM version doesn't support %s the HPT", + write ? "writing" : "reading"); return -ENOTSUP; } =20 ret =3D kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &s); if (ret < 0) { + error_setg(errp, "Unable to open fd for %s HPT %s KVM: %s", + write ? "writing" : "reading", write ? "to" : "from", + strerror(errno)); return -errno; } =20 @@ -2648,17 +2652,10 @@ void kvm_arch_init_irq_routing(KVMState *s) =20 void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n) { - struct kvm_get_htab_fd ghf =3D { - .flags =3D 0, - .start_index =3D ptex, - }; int fd, rc; int i; =20 - fd =3D kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &ghf); - if (fd < 0) { - hw_error("kvmppc_read_hptes: Unable to open HPT fd"); - } + fd =3D kvmppc_get_htab_fd(false, ptex, &error_abort); =20 i =3D 0; while (i < n) { @@ -2700,19 +2697,13 @@ void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwa= ddr ptex, int n) void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1) { int fd, rc; - struct kvm_get_htab_fd ghf; struct { struct kvm_get_htab_header hdr; uint64_t pte0; uint64_t pte1; } buf; =20 - ghf.flags =3D 0; - ghf.start_index =3D 0; /* Ignored */ - fd =3D kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &ghf); - if (fd < 0) { - hw_error("kvmppc_write_hpte: Unable to open HPT fd"); - } + fd =3D kvmppc_get_htab_fd(true, 0 /* Ignored */, &error_abort); =20 buf.hdr.n_valid =3D 1; buf.hdr.n_invalid =3D 0; diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 08aab46c5a56..349f892631bf 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -51,7 +51,7 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsigned = int hash_shift); #endif /* !CONFIG_USER_ONLY */ bool kvmppc_has_cap_epr(void); int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function); -int kvmppc_get_htab_fd(bool write); +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); @@ -245,7 +245,7 @@ static inline int kvmppc_define_rtas_kernel_token(uint3= 2_t token, return -1; } =20 -static inline int kvmppc_get_htab_fd(bool write) +static inline int kvmppc_get_htab_fd(bool write, uint64_t index, Error **e= rrp) { return -1; }