From patchwork Tue Sep 12 10:03:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 112274 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp5674427edi; Tue, 12 Sep 2017 03:05:43 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDhKVjVy36VYlBdqj921IoLCpOpTZYRiZg9iqOcocZSqVq7kC4Tl7V0dxK8ZLDkX9pAax9v X-Received: by 10.36.29.137 with SMTP id 131mr258442itj.91.1505210743896; Tue, 12 Sep 2017 03:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505210743; cv=none; d=google.com; s=arc-20160816; b=G4X2SavdskdXMQ5AtP8UU4Cc5060R3N6nNLvMP9SbzOPjicOGU4Cj3y18Vju7WX6IR VN2CCfl1/kLoe2Mxq19/XBs/1ZCyPQt7F8v96rsm9RsOBkIR/Fj4IT5vNFwdthDwuhBB Gb0ktOEZCrdPLzZHhnwp0gsd0jgVbkErqXD/1lFB6aI/7Lrt3IFxXP9I6KbU8WUz9w9X t27H2oVmDq/YQitdgZKAES5O+wi++J46Ws97Tz3QC8DC7VOP3jI86oXjWRt5zmcK0E4c 970PVo0KiDMsOElLaSh/eiofpsh9E5tP+tQj7QJevOOI88gqOtJCPWjqkL3PsnpYvGwv Tj/g== 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=/hfzjxyGu1E7IIxZQ6/RNSgK6lznxw9ga2HHCpAJHCA=; b=XfYImS646DO22ElXHv2HIz8vJ/RJLIlDR4VqcK07U2LrTAXUA2m5MTwp0K6dWpZ8bQ PCcqg8JyjTs2S9CNWKORNmmZFh6YlwUxrWnoWEIApG+AtuRmK2wAAuk6pE31NbhigCZ/ ysKg+2e0ISuZEFHse4panSWH+HfY2xsFdjAOnudtKBBEGa0aFtd2gyIBbDd2f8VJh+6l JgHIzbNmstNtThEAb3qKBs8myZfreJnrxzSgEHB7Mtw7EI0ybZH0k6hAW9FoMiLLmyF6 emkwyR7GI9X7c6H9z0LdzPMkE2hjUrS7d7vWDeVmA98uibq97mq0M448h4O6KwCtlm+Y aDlg== 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 p186si11334712ita.207.2017.09.12.03.05.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 03:05:43 -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 1dri2p-0002uq-Vy; Tue, 12 Sep 2017 10:03:51 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dri2p-0002tF-0y for xen-devel@lists.xen.org; Tue, 12 Sep 2017 10:03:51 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id B7/A8-02817-601B7B95; Tue, 12 Sep 2017 10:03:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsVysyfVTZdx4/Z IgxufdS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozOCx9ZC6ZLVFxYfoi1gfG8UBcjF4eQwGZG iVlTfrNCOKcZJfZ23mHrYuTkYBPQlLjz+RMTiC0iIC1x7fNlRhCbWSBS4vCHH+wgtrCAt8St2 YtYQWwWAVWJz/PegtXwClhIbNzwBKxGQkBeYlfbRbAaTgFLiRUff4HNFwKq+f7yB+MERu4FjA yrGNWLU4vKUot0zfWSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQL9ywAEOxiPTXY +xCjJwaQkyntk/fZIIb6k/JTKjMTijPii0pzU4kOMMhwcShK850FygkWp6akVaZk5wECDSUtw 8CiJ8F4DSfMWFyTmFmemQ6ROMepydNy8+4dJiCUvPy9VSpw3A6RIAKQoozQPbgQs6C8xykoJ8 zICHSXEU5BalJtZgir/ilGcg1FJmFduA9AUnsy8ErhNr4COYAI6gufSFpAjShIRUlINjN3llc wm51jf3pbbni23YVfItPMO/fWSTevDzryc4GHxR3VP7rvJQf9zLIKm3HuTbsLkb76ovfRLYNR jiSjVnRqRCx+e2zb74MqSPdlBdzX33Sk4ql+lpK3z1704/KvcthjWUydPlkTWCXhdDPm0UqKm 6IL7xbZS1oS9DPNblnfOWLbyX8o5EyWW4oxEQy3mouJEAE1vcid1AgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1505210625!97099909!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 33284 invoked from network); 12 Sep 2017 10:03:45 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-15.tower-206.messagelabs.com with SMTP; 12 Sep 2017 10:03:45 -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 E35611529; Tue, 12 Sep 2017 03:03:44 -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 010B73F578; Tue, 12 Sep 2017 03:03:43 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Sep 2017 11:03:10 +0100 Message-Id: <20170912100330.2168-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170912100330.2168-1-julien.grall@arm.com> References: <20170912100330.2168-1-julien.grall@arm.com> Cc: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 04/24] 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 965d0573a4..5716ef1123 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 ) {