Xen PV support for hugepages
PATCH 1/1 Xen PV support for hugepages
This is the latest version of a patch that adds hugepage support to the Xen hypervisor in a PV environment. It is against the latest xen-unstable tree on xenbits.xensource.com. I believe this version addresses the comments made about the previous version of the patch.
Hugepage support must be enabled via the hypervisor command line option "allowhugepage".
It assumes the guest guarantees that the hugepage is physically aligned and contiguous.
There is currently no support in the tools for saving/restoring/migrating guests who use hugepages.
Note to the maintainers: What else needs to be done for this patch to be considered for inclusion into the tree?
----
./xen/include/asm-x86/mm.h renamed from /./xen/include/asm-x86/mm.h +2 -0
@@ -240,6 +240,8 @@ pae_copy_root(struct vcpu *v, l3_pgentryint check_descriptor (const struct domain *,struct desc_struct *d); +extern int opt_allow_hugepage; +/****************************************************************************** * With shadow pagetables, the different kinds of address start * to get get confusing.
./xen/include/asm-x86/x86_32/page.h renamed from /./xen/include/asm-x86/x86_32/page.h +1 -1
@@ -115,7 +115,7 @@ extern unsigned int PAGE_HYPERVISOR_NOCA#define BASE_DISALLOW_MASK (0xFFFFF198U & ~_PAGE_NX)#define L1_DISALLOW_MASK (BASE_DISALLOW_MASK | _PAGE_GNTTAB) -#define L2_DISALLOW_MASK (BASE_DISALLOW_MASK) +#define L2_DISALLOW_MASK (BASE_DISALLOW_MASK & ~_PAGE_PSE)#define L3_DISALLOW_MASK 0xFFFFF1FEU/* must-be-zero */ #endif /* __X86_32_PAGE_H__ */
./xen/include/asm-x86/x86_64/page.h renamed from /./xen/include/asm-x86/x86_64/page.h +1 -1
@@ -115,7 +115,7 @@ typedef l4_pgentry_t root_pgentry_t;#define BASE_DISALLOW_MASK (0xFF800198U & ~_PAGE_NX)#define L1_DISALLOW_MASK (BASE_DISALLOW_MASK | _PAGE_GNTTAB) -#define L2_DISALLOW_MASK (BASE_DISALLOW_MASK) +#define L2_DISALLOW_MASK (BASE_DISALLOW_MASK & ~_PAGE_PSE)#define L3_DISALLOW_MASK (BASE_DISALLOW_MASK)#define L4_DISALLOW_MASK (BASE_DISALLOW_MASK)
./xen/arch/x86/mm.c renamed from /./xen/arch/x86/mm.c +75 -9
121 lines not on this page · raw message
./xen/arch/x86/traps.c renamed from /./xen/arch/x86/traps.c +7 -3
@@ -723,7 +723,8 @@ static void pv_cpuid(struct cpu_user_reg {/* Modify Feature Information. */ __clear_bit (X86_FEATURE_VME , &d); -__clear_bit (X86_FEATURE_PSE , &d); +if (!opt_allow_hugepage) +__clear_bit (X86_FEATURE_PSE , &d);__clear_bit (X86_FEATURE_PGE , &d);__clear_bit (X86_FEATURE_MCE , &d);__clear_bit (X86_FEATURE_MCA , &d);
@@ -2002,9 +2003,12 @@ static int emulate_privileged_op(structcase 4 :/* Read CR4 */ /* * Guests can read CR4 to see what features Xen has enabled. We -* therefore lie about PGE & PSE as they are unavailable to guests. +* therefore lie about PGE as it is unavailable to guests. +* Also disallow PSE if hugepages are not enabled. */ - *reg =read_cr4 () & ~(X86_CR4_PGE |X86_CR4_PSE ); + *reg =read_cr4 () & ~(X86_CR4_PGE ); +if (!opt_allow_hugepage) + *reg &= ~(X86_CR4_PSE );break ;default :
Quoted 8 lines · On 4/11/08 15:41, "[email protected]" <[email protected]> wrote:
This is the latest version of a patch that adds hugepage support to the Xen hypervisor in a PV environment. It is against the latest xen-unstable tree on xenbits.xensource.com. I believe this version addresses the comments made about the previous version of the patch.
Hugepage support must be enabled via the hypervisor command line option "allowhugepage".
Quoted 8 lines
It assumes the guest guarantees that the hugepage is physically aligned and contiguous.
There is currently no support in the tools for saving/restoring/migrating guests who use hugepages.
Note to the maintainers: What else needs to be done for this patch to be considered for inclusion into the tree?
I cleaned it up, fixed some return codes, and applied as c/s 18756. It may be worth Jan Beulich taking a quick look as the return-code conventions for the get/put functions in mm.c is now rather convoluted. I think I got it right but I'm not 100% sure. Indeed, Jan, it'd sure be nice to have some comments explaining what the <0,=0,>0 codes mean from the various get/put functions, and how they differ between the l1e variants and the others (I'm pretty sure they do differ).
-- Keir
Quoted 20 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 05.11.08 11:59 >>>
Quoted 8 lines · On 4/11/08 15:41, "[email protected]" <[email protected]> wrote:
This is the latest version of a patch that adds hugepage support to the Xen hypervisor in a PV environment. It is against the latest xen-unstable tree on xenbits.xensource.com. I believe this version addresses the comments made about the previous version of the patch.
Hugepage support must be enabled via the hypervisor command line option "allowhugepage".
Quoted 8 lines
It assumes the guest guarantees that the hugepage is physically aligned and contiguous.
There is currently no support in the tools for saving/restoring/migrating guests who use hugepages.
Note to the maintainers: What else needs to be done for this patch to be considered for inclusion into the tree?
Quoted 7 lines
I cleaned it up, fixed some return codes, and applied as c/s 18756. It may be worth Jan Beulich taking a quick look as the return-code conventions for the get/put functions in
mm.cis now rather convoluted. I think I got it right but I'm not 100% sure. Indeed, Jan, it'd sure be nice to have some comments explaining what the <0,=0,>0 codes mean from the various get/put functions, and how they differ between the l1e variants and the others (I'm pretty sure they do differ).
The return value handling seems correct, but the call to map_pages_to_xen() at the end of get_page_from_l2e() doesn't: Simply or-ing the guest-provided flags into PAGE_HYPERVISOR definitely isn't correct. The cache attributes must be extracted, converted to L1 notion, and then be or-ed in.
Also, the special code to deal with LDT pages in put_page_from_l1e() should now also be required in put_page_from_l2e(). Perhaps that logic could be moved into put_data_page()?
Further, with L2_DISALLOW_MASK now permitting _PAGE_PSE, the use site in mod_l2_entry() must certainly also be modified, i.e. the subsequent l2e_has_changed() would need to include _PAGE_PSE, and the case of _PAGE_RW toggling when _PAGE_PSE was and will be set needs to be taken care of.
Next, adjust_guest_l2e() would apparently also need to be modified.
Finally, no longer hiding X86_FEATURE_PSE from the guest seems rather
risky: I'm pretty sure the pv-ops kernel relies on this flag being clear - when set, it would blindly (i.e. without ensuring the underlying memory is contiguous and suitably aligned) try to use 2Mb mappings for e.g. the 1:1 mapping. I would think this capability ought to be propagated by another means. Likewise I'm uncertain about letting X86_CR4_PSE shine through.
And a general question: How is a trivial DomU going to be able to make use of this, without being permitted to allocate non-order-zero chunks of memory?
Jan
Quoted 4 lines · Jan Beulich
The return value handling seems correct, but the call to
map_pages_to_xen()at the end ofget_page_from_l2e()doesn't: Simply or-ing the guest-provided flags intoPAGE_HYPERVISORdefinitely isn't correct. The cache attributes must be extracted, converted to L1 notion, and then be or-ed in.
Oops. I thought I'd fixed that. Apparently I looked at it and got sidetracked. I'll fix.
Quoted 3 lines
Also, the special code to deal with LDT pages in
put_page_from_l1e()should now also be required input_page_from_l2e(). Perhaps that logic could be moved intoput_data_page()?
It looks to me like this is only done for PGT_seg_desc_page. I don't think any hugepage can be of this type. I can add it to put_data_page() if you think we need to be sure.
Quoted 7 lines
Further, with
L2_DISALLOW_MASKnow permitting_PAGE_PSE, the use site inmod_l2_entry()must certainly also be modified, i.e. the subsequentl2e_has_changed()would need to include_PAGE_PSE, and the case of_PAGE_RWtoggling when_PAGE_PSEwas and will be set needs to be taken care of.Next,
adjust_guest_l2e()would apparently also need to be modified.
I'll look more closely into those.
Quoted 10 lines
Finally, no longer hiding
X86_FEATURE_PSEfrom the guest seems rather
risky: I'm pretty sure the pv-ops kernel relies on this flag being clear - when set, it would blindly (i.e. without ensuring the underlying memory is contiguous and suitably aligned) try to use 2Mb mappings for e.g. the 1:1 mapping. I would think this capability ought to be propagated by another means. Likewise I'm uncertain about lettingX86_CR4_PSEshine through.And a general question: How is a trivial DomU going to be able to make use of this, without being permitted to allocate non-order-zero chunks of memory?
This is the point of having hugepages a command line option. It should only be turned on if you intend to run guests who enforce the alignment rules. I'm working on ways to get guests to run in aligned memory.
Dave McCracken
Oracle Corp.
Quoted 7 lines · Dave McCracken
Quoted 3 lines
Also, the special code to deal with LDT pages in
put_page_from_l1e()should now also be required input_page_from_l2e(). Perhaps that logic could be moved intoput_data_page()?It looks to me like this is only done for
PGT_seg_desc_page. I don't think any hugepage can be of this type. I can add it toput_data_page()if you think we need to be sure.
The data pages mapped by a superpage mapping aren't special. One of them could certainly be PGT_seg_desc_page. Hence moving the logic into put_data_page() makes sense.
-- Keir
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Dave McCracken <[email protected]> 06.11.08 14:44 >>>
Finally, no longer hiding
X86_FEATURE_PSEfrom the guest seems rather
risky: I'm pretty sure the pv-ops kernel relies on this flag being clear - when set, it would blindly (i.e. without ensuring the underlying memory is contiguous and suitably aligned) try to use 2Mb mappings for e.g. the 1:1 mapping. I would think this capability ought to be propagated by another means. Likewise I'm uncertain about lettingX86_CR4_PSEshine through.
Quoted 6 lines
Quoted 3 lines
And a general question: How is a trivial DomU going to be able to make use of this, without being permitted to allocate non-order-zero chunks of memory?
This is the point of having hugepages a command line option. It should only be turned on if you intend to run guests who enforce the alignment rules.
You mean 'if you intend to run *only* guests ...', including dom0. Any guest unaware of the connection of X86_FEATURE_PSE and the need to create contiguous 2M chunks would fail, and any guest not having I/O memory assigned would never manage to create such chunks.
Jan
Quoted 8 lines · Jan Beulich
Quoted 3 lines
This is the point of having hugepages a command line option. It should only be turned on if you intend to run guests who enforce the alignment rules.
You mean 'if you intend to run *only* guests ...', including dom0. Any guest unaware of the connection of
X86_FEATURE_PSEand the need to create contiguous 2M chunks would fail, and any guest not having I/O memory assigned would never manage to create such chunks.
Hmm... Sounds like a per-domain flag would be a good solution here. I'll look into it.
Dave McCracken
Quoted 6 lines · Dave McCracken
Quoted 4 lines · Jan Beulich
Quoted 4 lines
This is the point of having hugepages a command line option. It should only be turned on if you intend to run guests who enforce the alignment rules.
Quoted 8 lines
Quoted 5 lines
You mean 'if you intend to run *only* guests ...', including dom0. Any guest unaware of the connection of
X86_FEATURE_PSEand the need to create contiguous 2M chunks would fail, and any guest not having I/O memory assigned would never manage to create such chunks.Hmm... Sounds like a per-domain flag would be a good solution here. I'll look into it.
I think a guest should explicitly enable large page support via something like vmassist. In other words:
* keep PSE clear - you are not implementing something similar to PSE
* export the ability to map large pages via a feature flag or something
* require guests to explicitly enable large page support
I'm sceptical about the value of this patch as it stands. We already have a vast number of operating modes and combinations, and I think we need to have a pretty high bar before adding any more. If this work arranged things so that we could just set PSE - and thereby make supporting it on the guest side much simpler - then I think the decision to include it would be easier.
In practical terms, I think this means that we need to modify Xen and the domain builder to *always* allocate memory to guests in 2M contig chunks, and then sort out all the tricky details ;) In practice, however, we would lose a lot of the benefit of doing this we'd get from the native kernel, because all the RO pagetable mappings would chop up the linear and kernel maps so much that we'd not get much chance to use the 2M mappings. It would, however, make hugetlbfs work without much drama.
J