From patchwork Mon Sep 18 16:27:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 112935 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3858178qgf; Mon, 18 Sep 2017 09:30:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBorLQ7fJcHElAP4Unf/L10yNMBq8HRcrmDzZGgesPghVLgb9MQr8dn/9hT+duP5Rz+v2Gu X-Received: by 10.107.149.143 with SMTP id x137mr22298921iod.266.1505752205272; Mon, 18 Sep 2017 09:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505752205; cv=none; d=google.com; s=arc-20160816; b=wcdGV2oG9d24lLSM1vp3EJfYW8IZz5Gca8zRVDsjrXYLvnHUAZ5Ubynwj+N+D0PiW7 VdfWQVa7fgTY6BdOspQtJwH7rNCcHbZi7iERqN0JSo0w6VLnpKSU8fzV+mwcbsqAS6Yd pMb15I8bvcb43aI8MPARHEvCspd45DkGMBfTbsXEHc8L2GFsoJnsGBaHMRN7GY1z7X8p //uK+pGf2q7XBkjNcrY3YfAdLlmbK3crCcTjHfe32eZBHeZ0d+zUTrQQyFxVwqPhNRe6 ZVowFb2HjJ/ICaYpaedw+3PRhQ6D4IkVmduUJLSta4w/L2WiSbIl/6kGWQkEUc/H4yXh OYmg== 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=DVDbYjDAuSyfgXaKVpA8yDAXrUl8cTgq4QFzDKNTQlE=; b=ZB7jqkvHqz3BxHBI//MVNz/4bHXXn1j5ZIRqPveHdPWUKrdNC7J2tQdnMiO6SyEgwT 0EyH5S6VOHQL9iCgSYnkBDnr7Sv7ubHcoHPcoZLUk2EfX3js4rC1TPvS2+Uiz/Dq+Cc+ ZqG7q72EwfwQ6HJG9scUipKMuFIY3k4ZDUdrf3g91OzBEl100F9mb0S0QE2nZv3r7qcR SyD4UxUgzTOBJj7DqrE14xpIIiMyS/Hczo05icEcOe0mcu6WfgnGlAFTDyvOanxgiLJe 6w3/Li/9DaMzftF6z04kNopYnIpjJOf02KLtR1uAukGiRG4Kjx+ScyExECSu7rp8/H6W /fDw== 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 g11si6209417ioc.10.2017.09.18.09.30.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Sep 2017 09:30:05 -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 1dtytv-0004V4-Py; Mon, 18 Sep 2017 16:28:03 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dtytu-0004Ux-0R for xen-devel@lists.xen.org; Mon, 18 Sep 2017 16:28:02 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id A3/DA-02202-114FFB95; Mon, 18 Sep 2017 16:28:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRWlGSWpSXmKPExsVysyfVTVfgy/5 Ig0ePtCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oxDCw4yF5yTrFh/6R5LA+NMkS5GLg4hgc2M Ege3HGGDcE4zSlyY+5e9i5GTg01AU+LO509MILaIgLTEtc+XGUGKmAWeM0pMapnB2sXIwSEsY CdxaE8cSA2LgKrEhn33WEBsXgFLieO7m1hBbAkBeYldbRdZJzByLmBkWMWoXpxaVJZapGuol1 SUmZ5RkpuYmaNraGCql5taXJyYnpqTmFSsl5yfu4kR6K96BgbGHYxNvc6HGCU5mJREeUUj90c K8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuC9+QkoJ1iUmp5akZaZAwwcmLQEB4+SCK/4Z6A0b3FB Ym5xZjpE6hSjLkfHzbt/mIRY8vLzUqXEeV+DzBAAKcoozYMbAQviS4yyUsK8jAwMDEI8BalFu ZklqPKvGMU5GJWEeW+BTOHJzCuB2/QK6AgmoCNaduwBOaIkESEl1cBolpEufK34V0bbPsGTv1 9XXXLPWPo7TfuQ5HslYS///xKa0yw2b/qwa/f1mMpF71MO5svV+3slpM2p2b1m991/JW8kZ50 5P3cOU4+L9u6sUyt4Yt8V8OhdX8VfaD5jyk6/tysN3WRzBSce3bbk7eY5l3ZcStWpWX3UUCNM TqCTy8Hu+jZDu+S1SizFGYmGWsxFxYkAhAJKO10CAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1505752080!109221870!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 7319 invoked from network); 18 Sep 2017 16:28:00 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-7.tower-206.messagelabs.com with SMTP; 18 Sep 2017 16:28:00 -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 657021435; Mon, 18 Sep 2017 09:27:59 -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 94D4F3F53D; Mon, 18 Sep 2017 09:27:57 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 18 Sep 2017 17:27:52 +0100 Message-Id: <20170918162752.14091-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 v2] 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. 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 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 | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index c3895e6201..a6a168df6e 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,24 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame, 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; } + + if ( p2m_is_foreign(p2mt) ) + 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; }