qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: 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: Wed, 22 Aug 2012 16:06:09 +0400	[thread overview]
Message-ID: <CAMo8BfLmtwDDOmw0U95zkpH-q7TFfez45WA0y6EagOnRmWVEUQ@mail.gmail.com> (raw)
In-Reply-To: <CAAu8pHsy6WvzE1sCGnZ1e4aYadS2eXVcwsa92j0oTLPG1f5DVw@mail.gmail.com>

On Tue, Aug 21, 2012 at 10:19 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
> On Tue, Aug 21, 2012 at 7:21 AM, 陳韋任 (Wei-Ren Chen)
> <chenwj@iis.sinica.edu.tw> wrote:
>> Hi all,
>>
>>   I want to dump guest page table when guest writes to cr3,
>> the code snipt below,
>>
>> ---
>> uint32_t pgd[1024][1024]; // guest page table
>> static void dump_guest_pgtable(target_ulong cr3)
>> {
>>     int i, j;
>>     uint32_t phyaddr = cr3;
>>     uint32_t val;
>>
>>     for (i = 0; i < NUM_ENTRY; ++i)
>>     {
>>         phyaddr += i * 4;
>>         for (j = 0; j < NUM_ENTRY; ++j)
>>         {
>>             cpu_physical_memory_read(phyaddr, &val, 4);
>>             pgd[i][j] = val;
>>         }
>>     }
>> }
>>
>> void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3)
>> {
>>     env->cr[3] = new_cr3; // guest cr3
>>
>>     if (env->cr[0] & CR0_PG_MASK) {
>>         tlb_flush(env, 0);
>>
>>         // dump guest page table by using guest cr3
>>         dump_guest_pgtable(new_cr3);
>>     }
>> }
>> ---
>>
>>   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?

-- 
Thanks.
-- Max

  parent reply	other threads:[~2012-08-22 12:06 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 [this message]
2012-08-23  2:53     ` 陳韋任 (Wei-Ren Chen)
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=CAMo8BfLmtwDDOmw0U95zkpH-q7TFfez45WA0y6EagOnRmWVEUQ@mail.gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=blauwirbel@gmail.com \
    --cc=chenwj@iis.sinica.edu.tw \
    --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).