From patchwork Tue Oct 26 02:39:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 280872 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9Q2ds4c024356 for ; Tue, 26 Oct 2010 02:39:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756865Ab0JZCjw (ORCPT ); Mon, 25 Oct 2010 22:39:52 -0400 Received: from mga09.intel.com ([134.134.136.24]:50665 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756432Ab0JZCjv (ORCPT ); Mon, 25 Oct 2010 22:39:51 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 25 Oct 2010 19:39:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.58,239,1286175600"; d="scan'208";a="567339590" Received: from yhuang-dev.sh.intel.com (HELO [10.239.13.2]) ([10.239.13.2]) by orsmga002.jf.intel.com with ESMTP; 25 Oct 2010 19:39:50 -0700 Subject: [PATCH -v2] Monitor command: pfa2hva, translate guest physical address to host virtual address From: Huang Ying To: Avi Kivity , Marcelo Tosatti Cc: "kvm@vger.kernel.org" , Andi Kleen , Dean Nelson Date: Tue, 26 Oct 2010 10:39:48 +0800 Message-ID: <1288060789.2862.336.camel@yhuang-dev> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 26 Oct 2010 02:39:54 +0000 (UTC) --- a/monitor.c +++ b/monitor.c @@ -2272,6 +2272,28 @@ static void do_inject_mce(Monitor *mon, } #endif +static void do_pfa2hva_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_pfa2hva(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 @@ -293,6 +293,21 @@ Start gdbserver session (default @var{po ETEXI { + .name = "pfa2hva", + .args_type = "fmt:/,addr:l", + .params = "/fmt addr", + .help = "translate guest physical 'addr' to host virtual address", + .user_print = do_pfa2hva_print, + .mhandler.cmd_new = do_pfa2hva, + }, + +STEXI +@item pfa2hva @var{addr} +@findex pfa2hva +Translate guest physical @var{addr} to host virtual address. +ETEXI + + { .name = "x", .args_type = "fmt:/,addr:l", .params = "/fmt addr", --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -738,6 +738,33 @@ Example: EQMP { + .name = "pfa2hva", + .args_type = "addr:l", + .params = "addr", + .help = "translate guest physical 'addr' to host virtual address", + .user_print = do_pfa2hva_print, + .mhandler.cmd_new = do_pfa2hva, + }, + +SQMP +pfa2hva +--- + +Translate guest physical 'addr' to host virtual address. + +Arguments: + +- "addr": the guest physical address + +Example: + +-> { "execute": "pfa2hva", + "arguments": { "addr": 196608 } } +<- { "return": 139888084717568 } + +EQMP + + { .name = "qmp_capabilities", .args_type = "", .params = "",