From patchwork Thu Feb 16 12:03:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Anisov X-Patchwork-Id: 9576983 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 D82A6600F6 for ; Thu, 16 Feb 2017 12:05:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC9FD28578 for ; Thu, 16 Feb 2017 12:05:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D17FE285AE; Thu, 16 Feb 2017 12:05:47 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 4CB3528578 for ; Thu, 16 Feb 2017 12:05:47 +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 1ceKmh-0003YF-MU; Thu, 16 Feb 2017 12:03:39 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ceKmg-0003Xr-1b for xen-devel@lists.xenproject.org; Thu, 16 Feb 2017 12:03:38 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 5B/EB-01724-81595A85; Thu, 16 Feb 2017 12:03:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRWlGSWpSXmKPExsVyMbThsK741KU RBtuXyFh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnXN+1nLWg1rfjSt4W9gfGLRhcjF4eQwHRG icUPpzCCOCwCL1kk/v7qZQNxJAT6WSWW7Z3P0sXICeTESJzf/oAZwq6QWLRzCjuILSSgJrHv0 HUWiFGzmST2dB5hA0mwCehKXH/1gAnEFhFQkri3ajITSBGzwBdGicsfloAlhIGK9ndvAtvAIq AqsXDtdzCbV8BNYsLEZqjNchI3z3WCbeYUcJc4+fYpE8RmN4n73S1sExgFFjAyrGLUKE4tKks t0jWy1EsqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAyvegYGxh2Ml7f4HWKU5GBS EuX90b80QogvKT+lMiOxOCO+qDQntfgQowwHh5IEr+oUoJxgUWp6akVaZg4w0GHSEhw8SiK8z yYDpXmLCxJzizPTIVKnGI05erpOv2Ti2LPr8ksmIZa8/LxUKXHeNyClAiClGaV5cINgEXiJUV ZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjDvWpApPJl5JXD7XgGdwgR0SmcE2CkliQgpqQbGymf GFntm/9x/c9KEdz83WD5s27DjNEveqtuvbS8Ivv18acnXmGWZ7vqPp6imL86s4FM9X/+3qcaU kYdporh9YLb4lbn/1ru+Z5h5UOTiLc2kn7PDlvoFrwmyFjjWLadfWZJgrCzLtTNP7vYFca4bL JqBzMEsYaZydT8CP90U1Y/MjrkXa3FJiaU4I9FQi7moOBEAwRlFl7sCAAA= X-Env-Sender: andrii.anisov@gmail.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1487246615!67434702!1 X-Originating-IP: [209.85.128.195] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54314 invoked from network); 16 Feb 2017 12:03:35 -0000 Received: from mail-wr0-f195.google.com (HELO mail-wr0-f195.google.com) (209.85.128.195) by server-11.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Feb 2017 12:03:35 -0000 Received: by mail-wr0-f195.google.com with SMTP id c4so1792176wrd.1 for ; Thu, 16 Feb 2017 04:03:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4+I54Ek6rTZwiLpxwNs9qiEZdwY/s5VF8SUQit0LnPk=; b=WKIFIe6iWetxTeUaTh+jSpCOQumWKoaOLgS/QQ26a8tyMiaoyrVrv+5rUqeZ6KM7f8 jH067UlZBGApqvxAwbKCMPvmTPWFgrKdSZivlMbc5ix1V3rKE19VnL2xYrvXOo7J5Gpj w/oaNc9p8eCiH88VyF9K1XBW7baH4nO0/mjrsQAY3MeqeQgQsj19rZa58prQSqx8NDCz VeDrfQd0oV3YeMSpjw47sB+jIqna/H9tJXkYvMq5FJ6uJIrE4kRyOntEx+5hRLid6eUE dP9YFN+RzvfZDh86GHGrbh/hGfOAguLIaZOdUL9VugLIS48acxQnRdFYzkD3UXaQbWBk iUqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4+I54Ek6rTZwiLpxwNs9qiEZdwY/s5VF8SUQit0LnPk=; b=HfdabUlQWxNoQDLQjxiklEsL6JouQUvAgclaR4XDc/AP1qj7/FSvxPtCB1g6L7Jgi3 SCt9RwyAWSQDFMdq5Ou6Nq2hT6qsmpZUzB3Dqnia2x+6GhmMDEIOO6f5DtTsCKsyG78c 7H4ly6jksS79wVPrnibaEkivglRmYIrrtjP16GySGjd5HzRFkJTR2tLEQQC95dwz3NFF khHDe1+fKYTiAZXpuEsvFjFzKi575iLVw7oFw6bsESWdStsXKrK/Phf5+IYV007TTBp2 vRDsU7ZMFzSe7dpYOXcseHb+Uc639wG52X1vBX3HybFFNNlYob/gWw8euXlmY/PEIZZD GsPA== X-Gm-Message-State: AMke39l+lOVx6eOSBEwkfAQc8IdwdX9dlrRx/mnsBNrxUm9wp/Sw1scD3efQCxes6tkpjg== X-Received: by 10.223.152.2 with SMTP id v2mr1926808wrb.109.1487246614877; Thu, 16 Feb 2017 04:03:34 -0800 (PST) Received: from aanisov-work.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id w30sm8754047wrb.5.2017.02.16.04.03.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Feb 2017 04:03:34 -0800 (PST) From: Andrii Anisov To: xen-devel@lists.xenproject.org Date: Thu, 16 Feb 2017 14:03:25 +0200 Message-Id: <1487246610-8298-2-git-send-email-andrii.anisov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487246610-8298-1-git-send-email-andrii.anisov@gmail.com> References: <1487246610-8298-1-git-send-email-andrii.anisov@gmail.com> Cc: sstabellini@kernel.org, andrii_anisov@epam.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, paul.durrant@citrix.com, jbeulich@suse.com, wei.liu2@citrix.com Subject: [Xen-devel] [RFC 1/6] rangeset_new() refactoring 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 From: Andrii Anisov rangeset_new is made domain agnostic. The domain specific code is moved to common/domain.c:domain_rangeset_new(). It is still left a rangesets list functionality: rangeset_new() is returning its list head if requested. This would be reconsidered further. Signed-off-by: Andrii Anisov --- xen/arch/x86/domain.c | 2 +- xen/arch/x86/hvm/ioreq.c | 4 ++-- xen/arch/x86/mm/p2m.c | 4 ++-- xen/arch/x86/setup.c | 4 ++-- xen/common/domain.c | 22 ++++++++++++++++++++-- xen/common/rangeset.c | 12 ++++-------- xen/include/xen/domain.h | 3 +++ xen/include/xen/rangeset.h | 19 +++++++++++-------- 8 files changed, 45 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index eae643f..93f18d7 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -630,7 +630,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, d->arch.x86_model = boot_cpu_data.x86_model; d->arch.ioport_caps = - rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex); + domain_rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex); rc = -ENOMEM; if ( d->arch.ioport_caps == NULL ) goto fail; diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index 88071ab..6df191d 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -520,8 +520,8 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s, if ( rc ) goto fail; - s->range[i] = rangeset_new(s->domain, name, - RANGESETF_prettyprint_hex); + s->range[i] = domain_rangeset_new(s->domain, name, + RANGESETF_prettyprint_hex); xfree(name); diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 6a45185..46301ad 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -122,8 +122,8 @@ static int p2m_init_hostp2m(struct domain *d) if ( p2m ) { - p2m->logdirty_ranges = rangeset_new(d, "log-dirty", - RANGESETF_prettyprint_hex); + p2m->logdirty_ranges = domain_rangeset_new(d, "log-dirty", + RANGESETF_prettyprint_hex); if ( p2m->logdirty_ranges ) { d->arch.p2m = p2m; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index b130671..69a961c 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1419,8 +1419,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) /* Low mappings were only needed for some BIOS table parsing. */ zap_low_mappings(); - mmio_ro_ranges = rangeset_new(NULL, "r/o mmio ranges", - RANGESETF_prettyprint_hex); + mmio_ro_ranges = rangeset_new("r/o mmio ranges", + RANGESETF_prettyprint_hex, NULL); init_apic_mappings(); diff --git a/xen/common/domain.c b/xen/common/domain.c index 3abaca9..1b9bc3c 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -329,8 +329,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags, rangeset_domain_initialise(d); init_status |= INIT_rangeset; - d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex); - d->irq_caps = rangeset_new(d, "Interrupts", 0); + d->iomem_caps = domain_rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex); + d->irq_caps = domain_rangeset_new(d, "Interrupts", 0); if ( (d->iomem_caps == NULL) || (d->irq_caps == NULL) ) goto fail; @@ -1537,6 +1537,24 @@ int continue_hypercall_on_cpu( return 0; } +struct rangeset *domain_rangeset_new(struct domain *d, char *name, + unsigned int flags) +{ + struct list_head *head; + struct rangeset *r = rangeset_new(name, flags, &head); + + if ( d != NULL ) + { + spin_lock(&d->rangesets_lock); + list_add(head, &d->rangesets); + spin_unlock(&d->rangesets_lock); + } + + return r; +} + + + /* * Local variables: * mode: C diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index 6c6293c..478d232 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -322,8 +322,8 @@ bool_t rangeset_is_empty( return ((r == NULL) || list_empty(&r->range_list)); } -struct rangeset *rangeset_new( - struct domain *d, char *name, unsigned int flags) +struct rangeset *rangeset_new(char *name, unsigned int flags, + struct list_head **head) { struct rangeset *r; @@ -347,12 +347,8 @@ struct rangeset *rangeset_new( snprintf(r->name, sizeof(r->name), "(no name)"); } - if ( (r->domain = d) != NULL ) - { - spin_lock(&d->rangesets_lock); - list_add(&r->rangeset_list, &d->rangesets); - spin_unlock(&d->rangesets_lock); - } + if (head) + *head = &r->rangeset_list; return r; } diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index bce0ea1..cd62e6e 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -108,4 +108,7 @@ struct vnuma_info { void vnuma_destroy(struct vnuma_info *vnuma); +struct rangeset *domain_rangeset_new(struct domain *d, char *name, + unsigned int flags); + #endif /* __XEN_DOMAIN_H__ */ diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h index aa64082..395ba62 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -13,6 +13,7 @@ #include struct domain; +struct list_head; struct rangeset; /* @@ -28,15 +29,17 @@ void rangeset_domain_destroy( struct domain *d); /* - * Create/destroy a rangeset. Optionally attach to specified domain @d for - * auto-destruction when the domain dies. A name may be specified, for use - * in debug pretty-printing, and various RANGESETF flags (defined below). - * - * It is invalid to perform any operation on a rangeset @r after calling - * rangeset_destroy(r). + * Create a rangeset. Optionally attach to a specified list @head. + * A name may be specified, for use in debug pretty-printing, and various + * RANGESETF flags (defined below). + */ +struct rangeset *rangeset_new(char *name, unsigned int flags, + struct list_head **head); + +/* + * Destroy a rangeset. It is invalid to perform any operation on a rangeset @r + * after calling rangeset_destroy(r). */ -struct rangeset *rangeset_new( - struct domain *d, char *name, unsigned int flags); void rangeset_destroy( struct rangeset *r);