From patchwork Thu Sep 21 11:16:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 113234 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1890299qgf; Thu, 21 Sep 2017 04:18:22 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBxhTmbWQcZL7tXCmMZ1OO7dVuxHTJrjzkXZhkaeZhwNTmKiI1aw+uL9lm5A9B7CczJR+9/ X-Received: by 10.107.15.95 with SMTP id x92mr2242905ioi.37.1505992702699; Thu, 21 Sep 2017 04:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505992702; cv=none; d=google.com; s=arc-20160816; b=rgTY2xLWAby65WtzecKHmL+tF7M6D++zkzm/+Qwtu8xOO69KfeW4hyh3EDpmUZO6xH ywLvmp4N0w7y19zbvN5opjwAAF3lNy1yzlIIQ6AwsinDiq3tPaO/9kGnX6LU8p35OqA5 VG569A5vxKO171FMhIxTKDr3LEZBGVOMyS3q2ZFf8ReJl7m/wIrAfhQedqM+KxxTCbH2 TVTmLEohu7gsPEdwT+2vafnx90r4IYf3/LPq9pWyFgXVPgw+2Ubq7WnJbuyHDCQmompb CIz+AYaec/Q3rJ7p8CpUPmhicLGHBcTMjlYDZMbZpvxi+oReJnK2R7oSHS49lSzf3ECb ihJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:message-id:date:to:from :arc-authentication-results; bh=nBd8JlCytdZ7XDEwW2HdCu8GBP9Y1NS7bi2Of5kNMRc=; b=OdircO+2GetwaAR67WGge/8iD6pf190Sss8nj8XmCR6IS63eaLqRRpBioYioCg1Kam 2pPUJlj1/1VF7PkQnOJWgYIFqg5/1sGAaxWS4TQcGTVQARiZfNOz37Aa6keXvPHQtBSp zc32KBpvPJ3zBhZnsyGNYbDTeqyhYpRHgZhuJW4Zl2GBSuhi2Tzr92INE2HY8XImCerg 6V41J3hWgnDLkKBzLGe6BJkH3WebX/xx591w5vtW7ezREiHX36/4sLjYYX2cZ0PyUv6u Si5jS2GZE7NMezL/0YwvAth/FrjBnu7YAs7xQuRo6EY/6QPh58nbZnDo24P6whMce1PU soAg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b69si1015634ioa.236.2017.09.21.04.18.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 04:18:22 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duzT1-0001Y2-P9; Thu, 21 Sep 2017 11:16:27 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duzT0-0001Xm-GT for xen-devel@lists.xen.org; Thu, 21 Sep 2017 11:16:26 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 4A/1F-01754-98F93C95; Thu, 21 Sep 2017 11:16:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJLMWRWlGSWpSXmKPExsVysyfVTbdt/uF IgyVL2S2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyFvYEF+2UrHjWcZGlgvCnWxcjJISSwiVFi 0T/1LkYuIPs0o8SGO33MIAk2AU2JO58/MYHYIgLSEtc+X2YEKWIWeM4oMallBitIQljATmLpq SlgNouAqsTiD+/YQWxeAUuJVQ/2gMUlBOQldrVdZJ3AyLmAkWEVo3pxalFZapGusV5SUWZ6Rk luYmaOrqGBqV5uanFxYnpqTmJSsV5yfu4mRqC3GIBgB+Pef06HGCU5mJREeQPcD0cK8SXlp1R mJBZnxBeV5qQWH2KU4eBQkuDt9gXKCRalpqdWpGXmAMMGJi3BwaMkwrsGJM1bXJCYW5yZDpE6 xajL0XHz7h8mIZa8/LxUKXHeWSBFAiBFGaV5cCNgIXyJUVZKmJcR6CghnoLUotzMElT5V4ziH IxKwryFIFN4MvNK4Da9AjqCCeiI7A0HQI4oSURISTUw6iTFGU5JmfBLYOX8ytL1pmdkxSzzZg v+kz3zZUL6laqbivXnspZFbvVIjdxRKbB886ziQoXanttSqvXhzaLSrnKZKfM/qhk01Tu/v71 nbfvvX3d2LGng/7T+umn6bB1hbt83C6/YNERrfNI5nWd0z2Pjnc1m89q+mksU9c9ib5681OTQ lNUrlFiKMxINtZiLihMBEiI9RFwCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1505992581!98589155!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 62876 invoked from network); 21 Sep 2017 11:16:21 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-15.tower-206.messagelabs.com with SMTP; 21 Sep 2017 11:16:21 -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 C7DBC80D; Thu, 21 Sep 2017 04:16:20 -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 05E763F58C; Thu, 21 Sep 2017 04:16:18 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 12:16:13 +0100 Message-Id: <20170921111613.16810-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 v4] 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" 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 v4: - Update variables on error path to match the comment - Add Wei's reviewed-by 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 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index f48eeff7ad..0f09891f59 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -338,34 +338,36 @@ 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; + *frame = mfn_x(INVALID_MFN); *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); + put_page(*page); *page = NULL; - rc = GNTST_bad_page; + + return GNTST_bad_page; } -#endif + + *frame = page_to_mfn(*page); return rc; }