From patchwork Thu Sep 14 16:49:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9953577 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 8898B602C9 for ; Thu, 14 Sep 2017 16:52:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 971B329155 for ; Thu, 14 Sep 2017 16:52:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AFE529168; Thu, 14 Sep 2017 16:52:37 +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 D902729155 for ; Thu, 14 Sep 2017 16:52:36 +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 1dsXKv-0006LT-Px; Thu, 14 Sep 2017 16:49:57 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsXKu-0006LN-6v for xen-devel@lists.xen.org; Thu, 14 Sep 2017 16:49:56 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id B6/39-02023-333BAB95; Thu, 14 Sep 2017 16:49:55 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDLMWRWlGSWpSXmKPExsVysyfVTddo865 Ig58PDSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owVe1azF8wVq3i17SFzA+N9wS5GLg4hgc2M Ej3TzjBBOKcZJZqmdTN2MXJysAloStz5/IkJxBYRkJa49vkyI0gRs8BzJonP++6CFQkLWEmsP 3GBDcRmEVCVuNu0jBnE5hWwlPjcNIkdxJYQkJfY1XaRdQIj5wJGhlWMGsWpRWWpRbpGpnpJRZ npGSW5iZk5uoYGpnq5qcXFiempOYlJxXrJ+bmbGIE+q2dgYNzBuKvd7xCjJAeTkijvXt2dkUJ 8SfkplRmJxRnxRaU5qcWHGGU4OJQkeJ9v3BUpJFiUmp5akZaZAwwemLQEB4+SCO9ekDRvcUFi bnFmOkTqFKMuR8fNu3+YhFjy8vNSpcR59TcBFQmAFGWU5sGNgAXyJUZZKWFeRgYGBiGegtSi3 MwSVPlXjOIcjErCvEwgU3gy80rgNr0COoIJ6Igzp3eAHFGSiJCSamBcqqNw5djHE7tFXkcldH K8WCO87Ccf01ZznlLP42d338hyUpefriCse/jq7R1zjvOtit+WOHna/Xhx81e6l/ffsI7i67j P9V4q7PVJ7hj5OYFfZD1Cpp2J/+zxLnnyvhdr48QfV6dP1t/d75G8X3qzRvxb2clnp6wJjWae +mBB9ok+B9b1PPN+K7EUZyQaajEXFScCAIqrdQJfAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1505407794!111559991!1 X-Originating-IP: [217.140.101.70] 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 22887 invoked from network); 14 Sep 2017 16:49:54 -0000 Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-206.messagelabs.com with SMTP; 14 Sep 2017 16:49:54 -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 9503B1435; Thu, 14 Sep 2017 09:49:53 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C40EF3F483; Thu, 14 Sep 2017 09:49:51 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 14 Sep 2017 17:49:45 +0100 Message-Id: <20170914164945.11566-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH] xen: grant-table: Simplify get_page_frame 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 implementation of get_page_frame is currently different whether the architecture support sharing memory or paging memory. Both version are extremely similar so it is possible to consolidate in a single implementation. The check for shared/paged memory are gated with the respective ifdef. Potentially, dummy p2m_is_shared/p2m_is_paging could be implemented for Arm. Signed-off-by: Julien Grall --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu get_page_from_gfn will be able to get reference on foreign page and as per my understanding will allow to grant page on foreign memory. This was not allowed with a simple get_page(...) on the ARM implementation (no sharing nor paging supprot) but is allowed on the x86 implementation due to get_page_from_gfn. On x86, foreign pages are currently only allowed for PVH dom0, so I think it is not a big deal for now. On Arm, foreign pages can be present on any domain. So this patch would permit grant on foreing pages. So I would like to check whether it would be valid to grant a mapping on foreign pages? If not, I could add a check if ( p2m_is_foreign(...) ) return GTNST_bad_page. --- xen/common/grant_table.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index c3895e6201..97d3200313 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -259,7 +259,6 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame, struct domain *rd) { int rc = GNTST_okay; -#if defined(P2M_PAGED_TYPES) || defined(P2M_SHARED_TYPES) p2m_type_t p2mt; *page = get_page_from_gfn(rd, gfn, &p2mt, @@ -267,26 +266,20 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame, if ( !(*page) ) { *frame = mfn_x(INVALID_MFN); +#if defined(P2M_SHARED_TYPES) if ( p2m_is_shared(p2mt) ) return GNTST_eagain; +#endif +#if defined(P2M_PAGES_TYPES) if ( p2m_is_paging(p2mt) ) { p2m_mem_paging_populate(rd, gfn); return GNTST_eagain; } +#endif return GNTST_bad_page; } *frame = page_to_mfn(*page); -#else - *frame = mfn_x(gfn_to_mfn(rd, _gfn(gfn))); - *page = mfn_valid(_mfn(*frame)) ? mfn_to_page(*frame) : NULL; - if ( (!(*page)) || (!get_page(*page, rd)) ) - { - *frame = mfn_x(INVALID_MFN); - *page = NULL; - rc = GNTST_bad_page; - } -#endif return rc; }