Skip to contentSkip to conversation

xc_translate_foreign_address() returns mfn??

DISCUSSION Jun Koi 2 participants 4 messages Dec 19, 2008

lore
Share & tools
lore

Jun Koi

author
#0 lore raw

Hi,

I looked at the function xc_translate_foreign_address(), and see that it walks the page table of the guest VM. So at best, it should return the pfn of the guest (?)

We can see taht the Later part of the function is like this:
...

        if (pt_levels >= 3)
            mfn = (pte & L0_PAGETABLE_MASK_PAE) >> PAGE_SHIFT;
        else
            mfn = (pte & L0_PAGETABLE_MASK) >> PAGE_SHIFT;

..
return mfn;

So perhaps I miss something, but the "mfn" here should be "pfn", so this function should return pfn, not mfn as in the comment of xenctrl.h.

This makes me very confused now.

Thanks,
Jun

author
#1 lore raw
Quoted 12 lines · Jun Koi

Hi,

I looked at the function xc_translate_foreign_address(), and see that it walks the page table of the guest VM. So at best, it should return the pfn of the guest (?)

We can see taht the Later part of the function is like this:
...

       if (pt_levels >= 3)
           mfn = (pte & L0_PAGETABLE_MASK_PAE) >> PAGE_SHIFT;
       else
           mfn = (pte & L0_PAGETABLE_MASK) >> PAGE_SHIFT;
Quoted 8 lines

..
return mfn;

So perhaps I miss something, but the "mfn" here should be "pfn", so this function should return pfn, not mfn as in the comment of xenctrl.h.

This makes me very confused now.

So everything indicates that xc_translate_foreign_address() actually returns gfn, not mfn like in its comment. Could anybody confirms that the function works well on both PV and HVM?

And I think xc_map_foreign_range() actually works with gfn, not mfn. Does it work with both PV and HVM, too?

Thanks,
Jun

#2 lore raw

Hi,

Quoted 3 lines · Jun Koi

So everything indicates that xc_translate_foreign_address() actually returns gfn, not mfn like in its comment. Could anybody confirms that the function works well on both PV and HVM?

To the best of my knowledge that function does not work at all for HVM (at least, I know it is broken when using 32-bit tools and 64-bit xen). I have a half-done patchset that cleans it up considerably, fixing HVM and compat issues, which I'll probably post at the end of the month.

In any case, you are right: these functions (like _almost_ every other interface dealing with guest memory) deals in what in the shadow code are called GFNs. That is, untranslated GPFNs for HVM guests, and MFNs for PV.

The use of "mfn" in the source code is probably an indicator that this code pre-dates HVM guest support.

Quoted 2 lines

And I think xc_map_foreign_range() actually works with gfn, not mfn. Does it work with both PV and HVM, too?

Yes indeed! Lots of other things rely on it (qemu-dm, save/restore, etc).

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Citrix Systems (R&D) Ltd.
[Company #02300071, SL9 0DZ, UK.]
author
#3 lore raw
Quoted 12 lines · Tim Deegan

Hi,

Quoted 3 lines · Jun Koi

So everything indicates that xc_translate_foreign_address() actually returns gfn, not mfn like in its comment. Could anybody confirms that the function works well on both PV and HVM?

To the best of my knowledge that function does not work at all for HVM (at least, I know it is broken when using 32-bit tools and 64-bit xen). I have a half-done patchset that cleans it up considerably, fixing HVM and compat issues, which I'll probably post at the end of the month.

Quoted 6 lines

In any case, you are right: these functions (like _almost_ every other interface dealing with guest memory) deals in what in the shadow code are called GFNs. That is, untranslated GPFNs for HVM guests, and MFNs for PV.

The use of "mfn" in the source code is probably an indicator that this code pre-dates HVM guest support.

That is a smart guess, I think :-)

And please fix the comment to reflect this in your new code.

Many thanks,
J