From patchwork Mon May 16 02:58:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 95672 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5858CB6EF0 for ; Mon, 16 May 2011 12:59:07 +1000 (EST) Received: from localhost ([::1]:43192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLo1P-0003m0-Q2 for incoming@patchwork.ozlabs.org; Sun, 15 May 2011 22:59:03 -0400 Received: from eggs.gnu.org ([140.186.70.92]:60949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLo1I-0003lv-W5 for qemu-devel@nongnu.org; Sun, 15 May 2011 22:58:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QLo1H-0005un-U2 for qemu-devel@nongnu.org; Sun, 15 May 2011 22:58:56 -0400 Received: from mga11.intel.com ([192.55.52.93]:65263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLo1H-0005uE-Oz for qemu-devel@nongnu.org; Sun, 15 May 2011 22:58:55 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 15 May 2011 19:58:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.64,372,1301900400"; d="scan'208";a="2080993" Received: from yhuang-dev.sh.intel.com ([10.239.13.105]) by fmsmga002.fm.intel.com with ESMTP; 15 May 2011 19:58:50 -0700 From: Huang Ying To: aliguori@us.ibm.com Date: Mon, 16 May 2011 10:58:36 +0800 Message-Id: <1305514716-25761-1-git-send-email-ying.huang@intel.com> X-Mailer: git-send-email 1.7.4.4 Author: Max Asbock X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Cc: Jiajia Zheng , Max Asbock , mtosatti@redhat.com, qemu-devel@nongnu.org, andi@firstfloor.org, Huang Ying , dnelson@redhat.com Subject: [Qemu-devel] [PATCH -v4] Monitor command: x-gpa2hva, translate guest physical address to host virtual address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add command x-gpa2hva to translate guest physical address to host virtual address. Because gpa to hva translation is not consistent, so this command is only used for debugging. The x-gpa2hva command provides one step in a chain of translations from guest virtual to guest physical to host virtual to host physical. Host physical is then used to inject a machine check error. As a consequence the HWPOISON code on the host and the MCE injection code in qemu-kvm are exercised. v4: - Rebased on qemu.git v3: - Rename to x-gpa2hva - Remove QMP support, because gpa2hva is not consistent v2: - Add QMP support Signed-off-by: Max Asbock Signed-off-by: Jiajia Zheng Signed-off-by: Huang Ying --- hmp-commands.hx | 15 +++++++++++++++ monitor.c | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) --- a/monitor.c +++ b/monitor.c @@ -2713,6 +2713,28 @@ static void do_inject_mce(Monitor *mon, } #endif +static void do_gpa2hva_print(Monitor *mon, const QObject *data) +{ + QInt *qint; + + qint = qobject_to_qint(data); + monitor_printf(mon, "0x%lx\n", (unsigned long)qint->value); +} + +static int do_gpa2hva(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + target_phys_addr_t paddr; + target_phys_addr_t size = TARGET_PAGE_SIZE; + void *vaddr; + + paddr = qdict_get_int(qdict, "addr"); + vaddr = cpu_physical_memory_map(paddr, &size, 0); + cpu_physical_memory_unmap(vaddr, size, 0, 0); + *ret_data = qobject_from_jsonf("%ld", (unsigned long)vaddr); + + return 0; +} + static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *fdname = qdict_get_str(qdict, "fdname"); --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -330,6 +330,21 @@ Start gdbserver session (default @var{po ETEXI { + .name = "x-gpa2hva", + .args_type = "fmt:/,addr:l", + .params = "/fmt addr", + .help = "translate guest physical 'addr' to host virtual address, only for debugging", + .user_print = do_gpa2hva_print, + .mhandler.cmd_new = do_gpa2hva, + }, + +STEXI +@item x-gpa2hva @var{addr} +@findex x-gpa2hva +Translate guest physical @var{addr} to host virtual address, only for debugging. +ETEXI + + { .name = "x", .args_type = "fmt:/,addr:l", .params = "/fmt addr",