xen/arm: grant_table
v2 cover xen/arm: grant_table
Hi all,
this patch series implements the basic mechanisms needed by the grant table to work properly.
With this patch series applied and the corresponding Linux side patch series, I am able to boot a guest out of a PV disk and get the PV network up and running.
Changes in v2:
- create_grant_host_mapping returns error for read-only mappings;
- remove get_page_light reference;
- add a patch to fix the lr_queue initialization for the first 32 irqs;
- add a patch to implement get/put_page_type.
Stefano Stabellini (6):
Initialize lr_queue in vcpu_vgic_init for the first 32 irqs
xen/arm: set paging_mode_translate and paging_mode_external
xen/arm: implement page reference and grant table functions needed by grant_table.c xen/arm: implement get/put_page_type
xen/arm: create_p2m_entries should not call free_domheap_page xen/arm: grant table
xen/arch/arm/domain.c | 3 + xen/arch/arm/dummy.S | 13 -- xen/arch/arm/mm.c | 230 ++++++++++++++++++++++++++++++++++++++- xen/arch/arm/p2m.c | 82 +++++++++----- xen/arch/arm/traps.c | 1 + xen/arch/arm/vgic.c | 3 + xen/include/asm-arm/mm.h | 1 - xen/include/asm-arm/paging.h | 4 +- xen/include/public/hvm/params.h | 4 +- 9 files changed, 294 insertions(+), 47 deletions(-)
Cheers,
Stefano
PATCH v2 1/6 Initialize lr_queue in vcpu_vgic_init for the first 32 irqs
--- xen/arch/arm/vgic.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
xen/arch/arm/vgic.c +3 -0
@@ -102,7 +102,10 @@ int vcpu_vgic_init(struct vcpu *v)memset (&v->arch.vgic.pending_irqs,0 ,sizeof (v->arch.vgic.pending_irqs));for (i =0 ; i <32 ; i++) + {INIT_LIST_HEAD (&v->arch.vgic.pending_irqs[i].inflight); +INIT_LIST_HEAD (&v->arch.vgic.pending_irqs[i].lr_queue); + }printk ("vcpu_vgic_init irq[0] at %p desc is %p\n" , &v->arch.vgic.pending_irqs[0 ], v->arch.vgic.pending_irqs[0 ].desc);
Signature · 1 line
1.7.2.5
PATCH v2 2/6 xen/arm: set paging_mode_translate and paging_mode_external
On ARM, given the kind of guests we support, it makes sense to set paging_mode_translate and paging_mode_external by default.
--- xen/include/asm-arm/paging.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
xen/include/asm-arm/paging.h +2 -2
@@ -1,8 +1,8 @@#ifndef _XEN_PAGING_H#define _XEN_PAGING_H -#define paging_mode_translate (d) (0) -#define paging_mode_external (d) (0) +#define paging_mode_translate (d) (1) +#define paging_mode_external (d) (1)#endif /* XEN_PAGING_H */
Signature · 1 line
1.7.2.5
PATCH v2 3/6 xen/arm: implement page reference and grant table functions needed by grant_table.c
In reply to Stefano StabelliniThe implementation is strongly "inspired" by their x86 counterparts, except that we assume paging_mode_external and paging_mode_translate.
TODO: read_only mappings and gnttab_mark_dirty.
Changes in v2:
- create_grant_host_mapping returns error for read-only mappings;
- remove get_page_light reference.
--- xen/arch/arm/dummy.S | 9 ---- xen/arch/arm/mm.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 77 ++++++++++++++++++++++++----------- 3 files changed, 163 insertions(+), 33 deletions(-)
xen/arch/arm/dummy.S +0 -9
@@ -23,18 +23,10 @@ DUMMY(arch_vcpu_reset); NOP(update_vcpu_system_time); /* Page Reference & Type Maintenance */ -DUMMY(get_page); DUMMY(get_page_type); -DUMMY(page_get_owner_and_reference); -DUMMY(put_page); DUMMY(put_page_type); /* Grant Tables */ -DUMMY(create_grant_host_mapping); -DUMMY(gnttab_clear_flag); -DUMMY(gnttab_mark_dirty); -DUMMY(is_iomem_page); -DUMMY(replace_grant_host_mapping); DUMMY(steal_page); /* Page Offlining */
@@ -45,7 +37,6 @@ DUMMY(domain_get_maximum_gpfn); DUMMY(domain_relinquish_resources); DUMMY(domain_set_time_offset); DUMMY(dom_cow); -DUMMY(gmfn_to_mfn); DUMMY(hypercall_create_continuation); DUMMY(send_timer_event); DUMMY(share_xen_page_with_privileged_guests);
xen/arch/arm/mm.c +110 -0
116 lines not on this page · raw message
xen/arch/arm/p2m.c +53 -24
120 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH v2 3/6] xen/arm: implement page reference and grant table functions needed by grant_table.c
Quoted 4 lines · Stefano Stabellini
The implementation is strongly "inspired" by their x86 counterparts, except that we assume
paging_mode_externalandpaging_mode_translate.TODO:
read_onlymappings andgnttab_mark_dirty.
Can we add ASSERT(0) or BUG() or something on those paths, so it becomes obvious when we start hitting them.
...
Having read the patch I now see that some of them return errors, but others don't and I think they should do something noisy...
xen/arch/arm/mm.c
Quoted 8 lines
xen/arch/arm/mm.c +4
-0+ rc = -ENOMEM ; + page =alloc_domheap_page (d,0 ); +if ( page ==NULL ) { +printk ("p2m_populate_ram: failed to allocate page\n" );
Should be a gdprintk or something, since a guest can indirectly trigger this path.
Otherwise the patch looks good to me but I'd like to see Tim's opinion.
Ian.
Re: [PATCH v2 3/6] xen/arm: implement page reference and grant table functions needed by grant_table.c
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini
The implementation is strongly "inspired" by their x86 counterparts, except that we assume
paging_mode_externalandpaging_mode_translate.TODO:
read_onlymappings andgnttab_mark_dirty.
Quoted 7 lines
Can we add ASSERT(0) or
BUG()or something on those paths, so it becomes obvious when we start hitting them....
Having read the patch I now see that some of them return errors, but others don't and I think they should do something noisy...
The only path that is unimplemented is in create_grant_host_mapping, it is marked with "XXX", and prints an error message and returns an error.
Quoted 11 lines
xen/arch/arm/mm.c
Quoted 8 lines
xen/arch/arm/mm.c +4
-0+ rc = -ENOMEM ; + page =alloc_domheap_page (d,0 ); +if ( page ==NULL ) { +printk ("p2m_populate_ram: failed to allocate page\n" );Should be a gdprintk or something, since a guest can indirectly trigger this path.
yes, good idea.
Re: [PATCH v2 3/6] xen/arm: implement page reference and grant table functions needed by grant_table.c
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini
The implementation is strongly "inspired" by their x86 counterparts, except that we assume
paging_mode_externalandpaging_mode_translate.TODO:
read_onlymappings andgnttab_mark_dirty.Can we add ASSERT(0) or
BUG()or something on those paths, so it becomes obvious when we start hitting them.
Quoted 7 lines
Quoted 4 lines
...
Having read the patch I now see that some of them return errors, but others don't and I think they should do something noisy...
The only path that is unimplemented is in
create_grant_host_mapping, it is marked with "XXX", and prints an error message and returns an error.
What about gnttab_mark_dirty?
Quoted 15 lines
Quoted 13 lines
xen/arch/arm/mm.c
Quoted 10 lines
xen/arch/arm/mm.c +4
-0+ rc = -ENOMEM ; + page =alloc_domheap_page (d,0 ); +if ( page ==NULL ) { +printk ("p2m_populate_ram: failed to allocate page\n" );Should be a gdprintk or something, since a guest can indirectly trigger this path.
yes, good idea.
Re: [PATCH v2 3/6] xen/arm: implement page reference and grant table functions needed by grant_table.c
Quoted 13 lines · Ian Campbell
Quoted 12 lines · Stefano Stabellini
Quoted 11 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini
The implementation is strongly "inspired" by their x86 counterparts, except that we assume
paging_mode_externalandpaging_mode_translate.TODO:
read_onlymappings andgnttab_mark_dirty.Can we add ASSERT(0) or
BUG()or something on those paths, so it becomes obvious when we start hitting them....
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Having read the patch I now see that some of them return errors, but others don't and I think they should do something noisy...
The only path that is unimplemented is in
create_grant_host_mapping, it is marked with "XXX", and prints an error message and returns an error.What about
gnttab_mark_dirty?
The problem with gnttab_mark_dirty is that it is called rather often. I'll add a static variable so that it is going to print a warning only the first time it is called.
Re: [PATCH v2 3/6] xen/arm: implement page reference and grant table functions needed by grant_table.c
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Stefano Stabellini
Quoted 13 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini
The implementation is strongly "inspired" by their x86 counterparts, except that we assume
paging_mode_externalandpaging_mode_translate.TODO:
read_onlymappings andgnttab_mark_dirty.Can we add ASSERT(0) or
BUG()or something on those paths, so it becomes obvious when we start hitting them....
Having read the patch I now see that some of them return errors, but others don't and I think they should do something noisy...
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
The only path that is unimplemented is in
create_grant_host_mapping, it is marked with "XXX", and prints an error message and returns an error.What about
gnttab_mark_dirty?The problem with
gnttab_mark_dirtyis that it is called rather often. I'll add a static variable so that it is going to print a warning only the first time it is called.
That sounds good.
Ian.
PATCH v2 4/6 xen/arm: implement get/put_page_type
In reply to Stefano StabelliniAdd a basic get_page_type and put_page_type implementation: the implementation is similar to the x86 one, without all the code to handle shadow pagetables and other unneeded features.
Also remove PGT_shared_page, that is unused.
--- xen/arch/arm/dummy.S | 4 -- xen/arch/arm/mm.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/mm.h | 1 - 3 files changed, 91 insertions(+), 5 deletions(-)
xen/arch/arm/dummy.S +0 -4
@@ -22,10 +22,6 @@ DUMMY(arch_get_info_guest); DUMMY(arch_vcpu_reset); NOP(update_vcpu_system_time); -/* Page Reference & Type Maintenance */ -DUMMY(get_page_type); -DUMMY(put_page_type); - /* Grant Tables */ DUMMY(steal_page);
xen/arch/arm/mm.c +91 -0
105 lines not on this page · raw message
xen/include/asm-arm/mm.h +0 -1
@@ -71,7 +71,6 @@ struct page_info#define PGT_none PG_mask(0, 4)/* no special uses of this page */ #define PGT_writable_page PG_mask(7, 4)/* has writable mappings? */ -#define PGT_shared_page PG_mask(8, 4)/* CoW sharable page */ #define PGT_type_mask PG_mask(15, 4)/* Bits 28-31 or 60-63. */ /* Owning guest has pinned this page to its current type? */
Signature · 1 line
1.7.2.5
Re: [PATCH v2 4/6] xen/arm: implement get/put_page_type
Quoted 5 lines · Stefano Stabellini
Add a basic
get_page_typeandput_page_typeimplementation: the implementation is similar to the x86 one, without all the code to handle shadow pagetables and other unneeded features.Also remove
PGT_shared_page, that is unused.
I suppose it'll come back some day?
Is the existing page sharing stuff completely contained within the x86 arch code and not in generic code at all?
Quoted 33 lines
xen/arch/arm/mm.c +33
-0+int get_page_type (struct page_info *page,unsigned long type) +{ +unsigned long nx, x, y = page->u.inuse.type_info; + +for ( ; ; ) + { + x = y; + nx = x +1 ; +if (unlikely ((nx & PGT_count_mask) ==0 ) ) + { +printk ("Type count overflow on pfn %lx" ,page_to_mfn (page)); +return -EINVAL ; + } +else if ( (x & PGT_count_mask) ==0 ) + { +struct domain *d =page_get_owner (page); + +if ( (x & PGT_type_mask) != type ) + { +/* +* On type change we check to flush stale TLB entries. This +* may be unnecessary (e.g., page was GDT/LDT) but those +* circumstances should be very rare. +*/ +cpumask_t mask; + +cpumask_copy (&mask, d->domain_dirty_cpumask); + +/* Don't flush if the timestamp is old enough */ +tlbflush_filter (mask, page->tlbflush_timestamp); + +if (unlikely (!cpumask_empty (&mask)) ) + {
xen/arch/arm/mm.c int get_page(struct page_info *page, struct domain *domain) · line 673
Quoted 10 lines
xen/arch/arm/mm.c +10
-0+perfc_incr (need_flush_tlb_flush); +flush_tlb_mask (&mask); + } + +/* We lose existing type and validity. */ + nx &= ~(PGT_type_mask | PGT_validated); + nx |= type; + +/* No special validation needed for writable pages. */ +/* Page tables and GDT/LDT need to be scanned for validity. */
There is no GDT/LDT on ARM.
And do we really need PGT_validated when there is no direct paging support? (Hrm, maybe I'm confused about what PGT_validated means).
In fact, do the types make any sense at all for ARM? Is PGT_writable is really only meaningful when you have direct paging?
Ian.
Re: [PATCH v2 4/6] xen/arm: implement get/put_page_type
Quoted 8 lines · Ian Campbell
Quoted 5 lines · Stefano Stabellini
Add a basic
get_page_typeandput_page_typeimplementation: the implementation is similar to the x86 one, without all the code to handle shadow pagetables and other unneeded features.Also remove
PGT_shared_page, that is unused.I suppose it'll come back some day?
Only if we want to: it is not needed by common code.
Quoted 2 lines
Is the existing page sharing stuff completely contained within the x86 arch code and not in generic code at all?
Yes.
Quoted 46 lines
Quoted 33 lines
xen/arch/arm/mm.c +33
-0+int get_page_type (struct page_info *page,unsigned long type) +{ +unsigned long nx, x, y = page->u.inuse.type_info; + +for ( ; ; ) + { + x = y; + nx = x +1 ; +if (unlikely ((nx & PGT_count_mask) ==0 ) ) + { +printk ("Type count overflow on pfn %lx" ,page_to_mfn (page)); +return -EINVAL ; + } +else if ( (x & PGT_count_mask) ==0 ) + { +struct domain *d =page_get_owner (page); + +if ( (x & PGT_type_mask) != type ) + { +/* +* On type change we check to flush stale TLB entries. This +* may be unnecessary (e.g., page was GDT/LDT) but those +* circumstances should be very rare. +*/ +cpumask_t mask; + +cpumask_copy (&mask, d->domain_dirty_cpumask); + +/* Don't flush if the timestamp is old enough */ +tlbflush_filter (mask, page->tlbflush_timestamp); + +if (unlikely (!cpumask_empty (&mask)) ) + {xen/arch/arm/mm.c int get_page(struct page_info *page, struct domain *domain) · line 673
Quoted 10 lines
xen/arch/arm/mm.c +10
-0+perfc_incr (need_flush_tlb_flush); +flush_tlb_mask (&mask); + } + +/* We lose existing type and validity. */ + nx &= ~(PGT_type_mask | PGT_validated); + nx |= type; + +/* No special validation needed for writable pages. */ +/* Page tables and GDT/LDT need to be scanned for validity. */ There is no GDT/LDT on ARM.
Quoted 5 lines
And do we really need
PGT_validatedwhen there is no direct paging support? (Hrm, maybe I'm confused about whatPGT_validatedmeans).In fact, do the types make any sense at all for ARM? Is
PGT_writableis really only meaningful when you have direct paging?
I am starting to think that a better way to implement get_page_type is:
int get_page_type(struct page_info *page, unsigned long type)
{
return 1;
}Re: [PATCH v2 4/6] xen/arm: implement get/put_page_type
Quoted 9 lines · Stefano Stabellini
Quoted 2 lines
In fact, do the types make any sense at all for ARM? Is
PGT_writableis really only meaningful when you have direct paging?I am starting to think that a better way to implement
get_page_typeis:int
get_page_type(struct page_info *page, unsigned long type){ return 1; }
Would you need to take/release a regular reference count too? Or does common code always ensure it has a normal reference when manipulating types?
Ian.
Re: [PATCH v2 4/6] xen/arm: implement get/put_page_type
Quoted 6 lines · Ian Campbell
Quoted 5 lines · Stefano Stabellini
Quoted 2 lines
In fact, do the types make any sense at all for ARM? Is
PGT_writableis really only meaningful when you have direct paging?I am starting to think that a better way to implement
get_page_typeis:
Quoted 8 lines
Quoted 4 lines
int
get_page_type(struct page_info *page, unsigned long type){ return 1; }Would you need to take/release a regular reference count too? Or does common code always ensure it has a normal reference when manipulating types?
It seems to me that the common code always takes a normal reference to the page before increasing the typecount.
Re: [PATCH v2 4/6] xen/arm: implement get/put_page_type
In reply to Stefano StabelliniQuoted 3 lines · Stefano Stabellini
Add a basic
get_page_typeandput_page_typeimplementation: the implementation is similar to the x86 one, without all the code to handle shadow pagetables and other unneeded features.
OK, we definitely decided that ARM didn't need page typecounts. :) Is this needed for some common code?
Tim.
Quoted 153 lines
Signed-off-by Stefano Stabellini <[email protected]>--- xen/arch/arm/dummy.S | 4 -- xen/arch/arm/mm.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/mm.h | 1 - 3 files changed, 91 insertions(+), 5 deletions(-)xen/arch/arm/dummy.S +0
-4@@ -22,10 +22,6 @@ DUMMY(arch_get_info_guest); DUMMY(arch_vcpu_reset); NOP(update_vcpu_system_time); -/* Page Reference & Type Maintenance */ -DUMMY(get_page_type); -DUMMY(put_page_type); - /* Grant Tables */ DUMMY(steal_page);xen/arch/arm/mm.c +91
-0@@ -28,8 +28,10 @@#include <xen/guest_access.h> #include <asm/page.h> #include <asm/current.h> +#include <asm/flushtlb.h> #include <public/memory.h> #include <xen/sched.h> +#include <xen/perfc.h> struct domain *dom_xen, *dom_io;@@ -604,6 +606,95 @@ int get_page(struct page_info *page, struct domain *domain)return 0 ; } +void put_page_type (struct page_info *page) +{ +unsigned long nx, x, y = page->u.inuse.type_info; + +for ( ; ; ) + { + x = y; + nx = x -1 ; + +ASSERT ((x & PGT_count_mask) !=0 ); + +if (unlikely ((nx & PGT_count_mask) ==0 ) ) +/* +* Record TLB information for flush later +*/ + page->tlbflush_timestamp =tlbflush_current_time (); + +if (likely ((y =cmpxchg (&page->u.inuse.type_info, x, nx)) == x) ) +break ; + } +} + +int get_page_type (struct page_info *page,unsigned long type) +{ +unsigned long nx, x, y = page->u.inuse.type_info; + +for ( ; ; ) + { + x = y; + nx = x +1 ; +if (unlikely ((nx & PGT_count_mask) ==0 ) ) + { +printk ("Type count overflow on pfn %lx" ,page_to_mfn (page)); +return -EINVAL ; + } +else if ( (x & PGT_count_mask) ==0 ) + { +struct domain *d =page_get_owner (page); + +if ( (x & PGT_type_mask) != type ) + { +/* +* On type change we check to flush stale TLB entries. This +* may be unnecessary (e.g., page was GDT/LDT) but those +* circumstances should be very rare. +*/ +cpumask_t mask; + +cpumask_copy (&mask, d->domain_dirty_cpumask); + +/* Don't flush if the timestamp is old enough */ +tlbflush_filter (mask, page->tlbflush_timestamp); + +if (unlikely (!cpumask_empty (&mask)) ) + { +perfc_incr (need_flush_tlb_flush); +flush_tlb_mask (&mask); + } + +/* We lose existing type and validity. */ + nx &= ~(PGT_type_mask | PGT_validated); + nx |= type; + +/* No special validation needed for writable pages. */ +/* Page tables and GDT/LDT need to be scanned for validity. */ +if ( type == PGT_writable_page ) + nx |= PGT_validated; + } + } +else if (unlikely (!(x & PGT_validated)) ) + { +/* Someone else is updating validation of this page. Wait... */ +while ( (y = page->u.inuse.type_info) == x ) + { +cpu_relax (); + } +continue ; + } + +if (likely ((y =cmpxchg (&page->u.inuse.type_info, x, nx)) == x) ) +break ; + } + +if (unlikely (!(nx & PGT_validated)) ) +BUG (); + +return 1 ; +} +void gnttab_clear_flag (unsigned long nr,uint16_t *addr) {/* xen/include/asm-arm/mm.h +0
-1@@ -71,7 +71,6 @@ struct page_info#define PGT_none PG_mask(0, 4)/* no special uses of this page */ #define PGT_writable_page PG_mask(7, 4)/* has writable mappings? */ -#define PGT_shared_page PG_mask(8, 4)/* CoW sharable page */ #define PGT_type_mask PG_mask(15, 4)/* Bits 28-31 or 60-63. */ /* Owning guest has pinned this page to its current type? */ Signature · 7 lines
1.7.2.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v2 4/6] xen/arm: implement get/put_page_type
Quoted 8 lines · Tim Deegan
Quoted 3 lines · Stefano Stabellini
Add a basic
get_page_typeandput_page_typeimplementation: the implementation is similar to the x86 one, without all the code to handle shadow pagetables and other unneeded features.OK, we definitely decided that ARM didn't need page typecounts. :) Is this needed for some common code?
Yes, they are needed by grant_table.c :)
I was very tempted to just implement get_page_type as "return 1".
PATCH v2 5/6 xen/arm: create_p2m_entries should not call free_domheap_page
In reply to Stefano StabelliniThe guest is entitled to use valid memory pages as pfns for grant_table usage.
In these cases we shouldn't call free_domheap_page to free the existing page from create_p2m_entries, because it resets the reference counting but the page is still allocated to the guest (even if not in the p2m anymore) and common grant_table code is also going to call put_page on it.
--- xen/arch/arm/p2m.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
xen/arch/arm/p2m.c +0 -5
@@ -225,12 +225,7 @@ static int create_p2m_entries(struct domain *d,/* else: third already valid */ if ( third[third_table_offset (addr)].p2m.valid ) - { -/* p2m entry already present */ -free_domheap_page ( -mfn_to_page (third[third_table_offset (addr)].p2m.base));flush_tlb_all_local (); - }/* Allocate a new RAM page and attach */ switch (op) {
Signature · 1 line
1.7.2.5
Re: [PATCH v2 5/6] xen/arm: create_p2m_entries should not call free_domheap_page
Quoted 2 lines · Stefano Stabellini
The guest is entitled to use valid memory pages as pfns for
grant_tableusage.
I think it would be more accurate to say that the guest is entitled to leak a page from its p2m (by overwriting it) if it wants to. Sincethe memory is effectively lost to it (can't even be recovered by XENMEM increase reservation etc). Is that right?
Quoted 28 lines
In these cases we shouldn't call
free_domheap_pageto free the existing page fromcreate_p2m_entries, because it resets the reference counting but the page is still allocated to the guest (even if not in the p2m anymore) and commongrant_tablecode is also going to callput_pageon it.Signed-off-by Stefano Stabellini <[email protected]>--- xen/arch/arm/p2m.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)xen/arch/arm/p2m.c +0
-5@@ -225,12 +225,7 @@ static int create_p2m_entries(struct domain *d,/* else: third already valid */ if ( third[third_table_offset (addr)].p2m.valid ) - { -/* p2m entry already present */ -free_domheap_page ( -mfn_to_page (third[third_table_offset (addr)].p2m.base));flush_tlb_all_local (); - }/* Allocate a new RAM page and attach */ switch (op) {
Re: [PATCH v2 5/6] xen/arm: create_p2m_entries should not call free_domheap_page
Quoted 8 lines · Ian Campbell
Quoted 2 lines · Stefano Stabellini
The guest is entitled to use valid memory pages as pfns for
grant_tableusage.I think it would be more accurate to say that the guest is entitled to leak a page from its p2m (by overwriting it) if it wants to. Sincethe memory is effectively lost to it (can't even be recovered by XENMEM increase reservation etc). Is that right?
Yes, it is correct.
PATCH v2 6/6 xen/arm: grant table
In reply to Stefano StabelliniImplement XENMAPSPACE_grant_table and grant_table_op.
Introduce an HVM_PARAM to tell the guest where to map the grant table (HVM_PARAM_GRANT_START_PFN), similarly to what we do with HVM_PARAM_CONSOLE_PFN and HVM_PARAM_STORE_PFN.
However HVM_PARAM_GRANT_START_PFN is also going to be used by dom0, so we set the parameter in Xen rather than libxc.
Using HVM_PARAM_GRANT_START_PFN removes the need for a platform pci device.
Statically set HVM_PARAM_GRANT_START_PFN to 0xb0000000 for now.
--- xen/arch/arm/domain.c | 3 +++ xen/arch/arm/mm.c | 29 ++++++++++++++++++++++++++++- xen/arch/arm/traps.c | 1 + xen/include/public/hvm/params.h | 4 +++- 4 files changed, 35 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +3 -0
@@ -345,6 +345,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if ( (rc =p2m_alloc_table (d)) !=0 ) goto fail; + +/* XXX: select this dynamically */ + d->arch.hvm_domain.params[HVM_PARAM_GRANT_START_PFN ] =0xb0000 ; }if ( (rc =domain_vgic_init (d)) !=0 )
xen/arch/arm/mm.c +28 -1
@@ -25,6 +25,7 @@#include <xen/mm.h> #include <xen/preempt.h> #include <xen/errno.h> +#include <xen/grant_table.h> #include <xen/guest_access.h> #include <asm/page.h> #include <asm/current.h>
@@ -477,7 +478,7 @@ static int xenmem_add_to_physmap_once(struct domain *d, const struct xen_add_to_physmap *xatp) { - unsigned long mfn = 0; + unsigned long mfn = 0, idx = 0;int rc; switch ( xatp->space )
@@ -506,6 +507,32 @@ static int xenmem_add_to_physmap_once(rcu_unlock_domain (od);break ; } +case XENMAPSPACE_grant_table: +spin_lock (&d->grant_table->lock); + +if ( d->grant_table->gt_version ==0 ) + d->grant_table->gt_version =1 ; + + idx = xatp->idx; +if ( d->grant_table->gt_version ==2 && + (xatp->idx & XENMAPIDX_grant_table_status) ) + { + idx &= ~XENMAPIDX_grant_table_status; +if ( idx <nr_status_frames (d->grant_table) ) + mfn =virt_to_mfn (d->grant_table->status[idx]); + } +else + { +if ( (idx >=nr_grant_frames (d->grant_table)) && + (idx < max_nr_grant_frames) ) +gnttab_grow_table (d, idx +1 ); + +if ( idx <nr_grant_frames (d->grant_table) ) + mfn =virt_to_mfn (d->grant_table->shared_raw[idx]); + } + +spin_unlock (&d->grant_table->lock); +break ;default :return -ENOSYS ; }
xen/arch/arm/traps.c +1 -0
@@ -431,6 +431,7 @@ static arm_hypercall_t *arm_hypercall_table[] = {HYPERCALL (physdev_op),HYPERCALL (sysctl),HYPERCALL (hvm_op), + HYPERCALL(grant_table_op), };static void do_debug_trap (struct cpu_user_regs *regs,unsigned int code)
xen/include/public/hvm/params.h +3 -1
@@ -147,6 +147,8 @@#define HVM_PARAM_ACCESS_RING_PFN 28#define HVM_PARAM_SHARING_RING_PFN 29 -#define HVM_NR_PARAMS 30 +#define HVM_PARAM_GRANT_START_PFN 30 + +#define HVM_NR_PARAMS 31#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 1 line
1.7.2.5
Re: [PATCH v2 6/6] xen/arm: grant table
Quoted 9 lines · Stefano Stabellini
Implement
XENMAPSPACE_grant_tableandgrant_table_op.Introduce an
HVM_PARAMto tell the guest where to map the grant table (HVM_PARAM_GRANT_START_PFN), similarly to what we do withHVM_PARAM_CONSOLE_PFNandHVM_PARAM_STORE_PFN.
HoweverHVM_PARAM_GRANT_START_PFNis also going to be used by dom0, so we set the parameter in Xen rather than libxc.
UsingHVM_PARAM_GRANT_START_PFNremoves the need for a platform pci device.
In principal the guest can use whatever free (or not free) PFN space it wants for this region, right?
I suspect hybrid on x86 has a similar requirement and if we are going to add this sort of thing we should make sure that we can satisfy both architectures.
Or would it be better to use existing per-arch mechanisms to describe the memory map (E820 on x86 and DTB on ARM)? They already describe the rest of the memory layout.
The foreign page mapping stuff also needs to find a similar PFN region to use.
Quoted 106 lines
Statically set
HVM_PARAM_GRANT_START_PFNto0xb0000000for now.Signed-off-by Stefano Stabellini <[email protected]>Acked-by Tim Deegan <[email protected]>--- xen/arch/arm/domain.c | 3 +++ xen/arch/arm/mm.c | 29 ++++++++++++++++++++++++++++- xen/arch/arm/traps.c | 1 + xen/include/public/hvm/params.h | 4 +++- 4 files changed, 35 insertions(+), 2 deletions(-)xen/arch/arm/domain.c +3
-0@@ -345,6 +345,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if ( (rc =p2m_alloc_table (d)) !=0 ) goto fail; + +/* XXX: select this dynamically */ + d->arch.hvm_domain.params[HVM_PARAM_GRANT_START_PFN ] =0xb0000 ; }if ( (rc =domain_vgic_init (d)) !=0 )xen/arch/arm/mm.c +28
-1@@ -25,6 +25,7 @@#include <xen/mm.h> #include <xen/preempt.h> #include <xen/errno.h> +#include <xen/grant_table.h> #include <xen/guest_access.h> #include <asm/page.h> #include <asm/current.h> @@ -477,7 +478,7 @@ static int xenmem_add_to_physmap_once(struct domain *d, const struct xen_add_to_physmap *xatp) { - unsigned long mfn = 0; + unsigned long mfn = 0, idx = 0;int rc; switch ( xatp->space )@@ -506,6 +507,32 @@ static int xenmem_add_to_physmap_once(rcu_unlock_domain (od);break ; } +case XENMAPSPACE_grant_table: +spin_lock (&d->grant_table->lock); + +if ( d->grant_table->gt_version ==0 ) + d->grant_table->gt_version =1 ; + + idx = xatp->idx; +if ( d->grant_table->gt_version ==2 && + (xatp->idx & XENMAPIDX_grant_table_status) ) + { + idx &= ~XENMAPIDX_grant_table_status; +if ( idx <nr_status_frames (d->grant_table) ) + mfn =virt_to_mfn (d->grant_table->status[idx]); + } +else + { +if ( (idx >=nr_grant_frames (d->grant_table)) && + (idx < max_nr_grant_frames) ) +gnttab_grow_table (d, idx +1 ); + +if ( idx <nr_grant_frames (d->grant_table) ) + mfn =virt_to_mfn (d->grant_table->shared_raw[idx]); + } + +spin_unlock (&d->grant_table->lock); +break ;default :return -ENOSYS ; }xen/arch/arm/traps.c +1
-0@@ -431,6 +431,7 @@ static arm_hypercall_t *arm_hypercall_table[] = {HYPERCALL (physdev_op),HYPERCALL (sysctl),HYPERCALL (hvm_op), + HYPERCALL(grant_table_op), };static void do_debug_trap (struct cpu_user_regs *regs,unsigned int code)xen/include/public/hvm/params.h +3
-1@@ -147,6 +147,8 @@#define HVM_PARAM_ACCESS_RING_PFN 28#define HVM_PARAM_SHARING_RING_PFN 29 -#define HVM_NR_PARAMS 30 +#define HVM_PARAM_GRANT_START_PFN 30 + +#define HVM_NR_PARAMS 31#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Re: [PATCH v2 6/6] xen/arm: grant table
Quoted 18 lines · Ian Campbell
Quoted 9 lines · Stefano Stabellini
Implement
XENMAPSPACE_grant_tableandgrant_table_op.Introduce an
HVM_PARAMto tell the guest where to map the grant table (HVM_PARAM_GRANT_START_PFN), similarly to what we do withHVM_PARAM_CONSOLE_PFNandHVM_PARAM_STORE_PFN.
HoweverHVM_PARAM_GRANT_START_PFNis also going to be used by dom0, so we set the parameter in Xen rather than libxc.
UsingHVM_PARAM_GRANT_START_PFNremoves the need for a platform pci device.In principal the guest can use whatever free (or not free) PFN space it wants for this region, right?
I suspect hybrid on x86 has a similar requirement and if we are going to add this sort of thing we should make sure that we can satisfy both architectures.
Quoted 6 lines
Or would it be better to use existing per-arch mechanisms to describe the memory map (E820 on x86 and DTB on ARM)? They already describe the rest of the memory layout.
The foreign page mapping stuff also needs to find a similar PFN region to use.
I think that you are right.
In fact I have a prototype implementation using a memory range specified under a "/xen" node in the DT.
Re: [PATCH v2 1/6] Initialize lr_queue in vcpu_vgic_init for the first 32 irqs
In reply to Stefano StabelliniQuoted 1 line · Stefano Stabellini
Signed-off-by Stefano Stabellini <[email protected]>
Quoted 19 lines
--- xen/arch/arm/vgic.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)xen/arch/arm/vgic.c +3
-0@@ -102,7 +102,10 @@ int vcpu_vgic_init(struct vcpu *v)memset (&v->arch.vgic.pending_irqs,0 ,sizeof (v->arch.vgic.pending_irqs));for (i =0 ; i <32 ; i++) + {INIT_LIST_HEAD (&v->arch.vgic.pending_irqs[i].inflight); +INIT_LIST_HEAD (&v->arch.vgic.pending_irqs[i].lr_queue); + }printk ("vcpu_vgic_init irq[0] at %p desc is %p\n" , &v->arch.vgic.pending_irqs[0 ], v->arch.vgic.pending_irqs[0 ].desc);
Quoted 3 lines · Stefano Stabellini
Hi all,
this patch series implements the basic mechanisms needed by the grant table to work properly.
I've committed the first two (minor rejects in the first. please check).
xen/arm: set paging_mode_translate and paging_mode_external Initialize lr_queue in vcpu_vgic_init for the first 32 irqs
The rest I had comments on.
Ian.