From patchwork Fri Sep 22 11:41:31 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: 9965849 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 0FC3C6035E for ; Fri, 22 Sep 2017 11:43:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C2F52987F for ; Fri, 22 Sep 2017 11:43:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 110C829884; Fri, 22 Sep 2017 11:43:59 +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 7CFBE2987F for ; Fri, 22 Sep 2017 11:43:58 +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 1dvML0-0002KO-Gi; Fri, 22 Sep 2017 11:41:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvMKz-0002I6-JR for xen-devel@lists.xenproject.org; Fri, 22 Sep 2017 11:41:41 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 6B/9D-25201-4F6F4C95; Fri, 22 Sep 2017 11:41:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCLMWRWlGSWpSXmKPExsVyuP0Ov+6Xb0c iDdZMFLP4vmUykwOjx+EPV1gCGKNYM/OS8isSWDN+nH/DXnBHp+LQ9GtMDYyfFLsYOTkkBIwk 3k78x9TFyMUhJLCQUeJdQys7SIJNQFViw/VTrCC2iICSxL1Vk8GKmAV+Mkp8m7iQDSQhLOArc fz9aiYQmwWo4XXDA6BmDg5eAWOJ7ZvyIBbIS3QcmMwCYnMKmEjc2P4CbL4QUMmjg/fZJjByL2 BkWMWoUZxaVJZapGtoqJdUlJmeUZKbmJmja2hgqpebWlycmJ6ak5hUrJecn7uJEehfBiDYwbi y3fkQoyQHk5Iob+7nI5FCfEn5KZUZicUZ8UWlOanFhxg1ODgE+tasvsAoxZKXn5eqJMHLAwwj IcGi1PTUirTMHGAAwpRKcPAoifDqfAVK8xYXJOYWZ6ZDpE4xGnP8mHTlDxNHx827f5iEwCZJi fMuBykVACnNKM2DGwSLjEuMslLCvIxAZwrxFKQW5WaWoMq/YhTnYFQS5v0IMoUnM68Ebt8roF OYgE4pXw12SkkiQkqqgdExLfzZc50AoeRvajHZLTOeLH7HtuLt90N6La8i5wZ215xgLL1wheP tOsMLrDFPeg+vPHRx0d3+F6fLdVadcfrBePY906ZHgZfCK+QZbwanBp/9O+2v387P9YeDzvae CWGKtzPXEr4bdjX6sOby/csCv/nUrnCe8zNx6sO26Wk9vbJWRlG+LHVKLMUZiYZazEXFiQDLa 14+hwIAAA== X-Env-Sender: jgross@suse.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1506080500!91667539!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 39911 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-11.tower-206.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 relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 024DBACE5; 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:31 +0200 Message-Id: <20170922114134.9577-8-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 07/10] 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. Allocate the structures and the table frames only from grant_table_set_limits() (dom0: from grant_table_create()). Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant --- V9: - allocate initial grant frames from grant_table_init() (Jan Beulich) V6: - move call of grant_table_init() for dom0 to grant_table_create() (Jan Beulich) - move frame allocations to gnttab_grow_table() (Jan Beulich) - several other changes due to new patch order 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/grant_table.c | 118 +++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 60 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 0f09891f59..3250db4c5a 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1667,6 +1667,10 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) struct grant_table *gt = d->grant_table; unsigned int i, j; + ASSERT(gt->active); + + if ( req_nr_frames < INITIAL_NR_GRANT_FRAMES ) + req_nr_frames = INITIAL_NR_GRANT_FRAMES; ASSERT(req_nr_frames <= max_grant_frames); gdprintk(XENLOG_INFO, @@ -1723,6 +1727,48 @@ active_alloc_failed: return 0; } +static int +grant_table_init(struct domain *d, struct grant_table *gt) +{ + if ( gt->active ) + return -EBUSY; + + /* Active grant table. */ + gt->active = xzalloc_array(struct active_grant_entry *, + max_nr_active_grant_frames); + if ( gt->active == NULL ) + goto no_mem; + + /* Tracking of mapped foreign frames table */ + gt->maptrack = vzalloc(max_maptrack_frames * sizeof(*gt->maptrack)); + if ( gt->maptrack == NULL ) + goto no_mem; + + /* Shared grant table. */ + gt->shared_raw = xzalloc_array(void *, max_grant_frames); + if ( gt->shared_raw == NULL ) + goto no_mem; + + /* 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; + + /* gnttab_grow_table() allocates a min number of frames, so 0 is okay. */ + if ( gnttab_grow_table(d, 0) ) + return 0; + + no_mem: + xfree(gt->shared_raw); + gt->shared_raw = NULL; + vfree(gt->maptrack); + gt->maptrack = NULL; + xfree(gt->active); + gt->active = NULL; + return -ENOMEM; +} + static long gnttab_setup_table( XEN_GUEST_HANDLE_PARAM(gnttab_setup_table_t) uop, unsigned int count) @@ -3383,75 +3429,26 @@ grant_table_create( struct domain *d) { struct grant_table *t; - unsigned int i, j; + int ret = 0; 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; + /* Okay, install the structure. */ + d->grant_table = t; - /* 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 ( d->domain_id == 0 ) { - if ( (t->shared_raw[i] = alloc_xenheap_page()) == NULL ) - goto no_mem_4; - clear_page(t->shared_raw[i]); + grant_write_lock(t); + ret = grant_table_init(d, t); + grant_write_unlock(t); } - /* 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; + return ret; } void @@ -3653,8 +3650,9 @@ int grant_table_set_limits(struct domain *d, unsigned int grant_frames, grant_write_lock(gt); - ret = 0; - /* Set limits, alloc needed arrays. */ + /* Set limits. */ + if ( !gt->active ) + ret = grant_table_init(d, gt); grant_write_unlock(gt);