From nobody Thu Apr 18 01:46:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555082953; cv=none; d=zoho.com; s=zohoarc; b=oQCGwLuR++xlH9ujnM9vlVwJhP+3uIqGyisM5v+TwUF40lgoy5Lo5V3g9Lx5GCEdIWidqUYYYQK7VQI1pIB1RcVgzxUTYWZ/7Dxly/w6NmdQSLrEdw5me1j0gFJiSmdTZ4z739yllpgW0W51zuCZ0V+TMEg48/sRN829GGLu5l8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555082953; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=RLADVfMaMF99nGL5w6y0VaUJyT7gzYzlyoHq0x8LjdQ=; b=fF9en0VtVfegIBOYppX/sTDcJ+a3ESgqImvT2GGpa0zpZGdbrNfz7gDrZ1Ru5wv2zUKkkFEsuYvRfxRwv10cMPZEEHwmdC7E3eiRldSQ46nCPlI4y06barVkuxFnOWG+s+T65MMRiTYYg3RfkjnUWFg+oxazyzv1Qs0SPnFgvNY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555082953809561.0142877595171; Fri, 12 Apr 2019 08:29:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:38687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEy71-0004vO-Gl for importer@patchew.org; Fri, 12 Apr 2019 11:29:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEy53-0003jI-Be for qemu-devel@nongnu.org; Fri, 12 Apr 2019 11:27:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEy52-0004tA-AN for qemu-devel@nongnu.org; Fri, 12 Apr 2019 11:27:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36144) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEy51-0004qA-Vk for qemu-devel@nongnu.org; Fri, 12 Apr 2019 11:27:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 350B2316E915 for ; Fri, 12 Apr 2019 15:26:57 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.117.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAFD95C206; Fri, 12 Apr 2019 15:26:54 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 12 Apr 2019 16:26:52 +0100 Message-Id: <20190412152652.827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 12 Apr 2019 15:26:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] hmp: gva2gpa debug 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: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add a gva2gpa command purely for debug which performs address translation on the gva, the existing gpa2hva command can then also be used to find it in the qemu userspace; e.g. (qemu) info registers .... RSP=3Dffffffff81c03e98 .... (qemu) gva2gpa 0xffffffff81c03e98 gpa: 0x1c03e98 (qemu) gpa2hva 0x1c03e98 Host virtual address for 0x1c03e98 (pc.ram) is 0x7f0599a03e98 (qemu) x/10x 0xffffffff81c03e98 ffffffff81c03e98: 0x81c03eb8 0xffffffff 0x8101ea3f 0xffffffff ffffffff81c03ea8: 0x81d27b00 0xffffffff 0x00000000 0x00000000 ffffffff81c03eb8: 0x81c03ec8 0xffffffff gdb -p ...qemu... (gdb) x/10x 0x7f0599a03e98 0x7f0599a03e98: 0x81c03eb8 0xffffffff 0x8101ea3f 0xffffffff 0x7f0599a03ea8: 0x81d27b00 0xffffffff 0x00000000 0x00000000 0x7f0599a03eb8: 0x81c03ec8 0xffffffff Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- hmp-commands.hx | 15 +++++++++++++++ monitor.c | 22 ++++++++++++++++++++++ tests/test-hmp.c | 1 + 3 files changed, 38 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index d3bad2fc27..ba4690b9ac 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -585,6 +585,21 @@ STEXI @findex gpa2hpa Print the host physical address at which the guest's physical address @var= {addr} is mapped. +ETEXI + + { + .name =3D "gva2gpa", + .args_type =3D "addr:l", + .params =3D "addr", + .help =3D "print the guest physical address corresponding to= a guest virtual address", + .cmd =3D hmp_gva2gpa, + }, + +STEXI +@item gpa2hpa @var{addr} +@findex gpa2hpa +Print the guest physical address at which the guest's virtual address @var= {addr} +is mapped based on the mapping for the current CPU. ETEXI =20 { diff --git a/monitor.c b/monitor.c index 4807bbe811..2b6017b621 100644 --- a/monitor.c +++ b/monitor.c @@ -1676,6 +1676,28 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *q= dict) memory_region_unref(mr); } =20 +static void hmp_gva2gpa(Monitor *mon, const QDict *qdict) +{ + target_ulong addr =3D qdict_get_int(qdict, "addr"); + MemTxAttrs attrs; + CPUState *cs =3D mon_get_cpu(); + hwaddr gpa; + + if (!cs) { + monitor_printf(mon, "No cpu\n"); + return; + } + + gpa =3D cpu_get_phys_page_attrs_debug(mon_get_cpu(), + addr & TARGET_PAGE_MASK, &attrs); + if (gpa =3D=3D -1) { + monitor_printf(mon, "Unmapped\n"); + } else { + monitor_printf(mon, "gpa: %#" HWADDR_PRIx "\n", + gpa + (addr & ~TARGET_PAGE_MASK)); + } +} + #ifdef CONFIG_LINUX static uint64_t vtop(void *ptr, Error **errp) { diff --git a/tests/test-hmp.c b/tests/test-hmp.c index 54a01824dc..e344947f7c 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -39,6 +39,7 @@ static const char *hmp_cmds[] =3D { "dump-guest-memory /dev/null 0 4096", "dump-guest-memory /dev/null", "gdbserver", + "gva2gpa 0", "hostfwd_add tcp::43210-:43210", "hostfwd_remove tcp::43210-:43210", "i /w 0", --=20 2.21.0