device-mmio emulation in Xen
Hi there,
I am trying to understand how does Xen handle device MMIO. More specifically, I am looking at the network behavior, however my understanding is that other devices such as disk will use the same logic.
I noticed that during a network copy operation Xen page faults a lot and control goes to sh_page_fault function. When I printed some debugging info, it showed me gmfn = -1. Then the execution goes through the regular path of the page fault handler code, which means it creates an entry using shadow_get_and_create_l1e, propagates it using l1e_propagate_from_guest, and finally updates the entry using shadow_set_l1e. It finally goes into the device-model mmio condition. In this condition, it extracts a guest physical address and calls "goto mmio", which in turn calls handle_mmio function that emulates the instruction.
However with the gmfn = -1 condition, the execution sometimes directly goto
to handle_mmio function using the fast_fault_path with going through the regular path. It seems like there are two possible execution paths, and I did not understand which one is chosen when?
I have some questions related to this behavior:
1. Why are there so many faults duing network copy operation?
2. What does gmfn = -1 signify? Is it reserved for mmio addresses?
3. How does Xen handle this gmfn = -1? It seems like on the regular path
it still creates, propagates, and updates entries for gmfn = -1. How does Xen handles this at the shadow page table level?
4. What are these two code execution paths, and when does Xen decide which path to choose?
5. Finally, is there anyway these faults can be reduced?
I would very appreciate any help in this regard.
Thanks,
Abhinav
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Hi,
Quoted 5 lines · Abhinav Srivastava
I noticed that during a network copy operation Xen page faults a lot and control goes to
sh_page_faultfunction. When I printed some debugging info, it showed me gmfn = -1. Then the execution goes through the regular path of the page fault handler code, which means it creates an entry usingshadow_get_and_create_l1e, propagates it usingl1e_propagate_from_guest, and finally updates the entry usingshadow_set_l1e. It finally goes into the device-model mmio condition. In this condition, it extracts a guest physical address and calls "goto mmio", which in turn callshandle_mmiofunction that emulates the instruction.However with the gmfn = -1 condition, the execution sometimes directly goto
tohandle_mmiofunction using thefast_fault_pathwith going through the regular path. It seems like there are two possible execution paths, and I did not understand which one is chosen when?
/******************************************************************************
* We implement a "fast path" for two special cases: faults that require
* MMIO emulation, and faults where the guest PTE is not present. We
* record these as shadow l1 entries that have reserved bits set in
* them, so we can spot them immediately in the fault handler and handle
* them without needing to hold the shadow lock or walk the guest
* pagetables.
*
* This is only feasible for PAE and 64bit Xen: 32-bit non-PAE PTEs don't
* have reserved bits that we can use for this.
*/
Quoted 3 lines
I have some questions related to this behavior:
1. Why are there so many faults duing network copy operation?
The faults are a HVM guest doing MMIO operations to control its emulated network card.
Quoted 1 line
2. What does gmfn = -1 signify? Is it reserved for mmio addresses?
It's INVALID_MFN. It means there is no memory mapped at the address the guest accessed. Xen treats that as MMIO, though there's a plan to have MMIO regions explicitly registered instead.
Quoted 2 lines
3. How does Xen handle this gmfn = -1? It seems like on the regular path
it still creates, propagates, and updates entries for gmfn = -1. How does Xen handles this at the shadow page table level?
Yes, it creates a deliberately invalid shadow PTE; then in the pagefault handler it can use the pagefault error code and the contents of the PTE to skip the bulk of the shadow fault handling and go straight to handle_mmio.
Quoted 4 lines
4. What are these two code execution paths, and when does Xen decide which path to choose?
5. Finally, is there anyway these faults can be reduced?
Yes, use PV drivers in the guest. That eliminates the whole emulated-MMIO system, and all the pagefaults associated with it.
Cheers,
Tim.
Quoted 13 lines
I would very appreciate any help in this regard.
Thanks,
AbhinavThe INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]
Hi Tim,
Thanks for the reply. I understood what you had described. However, I have one question:
1. How does Xen know which code path to execute? What I am noticing is that sometimes it goes to all the way till the end of the page fault handler code to call handle_mmio function, and sometimes it goes into the fast path to call this function, bypassing all the page fault handlers code? Why it does not go into the fast path all the time? OR Xen does something at the first time so that second time, the execution can directly go into the fast path? And, does this needs to be done for all physical pages given to MMIO?
Thanks,
Abhinav
Quoted 101 lines · Tim Deegan
From: Tim Deegan <[email protected]>
Subject: Re: [Xen-devel] device-mmio emulation in Xen
To: "Abhinav Srivastava" <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Tuesday, 5 January, 2010, 9:30 PM
Hi,At 15:32 +0000 on 05 Jan (1262705557), Abhinav Srivastava
Quoted 1 line · wrote:
I noticed that during a network copy operation Xen
page faults a lot and control goes to
sh_page_faultfunction. When I printed some debugging info, it showed me gmfn = -1. Then the execution goes through the regular path of the page fault handler code, which means it creates an entry usingshadow_get_and_create_l1e, propagates it usingl1e_propagate_from_guest, and finally updates the entry usingshadow_set_l1e. It finally goes into the device-model mmio condition. In this condition, it extracts a guest physical address and calls "goto mmio", which in turn callshandle_mmiofunction that emulates the instruction.Quoted 2 lines
However with the gmfn = -1 condition, the execution
sometimes directly goto
Quoted 1 line
to
handle_mmiofunction using thefast_fault_pathwithgoing through the regular path. It seems like there are two possible execution paths, and I did not understand which one is chosen when?
Quoted 1 line
/******************************************************************************
* We implement a "fast path" for two special cases: faults
that require
* MMIO emulation, and faults where the guest PTE is not
present. We
* record these as shadow l1 entries that have reserved
bits set in
* them, so we can spot them immediately in the fault
handler and handle
* them without needing to hold the shadow lock or walk the
guest
* pagetables.
*
* This is only feasible for PAE and 64bit Xen: 32-bit
non-PAE PTEs don't
* have reserved bits that we can use for this.
*/Quoted 3 lines
I have some questions related to this behavior:
1. Why are there so many faults duing network copy
operation?
The faults are a HVM guest doing MMIO operations to control its emulated
network card.Quoted 1 line
2. What does gmfn = -1 signify? Is it reserved for
mmio addresses?
It's INVALID_MFN. It means there is no memory mapped at the address the
guest accessed. Xen treats that as MMIO, though there's a plan to have
MMIO regions explicitly registered instead.Quoted 1 line
3. How does Xen handle this gmfn = -1? It seems like
on the regular path
Quoted 1 line
it still creates, propagates, and updates entries for
gmfn = -1. How does Xen handles this at the shadow page table level?
Yes, it creates a deliberately invalid shadow PTE; then in the pagefault
handler it can use the pagefault error code and the contents of the PTE
to skip the bulk of the shadow fault handling and go straight tohandle_mmio.Quoted 1 line
4. What are these two code execution paths, and when
does Xen decide which
Quoted 3 lines
path to choose?
5. Finally, is there anyway these faults can be
reduced?
Yes, use PV drivers in the guest. That eliminates the whole
emulated-MMIO system, and all the pagefaults associated with it.Cheers,
Tim.
Quoted 7 lines
I would very appreciate any help in this regard.
Thanks,
Abhinav
Quoted 13 lines
Quoted 1 line
The INTERNET now has a
personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-develSignature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Quoted 7 lines · Abhinav Srivastava
1. How does Xen know which code path to execute? What I am noticing is that sometimes it goes to all the way till the end of the page fault handler code to call
handle_mmiofunction, and sometimes it goes into the fast path to call this function, bypassing all the page fault handlers code? Why it does not go into the fast path all the time? OR Xen does something at the first time so that second time, the execution can directly go into the fast path?
Yes. In the slow path, it creates a deliberately invalid shadow PTE. When the MMU signals an invalid-PTE fault, Xen knows tro take the fast path.
Quoted 1 line
And, does this needs to be done for all physical pages given to MMIO?
Yes. Some kind of pagefault needs to happen for emulated MMIO. The fast-path trick just makes the fault handler faster.
Tim.
Quoted 125 lines
Thanks,
AbhinavQuoted 101 lines · Tim Deegan
From: Tim Deegan <[email protected]>
Subject: Re: [Xen-devel] device-mmio emulation in Xen
To: "Abhinav Srivastava" <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Tuesday, 5 January, 2010, 9:30 PM
Hi,At 15:32 +0000 on 05 Jan (1262705557), Abhinav Srivastava
Quoted 1 line · wrote:
I noticed that during a network copy operation Xen
page faults a lot and control goes to
sh_page_faultfunction. When I printed some debugging info, it showed me gmfn = -1. Then the execution goes through the regular path of the page fault handler code, which means it creates an entry usingshadow_get_and_create_l1e, propagates it usingl1e_propagate_from_guest, and finally updates the entry usingshadow_set_l1e. It finally goes into the device-model mmio condition. In this condition, it extracts a guest physical address and calls "goto mmio", which in turn callshandle_mmiofunction that emulates the instruction.Quoted 2 lines
However with the gmfn = -1 condition, the execution
sometimes directly goto
Quoted 1 line
to
handle_mmiofunction using thefast_fault_pathwithgoing through the regular path. It seems like there are two possible execution paths, and I did not understand which one is chosen when?
Quoted 1 line
/******************************************************************************
* We implement a "fast path" for two special cases: faults
that require
* MMIO emulation, and faults where the guest PTE is not
present. We
* record these as shadow l1 entries that have reserved
bits set in
* them, so we can spot them immediately in the fault
handler and handle
* them without needing to hold the shadow lock or walk the
guest
* pagetables.
*
* This is only feasible for PAE and 64bit Xen: 32-bit
non-PAE PTEs don't
* have reserved bits that we can use for this.
*/Quoted 3 lines
I have some questions related to this behavior:
1. Why are there so many faults duing network copy
operation?
The faults are a HVM guest doing MMIO operations to control its emulated
network card.Quoted 1 line
2. What does gmfn = -1 signify? Is it reserved for
mmio addresses?
It's INVALID_MFN. It means there is no memory mapped at the address the
guest accessed. Xen treats that as MMIO, though there's a plan to have
MMIO regions explicitly registered instead.Quoted 1 line
3. How does Xen handle this gmfn = -1? It seems like
on the regular path
Quoted 1 line
it still creates, propagates, and updates entries for
gmfn = -1. How does Xen handles this at the shadow page table level?
Yes, it creates a deliberately invalid shadow PTE; then in the pagefault
handler it can use the pagefault error code and the contents of the PTE
to skip the bulk of the shadow fault handling and go straight tohandle_mmio.Quoted 1 line
4. What are these two code execution paths, and when
does Xen decide which
Quoted 3 lines
path to choose?
5. Finally, is there anyway these faults can be
reduced?
Yes, use PV drivers in the guest. That eliminates the whole
emulated-MMIO system, and all the pagefaults associated with it.Cheers,
Tim.
Quoted 7 lines
I would very appreciate any help in this regard.
Thanks,
AbhinavQuoted 13 lines
Quoted 1 line
The INTERNET now has a
personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-develSignature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]
Hi Tim,
Thanks for your reply. On the same topic, I see a lot of MMIO operations and corresponding faults on network copy operations. However, I do not see faults at the same rate on disk operations or graphics operations. Is it my perceptions or there are different tricks/methods to emulate different devices? Why networking load is showing so many MMIO faults, but not other workloads?
Thanks,
Abhinav
Quoted 201 lines · Tim Deegan
From: Tim Deegan <[email protected]>
Subject: Re: [Xen-devel] device-mmio emulation in Xen
To: "Abhinav Srivastava" <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Tuesday, 5 January, 2010, 10:08 PM
At 16:32 +0000 on 05 JanQuoted 1 line · Abhinav Srivastava
1. How does Xen know which code path to execute? What
I am noticing is
Quoted 1 line
that sometimes it goes to all the way till the end of
the page fault
Quoted 1 line
handler code to call
handle_mmiofunction, andsometimes it goes into
Quoted 1 line
the fast path to call this function, bypassing all the
page fault
Quoted 1 line
handlers code? Why it does not go into the fast path
all the time? OR
Quoted 1 line
Xen does something at the first time so that second
time, the execution
Quoted 1 line
can directly go into the fast path?
Yes. In the slow path, it creates a deliberately invalid shadow PTE.
When the MMU signals an invalid-PTE fault, Xen knows tro take the fast
path.Quoted 1 line
And, does this needs to be done for all physical pages
given to MMIO?
Yes. Some kind of pagefault needs to happen for emulated MMIO. The
fast-path trick just makes the fault handler faster.Tim.
Quoted 7 lines
Thanks,
Abhinav--- On Tue, 5/1/10, Tim Deegan <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
From: Tim Deegan <[email protected]>
Subject: Re: [Xen-devel] device-mmio emulation inXen
Quoted 2 lines
Quoted 2 lines
To: "Abhinav Srivastava" <[email protected]>
Cc: "[email protected]"Quoted 4 lines
Quoted 4 lines
Date: Tuesday, 5 January, 2010, 9:30 PM
Hi,At 15:32 +0000 on 05 Jan (1262705557), Abhinav
Srivastava
Quoted 2 lines
Quoted 2 lines
Quoted 1 line · wrote:
I noticed that during a network copy
operation Xen
Quoted 1 line
Quoted 1 line
page faults a lot and control goes to
sh_page_faultQuoted 1 line
Quoted 1 line
function. When I printed some debugging info, it
showed me
Quoted 1 line
Quoted 1 line
gmfn = -1. Then the execution goes through the
regular path
Quoted 1 line
Quoted 1 line
of the page fault handler code, which means it
creates an
Quoted 1 line
Quoted 1 line
entry using
shadow_get_and_create_l1e, propagatesit using
Quoted 1 line
Quoted 1 line
l1e_propagate_from_guest, and finally updates theentry
Quoted 1 line
Quoted 1 line
using
shadow_set_l1e. It finally goes into thedevice-model
Quoted 1 line
Quoted 1 line
mmio condition. In this condition, it extracts a
guest
Quoted 1 line
Quoted 1 line
physical address and calls "goto mmio", which in
turn calls
Quoted 1 line
Quoted 1 line
handle_mmiofunction that emulates theinstruction.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
However with the gmfn = -1 condition, the
execution
Quoted 2 lines
Quoted 2 lines
sometimes directly goto
Quoted 1 line
to
handle_mmiofunction using the
fast_fault_pathwithQuoted 1 line
Quoted 1 line
going through the regular path. It seems like
there are two
Quoted 1 line
Quoted 1 line
possible execution paths, and I did not
understand which one
Quoted 4 lines
Quoted 4 lines
is chosen when?
Quoted 1 line
/******************************************************************************
Quoted 1 line
Quoted 1 line
* We implement a "fast path" for two
special cases: faults
Quoted 2 lines
Quoted 2 lines
that require
* MMIO emulation, and faults where theguest PTE is not
Quoted 2 lines
Quoted 2 lines
present. We
* record these as shadow l1 entries thathave reserved
Quoted 2 lines
Quoted 2 lines
bits set in
* them, so we can spot them immediately inthe fault
Quoted 2 lines
Quoted 2 lines
handler and handle
* them without needing to hold the shadowlock or walk the
Quoted 4 lines
Quoted 4 lines
guest
* pagetables.
*
* This is only feasible for PAE and 64bitXen: 32-bit
Quoted 2 lines
Quoted 2 lines
non-PAE PTEs don't
* have reserved bits that we can use forthis.
Quoted 3 lines
Quoted 3 lines
*/
Quoted 1 line
I have some questions related to this
behavior:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
1. Why are there so many faults duing
network copy
Quoted 3 lines
Quoted 3 lines
operation?
The faults are a HVM guest doing MMIO operations
to control
Quoted 4 lines
Quoted 4 lines
its emulated
network card.Quoted 1 line
2. What does gmfn = -1 signify? Is it
reserved for
Quoted 3 lines
Quoted 3 lines
mmio addresses?
It's INVALID_MFN. It means there is no memory
mapped
Quoted 2 lines
Quoted 2 lines
at the address the
guest accessed. Xen treats that as MMIO,though
Quoted 4 lines
Quoted 4 lines
there's a plan to have
MMIO regions explicitly registered instead.Quoted 1 line
3. How does Xen handle this gmfn = -1? It
seems like
Quoted 2 lines
Quoted 2 lines
on the regular path
Quoted 1 line
it still creates, propagates, and updates
entries for
Quoted 1 line
Quoted 1 line
gmfn = -1. How does Xen handles this at the
shadow page
Quoted 3 lines
Quoted 3 lines
table level?
Yes, it creates a deliberately invalid shadow
PTE; then in
Quoted 2 lines
Quoted 2 lines
the pagefault
handler it can use the pagefault error code andthe
Quoted 2 lines
Quoted 2 lines
contents of the PTE
to skip the bulk of the shadow fault handling andgo
Quoted 3 lines
Quoted 3 lines
straight to
handle_mmio.Quoted 1 line
4. What are these two code execution paths,
and when
Quoted 4 lines
Quoted 4 lines
does Xen decide which
Quoted 3 lines
path to choose?
5. Finally, is there anyway these faults can
be
Quoted 3 lines
Quoted 3 lines
reduced?
Yes, use PV drivers in the guest. That
eliminates the
Quoted 2 lines
Quoted 2 lines
whole
emulated-MMIO system, and all the pagefaultsassociated
Quoted 7 lines
Quoted 7 lines
with it.
Cheers,
Tim.
Quoted 1 line
I would very appreciate any help in this
regard.
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Thanks,
AbhinavThe INTERNET now has a
personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Quoted 2 lines
_______________________________________________
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-develSignature · 2 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems
Quoted 18 lines
(R&D) Ltd.
Quoted 5 lines
Quoted 2 lines
[Company #02300071, SL9 0DZ, UK.]
The INTERNET now has a
personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Signature · 8 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.] _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/