From nobody Tue May 7 20:52:00 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 1526917143754658.1717716989591; Mon, 21 May 2018 08:39:03 -0700 (PDT) Received: from localhost ([::1]:51209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmtm-0003vw-AE for importer@patchew.org; Mon, 21 May 2018 11:38:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmrj-0001rI-0F for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKmrf-0005K7-Ti for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from zucker2.schokokeks.org ([178.63.68.90]:55995) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKmrf-0005J7-NH for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:47 -0400 Received: from blood-stain-child.lan.ruderich.org (localhost [::1]) (AUTH: PLAIN simon@ruderich.org, TLS: TLSv1/SSLv3, 128bits, ECDHE-RSA-AES128-GCM-SHA256) by zucker.schokokeks.org with ESMTPSA; Mon, 21 May 2018 17:37:07 +0200 id 000000000000007A.000000005B02E7A3.000008E3 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Mon, 21 May 2018 17:36:40 +0200 Message-Id: <1155d843cc79afa957f4365acccc00fc9a82e05a.1526916378.git.simon@ruderich.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v3 1/5] cpus: correct coding style in qmp_memsave/qmp_pmemsave 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: Simon Ruderich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Simon Ruderich Reviewed-by: Eric Blake --- cpus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index d1f16296de..4b1609fe90 100644 --- a/cpus.c +++ b/cpus.c @@ -2316,8 +2316,9 @@ void qmp_memsave(int64_t addr, int64_t size, const ch= ar *filename, =20 while (size !=3D 0) { l =3D sizeof(buf); - if (l > size) + if (l > size) { l =3D size; + } if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) !=3D 0) { error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRId64 " specified", orig_addr, orig_size); @@ -2350,8 +2351,9 @@ void qmp_pmemsave(int64_t addr, int64_t size, const c= har *filename, =20 while (size !=3D 0) { l =3D sizeof(buf); - if (l > size) + if (l > size) { l =3D size; + } cpu_physical_memory_read(addr, buf, l); if (fwrite(buf, 1, l, f) !=3D l) { error_setg(errp, QERR_IO_ERROR); --=20 2.15.0 From nobody Tue May 7 20:52:00 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 1526917271427797.6506635458991; Mon, 21 May 2018 08:41:11 -0700 (PDT) Received: from localhost ([::1]:51223 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmvu-00066k-J0 for importer@patchew.org; Mon, 21 May 2018 11:41:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmrj-0001rL-13 for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKmrf-0005Jx-TN for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from zucker2.schokokeks.org ([178.63.68.90]:50069) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKmrf-0005J9-N2 for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:47 -0400 Received: from blood-stain-child.lan.ruderich.org (localhost [::1]) (AUTH: PLAIN simon@ruderich.org, TLS: TLSv1/SSLv3, 128bits, ECDHE-RSA-AES128-GCM-SHA256) by zucker.schokokeks.org with ESMTPSA; Mon, 21 May 2018 17:37:07 +0200 id 0000000000000088.000000005B02E7A3.000008F4 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Mon, 21 May 2018 17:36:41 +0200 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v3 2/5] cpus: convert qmp_memsave/qmp_pmemsave to use qemu_open 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: Simon Ruderich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qemu_open() allows passing file descriptors to qemu which is used in restricted environments like libvirt where open() is prohibited. Suggested-by: Eric Blake Signed-off-by: Simon Ruderich Reviewed-by: Eric Blake --- cpus.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpus.c b/cpus.c index 4b1609fe90..7fd8d3c32e 100644 --- a/cpus.c +++ b/cpus.c @@ -2291,7 +2291,7 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp) void qmp_memsave(int64_t addr, int64_t size, const char *filename, bool has_cpu, int64_t cpu_index, Error **errp) { - FILE *f; + int fd; uint32_t l; CPUState *cpu; uint8_t buf[1024]; @@ -2308,8 +2308,8 @@ void qmp_memsave(int64_t addr, int64_t size, const ch= ar *filename, return; } =20 - f =3D fopen(filename, "wb"); - if (!f) { + fd =3D qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 06= 00); + if (fd < 0) { error_setg_file_open(errp, errno, filename); return; } @@ -2324,7 +2324,7 @@ void qmp_memsave(int64_t addr, int64_t size, const ch= ar *filename, " specified", orig_addr, orig_size); goto exit; } - if (fwrite(buf, 1, l, f) !=3D l) { + if (qemu_write_full(fd, buf, l) !=3D l) { error_setg(errp, QERR_IO_ERROR); goto exit; } @@ -2333,18 +2333,18 @@ void qmp_memsave(int64_t addr, int64_t size, const = char *filename, } =20 exit: - fclose(f); + qemu_close(fd); } =20 void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, Error **errp) { - FILE *f; + int fd; uint32_t l; uint8_t buf[1024]; =20 - f =3D fopen(filename, "wb"); - if (!f) { + fd =3D qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 06= 00); + if (fd < 0) { error_setg_file_open(errp, errno, filename); return; } @@ -2355,7 +2355,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const c= har *filename, l =3D size; } cpu_physical_memory_read(addr, buf, l); - if (fwrite(buf, 1, l, f) !=3D l) { + if (qemu_write_full(fd, buf, l) !=3D l) { error_setg(errp, QERR_IO_ERROR); goto exit; } @@ -2364,7 +2364,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const c= har *filename, } =20 exit: - fclose(f); + qemu_close(fd); } =20 void qmp_inject_nmi(Error **errp) --=20 2.15.0 From nobody Tue May 7 20:52:00 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526917145024261.13248064631534; Mon, 21 May 2018 08:39:05 -0700 (PDT) Received: from localhost ([::1]:51208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmtm-0003vJ-7J for importer@patchew.org; Mon, 21 May 2018 11:38:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmrj-0001rM-1l for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKmrf-0005Jz-Tq for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from zucker2.schokokeks.org ([178.63.68.90]:41627) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKmrf-0005JC-NC for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:47 -0400 Received: from blood-stain-child.lan.ruderich.org (localhost [::1]) (AUTH: PLAIN simon@ruderich.org, TLS: TLSv1/SSLv3, 128bits, ECDHE-RSA-AES128-GCM-SHA256) by zucker.schokokeks.org with ESMTPSA; Mon, 21 May 2018 17:37:07 +0200 id 0000000000000092.000000005B02E7A3.00000901 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Mon, 21 May 2018 17:36:42 +0200 Message-Id: <723d4fd2e9cd69ba6653322e0d2c18a2b0717b0a.1526916378.git.simon@ruderich.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v3 3/5] cpus: use size_t in qmp_memsave/qmp_pmemsave 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: Simon Ruderich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's the natural type for object sizes and matches the return value of sizeof(buf). Signed-off-by: Simon Ruderich Reviewed-by: Eric Blake --- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index 7fd8d3c32e..49d4d44916 100644 --- a/cpus.c +++ b/cpus.c @@ -2292,7 +2292,7 @@ void qmp_memsave(int64_t addr, int64_t size, const ch= ar *filename, bool has_cpu, int64_t cpu_index, Error **errp) { int fd; - uint32_t l; + size_t l; CPUState *cpu; uint8_t buf[1024]; int64_t orig_addr =3D addr, orig_size =3D size; @@ -2340,7 +2340,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const c= har *filename, Error **errp) { int fd; - uint32_t l; + size_t l; uint8_t buf[1024]; =20 fd =3D qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 06= 00); --=20 2.15.0 From nobody Tue May 7 20:52:00 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 1526917143880593.9245351629819; Mon, 21 May 2018 08:39:03 -0700 (PDT) Received: from localhost ([::1]:51210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmtp-00040w-DA for importer@patchew.org; Mon, 21 May 2018 11:39:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmrj-0001rH-02 for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKmrg-0005KW-Bx for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from zucker2.schokokeks.org ([178.63.68.90]:51641) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKmrg-0005J6-5a for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:48 -0400 Received: from blood-stain-child.lan.ruderich.org (localhost [::1]) (AUTH: PLAIN simon@ruderich.org, TLS: TLSv1/SSLv3, 128bits, ECDHE-RSA-AES128-GCM-SHA256) by zucker.schokokeks.org with ESMTPSA; Mon, 21 May 2018 17:37:07 +0200 id 00000000000000A4.000000005B02E7A3.0000090A From: Simon Ruderich To: qemu-devel@nongnu.org Date: Mon, 21 May 2018 17:36:43 +0200 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v3 4/5] hmp: don't truncate size in hmp_memsave/hmp_pmemsave 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: Simon Ruderich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The called function takes an uint64_t as size parameter and qdict_get_int() returns an uint64_t. Don't truncate it needlessly to an uint32_t. Signed-off-by: Simon Ruderich Reviewed-by: Eric Blake --- hmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hmp.c b/hmp.c index ef93f4878b..a4d28913bb 100644 --- a/hmp.c +++ b/hmp.c @@ -1079,7 +1079,7 @@ void hmp_cpu(Monitor *mon, const QDict *qdict) =20 void hmp_memsave(Monitor *mon, const QDict *qdict) { - uint32_t size =3D qdict_get_int(qdict, "size"); + uint64_t size =3D qdict_get_int(qdict, "size"); const char *filename =3D qdict_get_str(qdict, "filename"); uint64_t addr =3D qdict_get_int(qdict, "val"); Error *err =3D NULL; @@ -1096,7 +1096,7 @@ void hmp_memsave(Monitor *mon, const QDict *qdict) =20 void hmp_pmemsave(Monitor *mon, const QDict *qdict) { - uint32_t size =3D qdict_get_int(qdict, "size"); + uint64_t size =3D qdict_get_int(qdict, "size"); const char *filename =3D qdict_get_str(qdict, "filename"); uint64_t addr =3D qdict_get_int(qdict, "val"); Error *err =3D NULL; --=20 2.15.0 From nobody Tue May 7 20:52:00 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 1526917271472156.74229732333356; Mon, 21 May 2018 08:41:11 -0700 (PDT) Received: from localhost ([::1]:51224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmvu-00066z-OL for importer@patchew.org; Mon, 21 May 2018 11:41:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmrj-0001rK-0i for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKmrg-0005KR-CF for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:51 -0400 Received: from zucker2.schokokeks.org ([178.63.68.90]:50069) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKmrg-0005J9-5Q for qemu-devel@nongnu.org; Mon, 21 May 2018 11:36:48 -0400 Received: from blood-stain-child.lan.ruderich.org (localhost [::1]) (AUTH: PLAIN simon@ruderich.org, TLS: TLSv1/SSLv3, 128bits, ECDHE-RSA-AES128-GCM-SHA256) by zucker.schokokeks.org with ESMTPSA; Mon, 21 May 2018 17:37:07 +0200 id 00000000000000B4.000000005B02E7A3.00000915 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Mon, 21 May 2018 17:36:44 +0200 Message-Id: <851d095cd457109e4a22a2e5ecd36ccbdacbf48b.1526916378.git.simon@ruderich.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v3 5/5] qmp: add pmemload command 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: Simon Ruderich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Adapted patch from Baojun Wang [1] with the following commit message: I found this could be useful to have qemu-softmmu as a cross debugger (launch with -s -S command line option), then if we can have a command to load guest physical memory, we can use cross gdb to do some target debug which gdb cannot do directly. pmemload is necessary to directly write physical memory which is not possible with gdb alone as it uses only logical addresses. The QAPI for pmemload uses "val" as parameter name for the physical address. This name is not very descriptive but is consistent with the existing pmemsave. Changing the parameter name of pmemsave is not possible without breaking the existing API. [1]: https://lists.gnu.org/archive/html/qemu-trivial/2014-04/msg00074.html Based-on-patch-by: Baojun Wang Signed-off-by: Simon Ruderich --- cpus.c | 41 +++++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 14 ++++++++++++++ hmp.c | 12 ++++++++++++ hmp.h | 1 + qapi/misc.json | 20 ++++++++++++++++++++ 5 files changed, 88 insertions(+) diff --git a/cpus.c b/cpus.c index 49d4d44916..9b105336af 100644 --- a/cpus.c +++ b/cpus.c @@ -2367,6 +2367,47 @@ exit: qemu_close(fd); } =20 +void qmp_pmemload(int64_t addr, int64_t size, int64_t offset, + const char *filename, Error **errp) +{ + int fd; + size_t l; + ssize_t r; + uint8_t buf[1024]; + + fd =3D qemu_open(filename, O_RDONLY | O_BINARY); + if (fd < 0) { + error_setg_file_open(errp, errno, filename); + return; + } + if (offset > 0) { + if (lseek(fd, offset, SEEK_SET) !=3D offset) { + error_setg_errno(errp, errno, + "could not seek to offset %" PRIx64, offset); + goto exit; + } + } + + while (size !=3D 0) { + l =3D sizeof(buf); + if (l > size) { + l =3D size; + } + r =3D read(fd, buf, l); + if (r <=3D 0) { + error_setg(errp, QERR_IO_ERROR); + goto exit; + } + l =3D r; /* in case of short read */ + cpu_physical_memory_write(addr, buf, l); + addr +=3D l; + size -=3D l; + } + +exit: + qemu_close(fd); +} + void qmp_inject_nmi(Error **errp) { nmi_monitor_handle(monitor_get_cpu_index(), errp); diff --git a/hmp-commands.hx b/hmp-commands.hx index 0734fea931..84647c7c1d 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -822,6 +822,20 @@ STEXI @item pmemsave @var{addr} @var{size} @var{file} @findex pmemsave save to disk physical memory dump starting at @var{addr} of size @var{size= }. +ETEXI + + { + .name =3D "pmemload", + .args_type =3D "val:l,size:i,offset:i,filename:s", + .params =3D "addr size offset file", + .help =3D "load from disk physical memory dump starting at '= addr' of size 'size' at file offset 'offset'", + .cmd =3D hmp_pmemload, + }, + +STEXI +@item pmemload @var{addr} @var{size} @var{offset} @var{file} +@findex pmemload +load from disk physical memory dump starting at @var{addr} of size @var{si= ze} at file offset @var{offset}. ETEXI =20 { diff --git a/hmp.c b/hmp.c index a4d28913bb..b85c943b63 100644 --- a/hmp.c +++ b/hmp.c @@ -1105,6 +1105,18 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } =20 +void hmp_pmemload(Monitor *mon, const QDict *qdict) +{ + uint64_t size =3D qdict_get_int(qdict, "size"); + uint64_t offset =3D qdict_get_int(qdict, "offset"); + const char *filename =3D qdict_get_str(qdict, "filename"); + uint64_t addr =3D qdict_get_int(qdict, "val"); + Error *err =3D NULL; + + qmp_pmemload(addr, size, offset, filename, &err); + hmp_handle_error(mon, &err); +} + void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) { const char *chardev =3D qdict_get_str(qdict, "device"); diff --git a/hmp.h b/hmp.h index 20f27439d3..31767ea4a8 100644 --- a/hmp.h +++ b/hmp.h @@ -47,6 +47,7 @@ void hmp_system_powerdown(Monitor *mon, const QDict *qdic= t); void hmp_cpu(Monitor *mon, const QDict *qdict); void hmp_memsave(Monitor *mon, const QDict *qdict); void hmp_pmemsave(Monitor *mon, const QDict *qdict); +void hmp_pmemload(Monitor *mon, const QDict *qdict); void hmp_ringbuf_write(Monitor *mon, const QDict *qdict); void hmp_ringbuf_read(Monitor *mon, const QDict *qdict); void hmp_cont(Monitor *mon, const QDict *qdict); diff --git a/qapi/misc.json b/qapi/misc.json index f5988cc0b5..b4c0065b02 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1219,6 +1219,26 @@ { 'command': 'pmemsave', 'data': {'val': 'int', 'size': 'int', 'filename': 'str'} } =20 +## +# @pmemload: +# +# Load a portion of guest physical memory from a file. +# +# @val: the physical address of the guest to start from +# +# @size: the size of memory region to load +# +# @offset: the offset in the file to start from +# +# @filename: the file to load the memory from as binary data +# +# Returns: Nothing on success +# +# Since: 2.13 +## +{ 'command': 'pmemload', + 'data': {'val': 'int', 'size': 'int', 'offset': 'int', 'filename': 'str'= } } + ## # @cont: # --=20 2.15.0