From patchwork Mon Aug 14 14:23:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 110014 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp4281800obb; Mon, 14 Aug 2017 07:26:29 -0700 (PDT) X-Received: by 10.107.55.198 with SMTP id e189mr22541398ioa.34.1502720789391; Mon, 14 Aug 2017 07:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502720789; cv=none; d=google.com; s=arc-20160816; b=yiAhdeS4d5u1Cqef6a1vsZAvXOBcoNl8AeEIgBVMB0AA82NRGLA/dYzXLSgWUvDYLu k7PztqDUStwvBBYwXjGdgzhHCWDGZ59W8q1T2loOp9tSlmtFHKJOtbGR6aVBNdp3LMkS NbwYKi+TowN4p4riY1rq6BG4q0N4IrSrh4AWOLcN+t6VVRbpTB/A45HQiluoLN4Gareu cd46kE6FtedYtM2LccTkGfHKBmKv1dfYvE9Q3so+AaVuMg31wRcCQK8j0iAyarW38l53 P0IPqoX+lzp+3EA2rHskkGXne7tjjOhanlI15GQ8IdDzq+rP1WYbEMp5fk5tVXXmnmpD nwEg== 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:references:in-reply-to:message-id:date:to :from:arc-authentication-results; bh=vf2ziABXSBzmwBm84TseW46GLyFOKN5BnMzsNR79UwY=; b=KFShX1HiR9VYINRTGp2RqHhW/cm26R5bkVglSHuVxVm2sk1TmSnvHRQo5hcMzHanmF d+4BsBixQ6QrLGhhhtTDltBulrv7j+gsZiZhvj+ehKLQTI7E1A051GFE3CNXQAXvvgwE Ocq7XQkxlg7LnuLgV7NXfni5teltQx5KA7noMwwbItGjdcK8mYluB6+gWInGj4UvAKpP yGVpejQG98P147OikauUq2gEWKnLVnN08odTc0cycVzdoy6jCqdfh+6At55DvEnkd/fF up+nO7AVTjiyu3gmLPOpLctDjma5dhNpLweV5kyfcEl6IZCOQ5JKjI3GEy8+Iczq1mPA I1HQ== 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 w8si7405797iow.24.2017.08.14.07.26.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 07:26:29 -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 1dhGIP-0000L6-1D; Mon, 14 Aug 2017 14:24:45 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhGIN-0000Fh-PC for xen-devel@lists.xen.org; Mon, 14 Aug 2017 14:24:43 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id BB/8E-03937-BA2B1995; Mon, 14 Aug 2017 14:24:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMLMWRWlGSWpSXmKPExsVysyfVTXfVpom RBlsmWlgs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBkLHp1nLJguUXHn6HPGBsbzQl2MXBxCApsZ Ja7uuMMK4ZxmlFgx+QJzFyMnB5uApsSdz5+YQGwRAWmJa58vM4LYzAKREoc//GAHsYUFPCTuH r4NZrMIqEp8vnwNrJdXwFLiy+y7YHEJAXmJXW0XWUFsTgEric67O1lAbCGgmhOrZ7NNYORewM iwilGjOLWoLLVI18hML6koMz2jJDcxM0fX0MBMLze1uDgxPTUnMalYLzk/dxMj0MMMQLCD8cy CwEOMkhxMSqK8CT69kUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeFM3TowUEixKTU+tSMvMAYYa TFqCg0dJhPcGSJq3uCAxtzgzHSJ1ilGX49WE/9+YhFjy8vNSpcR5y0GKBECKMkrz4EbAwv4So 6yUMC8j0FFCPAWpRbmZJajyrxjFORiVhHk3g0zhycwrgdv0CugIJqAj+kDu5y0uSURISTUwzj Y5pKei9uibtp2xi8WXicpr6o+ejNQ4faOKPzlZXv7H92kf5B/q7Lm08vRx78bix0uPe+4wdTF 4OCvUpEPIXEf3lhcbq86Og6ne11ac/Lyysrt6RfrluQ2P5lrvTOV1MvkYJZR3wlxTReqvRu6b uvLpVyMn36mKKNl+zPzs1Rk3v3Es2so8W4mlOCPRUIu5qDgRAEuQArN2AgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1502720682!111835689!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 57328 invoked from network); 14 Aug 2017 14:24:42 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-9.tower-27.messagelabs.com with SMTP; 14 Aug 2017 14:24:42 -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 360C61713; Mon, 14 Aug 2017 07:24:42 -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 4A6B33F483; Mon, 14 Aug 2017 07:24:41 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 14 Aug 2017 15:23:58 +0100 Message-Id: <20170814142418.13267-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170814142418.13267-1-julien.grall@arm.com> References: <20170814142418.13267-1-julien.grall@arm.com> Cc: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH 07/27] xen/arm: mm: Redefine mfn_to_virt to use typesafe 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" This add a bit more safety in the memory subsystem code. Signed-off-by: Julien Grall --- xen/arch/arm/mm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b3def63ed7..349ac58ffe 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -47,6 +47,8 @@ struct domain *dom_xen, *dom_io, *dom_cow; /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) +#undef mfn_to_virt +#define mfn_to_virt(mfn) __mfn_to_virt(mfn_x(mfn)) /* Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching @@ -837,7 +839,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, * Virtual address aligned to previous 1GB to match physical * address alignment done above. */ - vaddr = (vaddr_t)mfn_to_virt(base_mfn) & FIRST_MASK; + vaddr = (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK; while ( mfn < end_mfn ) { @@ -849,7 +851,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, /* mfn_to_virt is not valid on the 1st 1st mfn, since it * is not within the xenheap. */ first = slot == xenheap_first_first_slot ? - xenheap_first_first : mfn_to_virt(p->pt.base); + xenheap_first_first : __mfn_to_virt(p->pt.base); } else if ( xenheap_first_first_slot == -1) { @@ -866,11 +868,11 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, { mfn_t first_mfn = alloc_boot_pages(1, 1); - clear_page(mfn_to_virt(mfn_x(first_mfn))); + clear_page(mfn_to_virt(first_mfn)); pte = mfn_to_xen_entry(first_mfn, WRITEALLOC); pte.pt.table = 1; write_pte(p, pte); - first = mfn_to_virt(mfn_x(first_mfn)); + first = mfn_to_virt(first_mfn); } pte = mfn_to_xen_entry(_mfn(mfn), WRITEALLOC); @@ -909,10 +911,10 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) /* Compute the number of second level pages. */ nr_second = ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT; second_base = alloc_boot_pages(nr_second, 1); - second = mfn_to_virt(mfn_x(second_base)); + second = mfn_to_virt(second_base); for ( i = 0; i < nr_second; i++ ) { - clear_page(mfn_to_virt(mfn_x(mfn_add(second_base, i)))); + clear_page(mfn_to_virt(mfn_add(second_base, i))); pte = mfn_to_xen_entry(mfn_add(second_base, i), WRITEALLOC); pte.pt.table = 1; write_pte(&xen_first[first_table_offset(FRAMETABLE_VIRT_START)+i], pte); @@ -1005,7 +1007,7 @@ static int create_xen_entries(enum xenmap_operation op, BUG_ON(!lpae_valid(*entry)); - third = mfn_to_virt(entry->pt.base); + third = __mfn_to_virt(entry->pt.base); entry = &third[third_table_offset(addr)]; switch ( op ) {