From patchwork Tue Sep 19 11:22:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9958687 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 C04CF6038F for ; Tue, 19 Sep 2017 11:25:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD76828DFE for ; Tue, 19 Sep 2017 11:25:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A18EF28E01; Tue, 19 Sep 2017 11:25:19 +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 CF5FC28DFE for ; Tue, 19 Sep 2017 11:25:18 +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 1duGbw-00052S-JQ; Tue, 19 Sep 2017 11:22:40 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duGbv-00052M-IV for xen-devel@lists.xen.org; Tue, 19 Sep 2017 11:22:39 +0000 Received: from [85.158.143.35] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta-6.messagelabs.com id 9A/1E-18817-EFDF0C95; Tue, 19 Sep 2017 11:22:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJLMWRWlGSWpSXmKPExsVysyfVTffP3wO RBptblS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozpkyazFfyRrjh+7hlTA+MJ0S5GLg4hgc2M Es9ad7N1MXICOacZJQ7d4gex2QQ0Je58/sQEYosISEtc+3yZEaSBWeA5o8SklhmsIAlhATuJ1 rvXgIo4OFgEVCW6+41BwrwClhJn7raygNgSAvISu9ousk5g5FzAyLCKUb04tagstUjXRC+pKD M9oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTI9BbDECwg7H7sv8hRkkOJiVR3r5fByKF+JL yUyozEosz4otKc1KLDzHKcHAoSfBqAb0vJFiUmp5akZaZAwwbmLQEB4+SCK8RSJq3uCAxtzgz HSJ1ilGXo+Pm3T9MQix5+XmpUuK81iBFAiBFGaV5cCNgIXyJUVZKmJcR6CghnoLUotzMElT5V 4ziHIxKwryOIFN4MvNK4Da9AjqCCeiI7A1gR5QkIqSkGhjZXCOu/ups2j6NZ//qO7EKD3pijq Vf/Li+tOnC+seRh83jW/4/EeHc3svCXqzgNf32XVUpVduy0uTzS/xO2HL/tjpXK/whpaEj2vR uxeVJi1682pN6d+4nd+Ur2dXuVwN/v7q3YLfbu9PdV9VnPet/fuj16qUustzlh4LS/QW2nhRK DnrEKvBViaU4I9FQi7moOBEA8paB3lwCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-9.tower-21.messagelabs.com!1505820155!83429781!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 10716 invoked from network); 19 Sep 2017 11:22:36 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-9.tower-21.messagelabs.com with SMTP; 19 Sep 2017 11:22:36 -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 564C91435; Tue, 19 Sep 2017 04:22:35 -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 85BEF3F483; Tue, 19 Sep 2017 04:22:33 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 19 Sep 2017 12:22:28 +0100 Message-Id: <20170919112228.22566-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Cc: sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, Julien Grall , jbeulich@suse.com Subject: [Xen-devel] [PATCH v3] xen: grant-table: Simplify get_paged_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_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them The check for shared/paged memory are now gated with the respective ifdef. Potentially, dummy p2m_is_shared/p2m_is_paging could be implemented for Arm. Lastly remove pointless parenthesis in the code modified. Signed-off-by: Julien Grall Reviewed-by: Wei Liu --- 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 Changes in v3: - Add missing put_page in the error path - Remove pointless parenthesis Changes in v2: - Deny grant on foreign page (aligned with the ARM code) - Use #ifdef rather than #if defined - Update commit message - Fix typo in the title 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. This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions? --- xen/common/grant_table.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index c3895e6201..b7deb57b85 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -259,34 +259,34 @@ 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, - (readonly) ? P2M_ALLOC : P2M_UNSHARE); - if ( !(*page) ) + readonly ? P2M_ALLOC : P2M_UNSHARE); + if ( !*page ) { *frame = mfn_x(INVALID_MFN); +#ifdef P2M_SHARED_TYPES if ( p2m_is_shared(p2mt) ) return GNTST_eagain; +#endif +#ifdef 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)) ) + + if ( p2m_is_foreign(p2mt) ) { - *frame = mfn_x(INVALID_MFN); - *page = NULL; - rc = GNTST_bad_page; + put_page(*page); + return GNTST_bad_page; } -#endif + + *frame = page_to_mfn(*page); return rc; }