From nobody Sat May 18 21:00:38 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 154229141931826.95086003750123; Thu, 15 Nov 2018 06:16:59 -0800 (PST) Received: from localhost ([::1]:39050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIRz-0006JV-8N for importer@patchew.org; Thu, 15 Nov 2018 09:16:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIv-00071V-HK for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIu-0005MK-HU for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:33 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:35965) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIq-0005H7-Jg for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:30 -0500 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; Thu, 15 Nov 2018 15:07:19 +0100 id 000000000000003E.000000005BED7D97.00002704 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:12 +0100 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 1/7] 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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Reviewed-by: Eric Blake Signed-off-by: Simon Ruderich --- cpus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index a2b33ccb29..e67efbb58b 100644 --- a/cpus.c +++ b/cpus.c @@ -2394,8 +2394,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); @@ -2428,8 +2429,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.19.1 From nobody Sat May 18 21:00:38 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 1542291294323779.6904015873944; Thu, 15 Nov 2018 06:14:54 -0800 (PST) Received: from localhost ([::1]:39036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIQ1-00052I-6y for importer@patchew.org; Thu, 15 Nov 2018 09:14:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIu-00070i-LE for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIo-0005Je-PD for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:32 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:51259) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIm-0005HN-MY for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:26 -0500 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; Thu, 15 Nov 2018 15:07:19 +0100 id 0000000000000053.000000005BED7D97.00002713 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:13 +0100 Message-Id: <120f15243e77b223b96ef65fe15ff4e1b31be9ca.1542290622.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 2/7] 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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" qemu_open() allow passing file descriptors to qemu which is used in restricted environments like libvirt where open() is prohibited. Suggested-by: Eric Blake Reviewed-by: Eric Blake Signed-off-by: Simon Ruderich --- cpus.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpus.c b/cpus.c index e67efbb58b..c0d796f441 100644 --- a/cpus.c +++ b/cpus.c @@ -2369,7 +2369,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]; @@ -2386,8 +2386,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; } @@ -2402,7 +2402,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; } @@ -2411,18 +2411,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; } @@ -2433,7 +2433,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; } @@ -2442,7 +2442,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.19.1 From nobody Sat May 18 21:00:38 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 154229154114545.17491363219767; Thu, 15 Nov 2018 06:19:01 -0800 (PST) Received: from localhost ([::1]:39056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIU0-0007on-24 for importer@patchew.org; Thu, 15 Nov 2018 09:19:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIv-00071c-Ia for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIu-0005MP-Hr for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:33 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:50591) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIq-0005HR-L3 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:30 -0500 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; Thu, 15 Nov 2018 15:07:19 +0100 id 000000000000005E.000000005BED7D97.00002723 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:14 +0100 Message-Id: <1238ad452bdff19db593dd11cb4a4c64ed5b9da8.1542290622.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 3/7] 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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It's the natural type for object sizes and matches the return value of sizeof(buf). Reviewed-by: Eric Blake Signed-off-by: Simon Ruderich --- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index c0d796f441..ee54595733 100644 --- a/cpus.c +++ b/cpus.c @@ -2370,7 +2370,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; @@ -2418,7 +2418,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.19.1 From nobody Sat May 18 21:00:38 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 1542290956869802.786209269061; Thu, 15 Nov 2018 06:09:16 -0800 (PST) Received: from localhost ([::1]:39001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIKZ-0008QN-Lg for importer@patchew.org; Thu, 15 Nov 2018 09:09:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIu-00070Z-HB for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIq-0005Kl-Mb for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:32 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:51259) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIp-0005HN-VL for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:28 -0500 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; Thu, 15 Nov 2018 15:07:19 +0100 id 0000000000000062.000000005BED7D97.00002735 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:15 +0100 Message-Id: <97aeb6f8fac7324729c574bc7cc984184f7d2af6.1542290622.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 4/7] hmp: use l for size argument in memsave/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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" i is only 32-bit. To prevent possible truncation when dumping large memory regions use l which is target long. Suggested-by: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Simon Ruderich --- hmp-commands.hx | 4 ++-- hmp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index db0c681f74..ff96c3ad24 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -833,7 +833,7 @@ ETEXI =20 { .name =3D "memsave", - .args_type =3D "val:l,size:i,filename:s", + .args_type =3D "val:l,size:l,filename:s", .params =3D "addr size file", .help =3D "save to disk virtual memory dump starting at 'add= r' of size 'size'", .cmd =3D hmp_memsave, @@ -847,7 +847,7 @@ ETEXI =20 { .name =3D "pmemsave", - .args_type =3D "val:l,size:i,filename:s", + .args_type =3D "val:l,size:l,filename:s", .params =3D "addr size file", .help =3D "save to disk physical memory dump starting at 'ad= dr' of size 'size'", .cmd =3D hmp_pmemsave, diff --git a/hmp.c b/hmp.c index 7828f93a39..42a5d163cd 100644 --- a/hmp.c +++ b/hmp.c @@ -1143,7 +1143,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; @@ -1160,7 +1160,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.19.1 From nobody Sat May 18 21:00:38 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 1542291613881747.9486381407385; Thu, 15 Nov 2018 06:20:13 -0800 (PST) Received: from localhost ([::1]:39061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIVA-0000Jl-Oq for importer@patchew.org; Thu, 15 Nov 2018 09:20:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIw-00072B-4P for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIu-0005Mw-R3 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:34 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:48671) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIu-0005H6-BX for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:32 -0500 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; Thu, 15 Nov 2018 15:07:20 +0100 id 000000000000006C.000000005BED7D98.00002745 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:16 +0100 Message-Id: <04bd8a8fe835765e6686e212ba422796b5023fa1.1542290622.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 5/7] hmp: use F for filename arguments in memsave/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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This enables completion for the filename arguments. Suggested-by: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Simon Ruderich --- hmp-commands.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index ff96c3ad24..2404a5210d 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -833,7 +833,7 @@ ETEXI =20 { .name =3D "memsave", - .args_type =3D "val:l,size:l,filename:s", + .args_type =3D "val:l,size:l,filename:F", .params =3D "addr size file", .help =3D "save to disk virtual memory dump starting at 'add= r' of size 'size'", .cmd =3D hmp_memsave, @@ -847,7 +847,7 @@ ETEXI =20 { .name =3D "pmemsave", - .args_type =3D "val:l,size:l,filename:s", + .args_type =3D "val:l,size:l,filename:F", .params =3D "addr size file", .help =3D "save to disk physical memory dump starting at 'ad= dr' of size 'size'", .cmd =3D hmp_pmemsave, --=20 2.19.1 From nobody Sat May 18 21:00:38 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 1542291738075378.6070576867436; Thu, 15 Nov 2018 06:22:18 -0800 (PST) Received: from localhost ([::1]:39077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIXA-0001k6-Lv for importer@patchew.org; Thu, 15 Nov 2018 09:22:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIw-00072o-MT for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIv-0005N9-83 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:34 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:51259) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIu-0005HN-FE for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:32 -0500 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; Thu, 15 Nov 2018 15:07:20 +0100 id 000000000000006F.000000005BED7D98.00002750 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:17 +0100 Message-Id: <0e061333411f8e64a6e53f14c4c067e5e3e1c91e.1542290622.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 6/7] 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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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. This patch contains only the qmp changes of the original patch. 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 Reviewed-by: Eric Blake Signed-off-by: Simon Ruderich --- cpus.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 20 ++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/cpus.c b/cpus.c index ee54595733..b80f331596 100644 --- a/cpus.c +++ b/cpus.c @@ -2445,6 +2445,61 @@ exit: qemu_close(fd); } =20 +void qmp_pmemload(int64_t addr, const char *filename, + bool has_size, int64_t size, + bool has_offset, int64_t offset, + 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 (has_offset && offset > 0) { + if (lseek(fd, offset, SEEK_SET) !=3D offset) { + error_setg_errno(errp, errno, + "could not seek to offset %" PRIx64, offset); + goto exit; + } + } + if (!has_size) { + struct stat s; + if (fstat(fd, &s)) { + error_setg_errno(errp, errno, "could not fstat fd to get size"= ); + goto exit; + } + if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode)) { + error_setg(errp, "pmemload doesn't support char/block devices"= ); + goto exit; + } + size =3D s.st_size; + } + + 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/qapi/misc.json b/qapi/misc.json index 6c1c5c0a37..e4f39e31e5 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1186,6 +1186,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 +# +# @filename: the file to load the memory from as binary data +# +# @size: the size of memory region to load (defaults to whole file) +# +# @offset: the offset in the file to start from (defaults to 0) +# +# Returns: Nothing on success +# +# Since: 4.0 +## +{ 'command': 'pmemload', + 'data': {'val': 'int', 'filename': 'str', '*size': 'int', '*offset': 'in= t'} } + ## # @cont: # --=20 2.19.1 From nobody Sat May 18 21:00:38 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 1542291786389911.73701073817; Thu, 15 Nov 2018 06:23:06 -0800 (PST) Received: from localhost ([::1]:39079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIXw-0002Ip-Na for importer@patchew.org; Thu, 15 Nov 2018 09:23:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIy-000756-IA for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIIv-0005Nf-Oq for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:36 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:35965) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIIv-0005H7-Hw for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:07:33 -0500 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; Thu, 15 Nov 2018 15:07:20 +0100 id 0000000000000075.000000005BED7D98.00002764 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:07:18 +0100 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 0.75 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.63.68.90 Subject: [Qemu-devel] [PATCH v8 7/7] hmp: 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 , David Alan Gilbert , Markus Armbruster , Peter Crosthwaite , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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. This patch contains only the hmp changes of the original patch. [1]: https://lists.gnu.org/archive/html/qemu-trivial/2014-04/msg00074.html Based-on-patch-by: Baojun Wang Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Simon Ruderich --- hmp-commands.hx | 14 ++++++++++++++ hmp.c | 12 ++++++++++++ hmp.h | 1 + 3 files changed, 27 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 2404a5210d..baadbb3a69 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -857,6 +857,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:l,offset:l,filename:F", + .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 42a5d163cd..c2a77fc390 100644 --- a/hmp.c +++ b/hmp.c @@ -1169,6 +1169,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, filename, true, size, true, offset, &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 5f1addcca2..6503146a8c 100644 --- a/hmp.h +++ b/hmp.h @@ -49,6 +49,7 @@ void hmp_exit_preconfig(Monitor *mon, const QDict *qdict); 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); --=20 2.19.1