qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "陳韋任 (Wei-Ren Chen)" <chenwj@iis.sinica.edu.tw>
To: Max Filippov <jcmvbkbc@gmail.com>
Cc: "Blue Swirl" <blauwirbel@gmail.com>,
	qemu-devel@nongnu.org,
	"陳韋任 (Wei-Ren Chen)" <chenwj@iis.sinica.edu.tw>
Subject: Re: [Qemu-devel] Dump guest page table inside QEMU makes system hang
Date: Thu, 23 Aug 2012 10:53:37 +0800	[thread overview]
Message-ID: <20120823025337.GA27969@cs.nctu.edu.tw> (raw)
In-Reply-To: <CAMo8BfLmtwDDOmw0U95zkpH-q7TFfez45WA0y6EagOnRmWVEUQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1258 bytes --]

> >>   The system will hang while booting. However, if I comment
> >> cpu_physical_memory_read in function dump_guest_pgtable, there
> >> is no problem. What I am missing here? Thanks.
> >
> > cpu_physical_memory_read() can cause faults or other side effects like
> > MMIO. Using cpu_get_phys_page_debug() may help.
> >
> 
> Maybe you just need to avoid accessing unsuitable physical addresses?
> Or maybe 'if (env->cr[0] & CR0_PG_MASK)' is not strong enough, may
> (CR0_PG_MASK | CR0_PE_MASK) be better?
> 
> At what stage does it hang? What CR3 value changes are observed before
> the hang?

  It's quite embarrassing. The code I posted before is buggy, and it dumps all
1024 * 1024 page table entries. It takes a lot of time, so that I think the
system hangs. Attach is the code snipt what I am using, which works fine now.
Another question is, I would like to know the hva corresponding to gpa (i.e.,
the guest page pointed by guest pte). Do you happen to know there is such
gpa2hva function in QEMU?

  Thanks.

Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj

[-- Attachment #2: qemu.patch --]
[-- Type: text/x-diff, Size: 871 bytes --]

// we only consider x86 w/o pae 
static void dump_guest_pgtable(CPUX86State *env)
{
    int i, j;
    target_ulong pde_addr, pte_addr;
    target_ulong phyaddr, phyaddr2;
    uint32_t pde, pte;

    pde_addr = (env->cr[3] & ~0xfff) & env->a20_mask;
    // first level page directory, iterate pde
    for (i = 0; i < NUM_ENTRY; ++i)
    {
        phyaddr = (pde_addr + i * 4) & env->a20_mask;
        pde = ldl_phys(phyaddr);
        pd[i] = pde;
        if (!(pde & PG_PRESENT_MASK))
            continue;

        pte_addr = (pde & ~0xfff) & env->a20_mask;
        // second level page table, iterate pte
        for (j = 0; j < NUM_ENTRY; ++j)
        {
            phyaddr2 = (pte_addr + j * 4) & env->a20_mask;
            pte = ldl_phys(phyaddr2);
            if (!(pte & PG_PRESENT_MASK))
                pt[i][j] = 0;
            pt[i][j] = pte;
        }
    }
}

  reply	other threads:[~2012-08-23  2:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21  7:21 [Qemu-devel] Dump guest page table inside QEMU makes system hang 陳韋任 (Wei-Ren Chen)
2012-08-21 18:19 ` Blue Swirl
2012-08-22  2:20   ` 陳韋任 (Wei-Ren Chen)
2012-08-22 12:06   ` Max Filippov
2012-08-23  2:53     ` 陳韋任 (Wei-Ren Chen) [this message]
2012-08-23  3:55       ` 陳韋任 (Wei-Ren Chen)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120823025337.GA27969@cs.nctu.edu.tw \
    --to=chenwj@iis.sinica.edu.tw \
    --cc=blauwirbel@gmail.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).