From patchwork Mon Jun 19 16:57:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9796857 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 B97D4600C5 for ; Mon, 19 Jun 2017 17:00:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FB051FF0B for ; Mon, 19 Jun 2017 17:00:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9496726861; Mon, 19 Jun 2017 17:00: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 40B521FF0B for ; Mon, 19 Jun 2017 17:00:37 +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 1dN00C-0003nK-3b; Mon, 19 Jun 2017 16:58:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dN00B-0003ir-6L for xen-devel@lists.xen.org; Mon, 19 Jun 2017 16:58:11 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id 0B/CB-03058-2A208495; Mon, 19 Jun 2017 16:58:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVysyfVTXcRk0e kwZblchZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aUz2UFi6Qqfq1cxNzAuFGoi5GTQ0hgE6PE oubCLkYuIPs0o8T5LTcYQRJsApoSdz5/YgKxRQSkJa59vgwWZxZwkHjz8R4LiC0s4C5x/Pszd hCbRUBVYtXhhawgNq+AlcS+dxvAeiUE5CV2tV0Ei3MCxb/Pv8YIsdhS4viTW2wTGLkXMDKsYl QvTi0qSy3SNdFLKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZLzs/dxAj0LQMQ7GDsvux/iFG Sg0lJlHfWf/dIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8mxg9IoUEi1LTUyvSMnOAQQaTluDg URLhtQMGmhBvcUFibnFmOkTqFKOilDjvSZA+AZBERmkeXBsssC8xykoJ8zICHSLEU5BalJtZg ir/ilGcg1FJmPcpyBSezLwSuOmvgBYzAS1mPuMCsrgkESEl1cDYI/T/l+CnJ3ZTI95uSuA4nb FN6Xds9e1wPRXBdF3GTW6OoRzP74SsN9q8L+CMaTXnYqWnCUf2fdjBypVztP+Z+93X0y+r8ln az0pec8L4lDTvbivxSVtYFzR1vs1UdFLSdOo/5jAhY/vT+h3iCdHTrV/kCTnbTJluXitl2zG5 74HfxEC7WzxKLMUZiYZazEXFiQADXcyJZwIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1497891490!98132485!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.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56788 invoked from network); 19 Jun 2017 16:58:10 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-8.tower-27.messagelabs.com with SMTP; 19 Jun 2017 16:58:10 -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 C5DDD344; Mon, 19 Jun 2017 09:58:09 -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 2297D3F41F; Mon, 19 Jun 2017 09:58:08 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 19 Jun 2017 17:57:46 +0100 Message-Id: <20170619165753.25049-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170619165753.25049-1-julien.grall@arm.com> References: <20170619165753.25049-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 09/16] xen/arm: create_xen_entries: Use typesafe MFN 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 Add a bit more safety when using create_xen_entries. Also when destroying/modifying mapping, the MFN is currently not used. Rather than passing _mfn(0) use INVALID_MFN to stay consistent with the other usage. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/mm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 5612834dfc..8d34ae7279 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -980,7 +980,7 @@ enum xenmap_operation { static int create_xen_entries(enum xenmap_operation op, unsigned long virt, - unsigned long mfn, + mfn_t mfn, unsigned long nr_mfns, unsigned int ai) { @@ -989,7 +989,7 @@ static int create_xen_entries(enum xenmap_operation op, lpae_t pte; lpae_t *third = NULL; - for(; addr < addr_end; addr += PAGE_SIZE, mfn++) + for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) { if ( !xen_second[second_linear_offset(addr)].pt.valid || !xen_second[second_linear_offset(addr)].pt.table ) @@ -1010,13 +1010,13 @@ static int create_xen_entries(enum xenmap_operation op, case RESERVE: if ( third[third_table_offset(addr)].pt.valid ) { - printk("create_xen_entries: trying to replace an existing mapping addr=%lx mfn=%lx\n", - addr, mfn); + printk("create_xen_entries: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n", + addr, mfn_x(mfn)); return -EINVAL; } if ( op == RESERVE ) break; - pte = mfn_to_xen_entry(_mfn(mfn), ai); + pte = mfn_to_xen_entry(mfn, ai); pte.pt.table = 1; write_pte(&third[third_table_offset(addr)], pte); break; @@ -1061,24 +1061,25 @@ int map_pages_to_xen(unsigned long virt, unsigned long nr_mfns, unsigned int flags) { - return create_xen_entries(INSERT, virt, mfn, nr_mfns, flags); + return create_xen_entries(INSERT, virt, _mfn(mfn), nr_mfns, flags); } int populate_pt_range(unsigned long virt, unsigned long mfn, unsigned long nr_mfns) { - return create_xen_entries(RESERVE, virt, mfn, nr_mfns, 0); + return create_xen_entries(RESERVE, virt, _mfn(mfn), nr_mfns, 0); } int destroy_xen_mappings(unsigned long v, unsigned long e) { - return create_xen_entries(REMOVE, v, 0, (e - v) >> PAGE_SHIFT, 0); + return create_xen_entries(REMOVE, v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); } int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags) { ASSERT((flags & (PTE_NX | PTE_RO)) == flags); - return create_xen_entries(MODIFY, s, 0, (e - s) >> PAGE_SHIFT, flags); + return create_xen_entries(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIFT, + flags); } enum mg { mg_clear, mg_ro, mg_rw, mg_rx };