From patchwork Thu Jul 28 14:20:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 72956 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp880343qga; Thu, 28 Jul 2016 07:24:15 -0700 (PDT) X-Received: by 10.36.79.9 with SMTP id c9mr41347337itb.28.1469715855093; Thu, 28 Jul 2016 07:24:15 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 185si13330592ioo.21.2016.07.28.07.24.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jul 2016 07:24:15 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSmAv-0007CB-9X; Thu, 28 Jul 2016 14:20:37 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSmAu-0007Bg-LH for xen-devel@lists.xen.org; Thu, 28 Jul 2016 14:20:36 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 23/13-24990-3B41A975; Thu, 28 Jul 2016 14:20:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTXezyKx wg7mnJC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1owtny0L3shX7Fpzg7GBca1kFyMXh5DAJkaJ udM6WCCc04wS556/Ze9i5ORgE9CUuPP5ExOILSIgLXHt82VGkCJmgXZGibX9vcwgCWGBEInnb cvZQGwWAVWJrluXwWxeAWeJs3+2gA2SEJCTOHlsMiuIzSngInGv7TuYLQRUc/rudvYJjNwLGB lWMWoUpxaVpRbpGlnqJRVlpmeU5CZm5ugaGpjq5aYWFyemp+YkJhXrJefnbmIEeriegYFxB+P lLX6HGCU5mJREecNCZ4YL8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuB1E54VLiRYlJqeWpGWmQMM NZi0BAePkghvJEiat7ggMbc4Mx0idYpRUUqc95cQUEIAJJFRmgfXBgvvS4yyUsK8jAwMDEI8B alFuZklqPKvGMU5GJWEeQ1AxvNk5pXATX8FtJgJaHFx7AyQxSWJCCmpBsaQMNbUdjGGj/nblx f3dz3R/1hhMHdzes+/tsKsRxM90yffd2I/dsST3XTh4hXC1tOfxu8Osg36ucJ1uWzZwQXKp1b GMHTNu+XFueThlbLyu+x7/vc13F2/xcEufTXP91nPI44V18UvtHV9f+/uw/hfrGWT/xjpbJNd Xs+5evnjKRNvLRE4LsGoxFKckWioxVxUnAgA0YsrbmoCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1469715634!35915149!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8462 invoked from network); 28 Jul 2016 14:20:35 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-16.tower-206.messagelabs.com with SMTP; 28 Jul 2016 14:20:35 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 67736BAF; Thu, 28 Jul 2016 07:21:51 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3898E3F21A; Thu, 28 Jul 2016 07:20:33 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 28 Jul 2016 15:20:11 +0100 Message-Id: <1469715620-4670-7-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469715620-4670-1-git-send-email-julien.grall@arm.com> References: <1469715620-4670-1-git-send-email-julien.grall@arm.com> Cc: proskurin@sec.in.tum.de, Julien Grall , sstabellini@kernel.org, steve.capper@arm.com, wei.chen@linaro.org Subject: [Xen-devel] [PATCH v2 06/15] xen/arm: p2m: Introduce p2m_{read, write}_{, un}lock helpers 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" Some functions in the p2m code do not require to modify the P2M code. Document it by introducing separate helpers to lock the p2m. This patch does not change the lock. This will be done in a subsequent patch. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/p2m.c | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index bcccaa4..5c67090 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -47,11 +47,36 @@ static bool_t p2m_mapping(lpae_t pte) return p2m_valid(pte) && !pte.p2m.table; } +static inline void p2m_write_lock(struct p2m_domain *p2m) +{ + spin_lock(&p2m->lock); +} + +static inline void p2m_write_unlock(struct p2m_domain *p2m) +{ + spin_unlock(&p2m->lock); +} + +static inline void p2m_read_lock(struct p2m_domain *p2m) +{ + spin_lock(&p2m->lock); +} + +static inline void p2m_read_unlock(struct p2m_domain *p2m) +{ + spin_unlock(&p2m->lock); +} + +static inline int p2m_is_locked(struct p2m_domain *p2m) +{ + return spin_is_locked(&p2m->lock); +} + void p2m_dump_info(struct domain *d) { struct p2m_domain *p2m = &d->arch.p2m; - spin_lock(&p2m->lock); + p2m_read_lock(p2m); printk("p2m mappings for domain %d (vmid %d):\n", d->domain_id, p2m->vmid); BUG_ON(p2m->stats.mappings[0] || p2m->stats.shattered[0]); @@ -60,7 +85,7 @@ void p2m_dump_info(struct domain *d) printk(" 2M mappings: %ld (shattered %ld)\n", p2m->stats.mappings[2], p2m->stats.shattered[2]); printk(" 4K mappings: %ld\n", p2m->stats.mappings[3]); - spin_unlock(&p2m->lock); + p2m_read_unlock(p2m); } void memory_type_changed(struct domain *d) @@ -166,7 +191,7 @@ static mfn_t __p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) p2m_type_t _t; unsigned int level, root_table; - ASSERT(spin_is_locked(&p2m->lock)); + ASSERT(p2m_is_locked(p2m)); BUILD_BUG_ON(THIRD_MASK != PAGE_MASK); /* Allow t to be NULL */ @@ -233,9 +258,9 @@ mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) mfn_t ret; struct p2m_domain *p2m = &d->arch.p2m; - spin_lock(&p2m->lock); + p2m_read_lock(p2m); ret = __p2m_lookup(d, gfn, t); - spin_unlock(&p2m->lock); + p2m_read_unlock(p2m); return ret; } @@ -475,7 +500,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn, #undef ACCESS }; - ASSERT(spin_is_locked(&p2m->lock)); + ASSERT(p2m_is_locked(p2m)); /* If no setting was ever set, just return rwx. */ if ( !p2m->mem_access_enabled ) @@ -944,7 +969,7 @@ static int apply_p2m_changes(struct domain *d, */ flush_pt = iommu_enabled && !iommu_has_feature(d, IOMMU_FEAT_COHERENT_WALK); - spin_lock(&p2m->lock); + p2m_write_lock(p2m); /* Static mapping. P2M_ROOT_PAGES > 1 are handled below */ if ( P2M_ROOT_PAGES == 1 ) @@ -1148,7 +1173,7 @@ out: unmap_domain_page(mappings[level]); } - spin_unlock(&p2m->lock); + p2m_write_unlock(p2m); if ( rc < 0 && ( op == INSERT ) && addr != start_gpaddr ) @@ -1529,7 +1554,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, if ( v != current ) return NULL; - spin_lock(&p2m->lock); + p2m_read_lock(p2m); rc = gvirt_to_maddr(va, &maddr, flags); @@ -1549,7 +1574,7 @@ err: if ( !page && p2m->mem_access_enabled ) page = p2m_mem_access_check_and_get_page(va, flags); - spin_unlock(&p2m->lock); + p2m_read_unlock(p2m); return page; } @@ -1823,9 +1848,9 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, int ret; struct p2m_domain *p2m = p2m_get_hostp2m(d); - spin_lock(&p2m->lock); + p2m_read_lock(p2m); ret = __p2m_get_mem_access(d, gfn, access); - spin_unlock(&p2m->lock); + p2m_read_unlock(p2m); return ret; }