From patchwork Fri Sep 22 11:41:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9965853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C78286035E for ; Fri, 22 Sep 2017 11:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D37FE2987F for ; Fri, 22 Sep 2017 11:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C86C229885; Fri, 22 Sep 2017 11:44:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 119CB2987F for ; Fri, 22 Sep 2017 11:44:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvML1-0002My-Rc; Fri, 22 Sep 2017 11:41:43 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvML0-0002IO-34 for xen-devel@lists.xenproject.org; Fri, 22 Sep 2017 11:41:42 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id C3/D5-02041-5F6F4C95; Fri, 22 Sep 2017 11:41:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVyuP0Ov+6Xb0c iDY691rf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDNWrjcqOOhYMX1+WQPjOb0uRk4OCQEjibcT /zF1MXJxCAksZJT4fvQ7O0iCTUBVYsP1U6wgtoiAksS9VZPBipgFfjJKfJu4kA0kISwQKXF50 QtGEJsFqGFFx3VmEJtXwFhiz6UNzBAb5CU6DkxmAbE5BUwkbmx/AbZACKjm0cH7bBMYuRcwMq xi1ChOLSpLLdI1MtdLKspMzyjJTczM0TU0MNbLTS0uTkxPzUlMKtZLzs/dxAj0bj0DA+MOxpa 9focYJTmYlER5cz8fiRTiS8pPqcxILM6ILyrNSS0+xKjBwSHQt2b1BUYplrz8vFQlCV4eYBAJ CRalpqdWpGXmAMMPplSCg0dJhFfnK1Cat7ggMbc4Mx0idYpRl6Pj5t0/TEJgM6TEeZeDFAmAF GWU5sGNgMXCJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvB9BpvBk5pXAbXoFdAQT0BHlq8 GOKElESEk1MEpN7niodaVP4KhC724jhxaufYf4RZvCWr5c+sRSyTM14ItWUfQbhs5ztlZ/Xda pS1mEBM+d7GcSIKd0XVPp0WFnR555SqnmVV+vz7sTEH2npD3Aj++w85ZiJS3upsMzOtMDsvoe /5hrELE++a/U78g7jtKrOuZrMF+8/TQ6gk3TzHLakY28SizFGYmGWsxFxYkAl/kp6YACAAA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1506080500!77506174!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35057 invoked from network); 22 Sep 2017 11:41:40 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-6.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 22 Sep 2017 11:41:40 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 79442ACF0; Fri, 22 Sep 2017 11:41:40 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 22 Sep 2017 13:41:32 +0200 Message-Id: <20170922114134.9577-9-jgross@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170922114134.9577-1-jgross@suse.com> References: <20170922114134.9577-1-jgross@suse.com> Cc: Juergen Gross , sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, julien.grall@arm.com, jbeulich@suse.com, dgdegra@tycho.nsa.gov Subject: [Xen-devel] [PATCH v9 08/10] xen/arm: move arch specific grant table bits into grant_table.c X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of attaching the ARM specific grant table data to the domain structure add it to struct grant_table. Add the needed arch functions to the asm-*/grant_table.h includes. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Acked-by: Jan Beulich [non-ARM parts] --- V9: - correct and cleanup gnttab_init_arch() for ARM (Julien Grall) V7: - re-add #include in grant_table.h (Julien Grall) --- xen/arch/arm/domain.c | 2 -- xen/common/grant_table.c | 27 ++++++++++++++++++++------- xen/include/asm-arm/domain.h | 1 - xen/include/asm-arm/grant_table.h | 29 ++++++++++++++++++++++------- xen/include/asm-x86/grant_table.h | 12 +++++++----- xen/include/xen/grant_table.h | 2 ++ 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 784ae392cf..e39a79885c 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -486,13 +486,11 @@ struct domain *alloc_domain_struct(void) return NULL; clear_page(d); - d->arch.grant_table_gfn = xzalloc_array(gfn_t, max_grant_frames); return d; } void free_domain_struct(struct domain *d) { - xfree(d->arch.grant_table_gfn); free_xenheap_page(d); } diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 3250db4c5a..73ba915a30 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -72,6 +72,8 @@ struct grant_table { struct active_grant_entry **active; /* Mapping tracking table per vcpu. */ struct grant_mapping **maptrack; + + struct grant_table_arch arch; }; #ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */ @@ -1730,6 +1732,8 @@ active_alloc_failed: static int grant_table_init(struct domain *d, struct grant_table *gt) { + int ret = -ENOMEM; + if ( gt->active ) return -EBUSY; @@ -1737,36 +1741,43 @@ grant_table_init(struct domain *d, struct grant_table *gt) gt->active = xzalloc_array(struct active_grant_entry *, max_nr_active_grant_frames); if ( gt->active == NULL ) - goto no_mem; + goto out; /* Tracking of mapped foreign frames table */ gt->maptrack = vzalloc(max_maptrack_frames * sizeof(*gt->maptrack)); if ( gt->maptrack == NULL ) - goto no_mem; + goto out; /* Shared grant table. */ gt->shared_raw = xzalloc_array(void *, max_grant_frames); if ( gt->shared_raw == NULL ) - goto no_mem; + goto out; /* Status pages for grant table - for version 2 */ gt->status = xzalloc_array(grant_status_t *, grant_to_status_frames(max_grant_frames)); if ( gt->status == NULL ) - goto no_mem; + goto out; + + ret = gnttab_init_arch(gt); + if ( ret ) + goto out; /* gnttab_grow_table() allocates a min number of frames, so 0 is okay. */ if ( gnttab_grow_table(d, 0) ) return 0; - no_mem: + out: + gnttab_destroy_arch(gt); + xfree(gt->status); + gt->status = NULL; xfree(gt->shared_raw); gt->shared_raw = NULL; vfree(gt->maptrack); gt->maptrack = NULL; xfree(gt->active); gt->active = NULL; - return -ENOMEM; + return ret; } static long @@ -3612,6 +3623,8 @@ grant_table_destroy( if ( t == NULL ) return; + gnttab_destroy_arch(t); + for ( i = 0; i < nr_grant_frames(t); i++ ) free_xenheap_page(t->shared_raw[i]); xfree(t->shared_raw); @@ -3738,7 +3751,7 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, } if ( !rc ) - gnttab_set_frame_gfn(d, idx, gfn); + gnttab_set_frame_gfn(gt, idx, gfn); grant_write_unlock(gt); diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index b174c65080..ce9b6a4032 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -50,7 +50,6 @@ struct arch_domain struct p2m_domain p2m; struct hvm_domain hvm_domain; - gfn_t *grant_table_gfn; struct vmmio vmmio; diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h index 0a248a765a..30db2d1616 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -6,6 +6,10 @@ #define INITIAL_NR_GRANT_FRAMES 4 +struct grant_table_arch { + gfn_t *gfn; +}; + void gnttab_clear_flag(unsigned long nr, uint16_t *addr); int create_grant_host_mapping(unsigned long gpaddr, unsigned long mfn, unsigned int flags, unsigned int @@ -22,11 +26,22 @@ static inline int replace_grant_supported(void) return 1; } -static inline void gnttab_set_frame_gfn(struct domain *d, unsigned long idx, - gfn_t gfn) -{ - d->arch.grant_table_gfn[idx] = gfn; -} +#define gnttab_init_arch(gt) \ +({ \ + (gt)->arch.gfn = xzalloc_array(gfn_t, max_grant_frames); \ + ( (gt)->arch.gfn ? 0 : -ENOMEM ); \ +}) + +#define gnttab_destroy_arch(gt) \ + do { \ + xfree((gt)->arch.gfn); \ + (gt)->arch.gfn = NULL; \ + } while ( 0 ) + +#define gnttab_set_frame_gfn(gt, idx, gfn) \ + do { \ + (gt)->arch.gfn[idx] = gfn; \ + } while ( 0 ) #define gnttab_create_shared_page(d, t, i) \ do { \ @@ -36,8 +51,8 @@ static inline void gnttab_set_frame_gfn(struct domain *d, unsigned long idx, } while ( 0 ) #define gnttab_shared_gmfn(d, t, i) \ - ( ((i >= nr_grant_frames(d->grant_table)) && \ - (i < max_grant_frames)) ? 0 : gfn_x(d->arch.grant_table_gfn[i])) + ( ((i >= nr_grant_frames(t)) && \ + (i < max_grant_frames)) ? 0 : gfn_x(t->arch.gfn[i])) #define gnttab_need_iommu_mapping(d) \ (is_domain_direct_mapped(d) && need_iommu(d)) diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_table.h index c865999a33..1b93c5720d 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -14,6 +14,9 @@ #define INITIAL_NR_GRANT_FRAMES 4 +struct grant_table_arch { +}; + /* * Caller must own caller's BIGLOCK, is responsible for flushing the TLB, and * must hold a reference to the page. @@ -36,6 +39,10 @@ static inline int replace_grant_host_mapping(uint64_t addr, unsigned long frame, return replace_grant_pv_mapping(addr, frame, new_addr, flags); } +#define gnttab_init_arch(gt) 0 +#define gnttab_destroy_arch(gt) do {} while ( 0 ) +#define gnttab_set_frame_gfn(gt, idx, gfn) do {} while ( 0 ) + #define gnttab_create_shared_page(d, t, i) \ do { \ share_xen_page_with_guest( \ @@ -75,11 +82,6 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st) asm volatile ("lock btrw %w1,%0" : "=m" (*st) : "Ir" (nr), "m" (*st)); } -static inline void gnttab_set_frame_gfn(struct domain *d, unsigned long idx, - gfn_t gfn) -{ -} - /* Foreign mappings of HHVM-guest pages do not modify the type count. */ #define gnttab_host_mapping_get_page_type(ro, ld, rd) \ (!(ro) && (((ld) == (rd)) || !paging_mode_external(rd))) diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index df11b31264..d2bd2416c4 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -29,6 +29,8 @@ #include #include +struct grant_table; + /* The maximum size of a grant table. */ extern unsigned int max_grant_frames;