• Jeremy Fitzhardinge's avatar
    xen64: allocate and manage user pagetables · d6182fbf
    Jeremy Fitzhardinge authored
    Because the x86_64 architecture does not enforce segment limits, Xen
    cannot protect itself with them as it does in 32-bit mode.  Therefore,
    to protect itself, it runs the guest kernel in ring 3.  Since it also
    runs the guest userspace in ring3, the guest kernel must maintain a
    second pagetable for its userspace, which does not map kernel space.
    Naturally, the guest kernel pagetables map both kernel and userspace.
    
    The userspace pagetable is attached to the corresponding kernel
    pagetable via the pgd's page->private field.  It is allocated and
    freed at the same time as the kernel pgd via the
    paravirt_pgd_alloc/free hooks.
    
    Fortunately, the user pagetable is almost entirely shared with the
    kernel pagetable; the only difference is the pgd page itself.  set_pgd
    will populate all entries in the kernel pagetable, and also set the
    corresponding user pgd entry if the address is less than
    STACK_TOP_MAX.
    
    The user pagetable must be pinned and unpinned with the kernel one,
    but because the pagetables are aliased, pgd_walk() only needs to be
    called on the kernel pagetable.  The user pgd page is then
    pinned/unpinned along with the kernel pgd page.
    
    xen_write_cr3 must write both the kernel and user cr3s.
    
    The init_mm.pgd pagetable never has a user pagetable allocated for it,
    because it can never be used while running usermode.
    
    One awkward area is that early in boot the page structures are not
    available.  No user pagetable can exist at that point, but it
    complicates the logic to avoid looking at the page structure.
    Signed-off-by: default avatarJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
    Cc: Stephen Tweedie <sct@redhat.com>
    Cc: Eduardo Habkost <ehabkost@redhat.com>
    Cc: Mark McLoughlin <markmc@redhat.com>
    Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
    d6182fbf
mmu.h 1.58 KB