From patchwork Thu Nov 15 13:22:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42whvx2Kvgz9s9G for ; Fri, 16 Nov 2018 00:26:21 +1100 (AEDT) Received: from localhost ([::1]:38810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHf0-0005PJ-Vl for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:26:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbb-0002vl-Pq for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHbY-0006uN-0p for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:47 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:37145) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbX-0006tj-7V for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:43 -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 14:22:40 +0100 id 0000000000000089.000000005BED7320.00004453 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:34 +0100 Message-Id: <84e82ec58c7f280bab1e5cf8b0386033140aba2f.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 a2b33ccb29..e67efbb58b 100644 --- a/cpus.c +++ b/cpus.c @@ -2394,8 +2394,9 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename, while (size != 0) { l = sizeof(buf); - if (l > size) + if (l > size) { l = size; + } if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) != 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 char *filename, while (size != 0) { l = sizeof(buf); - if (l > size) + if (l > size) { l = size; + } cpu_physical_memory_read(addr, buf, l); if (fwrite(buf, 1, l, f) != l) { error_setg(errp, QERR_IO_ERROR); From patchwork Thu Nov 15 13:22:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42whw005kZz9s5c for ; Fri, 16 Nov 2018 00:26:24 +1100 (AEDT) Received: from localhost ([::1]:38812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHf3-0005Tg-Jb for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:26:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbb-0002vi-P7 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHbZ-0006v0-Rq for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:47 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:34357) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbX-0006tx-Ul for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:45 -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 14:22:41 +0100 id 00000000000000F7.000000005BED7321.00004463 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:35 +0100 Message-Id: <292e35d1375b7bb87a641a8158a0e6e033070894.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" qemu_open() allow 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 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 char *filename, return; } - f = fopen(filename, "wb"); - if (!f) { + fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600); + 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 char *filename, " specified", orig_addr, orig_size); goto exit; } - if (fwrite(buf, 1, l, f) != l) { + if (qemu_write_full(fd, buf, l) != 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, } exit: - fclose(f); + qemu_close(fd); } 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]; - f = fopen(filename, "wb"); - if (!f) { + fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600); + 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 char *filename, l = size; } cpu_physical_memory_read(addr, buf, l); - if (fwrite(buf, 1, l, f) != l) { + if (qemu_write_full(fd, buf, l) != l) { error_setg(errp, QERR_IO_ERROR); goto exit; } @@ -2442,7 +2442,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, } exit: - fclose(f); + qemu_close(fd); } void qmp_inject_nmi(Error **errp) From patchwork Thu Nov 15 13:22:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42whrj1lQDz9s5c for ; Fri, 16 Nov 2018 00:23:31 +1100 (AEDT) Received: from localhost ([::1]:38793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHcG-00031X-W2 for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:23:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbb-0002vm-Pw for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHbZ-0006uu-RO for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:47 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:49179) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbX-0006u3-UB for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:45 -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 14:22:42 +0100 id 0000000000000103.000000005BED7322.0000447C From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:36 +0100 Message-Id: <788629f831cb1caa7676872cf65a9e5342bc76ae.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It's the natural type for object sizes and matches the return value of sizeof(buf). 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 char *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 = addr, orig_size = size; @@ -2418,7 +2418,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, Error **errp) { int fd; - uint32_t l; + size_t l; uint8_t buf[1024]; fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600); From patchwork Thu Nov 15 13:22:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998313 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42whrm51THz9s9G for ; Fri, 16 Nov 2018 00:23:36 +1100 (AEDT) Received: from localhost ([::1]:38794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHcM-00037r-7s for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:23:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbb-0002vj-PM for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHba-0006v8-0H for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:47 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:51727) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbZ-0006tV-PR for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:45 -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 14:22:42 +0100 id 0000000000000106.000000005BED7322.00004488 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:37 +0100 Message-Id: <7d1a33870ea5fd66ae92bab5164c939c633112a6.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 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 { .name = "memsave", - .args_type = "val:l,size:i,filename:s", + .args_type = "val:l,size:l,filename:s", .params = "addr size file", .help = "save to disk virtual memory dump starting at 'addr' of size 'size'", .cmd = hmp_memsave, @@ -847,7 +847,7 @@ ETEXI { .name = "pmemsave", - .args_type = "val:l,size:i,filename:s", + .args_type = "val:l,size:l,filename:s", .params = "addr size file", .help = "save to disk physical memory dump starting at 'addr' of size 'size'", .cmd = 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) void hmp_memsave(Monitor *mon, const QDict *qdict) { - uint32_t size = qdict_get_int(qdict, "size"); + uint64_t size = qdict_get_int(qdict, "size"); const char *filename = qdict_get_str(qdict, "filename"); uint64_t addr = qdict_get_int(qdict, "val"); Error *err = NULL; @@ -1160,7 +1160,7 @@ void hmp_memsave(Monitor *mon, const QDict *qdict) void hmp_pmemsave(Monitor *mon, const QDict *qdict) { - uint32_t size = qdict_get_int(qdict, "size"); + uint64_t size = qdict_get_int(qdict, "size"); const char *filename = qdict_get_str(qdict, "filename"); uint64_t addr = qdict_get_int(qdict, "val"); Error *err = NULL; From patchwork Thu Nov 15 13:22:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42why543m3z9s5c for ; Fri, 16 Nov 2018 00:28:13 +1100 (AEDT) Received: from localhost ([::1]:38817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHgo-0006dX-MR for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:28:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbb-0002vk-Pt for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHba-0006vS-IU for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:47 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:37145) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbZ-0006tj-Qv for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:45 -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 14:22:43 +0100 id 000000000000010B.000000005BED7323.0000449C From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:38 +0100 Message-Id: <4b75808e6c6e66b36fcbc905fc6cff411f1a7970.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This enables completion for the filename arguments. Suggested-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 { .name = "memsave", - .args_type = "val:l,size:l,filename:s", + .args_type = "val:l,size:l,filename:F", .params = "addr size file", .help = "save to disk virtual memory dump starting at 'addr' of size 'size'", .cmd = hmp_memsave, @@ -847,7 +847,7 @@ ETEXI { .name = "pmemsave", - .args_type = "val:l,size:l,filename:s", + .args_type = "val:l,size:l,filename:F", .params = "addr size file", .help = "save to disk physical memory dump starting at 'addr' of size 'size'", .cmd = hmp_pmemsave, From patchwork Thu Nov 15 13:22:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42whs24rPbz9s5c for ; Fri, 16 Nov 2018 00:23:50 +1100 (AEDT) Received: from localhost ([::1]:38796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHca-0003Gg-5v for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:23:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbi-0003Ca-Ej for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHbd-0006y9-Md for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:54 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:51727) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbb-0006tV-QA for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:49 -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 14:22:43 +0100 id 000000000000010F.000000005BED7323.000044A9 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:39 +0100 Message-Id: <4e25c4e14e76cee9a1b0d062f2623426e2a0e0bb.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Simon Ruderich --- cpus.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 20 ++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/cpus.c b/cpus.c index ee54595733..a12076dc68 100644 --- a/cpus.c +++ b/cpus.c @@ -2445,6 +2445,57 @@ exit: qemu_close(fd); } +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 = 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) != 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; + } + size = s.st_size; + } + + while (size != 0) { + l = sizeof(buf); + if (l > size) { + l = size; + } + r = read(fd, buf, l); + if (r <= 0) { + error_setg(errp, QERR_IO_ERROR); + goto exit; + } + l = r; /* in case of short read */ + cpu_physical_memory_write(addr, buf, l); + addr += l; + size -= 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..6eb9d29339 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1186,6 +1186,26 @@ { 'command': 'pmemsave', 'data': {'val': 'int', 'size': 'int', 'filename': 'str'} } +## +# @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: 3.1 +## +{ 'command': 'pmemload', + 'data': {'val': 'int', 'filename': 'str', '*size': 'int', '*offset': 'int'} } + ## # @cont: # From patchwork Thu Nov 15 13:22:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ruderich X-Patchwork-Id: 998320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ruderich.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42wj0J6g8Rz9s5c for ; Fri, 16 Nov 2018 00:30:08 +1100 (AEDT) Received: from localhost ([::1]:38824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHig-0008IE-EC for incoming@patchwork.ozlabs.org; Thu, 15 Nov 2018 08:30:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNHbe-00038R-KE for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNHbd-0006yG-NH for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:50 -0500 Received: from zucker2.schokokeks.org ([178.63.68.90]:34357) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNHbb-0006tx-Qn for qemu-devel@nongnu.org; Thu, 15 Nov 2018 08:22:49 -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 14:22:44 +0100 id 0000000000000049.000000005BED7324.000044B3 From: Simon Ruderich To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 14:22:40 +0100 Message-Id: <67e889e814ebdff93fb6648fdf1f873641f8f676.1542287931.git.simon@ruderich.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: <0e59c79ddc01e195ddc59d77d9df2b95bf89b600.1523395243.git.simon@ruderich.org> Mime-Version: 1.0 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 v7 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 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 = "pmemload", + .args_type = "val:l,size:l,offset:l,filename:F", + .params = "addr size offset file", + .help = "load from disk physical memory dump starting at 'addr' of size 'size' at file offset 'offset'", + .cmd = 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{size} at file offset @var{offset}. ETEXI { 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); } +void hmp_pmemload(Monitor *mon, const QDict *qdict) +{ + uint64_t size = qdict_get_int(qdict, "size"); + uint64_t offset = qdict_get_int(qdict, "offset"); + const char *filename = qdict_get_str(qdict, "filename"); + uint64_t addr = qdict_get_int(qdict, "val"); + Error *err = 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 = 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);