From patchwork Tue Oct 2 11:05:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10623357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E80C1515 for ; Tue, 2 Oct 2018 11:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 451C52881A for ; Tue, 2 Oct 2018 11:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37BF128829; Tue, 2 Oct 2018 11:05:49 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A02412881A for ; Tue, 2 Oct 2018 11:05:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B089D6B026F; Tue, 2 Oct 2018 07:05:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A65586B026A; Tue, 2 Oct 2018 07:05:42 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 865116B0270; Tue, 2 Oct 2018 07:05:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id 552626B026D for ; Tue, 2 Oct 2018 07:05:42 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id s68so1055504ota.11 for ; Tue, 02 Oct 2018 04:05:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Ka6oXZu8DJRXSCZkb2TermywvttDv1cohIKM9nr4o2s=; b=pqa1AVM9hY8QQ429BqlLuhlGUMDcXgE4IBRw6D6m+BJEpaWBZyYqc73meoX2onYWQx aoMSZ7Bvm9P2ZnG+jO7KwXDcj+3LuzKu40Dm4tz7zA58sXBKGr/dbAyLOmdVmRe8FKkm 1FDE6FhORsgn0fHACwj+79w4TBmdVglRHnTY7raZbs2DqaojYgqOSBy7aCmPHcrG4K/q WYIffFcc0GxHr/SKnS8JP8ZdoOAOHvFjXGTYgx3k8IUW+OdJBPjTlqRFATZ/Xx2KFHIB RYhj6m6wWoNbK2eiPndv/FfySD+3fPaC/eVGAI0DruzFDD0GhNqsNPm/tseBVk4GhpDR kmoQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of will.deacon@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=will.deacon@arm.com X-Gm-Message-State: ABuFfojAXSG3mEePoWZFnOnKk8FGvqukbgimWIbPk/nei7Ela2s73meS nwFJ+2S+peih1ke1nUuWsikff8GKpxZJTjnqZZxz5opGruQ6/AUqrt0mi6gTpjRreUttNimeEQ4 SmUQQc+cfiuJPTNntmZesWbBksVXCJNVxw4I9A+m3tLD6T5z4dmJFMk24IYRWQMahHA== X-Received: by 2002:aca:690c:: with SMTP id e12-v6mr7593995oic.323.1538478342048; Tue, 02 Oct 2018 04:05:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ERkVO8gCq2GwHIRxUEHHvfMx4Pyr2DeCjA8iQLA7Z58bukyWnJIZHYjoLmKZNSto7Cj67 X-Received: by 2002:aca:690c:: with SMTP id e12-v6mr7593962oic.323.1538478341109; Tue, 02 Oct 2018 04:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538478341; cv=none; d=google.com; s=arc-20160816; b=inigW7348U54yOeiIxmWtae9ppOaUzxnnjoViVg6q7ychtgxAkKYyt8VtNa4I9PFMG abtKBThJZMbe2fRkx1YeBHU5FCLRolhvCE+Lf6rSOJUZaojjWuyoVbHtdJPdjud0JIpR cBHMV0lqysKwOMSw0uoRpqblWlQNDbDSizA4vUduTwtv0821xcAC7es3OVsCHO8rv9OI 6G5WmDrbCbKrILE8OPq5V/6/xwQwLK5Hn2UDlCri7X0GBdZzGleKFb3e4q8hvLw2uGKe sD0d1cyKP3vAd5OPNlOXmE3CqXjLMT2IXVdGoXz+a4T/P+eut2z3dE7ne5+3BnRyh0tY ofcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ka6oXZu8DJRXSCZkb2TermywvttDv1cohIKM9nr4o2s=; b=hSGr7jNawNqdC33k/ieQzelCEIVW4YI4Fpt5tXhzt4iC6iVjMAaXfTvoU7ByWZVu/4 w/KeMau2YjEopr9awukS5BEC0D1ONwjtOwyLoQmuiBf8EN1WIJ5xOKBwzfjBConWGMMu 75o7L8WVR3U75WEP63FfAGVt4UP8yoX9COBHY6q/DnEgu9cYysejv1dP+RV8VdlD2c/T n0HHpngbH7zi3rz7GhidLA8fdAWc0c16Mc5UB+/PbOJTCQFzwARPfoDuffdXSG6fsd4f zhfj2NCEMcKpO6SYiq4RAuUKh1KzHBmZtyxcpByL3BC8eQvjE5NT4IWoLycsks3ZNA+c 5b5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of will.deacon@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=will.deacon@arm.com Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id v3-v6si7354156oiv.195.2018.10.02.04.05.40 for ; Tue, 02 Oct 2018 04:05:41 -0700 (PDT) Received-SPF: pass (google.com: domain of will.deacon@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of will.deacon@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=will.deacon@arm.com 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 890CD15B2; Tue, 2 Oct 2018 04:05:40 -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 59E8E3F774; Tue, 2 Oct 2018 04:05:40 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 4AEB81AE3D81; Tue, 2 Oct 2018 12:06:04 +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, sean.j.christopherson@intel.com, Will Deacon Subject: [PATCH v2 1/5] ioremap: Rework pXd_free_pYd_page() API Date: Tue, 2 Oct 2018 12:05:59 +0100 Message-Id: <1538478363-16255-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1538478363-16255-1-git-send-email-will.deacon@arm.com> References: <1538478363-16255-1-git-send-email-will.deacon@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Toshi Kani Signed-off-by: Will Deacon --- lib/ioremap.c | 56 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) 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;