From patchwork Wed Aug 30 18:32:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Proskurin X-Patchwork-Id: 9930597 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 9A4026032A for ; Wed, 30 Aug 2017 18:35:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91E15285C8 for ; Wed, 30 Aug 2017 18:35:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86D1E28717; Wed, 30 Aug 2017 18:35: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 1974C285C8 for ; Wed, 30 Aug 2017 18:35:56 +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 1dn7ny-0001wW-3k; Wed, 30 Aug 2017 18:33:34 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dn7nv-0001ij-10 for xen-devel@lists.xenproject.org; Wed, 30 Aug 2017 18:33:31 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id D5/9B-02224-AF407A95; Wed, 30 Aug 2017 18:33:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsXSPJ9BRfcny/J IgznTVC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxt208yFXzTqniwWbuBsVOui5GTQ0hgI6PE /pcFXYxcQPYmRolVC44zgiTYBAwkprxeyQpiiwgoSdxbNZkJpIhZoIlR4l7jAzaQhLCAncTVZ d/AbBYBVYn/C9vZQWxeAVuJLXP6mEFsCQF5iXMPboPZnEDxMwdmsEJstpG4N/c88wRG7gWMDK sY1YtTi8pSi3Qt9ZKKMtMzSnITM3N0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAr1bz8DAuIPx9U+ nQ4ySHExKorwrmJdHCvEl5adUZiQWZ8QXleakFh9ilOHgUJLgZQcGi5BgUWp6akVaZg4wzGDS Ehw8SiK8TiBp3uKCxNzizHSI1ClGRSlx3sUgMwVAEhmleXBtsNC+xCgrJczLyMDAIMRTkFqUm 1mCKv+KUZyDUUmY1xFkPE9mXgnc9FdAi5mAFsd6LQVZXJKIkJJqYNSIPd198pvYiux9cvYcZm YfmRbVH9m+pqM+b+fhyJ6rs2f+2O4SO6fkolEa274dCde3/wy7mj7ntZGb5rd/M47JHsvonl3 5XN1+20nWnKKXHX5xQqXqZZO9Aj1Ml3EevnrThSN8wcQLmjZ9VzYZefrsCGF9/Z1tv/vXjdwb 5nwv+fX280UB/4VKLMUZiYZazEXFiQCouKV/aAIAAA== X-Env-Sender: proskurin@sec.in.tum.de X-Msg-Ref: server-14.tower-31.messagelabs.com!1504118009!112210457!1 X-Originating-IP: [131.159.0.36] 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 25356 invoked from network); 30 Aug 2017 18:33:29 -0000 Received: from mail-out2.informatik.tu-muenchen.de (HELO mail-out2.informatik.tu-muenchen.de) (131.159.0.36) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Aug 2017 18:33:29 -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 29F7310CB7DF7; Wed, 30 Aug 2017 20:33:09 +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 1B817491F5; Wed, 30 Aug 2017 20:33:09 +0200 (CEST) From: Sergej Proskurin To: xen-devel@lists.xenproject.org Date: Wed, 30 Aug 2017 20:32:46 +0200 Message-Id: <20170830183258.14612-28-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 27/39] arm/p2m: Add altp2m_propagate_change 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 This commit introduces the function "altp2m_propagate_change" that is responsible to propagate changes applied to the host's p2m to a specific or even all altp2m views. In this way, Xen can in-/decrease the guest's physmem at run-time without leaving the altp2m views with stalled/invalid entries. Signed-off-by: Sergej Proskurin --- Cc: Stefano Stabellini Cc: Julien Grall --- v3: Cosmetic fixes. Changed the locking mechanism to "p2m_write_lock" inside the function "altp2m_reset". Removed TLB flushing and resetting of the max_mapped_gfn lowest_mapped_gfn fields within the function "altp2m_reset". These operations are performed in the function "p2m_flush_table". Protected altp2m_active(d) check in "altp2m_propagate_change". The function "altp2m_propagate_change" now decides whether an entry needs to be dropped out of the altp2m view only if the smfn value equals INVALID_MFN. Extended the function "altp2m_propagate_change" so that it returns an int value to the caller. Also, the function "apply_p2m_changes" checks the return value and fails the entire operation on error. Moved the funtion "modify_altp2m_range" out of this commit. v4: Use the functions "p2m_(set|get)_entry" instead of the helpers "p2m_lookup_attr" and "modify_altp2m_entry". --- xen/arch/arm/altp2m.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 4 +++ xen/include/asm-arm/altp2m.h | 8 +++++ 3 files changed, 96 insertions(+) diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c index 8c3212780a..4883b1323b 100644 --- a/xen/arch/arm/altp2m.c +++ b/xen/arch/arm/altp2m.c @@ -123,6 +123,90 @@ int altp2m_set_mem_access(struct domain *d, return rc; } +static inline void altp2m_reset(struct p2m_domain *p2m) +{ + p2m_write_lock(p2m); + p2m_flush_table(p2m); + p2m_write_unlock(p2m); +} + +int altp2m_propagate_change(struct domain *d, + gfn_t sgfn, + unsigned int page_order, + mfn_t smfn, + p2m_type_t p2mt, + p2m_access_t p2ma) +{ + int rc = 0; + unsigned int i; + unsigned int reset_count = 0; + unsigned int last_reset_idx = ~0; + struct p2m_domain *p2m; + mfn_t m; + + altp2m_lock(d); + + if ( !altp2m_active(d) ) + goto out; + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + p2m = d->arch.altp2m_p2m[i]; + + if ( p2m == NULL ) + continue; + + /* + * Get the altp2m mapping. If the smfn has not been dropped, a valid + * altp2m mapping needs to be changed/modified accordingly. + */ + p2m_read_lock(p2m); + m = p2m_get_entry(p2m, sgfn, NULL, NULL, NULL); + p2m_read_unlock(p2m); + + /* Check for a dropped page that may impact this altp2m. */ + if ( mfn_eq(smfn, INVALID_MFN) && + (gfn_x(sgfn) >= gfn_x(p2m->lowest_mapped_gfn)) && + (gfn_x(sgfn) <= gfn_x(p2m->max_mapped_gfn)) ) + { + if ( !reset_count++ ) + { + altp2m_reset(p2m); + last_reset_idx = i; + } + else + { + /* At least 2 altp2m's impacted, so reset everything. */ + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + p2m = d->arch.altp2m_p2m[i]; + + if ( i == last_reset_idx || p2m == NULL ) + continue; + + altp2m_reset(p2m); + } + goto out; + } + } + else if ( !mfn_eq(m, INVALID_MFN) ) + { + /* Align the gfn and mfn to the given pager order. */ + sgfn = _gfn(gfn_x(sgfn) & ~((1UL << page_order) - 1)); + smfn = _mfn(mfn_x(smfn) & ~((1UL << page_order) - 1)); + + p2m_write_lock(p2m); + rc = p2m_set_entry(p2m, sgfn, (1UL << page_order), smfn, p2mt, p2ma); + p2m_write_unlock(p2m); + } + } + +out: + altp2m_unlock(d); + + return rc; +} + static void altp2m_vcpu_reset(struct vcpu *v) { v->arch.ap2m_idx = INVALID_ALTP2M; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index e9274c74a8..dcf7be6439 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -958,6 +958,10 @@ static int __p2m_set_entry(struct p2m_domain *p2m, else rc = 0; + /* Update all affected altp2m views if necessary. */ + if ( p2m_is_hostp2m(p2m) ) + rc = altp2m_propagate_change(p2m->domain, sgfn, page_order, smfn, t, a); + out: unmap_domain_page(table); diff --git a/xen/include/asm-arm/altp2m.h b/xen/include/asm-arm/altp2m.h index f8e772f120..3e418cb0f0 100644 --- a/xen/include/asm-arm/altp2m.h +++ b/xen/include/asm-arm/altp2m.h @@ -80,4 +80,12 @@ int altp2m_set_mem_access(struct domain *d, p2m_access_t a, gfn_t gfn); +/* Propagates changes made to hostp2m to affected altp2m views. */ +int altp2m_propagate_change(struct domain *d, + gfn_t sgfn, + unsigned int page_order, + mfn_t smfn, + p2m_type_t p2mt, + p2m_access_t p2ma); + #endif /* __ASM_ARM_ALTP2M_H */