qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
@ 2012-08-10  2:11 Steven
  2012-08-10 15:47 ` Peter Maydell
  0 siblings, 1 reply; 7+ messages in thread
From: Steven @ 2012-08-10  2:11 UTC (permalink / raw)
  To: qemu-devel

Hi,
The function definition has a return address type tb_page_addr_t.
tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)

I am wondering is this address the guest physical address or the host
virtual address.
If it it is the guest physical address, why does Qemu waste guest
physical space to store these address for tb? Thanks.

Steven

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

* Re: [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
  2012-08-10  2:11 [Qemu-devel] Is the return address of get_page_addr_code guest physical address? Steven
@ 2012-08-10 15:47 ` Peter Maydell
  2012-08-10 17:36   ` Steven
  2012-08-10 18:53   ` Steven
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Maydell @ 2012-08-10 15:47 UTC (permalink / raw)
  To: Steven; +Cc: qemu-devel

On 10 August 2012 03:11, Steven <wangwangkang@gmail.com> wrote:
> The function definition has a return address type tb_page_addr_t.
> tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
>
> I am wondering is this address the guest physical address or the host
> virtual address.

In linux-user mode the returned address is the guest virtual address.
In system mode it is a ram_addr_t. (the comment above the implementation
says "the returned address is not exactly the physical address: it
is the offset relative to phys_ram_base" but this is out of date I think).
A ram_addr_t is neither a host address nor a guest physical address
but it's closely related to a guest physaddr (you can think of it as
if all the RAM in the system was put into a straight line and then the
ram_addr_t is an index into that).

> If it it is the guest physical address, why does Qemu waste guest
> physical space to store these address for tb? Thanks.

I'm not sure what you're asking here. This function returns a
physical address because we store TCG translated code blocks in
a hash table indexed by guest physaddr. Given the information
"the CPU is trying to execute code from this physaddr" we need to
be able to find out whether we already have a code block translated
for that. (there is also a fast code path so we can avoid doing
a complete lookup from physaddr most of the time.)

-- PMM

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

* Re: [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
  2012-08-10 15:47 ` Peter Maydell
@ 2012-08-10 17:36   ` Steven
  2012-08-10 18:53   ` Steven
  1 sibling, 0 replies; 7+ messages in thread
From: Steven @ 2012-08-10 17:36 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On Fri, Aug 10, 2012 at 11:47 AM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 10 August 2012 03:11, Steven <wangwangkang@gmail.com> wrote:
>> The function definition has a return address type tb_page_addr_t.
>> tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
>>
>> I am wondering is this address the guest physical address or the host
>> virtual address.
>
> In linux-user mode the returned address is the guest virtual address.
> In system mode it is a ram_addr_t. (the comment above the implementation
> says "the returned address is not exactly the physical address: it
> is the offset relative to phys_ram_base" but this is out of date I think).
> A ram_addr_t is neither a host address nor a guest physical address
> but it's closely related to a guest physaddr (you can think of it as
> if all the RAM in the system was put into a straight line and then the
> ram_addr_t is an index into that).
So if I want to get the guest physical address (GPA) of a
tb_page_addr_t, can I do
           tb_page_addr_t = returned value from get_page_addr_code  +
phys_ram_base
Is this translation correct?

>
>> If it it is the guest physical address, why does Qemu waste guest
>> physical space to store these address for tb? Thanks.
>
> I'm not sure what you're asking here. This function returns a
> physical address because we store TCG translated code blocks in
> a hash table indexed by guest physaddr. Given the information
> "the CPU is trying to execute code from this physaddr" we need to
> be able to find out whether we already have a code block translated
> for that. (there is also a fast code path so we can avoid doing
> a complete lookup from physaddr most of the time.)
>
> -- PMM

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

* Re: [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
  2012-08-10 15:47 ` Peter Maydell
  2012-08-10 17:36   ` Steven
@ 2012-08-10 18:53   ` Steven
  2012-08-11  2:06     ` Peter Maydell
  1 sibling, 1 reply; 7+ messages in thread
From: Steven @ 2012-08-10 18:53 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On Fri, Aug 10, 2012 at 11:47 AM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 10 August 2012 03:11, Steven <wangwangkang@gmail.com> wrote:
>> The function definition has a return address type tb_page_addr_t.
>> tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
>>
>> I am wondering is this address the guest physical address or the host
>> virtual address.
>
> In linux-user mode the returned address is the guest virtual address.
> In system mode it is a ram_addr_t. (the comment above the implementation
> says "the returned address is not exactly the physical address: it
> is the offset relative to phys_ram_base" but this is out of date I think).
> A ram_addr_t is neither a host address nor a guest physical address
> but it's closely related to a guest physaddr (you can think of it as
> if all the RAM in the system was put into a straight line and then the

My question is related to system mode.
Is the RAM you mean the guest physical address, which is a continuous
sequence of numbers beginning from 0 to the max of allocated RAM of
the guest?

> ram_addr_t is an index into that).

If the returned value of get_page_addr_code is the index to that
straight line, I am wondering if it is the guest physical address. For
example, a 512MB guest has two RAMBlocks
        block hva: 139980450037760, offset: 0, length: 536870912
        block hva: 139981262475264, offset: 537001984, length: 131072
Then I print out the value of pc and its phys_pc returned value from
get_page_addr_code in tb_gen_code(...).
        pc and phys_pc: 0x00000000000f207f  537075839
We can see that the phys_pc is within the second RAMBlock. So if we
consider the beginning of the RAM line is 0, the pays_pc value is the
offset to 0.
In other word the phys_pc is exactly the guest physical address. Is
this correct?

- Steven

>
>> If it it is the guest physical address, why does Qemu waste guest
>> physical space to store these address for tb? Thanks.
>
> I'm not sure what you're asking here. This function returns a
> physical address because we store TCG translated code blocks in
> a hash table indexed by guest physaddr. Given the information
> "the CPU is trying to execute code from this physaddr" we need to
> be able to find out whether we already have a code block translated
> for that. (there is also a fast code path so we can avoid doing
> a complete lookup from physaddr most of the time.)
>
> -- PMM

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

* Re: [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
  2012-08-10 18:53   ` Steven
@ 2012-08-11  2:06     ` Peter Maydell
  2012-08-11  3:41       ` Steven
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Maydell @ 2012-08-11  2:06 UTC (permalink / raw)
  To: Steven; +Cc: qemu-devel

On 10 August 2012 19:53, Steven <wangwangkang@gmail.com> wrote:
> On Fri, Aug 10, 2012 at 11:47 AM, Peter Maydell
> <peter.maydell@linaro.org> wrote:
>> On 10 August 2012 03:11, Steven <wangwangkang@gmail.com> wrote:
>>> The function definition has a return address type tb_page_addr_t.
>>> tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
>>>
>>> I am wondering is this address the guest physical address or the host
>>> virtual address.
>>
>> In linux-user mode the returned address is the guest virtual address.
>> In system mode it is a ram_addr_t. (the comment above the implementation
>> says "the returned address is not exactly the physical address: it
>> is the offset relative to phys_ram_base" but this is out of date I think).
>> A ram_addr_t is neither a host address nor a guest physical address
>> but it's closely related to a guest physaddr (you can think of it as
>> if all the RAM in the system was put into a straight line and then the
>
> My question is related to system mode.
> Is the RAM you mean the guest physical address, which is a continuous
> sequence of numbers beginning from 0 to the max of allocated RAM of
> the guest?
>
>> ram_addr_t is an index into that).
>
> If the returned value of get_page_addr_code is the index to that
> straight line, I am wondering if it is the guest physical address.

No, it is definitely not the guest physical address. Consider
the case where there are two aliases of the same RAM in
guest physical memory -- two physical addresses might
map to a single ram_addr_t. Consider the case where there
is a 'hole' in memory -- ram_addr_t and physical address are
not identical there either.

> So if I want to get the guest physical address (GPA) of a
> tb_page_addr_t, can I do
>   tb_page_addr_t = returned value from get_page_addr_code  + phys_ram_base
> Is this translation correct?

This is wrong on several counts: (a) there's no such thing
as phys_ram_base any more (it was removed several years
ago) and (b) there is no single unique guest physical
address corresponding to a tb_page_addr_t, so what
you are trying to do is not well defined.

What are you trying to do anyway and why do you want
to call get_page_addr_code() ?

-- PMM

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

* Re: [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
  2012-08-11  2:06     ` Peter Maydell
@ 2012-08-11  3:41       ` Steven
  2012-08-11 11:16         ` Laurent Desnogues
  0 siblings, 1 reply; 7+ messages in thread
From: Steven @ 2012-08-11  3:41 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On Fri, Aug 10, 2012 at 10:06 PM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 10 August 2012 19:53, Steven <wangwangkang@gmail.com> wrote:
>> On Fri, Aug 10, 2012 at 11:47 AM, Peter Maydell
>> <peter.maydell@linaro.org> wrote:
>>> On 10 August 2012 03:11, Steven <wangwangkang@gmail.com> wrote:
>>>> The function definition has a return address type tb_page_addr_t.
>>>> tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
>>>>
>>>> I am wondering is this address the guest physical address or the host
>>>> virtual address.
>>>
>>> In linux-user mode the returned address is the guest virtual address.
>>> In system mode it is a ram_addr_t. (the comment above the implementation
>>> says "the returned address is not exactly the physical address: it
>>> is the offset relative to phys_ram_base" but this is out of date I think).
>>> A ram_addr_t is neither a host address nor a guest physical address
>>> but it's closely related to a guest physaddr (you can think of it as
>>> if all the RAM in the system was put into a straight line and then the
>>
>> My question is related to system mode.
>> Is the RAM you mean the guest physical address, which is a continuous
>> sequence of numbers beginning from 0 to the max of allocated RAM of
>> the guest?
>>
>>> ram_addr_t is an index into that).
>>
>> If the returned value of get_page_addr_code is the index to that
>> straight line, I am wondering if it is the guest physical address.
>
> No, it is definitely not the guest physical address. Consider
> the case where there are two aliases of the same RAM in
> guest physical memory -- two physical addresses might
> map to a single ram_addr_t. Consider the case where there
> is a 'hole' in memory -- ram_addr_t and physical address are
> not identical there either.
>
>> So if I want to get the guest physical address (GPA) of a
>> tb_page_addr_t, can I do
>>   tb_page_addr_t = returned value from get_page_addr_code  + phys_ram_base
>> Is this translation correct?
>
> This is wrong on several counts: (a) there's no such thing
> as phys_ram_base any more (it was removed several years
> ago) and (b) there is no single unique guest physical
> address corresponding to a tb_page_addr_t, so what
> you are trying to do is not well defined.
>
> What are you trying to do anyway and why do you want
> to call get_page_addr_code() ?
>
> -- PMM

I want to get the guest physical address of a pc. I note the part of
the function cpu_x86_handle_mmu_fault will do something like page
walking to convert a pc to its guest physical address. I think this is
the guest physical address I need. However, there is no other function
available to do this page walking.
So I am thinking add a function to do the conversion.

After you mentions about the memory region, do you think the following
formula is correct

        guest_physical address = block->mr->addr + (pc's host virtual
address - block->host)
                                                    ^
                          ^
                             Base of the mapped memory block
    (offset in the memory block)
Or do you have any suggestion? Thanks.

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

* Re: [Qemu-devel] Is the return address of get_page_addr_code guest physical address?
  2012-08-11  3:41       ` Steven
@ 2012-08-11 11:16         ` Laurent Desnogues
  0 siblings, 0 replies; 7+ messages in thread
From: Laurent Desnogues @ 2012-08-11 11:16 UTC (permalink / raw)
  To: Steven; +Cc: Peter Maydell, qemu-devel

On Sat, Aug 11, 2012 at 5:41 AM, Steven <wangwangkang@gmail.com> wrote:
[...]
> I want to get the guest physical address of a pc. I note the part of
> the function cpu_x86_handle_mmu_fault will do something like page
> walking to convert a pc to its guest physical address. I think this is
> the guest physical address I need. However, there is no other function
> available to do this page walking.
> So I am thinking add a function to do the conversion.

If you want the translation of any guest virtual address to guest physical
address then cpu_x86_handle_mmu_fault is close to what you want.  Of
course you'd have to rewrite it as you probably don't want your function
to change the CPU env.

Perhaps cpu_get_phys_page_debug is even closer to what you need,
but I'm not familiar enough with x86 to say for sure.


Laurent

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

end of thread, other threads:[~2012-08-11 11:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-10  2:11 [Qemu-devel] Is the return address of get_page_addr_code guest physical address? Steven
2012-08-10 15:47 ` Peter Maydell
2012-08-10 17:36   ` Steven
2012-08-10 18:53   ` Steven
2012-08-11  2:06     ` Peter Maydell
2012-08-11  3:41       ` Steven
2012-08-11 11:16         ` Laurent Desnogues

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