From patchwork Wed Aug 30 18:32:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Proskurin X-Patchwork-Id: 9930613 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 25AA46032A for ; Wed, 30 Aug 2017 18:36:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DA9B285C8 for ; Wed, 30 Aug 2017 18:36:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 128A82874B; Wed, 30 Aug 2017 18:36:05 +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 9F2E0285C8 for ; Wed, 30 Aug 2017 18:36:04 +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 1dn7np-0001YY-Kh; Wed, 30 Aug 2017 18:33:25 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dn7nn-0001UG-Sm for xen-devel@lists.xenproject.org; Wed, 30 Aug 2017 18:33:23 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 2B/95-03616-3F407A95; Wed, 30 Aug 2017 18:33:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsXSPJ+BQ/cTy/J Ig8971S2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyJC2czF5yQq/ixQayBca94FyMXh5DARkaJ oxduskE4mxgl1k9+ztLFyMnBJmAgMeX1SlYQW0RASeLeqslMIEXMAk2MEvcaHwB1cHAIC9hJ/ J9hA1LDIqAq8XTyVBaQMK+ArcTFMwIgYQkBeYlzD24zg9icQOEzB2aAjRQSsJG4N/c88wRG7g WMDKsY1YtTi8pSi3Qt9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK9ZLzczcxAn3LAAQ7GO9 uCjjEKMnBpCTKu4J5eaQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd5ZIDnBotT01Iq0zBxgkMGk JTh4lER4hUHSvMUFibnFmekQqVOMilLivItBEgIgiYzSPLg2WGBfYpSVEuZlBDpEiKcgtSg3s wRV/hWjOAejkjBvP8gUnsy8Erjpr4AWMwEtjvVaCrK4JBEhJdXAmLSM50Wdm6FT1Dcr+anLZ6 c/ddC/d/p0yonDtpkBDqrnL5b3u4YemGX86/ySQ/eCvwfkvrNqL3E59jLKXMHcPrlsjkW30Wf DCSdFOfRv3/Xdd6rN1MFFfbeupVbfTM0lXob5bauN906Lrtx7Pyqfp/oV9zTpk/pZj9efucTZ 654cvpBDzOWjEktxRqKhFnNRcSIAkC0NqmcCAAA= X-Env-Sender: proskurin@sec.in.tum.de X-Msg-Ref: server-9.tower-27.messagelabs.com!1504118002!114333400!1 X-Originating-IP: [131.159.0.8] 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 64494 invoked from network); 30 Aug 2017 18:33:22 -0000 Received: from mail-out1.informatik.tu-muenchen.de (HELO mail-out1.informatik.tu-muenchen.de) (131.159.0.8) by server-9.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Aug 2017 18:33:22 -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 8F8C810CB7DF7; Wed, 30 Aug 2017 20:33:08 +0200 (CEST) Received: from thanatos.sec.in.tum.de (thanatos.sec.in.tum.de [131.159.50.57]) by files.sec.in.tum.de (Postfix) with ESMTP id 81F7A491F5; Wed, 30 Aug 2017 20:33:08 +0200 (CEST) From: Sergej Proskurin To: xen-devel@lists.xenproject.org Date: Wed, 30 Aug 2017 20:32:36 +0200 Message-Id: <20170830183258.14612-18-proskurin@sec.in.tum.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170830183258.14612-1-proskurin@sec.in.tum.de> References: <20170830183258.14612-1-proskurin@sec.in.tum.de> Cc: Sergej Proskurin , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH v4 17/39] arm/p2m: Add HVMOP_altp2m_switch_p2m 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 Signed-off-by: Sergej Proskurin --- Cc: Stefano Stabellini Cc: Julien Grall --- v3: Extended the function "altp2m_switch_domain_altp2m_by_id" so that if the guest domain indirectly calles this function, the current vcpu also changes the altp2m view without performing an explicit context switch. Exchanged the check "altp2m_vttbr[idx] == INVALID_VTTBR" for "altp2m_p2m[idx] == NULL" in "altp2m_switch_domain_altp2m_by_id". v4: ARM supports an external-only interface to the altp2m subsystem, i.e, the guest does not have access to altp2m. Thus, we don't have to consider that the current vcpu will not switch its context in the function "p2m_restore_state". For this reason, we do not check for whether we are working on the current vcpu in the function altp2m_switch_domain_altp2m_by_id. If the current guest access restriction to the altp2m subsystem should change in the future, we have to update VTTBR_EL2 directly. Cosmetic fixes. --- xen/arch/arm/altp2m.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/hvm.c | 2 +- xen/include/asm-arm/altp2m.h | 4 ++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c index 1128e1af16..9a2cf5a018 100644 --- a/xen/arch/arm/altp2m.c +++ b/xen/arch/arm/altp2m.c @@ -32,6 +32,51 @@ struct p2m_domain *altp2m_get_altp2m(struct vcpu *v) return v->domain->arch.altp2m_p2m[idx]; } +int altp2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx) +{ + struct vcpu *v; + int rc = -EINVAL; + + if ( idx >= MAX_ALTP2M ) + return rc; + + domain_pause_except_self(d); + + altp2m_lock(d); + + if ( d->arch.altp2m_p2m[idx] != NULL ) + { + for_each_vcpu( d, v ) + { + if ( idx == v->arch.ap2m_idx ) + continue; + + atomic_dec(&altp2m_get_altp2m(v)->active_vcpus); + v->arch.ap2m_idx = idx; + atomic_inc(&altp2m_get_altp2m(v)->active_vcpus); + + /* + * ARM supports an external-only interface to the altp2m subsystem, + * i.e, the guest does not have access to altp2m. Thus, we don't + * have to consider that the current vcpu will not switch its + * context in the function "p2m_restore_state". + * + * XXX: If the current guest access restriction to the altp2m + * subsystem should change in the future, we have to update + * VTTBR_EL2 directly. + */ + } + + rc = 0; + } + + altp2m_unlock(d); + + domain_unpause_except_self(d); + + return rc; +} + static void altp2m_vcpu_reset(struct vcpu *v) { v->arch.ap2m_idx = INVALID_ALTP2M; diff --git a/xen/arch/arm/hvm.c b/xen/arch/arm/hvm.c index 4bf2f28a1a..9bddc7e17e 100644 --- a/xen/arch/arm/hvm.c +++ b/xen/arch/arm/hvm.c @@ -135,7 +135,7 @@ static int do_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg) break; case HVMOP_altp2m_switch_p2m: - rc = -EOPNOTSUPP; + rc = altp2m_switch_domain_altp2m_by_id(d, a.u.view.view); break; case HVMOP_altp2m_set_mem_access: diff --git a/xen/include/asm-arm/altp2m.h b/xen/include/asm-arm/altp2m.h index 778c6c4f12..d59f704489 100644 --- a/xen/include/asm-arm/altp2m.h +++ b/xen/include/asm-arm/altp2m.h @@ -49,6 +49,10 @@ void altp2m_vcpu_destroy(struct vcpu *v); /* Get current alternate p2m table. */ struct p2m_domain *altp2m_get_altp2m(struct vcpu *v); +/* Switch alternate p2m for entire domain */ +int altp2m_switch_domain_altp2m_by_id(struct domain *d, + unsigned int idx); + /* Make a specific alternate p2m valid. */ int altp2m_init_by_id(struct domain *d, unsigned int idx);