From patchwork Wed Sep 12 10:26:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 146547 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4647131ljw; Wed, 12 Sep 2018 03:26:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbY7BTOYVlFkW6EGEolA9b6KQ+J+3DCVN64kh3jWdpTIrUN6ciMxdGIWoGlX+gfa5w+Iq2n X-Received: by 2002:a17:902:8e81:: with SMTP id bg1-v6mr1416703plb.129.1536747979838; Wed, 12 Sep 2018 03:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536747979; cv=none; d=google.com; s=arc-20160816; b=kVlThctpnaOEdWTwzBbeN5o1d8WUAuVIH0tgHSrijReM5cGIcAkSmN6SkUUHd5iPUI 0zsYlkAKaM51M87Gs/7xTb6d+IDEq6FBWm36dMg7TG88kzvkce/L3CcfiWqZ32yGbjuG 28snw5dbmupdEjbfUwoXxsGHKTIVjm2TD+c7RLf8xsHaEhhk/2NxsDm7/WWhuyDYL2yA YZzFCZpzIJywtH9GjsV8BOTTutx0WOlx9enTakl27PfpdefdZgP2KZFNgNuZdYHMs+HZ nEyBbMB7HqrWamcFL2Fhye36uPIO7eFuurrmhLaSBNup8IVj9CNn82aeRSuAQp9ovMe+ 0g8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=9KAgIv8nfsqMOg72uzaVHfLrGe37Gw1OAqB4rZKj4mk=; b=EYA3JuMskTvCAMnUsMJjYCvh+AtHKFGGJVA5w/2v8efAmb7DHzDieDpp02cyyorvag Wqv5/0Q4ROYqOzUhrASxI+snFrHiKVMjMkwFWurIAJL2565/VsqSx89ub5chGf58Jnvx Q2ZiWuidUUpNlaIvQV++o0wG1qFQtODY/3nxO6LEO7Zz+jKApmmBQ1PAPglrRhwzsbL4 216LcVhwDdCjZDqL+17W9iH/Ss4sTyIeQ6CiP7G1MUBy5RXP3sCz+P41DBRv+cmNVGY5 Qx7CCsOIXey56nHOnVzPTWjVjwWCN6VQ+bsiM5SUKwCFEbJBNIrk9K1owx7ow5/mYEz8 2xmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12-v6si669661pgh.264.2018.09.12.03.26.19; Wed, 12 Sep 2018 03:26:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbeILP3z (ORCPT + 32 others); Wed, 12 Sep 2018 11:29:55 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:56964 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbeILP3z (ORCPT ); Wed, 12 Sep 2018 11:29:55 -0400 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 E54361596; Wed, 12 Sep 2018 03:26:01 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B73E03F71F; Wed, 12 Sep 2018 03:26:01 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 841A41AE3018; Wed, 12 Sep 2018 11:26:18 +0100 (BST) From: Will Deacon To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: cpandya@codeaurora.org, toshi.kani@hpe.com, tglx@linutronix.de, mhocko@suse.com, akpm@linux-foundation.org, Will Deacon Subject: [PATCH 1/5] ioremap: Rework pXd_free_pYd_page() API Date: Wed, 12 Sep 2018 11:26:10 +0100 Message-Id: <1536747974-25875-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1536747974-25875-1-git-send-email-will.deacon@arm.com> References: <1536747974-25875-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The recently merged API for ensuring break-before-make on page-table entries when installing huge mappings in the vmalloc/ioremap region is fairly counter-intuitive, resulting in the arch freeing functions (e.g. pmd_free_pte_page()) being called even on entries that aren't present. This resulted in a minor bug in the arm64 implementation, giving rise to spurious VM_WARN messages. This patch moves the pXd_present() checks out into the core code, refactoring the callsites at the same time so that we avoid the complex conjunctions when determining whether or not we can put down a huge mapping. Cc: Chintan Pandya Cc: Toshi Kani Cc: Thomas Gleixner Cc: Michal Hocko Cc: Andrew Morton Suggested-by: Linus Torvalds Signed-off-by: Will Deacon --- lib/ioremap.c | 56 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) -- 2.1.4 Reviewed-by: Toshi Kani Reviewed-by: Toshi Kani diff --git a/lib/ioremap.c b/lib/ioremap.c index 517f5853ffed..6c72764af19c 100644 --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -76,6 +76,25 @@ static int ioremap_pte_range(pmd_t *pmd, unsigned long addr, return 0; } +static int ioremap_try_huge_pmd(pmd_t *pmd, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, + pgprot_t prot) +{ + if (!ioremap_pmd_enabled()) + return 0; + + if ((end - addr) != PMD_SIZE) + return 0; + + if (!IS_ALIGNED(phys_addr, PMD_SIZE)) + return 0; + + if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)) + return 0; + + return pmd_set_huge(pmd, phys_addr, prot); +} + static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { @@ -89,13 +108,8 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, do { next = pmd_addr_end(addr, end); - if (ioremap_pmd_enabled() && - ((next - addr) == PMD_SIZE) && - IS_ALIGNED(phys_addr + addr, PMD_SIZE) && - pmd_free_pte_page(pmd, addr)) { - if (pmd_set_huge(pmd, phys_addr + addr, prot)) - continue; - } + if (ioremap_try_huge_pmd(pmd, addr, next, phys_addr + addr, prot)) + continue; if (ioremap_pte_range(pmd, addr, next, phys_addr + addr, prot)) return -ENOMEM; @@ -103,6 +117,25 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, return 0; } +static int ioremap_try_huge_pud(pud_t *pud, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, + pgprot_t prot) +{ + if (!ioremap_pud_enabled()) + return 0; + + if ((end - addr) != PUD_SIZE) + return 0; + + if (!IS_ALIGNED(phys_addr, PUD_SIZE)) + return 0; + + if (pud_present(*pud) && !pud_free_pmd_page(pud, addr)) + return 0; + + return pud_set_huge(pud, phys_addr, prot); +} + static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { @@ -116,13 +149,8 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, do { next = pud_addr_end(addr, end); - if (ioremap_pud_enabled() && - ((next - addr) == PUD_SIZE) && - IS_ALIGNED(phys_addr + addr, PUD_SIZE) && - pud_free_pmd_page(pud, addr)) { - if (pud_set_huge(pud, phys_addr + addr, prot)) - continue; - } + if (ioremap_try_huge_pud(pud, addr, next, phys_addr + addr, prot)) + continue; if (ioremap_pmd_range(pud, addr, next, phys_addr + addr, prot)) return -ENOMEM;