From patchwork Mon Aug 1 17:10:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Proskurin X-Patchwork-Id: 9254611 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 2928A6048B for ; Mon, 1 Aug 2016 17:13:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14A522843C for ; Mon, 1 Aug 2016 17:13:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 093A4284AE; Mon, 1 Aug 2016 17:13:56 +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 396D22843C for ; Mon, 1 Aug 2016 17:13:55 +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 1bUGkF-0006PI-86; Mon, 01 Aug 2016 17:11:15 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUGkD-0006Lc-E5 for xen-devel@lists.xenproject.org; Mon, 01 Aug 2016 17:11:13 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 16/77-13744-0B28F975; Mon, 01 Aug 2016 17:11:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsXSPJ+BQ3dD0/x wgyVLhCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oypxzawFLwxrpjZuY65gfGzZhcjF4eQwEZG icV/F7N1MXICOcsZJZbc1QGx2QQMJKa8XskKYosIKEncWzWZCaSBWaCJUeJe4wOwBmEBD4l7T z6yg9gsAqoSx3a9ZgGxeQVsJKbv+wjWLCEgJ9Fw/j4ziM0pYCvRd3s5C8QyG4nFV/czT2DkXs DIsIpRvTi1qCy1SNdEL6koMz2jJDcxM0fX0MBMLze1uDgxPTUnMalYLzk/dxMj0L8MQLCDsfu y/yFGSQ4mJVHehIL54UJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeL0bgXKCRanpqRVpmTnAQINJ S3DwKInweoGkeYsLEnOLM9MhUqcYdTmOzb2xlkmIJS8/L1VKnPdsA1CRAEhRRmke3AhY0F9il JUS5mUEOkqIpyC1KDezBFX+FaM4B6OSMG8ByCqezLwSuE2vgI5gAjoi0X4OyBEliQgpqQZG+d QKZqci9bY4Tr+XCp7HDXm82WelqknfMn4VHVrkIV6x4sJctwS2CzoVXodDl/nvf3LK61O0QtD UaxeMLy6ZtOzS8a4f+psmGS29IL5S/GLvxdwDD98f0v9yqJd5/yfNIz8M9AtZ/ntHrVt+YeqR 2AubBOe78f4W0Nnn3lA6L+54zMIMZt6zSizFGYmGWsxFxYkAONjyUHUCAAA= X-Env-Sender: proskurin@sec.in.tum.de X-Msg-Ref: server-10.tower-21.messagelabs.com!1470071472!26508475!1 X-Originating-IP: [131.159.0.8] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12804 invoked from network); 1 Aug 2016 17:11:12 -0000 Received: from mail-out1.informatik.tu-muenchen.de (HELO mail-out1.informatik.tu-muenchen.de) (131.159.0.8) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Aug 2016 17:11:12 -0000 Received: from files.sec.in.tum.de (files.sec.in.tum.de [131.159.50.1]) by services.sec.in.tum.de (Postfix) with ESMTP id 0D28010100EA1; Mon, 1 Aug 2016 19:11:11 +0200 (CEST) Received: from ker.sec.in.tum.de (ker.sec.in.tum.de [131.159.50.36]) by files.sec.in.tum.de (Postfix) with ESMTP id F40024428; Mon, 1 Aug 2016 19:11:10 +0200 (CEST) From: Sergej Proskurin To: xen-devel@lists.xenproject.org Date: Mon, 1 Aug 2016 19:10:10 +0200 Message-Id: <20160801171028.11615-8-proskurin@sec.in.tum.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160801171028.11615-1-proskurin@sec.in.tum.de> References: <20160801171028.11615-1-proskurin@sec.in.tum.de> Cc: Sergej Proskurin , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH v2 07/25] arm/altp2m: Add altp2m init/teardown routines. 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 The p2m initialization now invokes initialization routines responsible for the allocation and initialization of altp2m structures. The same applies to teardown routines. The functionality has been adopted from the x86 altp2m implementation. Signed-off-by: Sergej Proskurin --- Cc: Stefano Stabellini Cc: Julien Grall --- v2: Shared code between host/altp2m init/teardown functions. Added conditional init/teardown of altp2m. Altp2m related functions are moved to altp2m.c --- xen/arch/arm/Makefile | 1 + xen/arch/arm/altp2m.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 28 +++++++++++++---- xen/include/asm-arm/altp2m.h | 6 ++++ xen/include/asm-arm/domain.h | 4 +++ xen/include/asm-arm/p2m.h | 5 ++++ 6 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 xen/arch/arm/altp2m.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 23aaf52..4a7f660 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -5,6 +5,7 @@ subdir-$(CONFIG_ARM_64) += efi subdir-$(CONFIG_ACPI) += acpi obj-$(CONFIG_ALTERNATIVE) += alternative.o +obj-y += altp2m.o obj-y += bootfdt.o obj-y += cpu.o obj-y += cpuerrata.o diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c new file mode 100644 index 0000000..abbd39a --- /dev/null +++ b/xen/arch/arm/altp2m.c @@ -0,0 +1,71 @@ +/* + * arch/arm/altp2m.c + * + * Alternate p2m + * Copyright (c) 2016 Sergej Proskurin + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ + +#include +#include + +int altp2m_init(struct domain *d) +{ + unsigned int i; + + spin_lock_init(&d->arch.altp2m_lock); + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + d->arch.altp2m_p2m[i] = NULL; + d->arch.altp2m_vttbr[i] = INVALID_VTTBR; + } + + return 0; +} + +void altp2m_teardown(struct domain *d) +{ + unsigned int i; + struct p2m_domain *p2m; + + altp2m_lock(d); + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + if ( !d->arch.altp2m_p2m[i] ) + continue; + + p2m = d->arch.altp2m_p2m[i]; + p2m_free_one(p2m); + xfree(p2m); + + d->arch.altp2m_vttbr[i] = INVALID_VTTBR; + d->arch.altp2m_p2m[i] = NULL; + } + + d->arch.altp2m_active = false; + + altp2m_unlock(d); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index ff9c0d1..29ec5e5 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -14,6 +14,8 @@ #include #include +#include + #ifdef CONFIG_ARM_64 static unsigned int __read_mostly p2m_root_order; static unsigned int __read_mostly p2m_root_level; @@ -1392,7 +1394,7 @@ void p2m_flush_table(struct p2m_domain *p2m) free_domheap_page(pg); } -static inline void p2m_free_one(struct p2m_domain *p2m) +void p2m_free_one(struct p2m_domain *p2m) { p2m_flush_table(p2m); @@ -1415,9 +1417,13 @@ int p2m_init_one(struct domain *d, struct p2m_domain *p2m) rwlock_init(&p2m->lock); INIT_PAGE_LIST_HEAD(&p2m->pages); - rc = p2m_alloc_vmid(p2m); - if ( rc != 0 ) - return rc; + /* Reused altp2m views keep their VMID. */ + if ( p2m->vmid == INVALID_VMID ) + { + rc = p2m_alloc_vmid(p2m); + if ( rc != 0 ) + return rc; + } p2m->domain = d; p2m->access_required = false; @@ -1441,6 +1447,9 @@ static void p2m_teardown_hostp2m(struct domain *d) void p2m_teardown(struct domain *d) { + if ( altp2m_enabled(d) ) + altp2m_teardown(d); + p2m_teardown_hostp2m(d); } @@ -1460,7 +1469,16 @@ static int p2m_init_hostp2m(struct domain *d) int p2m_init(struct domain *d) { - return p2m_init_hostp2m(d); + int rc; + + rc = p2m_init_hostp2m(d); + if ( rc ) + return rc; + + if ( altp2m_enabled(d) ) + rc = altp2m_init(d); + + return rc; } int relinquish_p2m_mapping(struct domain *d) diff --git a/xen/include/asm-arm/altp2m.h b/xen/include/asm-arm/altp2m.h index d47b249..79ea66b 100644 --- a/xen/include/asm-arm/altp2m.h +++ b/xen/include/asm-arm/altp2m.h @@ -22,6 +22,9 @@ #include +#define altp2m_lock(d) spin_lock(&(d)->arch.altp2m_lock) +#define altp2m_unlock(d) spin_unlock(&(d)->arch.altp2m_lock) + #define altp2m_enabled(d) ((d)->arch.hvm_domain.params[HVM_PARAM_ALTP2M]) /* Alternate p2m on/off per domain */ @@ -38,4 +41,7 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v) return 0; } +int altp2m_init(struct domain *d); +void altp2m_teardown(struct domain *d); + #endif /* __ASM_ARM_ALTP2M_H */ diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index cc4bda0..3c25ea5 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -129,6 +129,10 @@ struct arch_domain /* altp2m: allow multiple copies of host p2m */ bool_t altp2m_active; + struct p2m_domain *altp2m_p2m[MAX_ALTP2M]; + uint64_t altp2m_vttbr[MAX_ALTP2M]; + /* Covers access to members of the struct altp2m. */ + spinlock_t altp2m_lock; } __cacheline_aligned; struct arch_vcpu diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 1f9c370..24a1f61 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -9,6 +9,8 @@ #include #include +#define MAX_ALTP2M 10 /* ARM might contain an arbitrary number of + altp2m views. */ #define paddr_bits PADDR_BITS /* Holds the bit size of IPAs in p2m tables. */ @@ -212,6 +214,9 @@ void guest_physmap_remove_page(struct domain *d, mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn); +/* Release resources held by the p2m structure. */ +void p2m_free_one(struct p2m_domain *p2m); + /* * Populate-on-demand */