From patchwork Thu Sep 7 13:47:30 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: 9942323 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 A7CCA604D7 for ; Thu, 7 Sep 2017 13:50:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD3402869B for ; Thu, 7 Sep 2017 13:50:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB777286E0; Thu, 7 Sep 2017 13:50:17 +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 E2B6F2869B for ; Thu, 7 Sep 2017 13:50:11 +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 1dpx9j-000326-IB; Thu, 07 Sep 2017 13:47:43 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpx9i-00031M-FA for xen-devel@lists.xen.org; Thu, 07 Sep 2017 13:47:42 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id EE/46-24671-DFD41B95; Thu, 07 Sep 2017 13:47:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVyuP0Ov+4f342 RBlc+21gs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBkfO0QLdttUnGqZzN7AuFm3i5GTQ0LASOLt xH9MXYxcHEICCxklnr+6xwaSYBNQldhw/RQriC0iIC1x7fNlRpAiZoFJTBILutexgySEBbwlF p55DWazADV0vHrAAmLzCphIzHh5ihFig7xEx4HJYHFOAVOJtS0PweJCQDWtv3awTmDkXsDIsI pRozi1qCy1SNfIQC+pKDM9oyQ3MTNH19DAVC83tbg4MT01JzGpWC85P3cTI9C/9QwMjDsYG2f 7HWKU5GBSEuU9rrExUogvKT+lMiOxOCO+qDQntfgQowYHh0DfmtUXGKVY8vLzUpUkeHmAYSQk WJSanlqRlpkDDECYUgkOHiUR3ik+QGne4oLE3OLMdIjUKUZdjo6bd/8wCYHNkBLnXQpSJABSl FGaBzcCFg2XGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzLgeZwpOZVwK36RXQEUxAR5Q83w ByREkiQkqqgdFxHYOjvlkM/9bFH8NSGi/tz4leNi1BdNIOlUf8PBtXvn1efKJ6r/Xk1EaPuNe LN5+ufPBMTk7Jfk+Ycfn8uU9vzlnPybBm372w/MOr65JVHp1WafOa99H/b/zSH47S1qmcdUnO vk3Clbfff7ssWfFtgc/FhAmXf8nzrj3es9o09OqzDUfv+q9QYinOSDTUYi4qTgQAQEh394ECA AA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1504792060!108932877!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 49783 invoked from network); 7 Sep 2017 13:47:40 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-5.tower-206.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 7 Sep 2017 13:47:40 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8B480ABDF; Thu, 7 Sep 2017 13:47:40 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org Date: Thu, 7 Sep 2017 15:47:30 +0200 Message-Id: <20170907134735.20434-4-jgross@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170907134735.20434-1-jgross@suse.com> References: <20170907134735.20434-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 v4 3/8] xen: delay allocation of grant table sub structures 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 Delay the allocation of the grant table sub structures in order to allow modifying parameters needed for sizing of these structures at a per domain basis. Either do it from gnttab_setup_table() or just before the domain is started the first time. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Reviewed-by: Wei Liu --- V4: - make ret more local (Wei Liu) V3: - move call of grant_table_init() from gnttab_setup_table() to gnttab_grow_table() (Paul Durrant) --- xen/common/domain.c | 17 +++++- xen/common/grant_table.c | 138 ++++++++++++++++++++++++------------------ xen/include/xen/grant_table.h | 2 + 3 files changed, 96 insertions(+), 61 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 5aebcf265f..983f3336a9 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -363,6 +363,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags, goto fail; init_status |= INIT_gnttab; + if ( domid == 0 && grant_table_init(d) ) + goto fail; + poolid = 0; err = -ENOMEM; @@ -998,7 +1001,8 @@ int __domain_pause_by_systemcontroller(struct domain *d, prev = cmpxchg(&d->controller_pause_count, old, new); } while ( prev != old ); - pause_fn(d); + if ( pause_fn ) + pause_fn(d); return 0; } @@ -1029,8 +1033,17 @@ int domain_unpause_by_systemcontroller(struct domain *d) * Creation is considered finished when the controller reference count * first drops to 0. */ - if ( new == 0 ) + if ( new == 0 && !d->creation_finished ) + { + int ret = grant_table_init(d); + + if ( ret ) + { + __domain_pause_by_systemcontroller(d, NULL); + return ret; + } d->creation_finished = true; + } domain_unpause(d); diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 4520e36d90..29e7fa539b 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1655,6 +1655,78 @@ gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt) gt->nr_status_frames = 0; } +int +grant_table_init(struct domain *d) +{ + struct grant_table *gt = d->grant_table; + unsigned int i, j; + + if ( gt->nr_grant_frames ) + return 0; + + gt->nr_grant_frames = INITIAL_NR_GRANT_FRAMES; + + /* Active grant table. */ + if ( (gt->active = xzalloc_array(struct active_grant_entry *, + max_nr_active_grant_frames)) == NULL ) + goto no_mem_1; + for ( i = 0; + i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ ) + { + if ( (gt->active[i] = alloc_xenheap_page()) == NULL ) + goto no_mem_2; + clear_page(gt->active[i]); + for ( j = 0; j < ACGNT_PER_PAGE; j++ ) + spin_lock_init(>->active[i][j].lock); + } + + /* Tracking of mapped foreign frames table */ + gt->maptrack = vzalloc(max_maptrack_frames * sizeof(*gt->maptrack)); + if ( gt->maptrack == NULL ) + goto no_mem_2; + + /* Shared grant table. */ + if ( (gt->shared_raw = xzalloc_array(void *, max_grant_frames)) == NULL ) + goto no_mem_3; + for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) + { + if ( (gt->shared_raw[i] = alloc_xenheap_page()) == NULL ) + goto no_mem_4; + clear_page(gt->shared_raw[i]); + } + + /* 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_4; + + for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) + gnttab_create_shared_page(d, gt, i); + + gt->nr_status_frames = 0; + + return 0; + + no_mem_4: + for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) + free_xenheap_page(gt->shared_raw[i]); + xfree(gt->shared_raw); + gt->shared_raw = NULL; + no_mem_3: + vfree(gt->maptrack); + gt->maptrack = NULL; + no_mem_2: + for ( i = 0; + i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ ) + free_xenheap_page(gt->active[i]); + xfree(gt->active); + gt->active = NULL; + no_mem_1: + gt->nr_grant_frames = 0; + return -ENOMEM; +} + /* * Grow the grant table. The caller must hold the grant table's * write lock before calling this function. @@ -1665,6 +1737,12 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) struct grant_table *gt = d->grant_table; unsigned int i, j; + if ( !gt->nr_grant_frames && grant_table_init(d) ) + { + gdprintk(XENLOG_INFO, "Allocation failure in grant table init.\n"); + return 0; + } + ASSERT(req_nr_frames <= max_grant_frames); gdprintk(XENLOG_INFO, @@ -3380,75 +3458,17 @@ grant_table_create( struct domain *d) { struct grant_table *t; - unsigned int i, j; if ( (t = xzalloc(struct grant_table)) == NULL ) - goto no_mem_0; + return -ENOMEM; /* Simple stuff. */ percpu_rwlock_resource_init(&t->lock, grant_rwlock); spin_lock_init(&t->maptrack_lock); - t->nr_grant_frames = INITIAL_NR_GRANT_FRAMES; - - /* Active grant table. */ - if ( (t->active = xzalloc_array(struct active_grant_entry *, - max_nr_active_grant_frames)) == NULL ) - goto no_mem_1; - for ( i = 0; - i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ ) - { - if ( (t->active[i] = alloc_xenheap_page()) == NULL ) - goto no_mem_2; - clear_page(t->active[i]); - for ( j = 0; j < ACGNT_PER_PAGE; j++ ) - spin_lock_init(&t->active[i][j].lock); - } - - /* Tracking of mapped foreign frames table */ - t->maptrack = vzalloc(max_maptrack_frames * sizeof(*t->maptrack)); - if ( t->maptrack == NULL ) - goto no_mem_2; - - /* Shared grant table. */ - if ( (t->shared_raw = xzalloc_array(void *, max_grant_frames)) == NULL ) - goto no_mem_3; - for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) - { - if ( (t->shared_raw[i] = alloc_xenheap_page()) == NULL ) - goto no_mem_4; - clear_page(t->shared_raw[i]); - } - - /* Status pages for grant table - for version 2 */ - t->status = xzalloc_array(grant_status_t *, - grant_to_status_frames(max_grant_frames)); - if ( t->status == NULL ) - goto no_mem_4; - - for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) - gnttab_create_shared_page(d, t, i); - - t->nr_status_frames = 0; /* Okay, install the structure. */ d->grant_table = t; return 0; - - no_mem_4: - for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) - free_xenheap_page(t->shared_raw[i]); - xfree(t->shared_raw); - no_mem_3: - vfree(t->maptrack); - no_mem_2: - for ( i = 0; - i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ ) - free_xenheap_page(t->active[i]); - xfree(t->active); - no_mem_1: - xfree(t); - no_mem_0: - return -ENOMEM; } void diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index 43b07e60c5..84a8d61616 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -35,6 +35,8 @@ extern unsigned int max_grant_frames; /* Create/destroy per-domain grant table context. */ int grant_table_create( struct domain *d); +int grant_table_init( + struct domain *d); void grant_table_destroy( struct domain *d); void grant_table_init_vcpu(struct vcpu *v);