Placing virtual machine monitor (VMM) code in guest context to speed memory mapped input/output virtualization
In one embodiment, a method comprises: obtaining use of one or more pages in a guest physical address space of a guest; storing handler code to process one or more input/output (I/O) and/or interrupt events in the one or more pages; and redirecting a first event of the one or more I/O events from guest handler code that would process the first event to the handler code in the one or more pages. Also contemplated is a computer accessible medium comprising a plurality of instructions, which, when executed by a computer, implement the method.
1. A method comprising:
obtaining use of one or more pages in a guest physical address space of a guest;
storing handler code to process one or more input/output (I/O) events in the one or more pages; and
redirecting a first event of the one or more I/O events from guest handler code that would process the first event to the handler code in the one or more pages.
2. The method as recited in claim 1 further comprising:
determining, in the handler code, that the handler code cannot complete processing of the first event; and
exiting the guest to a virtual machine monitor (VMM) to complete processing of the first event.
3. The method as recited in claim 1 further comprising:
completing the processing of the event in the handler code without exiting to a virtual machine monitor (VMM); and
continuing execution of the guest.
4. The method as recited in claim 1 wherein the first event comprises an access to an address in the guest that is memory-mapped to I/O, and wherein the method further comprises marking a translation from a guest virtual page to a memory-mapped I/O page that includes the memory-mapped I/O address not present in the guest page table, wherein an attempt to access the memory-mapped I/O address from the guest causes a page fault, and wherein the handler code is executed to handle the page fault.
5. The method as recited in claim 4 further comprising:
determining, in the handler code, that a second page fault is a page fault experienced in the guest that is not an I/O event; and
reflecting the second page fault back to the guest for handling.
6. The method as recited in claim 4 further comprising:
completing processing of the page fault in the handler code; and
returning from the handler code to the source of the page fault.
7. The method as recited in claim 4 further comprising:
determining, in the handler code, that the handler code cannot complete processing of the first event; and
exiting the guest to a virtual machine monitor (VMM) to complete processing of the first event.
8. The method as recited in claim 7 wherein the exiting comprises executing a VMMCALL instruction.
9. The method as recited in claim 7 wherein the exiting comprises a virtual machine (VM) exit.
10. The method as recited in claim 1 wherein the redirecting comprises:
copying a guest data structure that maps I/O events to various handlers to a shadow data structure;
modifying the shadow data structure to map the first event to the handler code; and
causing the guest to use the shadow data structure during execution instead of the guest data structure.
11. The method as recited in claim 10 wherein the data structure comprises an interrupt descriptor table (IDT).
12. The method as recited in claim 11 wherein modifying the shadow data structure comprises modifying a page fault entry of the IDT to indicate a task switch to the handler code.
13. The method as recited in claim 11 wherein another event of the I/O events is an interrupt.
14. A computer accessible storage medium storing a plurality of instructions which are executable to perform a method comprising:
obtaining use of one or more pages in a guest physical address space of a guest;
storing handler code to process one or more input/output (I/O) events in the one or more pages; and
redirecting a first event of the one or more I/O events from guest handler code that would process the first event to the handler code in the one or more pages.
15. The computer accessible storage medium as recited in claim 14 wherein the plurality of instructions comprises the handler code, and the method further comprises:
determining, in the handler code, that the handler code cannot complete processing of the first event; and
exiting the guest to a virtual machine monitor (VMM) to complete processing of the first event.
16. The computer accessible storage medium as recited in claim 14 wherein the wherein the redirecting comprises:
copying a guest data structure that maps I/O events to various handlers to a shadow data structure;
modifying the shadow data structure to map the first event to the handler code; and
causing the guest to use the shadow data structure during execution instead of the guest data structure.
17. The computer accessible storage medium as recited in claim 16 wherein the data structure comprises an interrupt descriptor table (IDT), and wherein the modifying comprises modifying a page fault entry of the IDT to indicate a task switch to the handler code.
18. A computer accessible storage medium storing a plurality of instructions which are executable to perform a method comprising:
obtaining use of one or more pages in a guest physical address space of a guest;
storing handler code to process one or more input/output (I/O) events in the one or more pages;
redirecting a first event of the one or more I/O events from guest handler code that would process the first event to the handler code in the one or more pages, wherein the first event comprises an access to an address in the guest that is memory-mapped to I/O; and
marking a translation from a guest virtual page to a memory-mapped I/O page that includes the memory-mapped I/O address not present in the guest page table, wherein an attempt to access the memory-mapped I/O address from the guest causes a page fault, and wherein the handler code is executed to handle the page fault.
19. The computer accessible storage medium as recited in claim 18 wherein the method further comprises:
determining, in the handler code, that a second page fault is a page fault experienced in the guest that is not an I/O event; and
reflecting the second page fault back to the guest for handling.
20. The computer accessible storage medium as recited in claim 18 wherein the method further comprises:
completing processing of the page fault in the handler code; and
returning from the handler code to the source of the page fault.
21. The computer accessible storage medium as recited in claim 18 wherein the method further comprises:
determining, in the handler code, that the handler code cannot complete processing of the first event; and
exiting the guest to a virtual machine monitor (VMM) to complete processing of the first event.