qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] What's the proper type of guest pde address, target_ulong or target_phys_addr_t?
@ 2012-08-24  3:34 陳韋任 (Wei-Ren Chen)
  2012-08-24  7:09 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-08-24  3:34 UTC (permalink / raw)
  To: qemu-devel

Hi all,

  When I read cpu_get_phys_page_debug (target-i386/helper.c), I found
the type of pde_addr and pte_addr might be not correct. See below,

---
target_phys_addr_t cpu_get_phys_page_debug(CPUX86State *env, target_ulong addr)
{
    target_ulong pde_addr, pte_addr;

    ...

    pde_addr = ((pdpe & ~0xfff & ~(PG_NX_MASK | PG_HI_USER_MASK)) +
                (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask;
    pde = ldq_phys(pde_addr);

    ...
}
---

HACKING says target_ulong is for guest virtual address and target_phys_addr_t
is for guest physical address. IIUC, pde_addr and pte_addr should be the
guest physical address for guest page table and guest page respectively,
right? If no one object, I'll send a patch which replaces target_ulong
with target_phys_addr_t.

  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] What's the proper type of guest pde address, target_ulong or target_phys_addr_t?
  2012-08-24  3:34 [Qemu-devel] What's the proper type of guest pde address, target_ulong or target_phys_addr_t? 陳韋任 (Wei-Ren Chen)
@ 2012-08-24  7:09 ` Peter Maydell
  2012-08-24  9:27   ` 陳韋任 (Wei-Ren Chen)
  2012-08-24 10:43   ` 陳韋任 (Wei-Ren Chen)
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Maydell @ 2012-08-24  7:09 UTC (permalink / raw)
  To: 陳韋任 (Wei-Ren Chen); +Cc: qemu-devel

On 24 August 2012 04:34, 陳韋任 (Wei-Ren Chen) <chenwj@iis.sinica.edu.tw> wrote:
> Hi all,
>
>   When I read cpu_get_phys_page_debug (target-i386/helper.c), I found
> the type of pde_addr and pte_addr might be not correct. See below,
>
> ---
> target_phys_addr_t cpu_get_phys_page_debug(CPUX86State *env, target_ulong addr)
> {
>     target_ulong pde_addr, pte_addr;
>
>     ...
>
>     pde_addr = ((pdpe & ~0xfff & ~(PG_NX_MASK | PG_HI_USER_MASK)) +
>                 (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask;
>     pde = ldq_phys(pde_addr);
>
>     ...
> }
> ---
>
> HACKING says target_ulong is for guest virtual address and target_phys_addr_t
> is for guest physical address. IIUC, pde_addr and pte_addr should be the
> guest physical address for guest page table and guest page respectively,
> right? If no one object, I'll send a patch which replaces target_ulong
> with target_phys_addr_t.

In principle, yes, but you need to check the code carefully to make
sure your type change doesn't change any of the results. (Or if it
does, you then need to confirm against the specs that this was a bug
that is being fixed, not a new one being introduced). The thing you have
to remember is that for the 32 bit x86 cores guest physical addresses
are only 32 bits but target_phys_addr_t is still a 64 bit type.
It may be we're deliberately (mis)using target_ulong to get the
right behaviour on both 32 and 64 bit cores.

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] What's the proper type of guest pde address, target_ulong or target_phys_addr_t?
  2012-08-24  7:09 ` Peter Maydell
@ 2012-08-24  9:27   ` 陳韋任 (Wei-Ren Chen)
  2012-08-24 10:43   ` 陳韋任 (Wei-Ren Chen)
  1 sibling, 0 replies; 4+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-08-24  9:27 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, 陳韋任 (Wei-Ren Chen)

> In principle, yes, but you need to check the code carefully to make
> sure your type change doesn't change any of the results. (Or if it
> does, you then need to confirm against the specs that this was a bug
> that is being fixed, not a new one being introduced). The thing you have
> to remember is that for the 32 bit x86 cores guest physical addresses
> are only 32 bits but target_phys_addr_t is still a 64 bit type.

  Yes, I saw in configure x86 and x86_64 both have target_phys_bits
set to 64.

---
case "$target_arch2" in
  i386)
    target_phys_bits=64
  ;;

if test "$target_softmmu" = "yes" ; then
  echo "TARGET_PHYS_ADDR_BITS=$target_phys_bits" >> $config_target_mak
---

  So that in targphys.h, it typedef target_phys_addr_t to uint_64,

#elif TARGET_PHYS_ADDR_BITS == 64
typedef uint64_t target_phys_addr_t;

> It may be we're deliberately (mis)using target_ulong to get the
> right behaviour on both 32 and 64 bit cores.

  Need to be further investigated. :)

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] What's the proper type of guest pde address, target_ulong or target_phys_addr_t?
  2012-08-24  7:09 ` Peter Maydell
  2012-08-24  9:27   ` 陳韋任 (Wei-Ren Chen)
@ 2012-08-24 10:43   ` 陳韋任 (Wei-Ren Chen)
  1 sibling, 0 replies; 4+ messages in thread
From: 陳韋任 (Wei-Ren Chen) @ 2012-08-24 10:43 UTC (permalink / raw)
  To: qemu-devel

> In principle, yes, but you need to check the code carefully to make
> sure your type change doesn't change any of the results. (Or if it
> does, you then need to confirm against the specs that this was a bug
> that is being fixed, not a new one being introduced). The thing you have
> to remember is that for the 32 bit x86 cores guest physical addresses
> are only 32 bits but target_phys_addr_t is still a 64 bit type.
> It may be we're deliberately (mis)using target_ulong to get the
> right behaviour on both 32 and 64 bit cores.

  Just want to make a note here. According to Intel Software Developer's Manual
Volume 3A, 4.4.2 Linear-Address Translation with PAE Paging [1],

    A PDE is selected using the physical address defined as follows:

    - Bits 51:12 are from PDPTEi.

    - Bits 11:3 are bits 29:21 of the linear address.

    - Bits 2:0 are 0.

IIUC, pde_addr/pte_addr are 52-bit wide, but cpu_get_phys_page_debug
declares pde_addr/pte_addr as target_ulong, which is uint32_t for x86
guest. That might be a problem.

target_phys_addr_t cpu_get_phys_page_debug(CPUX86State *env, target_ulong addr)
{
    target_ulong pde_addr, pte_addr;

    ... snip ...
}

Regards,
chenwj
  
[1]
http://download.intel.com/products/processor/manual/253668.pdf

-- 
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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-24 10:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-24  3:34 [Qemu-devel] What's the proper type of guest pde address, target_ulong or target_phys_addr_t? 陳韋任 (Wei-Ren Chen)
2012-08-24  7:09 ` Peter Maydell
2012-08-24  9:27   ` 陳韋任 (Wei-Ren Chen)
2012-08-24 10:43   ` 陳韋任 (Wei-Ren Chen)

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).