grant table interface addition?
In order to be able to set some of the available bits in the pte resulting from gnttab_set_map_op() (in particular PAGE_SPECIAL and possibly PAGE_IO), it would seem necessary to extend the set of flags that can be passed to that function. While the addition by itself is a simple operation, the question is how to deal with backward compatibility here: Is there anything preventing the guest kernel from setting the flags it wants manually after Xen established the mapping, i.e. would Xen either disallow any modification to such pte-s, or get confused by the pte not being identical to what it set it to?
As to PAGE_IO, wouldn't it be appropriate to set this flag on pte-s created with GNTMAP_device_map? Or is the name misleading me? I'm perhaps confused by the fact that the use of this flag is not tied to granting iomem pages...
Thanks, Jan
Quoted 11 lines · Jan Beulich
In order to be able to set some of the available bits in the pte resulting from
gnttab_set_map_op()(in particularPAGE_SPECIALand possiblyPAGE_IO), it would seem necessary to extend the set of flags that can be passed to that function. While the addition by itself is a simple operation, the question
is how to deal with backward compatibility here: Is there anything preventing the guest kernel from setting the flags it wants manually after Xen established the mapping, i.e. would Xen either disallow any modification to such pte-s, or get confused by the pte not being identical to what it set it to?
I think mod_l1_entry() would allow this since it does no validation unless the mapping or PRESENT/RW change. Direct page-table writing won't work as it happens since it will want to get_page() which of course won't work on a foreign page. It could be given the same fast path as mod_l1_entry(), of course.
Quoted 4 lines
As to
PAGE_IO, wouldn't it be appropriate to set this flag on pte-s created withGNTMAP_device_map? Or is the name misleading me? I'm perhaps confused by the fact that the use of this flag is not tied to granting iomem pages...
The idea was that this would grant-map pages into an iommu. Really it's not actually been used, but GNTMAP_device_map doesn't cause mappings to appear in host page tables.
-- Keir
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 30.10.08 15:15 >>>
Quoted 4 lines · Jan Beulich
As to
PAGE_IO, wouldn't it be appropriate to set this flag on pte-s created withGNTMAP_device_map? Or is the name misleading me? I'm perhaps confused by the fact that the use of this flag is not tied to granting iomem pages...The idea was that this would grant-map pages into an iommu. Really it's not actually been used, but
GNTMAP_device_mapdoesn't cause mappings to appear in host page tables.
It actually is being used in Solarflare's acceleration backend - what you say makes me think this could be wrong then.
Jan
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 30.10.08 15:15 >>>
Quoted 4 lines · Jan Beulich
As to
PAGE_IO, wouldn't it be appropriate to set this flag on pte-s created withGNTMAP_device_map? Or is the name misleading me? I'm perhaps confused by the fact that the use of this flag is not tied to granting iomem pages...
Quoted 6 lines
Quoted 3 lines
The idea was that this would grant-map pages into an iommu. Really it's not actually been used, but
GNTMAP_device_mapdoesn't cause mappings to appear in host page tables.It actually is being used in Solarflare's acceleration backend - what you say makes me think this could be wrong then.
I suppose it's useful if you only want the machine address of the granted page, and don't care about getting a host mapping.
-- Keir
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 30.10.08 15:15 >>>
Quoted 11 lines · Jan Beulich
In order to be able to set some of the available bits in the pte resulting from
gnttab_set_map_op()(in particularPAGE_SPECIALand possiblyPAGE_IO), it would seem necessary to extend the set of flags that can be passed to that function. While the addition by itself is a simple operation, the question
is how to deal with backward compatibility here: Is there anything preventing the guest kernel from setting the flags it wants manually after Xen established the mapping, i.e. would Xen either disallow any modification to such pte-s, or get confused by the pte not being identical to what it set it to?
Quoted 5 lines
I think
mod_l1_entry()would allow this since it does no validation unless the mapping or PRESENT/RW change. Direct page-table writing won't work as it happens since it will want toget_page()which of course won't work on a foreign page. It could be given the same fast path asmod_l1_entry(), of course.
That's probably not needed. Since we know the (machine) address of the pte at that point anyway, the cheapest thing to do would be to use mmu_update here (and as honoring these new flags will need to be advertised through another new feature flag, batching the two steps would anyway be desirable.
Looking at that code I see some other potential issue, though:GRANT_PTE_FLAGS include PAGE_USER for x86-64, but the generated pte is passed through adjust_guest_l1e(), so without GNTMAP_application_map we'd get global kernel mappings. Am I wrong here?
Plus I would think that GRANT_PTE_FLAGS really should include PAGE_NX.
Jan
Quoted 5 lines · Jan Beulich
Looking at that code I see some other potential issue, though:
GRANT_PTE_FLAGSincludePAGE_USERfor x86-64, but the generated pte is passed throughadjust_guest_l1e(), so withoutGNTMAP_application_mapwe'd get global kernel mappings. Am I wrong here?
GRANT_PTE_FLAGS should include _PAGE_GUEST_KERNEL then?
Quoted 1 line
Plus I would think that
GRANT_PTE_FLAGSreally should includePAGE_NX.
Yeah, makes sense.
-- Keir
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 31.10.08 17:03 >>>
Quoted 5 lines · Jan Beulich
Looking at that code I see some other potential issue, though:
GRANT_PTE_FLAGSincludePAGE_USERfor x86-64, but the generated pte is passed throughadjust_guest_l1e(), so withoutGNTMAP_application_mapwe'd get global kernel mappings. Am I wrong here?
GRANT_PTE_FLAGSshould include_PAGE_GUEST_KERNELthen?
No, it should uniformly include neither _PAGE_USER nor _PAGE_GUEST_KERNEL. _PAGE_USER gets set when GNTMAP_application_map is specified, and based on this setting of _PAGE_USER, adjust_guest_l1e() will set either _PAGE_GUEST_KERNEL or _PAGE_GLOBAL.
Jan
Quoted 6 lines · Jan Beulich
Quoted 1 line
GRANT_PTE_FLAGSshould include_PAGE_GUEST_KERNELthen?No, it should uniformly include neither
_PAGE_USERnor_PAGE_GUEST_KERNEL._PAGE_USERgets set whenGNTMAP_application_mapis specified, and based on this setting of_PAGE_USER,adjust_guest_l1e()will set either_PAGE_GUEST_KERNELor_PAGE_GLOBAL.
The grant code doesn't use adjust_l1e() though.
-- Keir
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 31.10.08 17:17 >>>
Quoted 6 lines · Jan Beulich
Quoted 1 line
GRANT_PTE_FLAGSshould include_PAGE_GUEST_KERNELthen?No, it should uniformly include neither
_PAGE_USERnor_PAGE_GUEST_KERNEL._PAGE_USERgets set whenGNTMAP_application_mapis specified, and based on this setting of_PAGE_USER,adjust_guest_l1e()will set either_PAGE_GUEST_KERNELor_PAGE_GLOBAL.The grant code doesn't use
adjust_l1e()though.
Both create_grant_pte_mapping() and create_grant_va_mapping() do afaics.
Jan
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 31.10.08 17:17 >>>
Quoted 6 lines · Jan Beulich
Quoted 1 line
GRANT_PTE_FLAGSshould include_PAGE_GUEST_KERNELthen?No, it should uniformly include neither
_PAGE_USERnor_PAGE_GUEST_KERNEL._PAGE_USERgets set whenGNTMAP_application_mapis specified, and based on this setting of_PAGE_USER,adjust_guest_l1e()will set either_PAGE_GUEST_KERNELor_PAGE_GLOBAL.
Quoted 4 lines
Quoted 1 line
The grant code doesn't use
adjust_l1e()though.Both
create_grant_pte_mapping()andcreate_grant_va_mapping()do afaics.
Ah yes, indeed. Please send a patch to deal with this and _PAGE_NX.
-- Keir
Quoted 13 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 31.10.08 18:00 >>>
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 31.10.08 17:17 >>>
Quoted 6 lines · Jan Beulich
Quoted 1 line
GRANT_PTE_FLAGSshould include_PAGE_GUEST_KERNELthen?No, it should uniformly include neither
_PAGE_USERnor_PAGE_GUEST_KERNEL._PAGE_USERgets set whenGNTMAP_application_mapis specified, and based on this setting of_PAGE_USER,adjust_guest_l1e()will set either_PAGE_GUEST_KERNELor_PAGE_GLOBAL.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
The grant code doesn't use
adjust_l1e()though.Both
create_grant_pte_mapping()andcreate_grant_va_mapping()do afaics.Ah yes, indeed. Please send a patch to deal with this and
_PAGE_NX.
Since page table entries created through e.g. GNTTABOP_map_grant_ref are being passed through adjust_guest_l1e(), they must not generally get _PAGE_USER set - this will be taken care of by adjust_guest_l1e(), and it will ensure that these don't get _PAGE_GLOBAL set inadvertently.
Due to the implied security aspect here (_PAGE_GLOBAL getting set on kernel pages for x86-64), I'd like to ask that this also be applied to older maintained branches.
At the same time, set _PAGE_NX for pte-s created for grants (as long as hardware supports it), since it should be only data pages that remote domains are being given access to.
xen/include/asm-x86/page.h +3 -0
@@ -314,6 +314,9 @@ unsigned long clone_idle_pagetable(struc#define __PAGE_HYPERVISOR_NOCACHE \ (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED) +#define GRANT_PTE_FLAGS \ + (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_NX | _PAGE_GNTTAB) +#ifndef __ASSEMBLY__static inline int get_order_from_bytes (paddr_t size)
xen/include/asm-x86/x86_32/page.h +0 -3
@@ -105,9 +105,6 @@ extern unsigned int PAGE_HYPERVISOR_NOCA#define get_pte_flags (x) (((int)((x) >> 32) & ~0xFFF) | ((int)(x) & 0xFFF))#define put_pte_flags (x) (((intpte_t)((x) & ~0xFFF) << 32) | ((x) & 0xFFF)) -#define GRANT_PTE_FLAGS \ - (_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_GNTTAB) -/* * Disallow unused flag bits plus PAT/PSE, PCD, PWT and GLOBAL. * Permit the NX bit if the hardware supports it.
xen/include/asm-x86/x86_64/page.h +0 -3
@@ -124,9 +124,6 @@ typedef l4_pgentry_t root_pgentry_t;#define PAGE_HYPERVISOR (__PAGE_HYPERVISOR | _PAGE_GLOBAL)#define PAGE_HYPERVISOR_NOCACHE (__PAGE_HYPERVISOR_NOCACHE | _PAGE_GLOBAL) -#define GRANT_PTE_FLAGS \ - (_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_GNTTAB|_PAGE_USER) -#define USER_MAPPINGS_ARE_GLOBAL #ifdef USER_MAPPINGS_ARE_GLOBAL /*