From patchwork Mon Nov 26 17:07:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10698787 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 D86C313AD for ; Mon, 26 Nov 2018 17:07:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2431286B6 for ; Mon, 26 Nov 2018 17:07:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3BCE2896F; Mon, 26 Nov 2018 17:07:34 +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 29287286B6 for ; Mon, 26 Nov 2018 17:07:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AC7D6B42C9; Mon, 26 Nov 2018 12:07:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 15A3D6B42CA; Mon, 26 Nov 2018 12:07:33 -0500 (EST) 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 F175E6B42CB; Mon, 26 Nov 2018 12:07:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id C37BA6B42C9 for ; Mon, 26 Nov 2018 12:07:32 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id t13so6694613otk.4 for ; Mon, 26 Nov 2018 09:07:32 -0800 (PST) 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=UwvA2fDusmuOLgmwSK2WqVT36zVRPOKyyfzBpXo94V9AwfIai+bsc010d65WjZba1h egWiMfCBKLYX5hCXI0mYZ5pCxtoPBhaW2PRvpFE9iI4DJZCUNWkuBKcqnuJRfSFYth/T X07UoSwa6nc2gxrgqrvMCf8BNZiPk50b+OWcszso947/ChknLDWEdQ+aXQRd3JCCheAv DSUOqfE92UBMPNZTxVUjBktQOPJjEfT5xfgtrzY42SPDZJuMklcF27rXsYgKwvCTTCcu EgYGgYl/ONB/BSRsrni2WMtrMZKxJI1ZONtRuy5mJrmrFUEZYtZScu/TUXGOVY883qu3 3GgQ== 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: AGRZ1gLqXkTaMsd0IY7mE+mM4hcrzwgJaZcjPMy5FdqNign2cwOVdk8s RBszdhQ/oDtiNLKonegB8+yUmVHvbAz2/SR8G3kp7fJ3rPgf67TttzflnIkPjif5CIh7qfeqZ94 J9Owe3Www1JuRw6os0ptBC4CXb+0/tjoxPv2nKoiGq2sbV26T7yPdhDcW+JIegzo/HA== X-Received: by 2002:aca:6a02:: with SMTP id f2mr16624825oic.260.1543252052487; Mon, 26 Nov 2018 09:07:32 -0800 (PST) X-Google-Smtp-Source: AJdET5e77e1pBAhRSXm91adOJtXnZ80XE2pBnCMXVMfh2QFm5dyPNWmk/FxZiV6gSqaavh317jgb X-Received: by 2002:aca:6a02:: with SMTP id f2mr16624779oic.260.1543252051607; Mon, 26 Nov 2018 09:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543252051; cv=none; d=google.com; s=arc-20160816; b=MYr4+K1GnOXI3Uv6hYcpUBZtwL6szGNjW1wqEJLbolbtWoh8h5QOmjHjdsdx+/TH/f Lu49IK8CdoMb88iqsPe7GO0tcsuAbGHQlrIBnuRvSCsR6MWTiefsDY6D0HP5xQXm4E1a urYiZwNqyJ/7YV4SD+NNhevzEh0qqxZfVlFFJ7ctBxNumxP0dFrdr4Jh4xEYhpVNB7U3 hZ6F6BbNyNjiBvLXTXGfR623uhk+WU6TS8kalRdSFzBp8N71Vp3DP3fROuO2aUZcLwkT P5Jt6oWdLNOeI2AhZwwoB+bK6HUnFqnhWezNeM9NxbEPjvXvCnD12YKizbAShTO0OFY0 p3nA== 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=SDsHhL7xSIGkWDPvOGwyYFKgSq/g2ehUpeqD5+apbh3n752QJP+joaUSi2r+83fzW8 Zh3LU1IZZrHCQRRir8KTql4gdKYZkcgpAbvRbBqOf+Q5stOoA0VJvFa/Kqz01ck1FrqW Z6sT9+rHJfqYAd0rjD7zUN876CB+LttBByMSNeR+gqHPOrkIkDtfcR4mXc/o5QO7xHRk SIqwvY+ncC+v1yQNzKIbOAWo0ehUQJUNOr1eodiMls1D1eRPRcLaM3PiwGlIV2GmAnk1 X7JqODWwzVoRCiNTU503DA3ZAfDNfH3BHEieNKAUms8QEevr+d6bDCRqV3c9V+RLlqUd H5+g== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id 4si345997ote.30.2018.11.26.09.07.31 for ; Mon, 26 Nov 2018 09:07:31 -0800 (PST) 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 CA76115AD; Mon, 26 Nov 2018 09:07:30 -0800 (PST) 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 9A9353F71D; Mon, 26 Nov 2018 09:07:30 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 178121AE0776; Mon, 26 Nov 2018 17:07:48 +0000 (GMT) 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 v4 1/5] ioremap: Rework pXd_free_pYd_page() API Date: Mon, 26 Nov 2018 17:07:43 +0000 Message-Id: <1543252067-30831-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1543252067-30831-1-git-send-email-will.deacon@arm.com> References: <1543252067-30831-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; From patchwork Mon Nov 26 17:07:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10698795 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 6F79313AD for ; Mon, 26 Nov 2018 17:07:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56B262896F for ; Mon, 26 Nov 2018 17:07:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48141286D0; Mon, 26 Nov 2018 17:07:47 +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 C75FE286D0 for ; Mon, 26 Nov 2018 17:07:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBD576B42CE; Mon, 26 Nov 2018 12:07:36 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B6D106B42D0; Mon, 26 Nov 2018 12:07:36 -0500 (EST) 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 A38326B42D1; Mon, 26 Nov 2018 12:07:36 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 7ED656B42CE for ; Mon, 26 Nov 2018 12:07:36 -0500 (EST) Received: by mail-ot1-f69.google.com with SMTP id a89so8649479otc.8 for ; Mon, 26 Nov 2018 09:07:36 -0800 (PST) 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=/V6Ii5Ay/gyCu4FDeRHUvTmr/uoACgypNN/miYDcTTU=; b=NfQmXNXxTZwa6EXrUrNlAROUzs0v6H3e62NfrfaBKG2QsJG9bhoUBU/JeKuyZ0qJrj 1oE6EudMQsniWQh12K5A44XmUfGPmhQjg/cp9+4c4ExFUaCBsuS3mzilSnX0RhLlKebC pqd/6KzACcUqQovCYbeoJxEu/8c++ICq+IxgwjD15bgd5kRgiqLqaOzbSvw/bsaSgZQ5 W5g5mNogMiadym78l1dPGxzPY0SUrVjyJQUQt/6gHIE0VLfTAkjAUPWvWjKpik8CbTWD BG8AaC4RdH7Shoh6v/vOUg9PmIuLiB1neCXqx0rt/5AAuiF9HUvLkZWDixAQhUkslGwJ D7LA== 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: AA+aEWZxQCHOPOk3uS5XHUcR7UBg5NpNwhZrKk9oxSvLgntLmyrT/at2 eQySWNphrBkflK5zUts/YJ8pG+bicyQczkFNvNyxBFbM28vpgjLJ/V6bDKqxzzNxLJCHWiy5/RQ tnd99MfaRFw1QiA0u0sl91pmT4y+sfIeO3VK8ukK4YZqlBvth2Hm6zpjApglNcl8nhw== X-Received: by 2002:a9d:220c:: with SMTP id o12mr10966797ota.19.1543252056270; Mon, 26 Nov 2018 09:07:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/XXLLCni9ZAUc8u3FG80Hf8u8k1zFxXB6i9LEZXH/pmaWXNDQy9orAYlKDdBT/yqQqL0D/U X-Received: by 2002:a9d:220c:: with SMTP id o12mr10966616ota.19.1543252051904; Mon, 26 Nov 2018 09:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543252051; cv=none; d=google.com; s=arc-20160816; b=Gzfm++q24p2bjl+j4S9eNxbOU7zaW6ncJIQ8fS9m92cjn92tX9qmmIQ8VTVCZ44RHc iuFlEUjgq0wLlkoU9ZyMlVMFB5jHwNbR0/z6vs8NKBzO7B/cbWoAY0zJAW/bEeAeSYo2 ZYmrgAICjKIpnQ6h6qOnyk/ZYYk7Mkw02sJP6ZdwSP2WFB3uoYCNumRplgqtIVH9rhxJ KS6QpsDMebIuq0IVtr4oVw6VJZePm6unTkrs4XCMUrkSXqHQsfwU8f++CU0D99yMjYM8 THiIQF/s4V2B95WDdLdFxtGWNedRIo8pOy9bAUkk95UwSPe8Y//MumJldT4birJIlcgR x7Rg== 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=/V6Ii5Ay/gyCu4FDeRHUvTmr/uoACgypNN/miYDcTTU=; b=Exc3SStcr70cSsQIZlpR5Ob+QbXtaX1t04CRlxvdEkNlair6zSEKPkZHc/Jsuoh5/t 9kTZTppgB4gyF/CyFN6TIz53mWH2BNEm39CCPky9lpBl0C82UJjXPU2KBeejsxsRtaTO 5qea0uBDT0rA2JSRB64D3qg5uqygVYxljyup+UzhXhCiAEVXB3n+UX8Dsc0Q0jHE2src 93mv2hAcsDTPf2lCih1TiNgP2rfcQFmYpbq5HwzDcDvjkl1EKQkOyDv2ET2OoWK24kNq mXK6YLrV4Dp8F3Ij44tRuVATM42imGCIzMd4O2OCCYNNmnQ41p5LqMlnfLiO7819DiKm /KCw== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id 203si374148oid.154.2018.11.26.09.07.31 for ; Mon, 26 Nov 2018 09:07:31 -0800 (PST) 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 D839E168F; Mon, 26 Nov 2018 09:07:30 -0800 (PST) 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 A8CC93F906; Mon, 26 Nov 2018 09:07:30 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 271771AE088D; Mon, 26 Nov 2018 17:07:48 +0000 (GMT) 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 v4 2/5] arm64: mmu: Drop pXd_present() checks from pXd_free_pYd_table() Date: Mon, 26 Nov 2018 17:07:44 +0000 Message-Id: <1543252067-30831-3-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1543252067-30831-1-git-send-email-will.deacon@arm.com> References: <1543252067-30831-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 core code already has a check for pXd_none(), so remove it from the architecture implementation. Cc: Chintan Pandya Cc: Toshi Kani Cc: Thomas Gleixner Cc: Michal Hocko Cc: Andrew Morton Signed-off-by: Will Deacon --- arch/arm64/mm/mmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index d1d6601b385d..786cfa6355be 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -989,10 +989,8 @@ int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr) pmd = READ_ONCE(*pmdp); - if (!pmd_present(pmd)) - return 1; if (!pmd_table(pmd)) { - VM_WARN_ON(!pmd_table(pmd)); + VM_WARN_ON(1); return 1; } @@ -1012,10 +1010,8 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr) pud = READ_ONCE(*pudp); - if (!pud_present(pud)) - return 1; if (!pud_table(pud)) { - VM_WARN_ON(!pud_table(pud)); + VM_WARN_ON(1); return 1; } From patchwork Mon Nov 26 17:07:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10698789 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 439DC13BB for ; Mon, 26 Nov 2018 17:07:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CB60286B6 for ; Mon, 26 Nov 2018 17:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20D552896F; Mon, 26 Nov 2018 17:07:38 +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 A68CB286B6 for ; Mon, 26 Nov 2018 17:07:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 617486B42CB; Mon, 26 Nov 2018 12:07:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C5F76B42CA; Mon, 26 Nov 2018 12:07:33 -0500 (EST) 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 48D2E6B42CD; Mon, 26 Nov 2018 12:07:33 -0500 (EST) 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 22E1D6B42CC for ; Mon, 26 Nov 2018 12:07:33 -0500 (EST) Received: by mail-ot1-f72.google.com with SMTP id 32so8793776ots.15 for ; Mon, 26 Nov 2018 09:07:33 -0800 (PST) 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=S3Pe7jCrFGE7JxF6m5RucqgSGzB7M8lCaWDcweULJ1Y=; b=p5gPveQPzf7zUbggtuKfhGhbGMZG5H1tWLS5eRb1WWlBcGVOEgFBUbixYR81Vu9W0y OSyGP4ZCayBZu+CL3mfYFmJBPnVeaCFJKCgOC249m5t88mO1APa6KmG9NvifUQL2Sz3S esu9dmpmeJimGS+zpM7ebUYAmS3o5nlTy4Q56Ivi/2rF+kEjRK9qiDW9clh20GznfW95 sgkowYYuX3TfcP8MEtiMHIRsK4p6jnMeTG3NwxBNALIEHpptjBTxH3bxVW07u0M1EA1G NYCNk//UuexObuzvR6E8hngejxWxt9rve8DfCRXJdDbkRr4s0H1qkGbphPZwbR/75n6T E9Iw== 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: AA+aEWaA4eba1aSzVKdM9e4iVU3pOqtWIqAy5Mn8DNtNyC1GtF61zG5N Ye3Lpxvzmj6ncT9op9hTroWwJ5yPIrZaq2USeA6AkpziSo3tW6bHhHqcLYu+MoOTk44yJ/sn6bH nf0eWk3qq7lDsc5ImPI1qxlykysmqxm2W52SAipxwWjUBjuPyZhyBzSHBB9NCoG2rdw== X-Received: by 2002:aca:36d5:: with SMTP id d204mr8557104oia.234.1543252052885; Mon, 26 Nov 2018 09:07:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/XTWawqORx+TDr+lO5BD8NXmGJBDT/O6ZNedYOkAfqhVkpzNXRxs8BXvaJ++JKrKgF9ZhW3 X-Received: by 2002:aca:36d5:: with SMTP id d204mr8557039oia.234.1543252051607; Mon, 26 Nov 2018 09:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543252051; cv=none; d=google.com; s=arc-20160816; b=QtEoMa61J9AV0U8crfqGhRtKdROc6roTHDfu56QTZ5QcwksXFcyMedTX9QqetsyP+X 4cdq0G/3Qh+NdQYGY3R9zwDHT4HDWYkdxMdUQPhjb5xrHVzOTC9cgNMZMLg6ce44gKEq ElibeLuU0NMaz4vz2A/nb+qoW3iuKJez2CsGX6+jP4HyK87EQrwHkNKMZ9Ozb78qgE74 0bKwZPqH4iMJJ2esgevEoNEva1RyRVtlg2/STgeEaH7u2rPm5soQisXdNZTWkXkX0Uav yVdc1Nklnenyc/hMcpnH1BMhiCoQDDEmf2iPPo9uW/CvO72sMbWlq656sBvYt9xBbDSH cTtQ== 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=S3Pe7jCrFGE7JxF6m5RucqgSGzB7M8lCaWDcweULJ1Y=; b=qJHu7ro0GQU4Rd0Q74sdaqOYLuMP51hV9F6JCixjgxyBGk6tmXXfBH0ikkYnorNQqp lqNi/f+8kIDn7TTuQ4EEplN9N4tn1wPB6bm5kSKjM4PiA8pVF5xIIIl5nyM89yg0gCNH ubdImG+Iug59Xg3eEQZOBSpa/E6Hecqmn2M0ZFqdJUyBizRlDWINnQVMIfzWCo7kxQvv HOObapIItVPQMDR37/FyENu/ZR4SKw+p43YaLKCsPpGWgRG4gbnIy86z5W7WlMu0IQnt I5x+hnXG6BQOI8i4GuJGqO6SqRPMsoj+7TWyUeCp8Zb5haeJXW4W90hRZv3nSBK9Quvz jJcw== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id 68si358023otp.89.2018.11.26.09.07.31 for ; Mon, 26 Nov 2018 09:07:31 -0800 (PST) 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 EAB75169E; Mon, 26 Nov 2018 09:07:30 -0800 (PST) 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 BA90A3F911; Mon, 26 Nov 2018 09:07:30 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 3555C1AE0B58; Mon, 26 Nov 2018 17:07:48 +0000 (GMT) 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 v4 3/5] x86/pgtable: Drop pXd_none() checks from pXd_free_pYd_table() Date: Mon, 26 Nov 2018 17:07:45 +0000 Message-Id: <1543252067-30831-4-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1543252067-30831-1-git-send-email-will.deacon@arm.com> References: <1543252067-30831-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 core code already has a check for pXd_none(), so remove it from the architecture implementation. Cc: Chintan Pandya Cc: Toshi Kani Cc: Michal Hocko Cc: Andrew Morton Acked-by: Thomas Gleixner Reviewed-by: Toshi Kani Signed-off-by: Will Deacon --- arch/x86/mm/pgtable.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 59274e2c1ac4..e95a7d6ac8f8 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -811,9 +811,6 @@ int pud_free_pmd_page(pud_t *pud, unsigned long addr) pte_t *pte; int i; - if (pud_none(*pud)) - return 1; - pmd = (pmd_t *)pud_page_vaddr(*pud); pmd_sv = (pmd_t *)__get_free_page(GFP_KERNEL); if (!pmd_sv) @@ -855,9 +852,6 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) { pte_t *pte; - if (pmd_none(*pmd)) - return 1; - pte = (pte_t *)pmd_page_vaddr(*pmd); pmd_clear(pmd); From patchwork Mon Nov 26 17:07:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10698791 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 7DAB413BB for ; Mon, 26 Nov 2018 17:07:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67853286B6 for ; Mon, 26 Nov 2018 17:07:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B2622896F; Mon, 26 Nov 2018 17:07:40 +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 BDCEE286B6 for ; Mon, 26 Nov 2018 17:07:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85E4A6B42CA; Mon, 26 Nov 2018 12:07:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5B56B42CE; Mon, 26 Nov 2018 12:07:33 -0500 (EST) 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 56D686B42CC; Mon, 26 Nov 2018 12:07:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 1F7616B42CB for ; Mon, 26 Nov 2018 12:07:33 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id j15so8637375ota.17 for ; Mon, 26 Nov 2018 09:07:33 -0800 (PST) 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=gyaouhO6M09bNRRp3jEmM8H6PKnPVZFp5tgRSOGTTCE=; b=uPbFwSgrMvzv/+7mK9PowhA2KBuFrcDF5NRNu5GcY4VC/UoulT9wuk4w5MiM0PS6K5 5XaVlqlTpoaPZiA6sxoo47nZdNg3lXUomfK7uZXnu03wJhnrupH4GXHXCYsmbSusTrJV EC5BVLzeGY7Z0CH67Zlvackr0e0BSzd235QQmgQMW3wYfwLlehGrBxPRGpWubpFlUbI+ XO+MZ95FfxcwdTeURFp59S/sZaU2IZcumZk1fkg4g8GU5WYW2jnIzqg2z59F7iJzRLSb zkjI0CHciPdhjrJlkio9FKGHI7Mr24Fs6Jt5VLKOfMXuYq8d7zViJhTk3XiuC0UUELYG NZMA== 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: AA+aEWZzE/IWU6u1nFVZcspj5mxKDWnRQMckLFCcgHbvDAHSn09a3ibr XuIZQdNhg6n3anOponV193H4n702yw+b/UMgkPjSOyAFKqCH8ZGitiQlBOVVkTJ5qPb9ddpICKZ S0nPNmBQubD88bqJtTpwHYF1F7UHVIPeBNtmZ4A8qGseB8E1jDSLkiQdRSIvvKHoBmQ== X-Received: by 2002:aca:684a:: with SMTP id d71mr9834115oic.264.1543252052846; Mon, 26 Nov 2018 09:07:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/XmwHpk4blWQDLEgMAsiH/MrpXEGzB8HWwp6zY5pCIIHhCassijB+Hgx/oOxttUk9KO5S9k X-Received: by 2002:aca:684a:: with SMTP id d71mr9834068oic.264.1543252051695; Mon, 26 Nov 2018 09:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543252051; cv=none; d=google.com; s=arc-20160816; b=PLhn34T3HqG+J+f5UwM28eECkMn6w8rvkJGeKCxRHMzYGh2tjKScKUmOatBvAgiIv+ vzrP5mDPS7GZlJ+dFyaU6HV+bsHSUvkyq+oUbXhHWUCURs9aWX3eqpdX0U/OiqpIq7Fk 3iFaqfgkOLwmc6CvKfEHzGFbvmerulWH6Dd7cmC3wl5XadqVXX5FvLX6YIKkSXe73AeO ehfrofdQj1BIjBNq/ILdvy/G099+CeileceVyOIjIJCB1xc465/3VIOcQkTcFpti1G6F G8kGfqSgGQn6rND3jNiOGbrg+M4ZZ9lTmo81dyrbm2Q/2+8nVrHdG8BonHwZJVrIGIXm WSuQ== 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=gyaouhO6M09bNRRp3jEmM8H6PKnPVZFp5tgRSOGTTCE=; b=JuAENjiT47MKix5yjrfnanWFdc7o4HSX5Jald7VO1rs1EoczL5n8EAPW+Bg6KwKt79 0agiAH33dGE/MigGNXurmS1Yyn242jhYWXWkuPMw84HliUtXByEEuazyZ5ubqR4hlSpP 3+8E+iisjTZpkAy3VrRU1ZXG22FFUWUZDfiBJbretxfEieczlOLilWrA/xo/P4JTLwaP E39R5II98Ck2+G8JvysboQNZWy9AKuKrx7ag1mvikh3Bd4pDSumpj0liAL0iaeOMUeN7 2Swb76/RtiikFXCSziuiRZBJDej3C+NxFN/yvI1DpgpAe7hQLJSi1kyGSNIcumxiQPFR C9NQ== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id t32si369876otc.126.2018.11.26.09.07.31 for ; Mon, 26 Nov 2018 09:07:31 -0800 (PST) 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 090881993; Mon, 26 Nov 2018 09:07:31 -0800 (PST) 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 CD0B03F59C; Mon, 26 Nov 2018 09:07:30 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 47AA11AE0B68; Mon, 26 Nov 2018 17:07:48 +0000 (GMT) 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 v4 4/5] lib/ioremap: Ensure phys_addr actually corresponds to a physical address Date: Mon, 26 Nov 2018 17:07:46 +0000 Message-Id: <1543252067-30831-5-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1543252067-30831-1-git-send-email-will.deacon@arm.com> References: <1543252067-30831-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 current ioremap() code uses a phys_addr variable at each level of page table, which is confusingly offset by subtracting the base virtual address being mapped so that adding the current virtual address back on when iterating through the page table entries gives back the corresponding physical address. This is fairly confusing and results in all users of phys_addr having to add the current virtual address back on. Instead, this patch just updates phys_addr when iterating over the page table entries, ensuring that it's always up-to-date and doesn't require explicit offsetting. Cc: Chintan Pandya Cc: Toshi Kani Cc: Thomas Gleixner Cc: Michal Hocko Cc: Andrew Morton Cc: Sean Christopherson Signed-off-by: Will Deacon Tested-by: Sean Christopherson Reviewed-by: Sean Christopherson --- lib/ioremap.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/ioremap.c b/lib/ioremap.c index 6c72764af19c..10d7c5485c39 100644 --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -101,19 +101,18 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, pmd_t *pmd; unsigned long next; - phys_addr -= addr; pmd = pmd_alloc(&init_mm, pud, addr); if (!pmd) return -ENOMEM; do { next = pmd_addr_end(addr, end); - if (ioremap_try_huge_pmd(pmd, addr, next, phys_addr + addr, prot)) + if (ioremap_try_huge_pmd(pmd, addr, next, phys_addr, prot)) continue; - if (ioremap_pte_range(pmd, addr, next, phys_addr + addr, prot)) + if (ioremap_pte_range(pmd, addr, next, phys_addr, prot)) return -ENOMEM; - } while (pmd++, addr = next, addr != end); + } while (pmd++, phys_addr += (next - addr), addr = next, addr != end); return 0; } @@ -142,19 +141,18 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, pud_t *pud; unsigned long next; - phys_addr -= addr; pud = pud_alloc(&init_mm, p4d, addr); if (!pud) return -ENOMEM; do { next = pud_addr_end(addr, end); - if (ioremap_try_huge_pud(pud, addr, next, phys_addr + addr, prot)) + if (ioremap_try_huge_pud(pud, addr, next, phys_addr, prot)) continue; - if (ioremap_pmd_range(pud, addr, next, phys_addr + addr, prot)) + if (ioremap_pmd_range(pud, addr, next, phys_addr, prot)) return -ENOMEM; - } while (pud++, addr = next, addr != end); + } while (pud++, phys_addr += (next - addr), addr = next, addr != end); return 0; } @@ -164,7 +162,6 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, p4d_t *p4d; unsigned long next; - phys_addr -= addr; p4d = p4d_alloc(&init_mm, pgd, addr); if (!p4d) return -ENOMEM; @@ -173,14 +170,14 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, if (ioremap_p4d_enabled() && ((next - addr) == P4D_SIZE) && - IS_ALIGNED(phys_addr + addr, P4D_SIZE)) { - if (p4d_set_huge(p4d, phys_addr + addr, prot)) + IS_ALIGNED(phys_addr, P4D_SIZE)) { + if (p4d_set_huge(p4d, phys_addr, prot)) continue; } - if (ioremap_pud_range(p4d, addr, next, phys_addr + addr, prot)) + if (ioremap_pud_range(p4d, addr, next, phys_addr, prot)) return -ENOMEM; - } while (p4d++, addr = next, addr != end); + } while (p4d++, phys_addr += (next - addr), addr = next, addr != end); return 0; } @@ -196,14 +193,13 @@ int ioremap_page_range(unsigned long addr, BUG_ON(addr >= end); start = addr; - phys_addr -= addr; pgd = pgd_offset_k(addr); do { next = pgd_addr_end(addr, end); - err = ioremap_p4d_range(pgd, addr, next, phys_addr+addr, prot); + err = ioremap_p4d_range(pgd, addr, next, phys_addr, prot); if (err) break; - } while (pgd++, addr = next, addr != end); + } while (pgd++, phys_addr += (next - addr), addr = next, addr != end); flush_cache_vmap(start, end); From patchwork Mon Nov 26 17:07:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10698797 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 3FD5813BB for ; Mon, 26 Nov 2018 17:07:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28F672896F for ; Mon, 26 Nov 2018 17:07:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D2C029201; Mon, 26 Nov 2018 17:07:52 +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 893132896F for ; Mon, 26 Nov 2018 17:07:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13E366B42CF; Mon, 26 Nov 2018 12:07:37 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 023A96B42D0; Mon, 26 Nov 2018 12:07:36 -0500 (EST) 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 D49DF6B42D2; Mon, 26 Nov 2018 12:07:36 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id 8C6A26B42CF for ; Mon, 26 Nov 2018 12:07:36 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id w80so10795251oiw.19 for ; Mon, 26 Nov 2018 09:07:36 -0800 (PST) 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=l44sI+xexd99+rlEiWTnTtPsv1VhQI3OmU75tH27288=; b=sycMbVjKNsTeHNzvOIKLBVeqtOiQLV1E2yu0X1U0/9H7c47N0RN3Sp67JEQC7gnkTO /XobQjhgQ+OOeLl5v8X/Z8KrXw6lQ1QzTzYXDwxpmBpTf84kKqmN9lYxvvIkhr7BxklX 2t54Msy9qmoJmCiZ/5VUwd/0dLHZyb6ncPq8YO9g5YB8wvlp7kcr+kY5rdwXP5KtN0QN jtsRDawAd4V5klRPg3WM4f6AsaPg08dQQT9DTvJozm7YxwpgtrocsAtrdyTbmClebmct GPA40HQu6AU0REWdoSgUwtdzmT0oDS6wYqBilfU3s1CEw1wrK7ryQkcBsRzxysK67+rO I1cw== 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: AA+aEWaUzsrIu4ANEbC30mfWo87JGC+kJ+3td61S4QOd3wM8ZTaTI6tq 5++zg3ygwoTO0ZQPusoV5UdUr0zkaG1al1FpFpKAZFtrnUSsIyYZN2KhFYNfrCDX1IudNcMfywp TN2GKTkISiVSVj1WAQ/X87thd4HfLzUKon6FSLyiybFypIgQZM8FGlIJq6pGU1xJfsg== X-Received: by 2002:a9d:582e:: with SMTP id r46mr16158642oth.238.1543252056306; Mon, 26 Nov 2018 09:07:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xs3NzAu/JvpKhE/wwFvkV8g5Pk45of4fp7oUvw1WRRJkN0NmkgdKcd/ZyTsVfqcoMqrwnt X-Received: by 2002:a9d:582e:: with SMTP id r46mr16158479oth.238.1543252052417; Mon, 26 Nov 2018 09:07:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543252052; cv=none; d=google.com; s=arc-20160816; b=XUx+K8s7jkKm9NjfYDuAiBj+xqWexOaRRtVH7ELlac8Tz1xIRlyDKg5TzbYNuh4jCN HyW48h140YsKgeDxafLrtLGGVMrXNcFraMH90IBp2+TCfcXMJNjLAWKqD3u0X4KUQ104 oPaDIHGLCbusIyFSYsbPp73Vhu0Ny5tXUNY1eMyqzMJwsCpGyYXMm3in4nCPwK7w6HvQ Ms3P0F+7G2mW4pTb9omFJBpyjkxODzb8OLmSWKLVZImtxGIxSyRnLIqMaoOnREWSI6VB Yn4wgpyJnynehKhuR3qQ3bi5dbPkR3+rnRE0g3w+5Dk9L3x6IRVvSnk55tGzUJGk7JHu QPcw== 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=l44sI+xexd99+rlEiWTnTtPsv1VhQI3OmU75tH27288=; b=s7uoMjBDY2+dIyyi+ZBj6P4b2vv2GYXjUaSU6zJgpcA/GBNPXj5xq1qo6h2vv4pbbX moBbSkEGTrb7zLvgwwwxIyCMueFZ6hHK8GFo98KutwZuakPX+0/joXwBihiTmrTGbhg9 6LM+7BYB061DJ/L3qQFb+ZCxQfZg6b8eXmXpxB59/RJ0NeSKyhOYlEl4zkGd9jnA1xGs coj1LnV62Nc+Bb2S/vqomLxBD2Clh5WUgwtZVMEsU3UzLNBwlTrbQWwmIdDdcBDCss3w MFHyNgsMb77m7GF6S0mSSZPJ1qMrBhaClS0nzv7k73C3X4QBGVv+SSljd3w+a6dto4oW zh8g== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id h16si444614otg.62.2018.11.26.09.07.32 for ; Mon, 26 Nov 2018 09:07:32 -0800 (PST) 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 AB6F019BF; Mon, 26 Nov 2018 09:07:31 -0800 (PST) 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 7C2B43F59C; Mon, 26 Nov 2018 09:07:31 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 59FE01AE0C3D; Mon, 26 Nov 2018 17:07:48 +0000 (GMT) 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 v4 5/5] lib/ioremap: Ensure break-before-make is used for huge p4d mappings Date: Mon, 26 Nov 2018 17:07:47 +0000 Message-Id: <1543252067-30831-6-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1543252067-30831-1-git-send-email-will.deacon@arm.com> References: <1543252067-30831-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 Whilst no architectures actually enable support for huge p4d mappings in the vmap area, the code that is implemented should be using break-before-make, as we do for pud and pmd huge entries. Cc: Chintan Pandya Cc: Toshi Kani Cc: Thomas Gleixner Cc: Michal Hocko Cc: Andrew Morton Reviewed-by: Toshi Kani Signed-off-by: Will Deacon --- arch/arm64/mm/mmu.c | 5 +++++ arch/x86/mm/pgtable.c | 8 ++++++++ include/asm-generic/pgtable.h | 5 +++++ lib/ioremap.c | 27 +++++++++++++++++++++------ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 786cfa6355be..cf9a26d3d7f5 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1028,3 +1028,8 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr) pmd_free(NULL, table); return 1; } + +int p4d_free_pud_page(p4d_t *p4d, unsigned long addr) +{ + return 0; /* Don't attempt a block mapping */ +} diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index e95a7d6ac8f8..b0284eab14dc 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -794,6 +794,14 @@ int pmd_clear_huge(pmd_t *pmd) return 0; } +/* + * Until we support 512GB pages, skip them in the vmap area. + */ +int p4d_free_pud_page(p4d_t *p4d, unsigned long addr) +{ + return 0; +} + #ifdef CONFIG_X86_64 /** * pud_free_pmd_page - Clear pud entry and free pmd page. diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index 359fb935ded6..e0381a4ce7d4 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -1019,6 +1019,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot); int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); int pud_clear_huge(pud_t *pud); int pmd_clear_huge(pmd_t *pmd); +int p4d_free_pud_page(p4d_t *p4d, unsigned long addr); int pud_free_pmd_page(pud_t *pud, unsigned long addr); int pmd_free_pte_page(pmd_t *pmd, unsigned long addr); #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ @@ -1046,6 +1047,10 @@ static inline int pmd_clear_huge(pmd_t *pmd) { return 0; } +static inline int p4d_free_pud_page(p4d_t *p4d, unsigned long addr) +{ + return 0; +} static inline int pud_free_pmd_page(pud_t *pud, unsigned long addr) { return 0; diff --git a/lib/ioremap.c b/lib/ioremap.c index 10d7c5485c39..063213685563 100644 --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -156,6 +156,25 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, return 0; } +static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, + pgprot_t prot) +{ + if (!ioremap_p4d_enabled()) + return 0; + + if ((end - addr) != P4D_SIZE) + return 0; + + if (!IS_ALIGNED(phys_addr, P4D_SIZE)) + return 0; + + if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)) + return 0; + + return p4d_set_huge(p4d, phys_addr, prot); +} + static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { @@ -168,12 +187,8 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, do { next = p4d_addr_end(addr, end); - if (ioremap_p4d_enabled() && - ((next - addr) == P4D_SIZE) && - IS_ALIGNED(phys_addr, P4D_SIZE)) { - if (p4d_set_huge(p4d, phys_addr, prot)) - continue; - } + if (ioremap_try_huge_p4d(p4d, addr, next, phys_addr, prot)) + continue; if (ioremap_pud_range(p4d, addr, next, phys_addr, prot)) return -ENOMEM;