xen/arm: grant_table
v3 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 v3:
- rebased on 9e0de31c672fd127e6fb0c88a26eb147037a9abc, drop patches already applied from the series;
- replace printk with gdprintk in create_grant_host_mapping;
- print a warning once in gnttab_mark_dirty;
- replace get_page_type and put_page_type with an empty implementation;
- rephrase commit message of "create_p2m_entries should not call free_domheap_page";
- remove HVM_PARAM_GRANT_START_PFN.
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 (4):
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/dummy.S | 13 ---- xen/arch/arm/mm.c | 157 +++++++++++++++++++++++++++++++++++++++++++++- xen/arch/arm/p2m.c | 82 ++++++++++++++++--------- xen/arch/arm/traps.c | 1 + xen/include/asm-arm/mm.h | 1 - 5 files changed, 210 insertions(+), 44 deletions(-)
Cheers,
Stefano
PATCH v3 1/4 xen/arm: implement page reference and grant table functions needed by grant_table.c
The 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 v3:
- replace printk with gdprintk in create_grant_host_mapping;
- print a warning once in 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 | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 77 +++++++++++++++++++++++---------- 3 files changed, 168 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 +115 -0
121 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
PATCH v3 2/4 xen/arm: implement get/put_page_type
In reply to Stefano StabelliniAdd a basic get_page_type and put_page_type implementation: we don't care about typecounts so just return success.
Also remove PGT_shared_page, that is unused.
Changes in v3:
- replace get_page_type and put_page_type with an empty implementation.
--- xen/arch/arm/dummy.S | 4 ---- xen/arch/arm/mm.c | 13 +++++++++++++ xen/include/asm-arm/mm.h | 1 - 3 files changed, 13 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 +13 -0
@@ -594,6 +594,19 @@ int get_page(struct page_info *page, struct domain *domain)return 0 ; } +/* Common code requires get_page_type and put_page_type. +* We don't care about typecounts so we just do the minimum to make it +* happy. */ +int get_page_type (struct page_info *page,unsigned long type) +{ +return 1 ; +} + +void put_page_type (struct page_info *page) +{ +return ; +} +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 · 1 line
1.7.2.5
Re: [PATCH v3 2/4] xen/arm: implement get/put_page_type
Quoted 9 lines · Stefano Stabellini
Add a basic
get_page_typeandput_page_typeimplementation: we don't care about typecounts so just return success.Also remove
PGT_shared_page, that is unused.Changes in v3:
- replace
get_page_typeandput_page_typewith an empty implementation.
Tim suggested that we consider adding an assert that the reference count is non-zero in both of these, since it is incorrect to take a type count without a reference count (we think).
In the future maybe we should consider refactoring the gnttab code (and anything else using type counts directly) to use a "pg_make_writable" arch abstraction so we an hide the type counts inside x86 code where they properly belong.
Quoted 60 lines
Signed-off-by Stefano Stabellini <[email protected]>--- xen/arch/arm/dummy.S | 4 ---- xen/arch/arm/mm.c | 13 +++++++++++++ xen/include/asm-arm/mm.h | 1 - 3 files changed, 13 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 +13
-0@@ -594,6 +594,19 @@ int get_page(struct page_info *page, struct domain *domain)return 0 ; } +/* Common code requires get_page_type and put_page_type. +* We don't care about typecounts so we just do the minimum to make it +* happy. */ +int get_page_type (struct page_info *page,unsigned long type) +{ +return 1 ; +} + +void put_page_type (struct page_info *page) +{ +return ; +} +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? */
PATCH v3 3/4 xen/arm: create_p2m_entries should not call free_domheap_page
In reply to Stefano StabelliniThe guest is entitled to leak a page from its p2m (by overwriting it) if it wants to. Since the memory is effectively lost to it (can't even be recovered by XENMEM increase reservation etc).
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.
Changes in v3:
- rephrase commit message.
--- xen/arch/arm/p2m.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
xen/arch/arm/p2m.c +0 -5
@@ -189,12 +189,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
PATCH v3 4/4 xen/arm: grant table
In reply to Stefano StabelliniImplement XENMAPSPACE_grant_table and grant_table_op.
Changes in v3:
- remove HVM_PARAM_GRANT_START_PFN.
--- xen/arch/arm/mm.c | 29 ++++++++++++++++++++++++++++- xen/arch/arm/traps.c | 1 + 2 files changed, 29 insertions(+), 1 deletions(-)
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 <xen/domain_page.h> #include <asm/page.h>
@@ -465,11 +466,37 @@ 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 ) { +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 ;case XENMAPSPACE_shared_info:if ( xatp->idx ==0 ) mfn =virt_to_mfn (d->shared_info);
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)
Signature · 1 line
1.7.2.5
Quoted 3 lines · Stefano Stabellini
Hi all,
this patch series implements the basic mechanisms needed by the grant table to work properly.
I've applied all 4 of these to my "arm-for-4.3" branch which I'll announce shortly.