From patchwork Sun Jun 23 09:44:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11011649 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 1A43313AF for ; Sun, 23 Jun 2019 09:46:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03E0E28B08 for ; Sun, 23 Jun 2019 09:46:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E612D28B16; Sun, 23 Jun 2019 09:46:03 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C02328B08 for ; Sun, 23 Jun 2019 09:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7sHUahc4+Yw5me13JXg/+jQYe9DVklDQxb6bLd6xLl8=; b=CarSQJzqbpJiH9 /gMj04al/7WZpUiolB/WHNiokFhLH3iBjHHyJWjh8tErQ6wi5kVTbukcdAqbOoj0MznqrtoP5Nol4 aJZuJ9afqC5NHcV+kH9PKAhZZ2f7vDzHstwApuBIWni72IP0kwGsyNvnCOeKeNnxosrn6rYs0RgLa kmZ3uleW+Bsm8Mc6xKZvvbYBv8WFHn1gsEYoFv2Yh4SggrZ8W8r8LL7q/vJ+YpimJFqmzn4Ibc6qt SG4UvElD8oySUuSMb04+prxOfI3SoCUR3/56qNQ/D4VaWQM6mMH0ufRo0JW/HB4HJawHl7zPf9Yo1 EJW9UKaLQ3iqQ/kch33g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hez4U-0001JS-W1; Sun, 23 Jun 2019 09:46:03 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hez45-00017L-1M for linux-arm-kernel@lists.infradead.org; Sun, 23 Jun 2019 09:45:39 +0000 Received: by mail-pl1-x643.google.com with SMTP id p1so5209766plo.2 for ; Sun, 23 Jun 2019 02:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wnbjux+HxNYOkFaRKhTh2OlBlr6Yjq4h8O9uCggPaW0=; b=nZ1uAEh/l/iH3XHgJ4JMzpVgG2BAjVP+Z4uP0nLctfLAj7AD/MmtA4UP0ovGBefyCX oi/eiKdn5rkb+cERs9Q8dHLJnb+ghuSMilmtfbCoNwrAS8IHMPARnfgHf8n9HMnua6zS +dxXBrDAzpJmAl2a5WPEl0+v9WftLVMpwR+Ki8qD5BEfrZHM6Z+MwQFgDagG17N4lc1g 5g3hUt3k1Vuvyww7G6od0qdoZYGYGxV4ZJ+E/1RRGg0hnv1OCHh2088YsdWh7C6PTe+t pG1oasPj0r+b4PVWCRQ/vj3KXGeUaEOXaQbg+/rH4Dd4SeFUb1BicT4qR09j10i/WFg9 yGJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wnbjux+HxNYOkFaRKhTh2OlBlr6Yjq4h8O9uCggPaW0=; b=OpzcYG3ZqCjqADPX7AuCdj6Ns1ft5ZyHYdq9TG7AWOE+xIYV/zo71k+ROYSZRUc+a9 97H544P9gFInWhHH5DdMRUJxi2xryX+ZsjFU+9SOvI71Em1b110EjwQLXc36goLT/d3z qlnnSQtb2k25vJ/3OlaBfDlsrvWXF9bSlTNAR25U9mnE5bn5pHIS/5bIe9ji+tVIcpM6 FRZxoJw4mcWN5ViWMQz0R7KV3ZvEO+C5dP8aixQKanHqXDQ6K+3HrDUAheKKAzZeGRE0 Mi276eEtfDInPXQ0pLQdsdoh0gMwSsmsX7PhLlMgXd8JdXBcQqKbhzrE5p3pS/euLifl VJ6w== X-Gm-Message-State: APjAAAVDRXtLsdFVFXCdWFoSC5vmHnmPH7EOYMgKElCjsQ8LwBM6dQB8 C0u4cr3iTxg4f5EyNIFy0to= X-Google-Smtp-Source: APXvYqy03K0Z/MbKC+X3ScMS1p5nrg83Wdw/gotWUEhNW5qLKL0hUnw5AV3nEp2FnFcsXPqkd+XVzA== X-Received: by 2002:a17:902:7c03:: with SMTP id x3mr117368602pll.242.1561283136704; Sun, 23 Jun 2019 02:45:36 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([1.129.156.141]) by smtp.gmail.com with ESMTPSA id d26sm6181062pfn.29.2019.06.23.02.45.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 02:45:36 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Subject: [PATCH 1/3] arm64: mm: Add p?d_large() definitions Date: Sun, 23 Jun 2019 19:44:44 +1000 Message-Id: <20190623094446.28722-2-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190623094446.28722-1-npiggin@gmail.com> References: <20190623094446.28722-1-npiggin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190623_024537_562073_613A2625 X-CRM114-Status: GOOD ( 12.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christophe Leroy , Mark Rutland , Anshuman Khandual , Catalin Marinas , Ard Biesheuvel , Will Deacon , Nicholas Piggin , Steven Price , Andrew Morton , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP walk_page_range() is going to be allowed to walk page tables other than those of user space. For this it needs to know when it has reached a 'leaf' entry in the page tables. This information will be provided by the p?d_large() functions/macros. For arm64, we already have p?d_sect() macros which we can reuse for p?d_large(). pud_sect() is defined as a dummy function when CONFIG_PGTABLE_LEVELS < 3 or CONFIG_ARM64_64K_PAGES is defined. However when the kernel is configured this way then architecturally it isn't allowed to have a large page that this level, and any code using these page walking macros is implicitly relying on the page size/number of levels being the same as the kernel. So it is safe to reuse this for p?d_large() as it is an architectural restriction. Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Steven Price --- This patch is taken from arm64 but is required if this series is not build together with arm64 tree. arch/arm64/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index fca26759081a..0e973201bc16 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -417,6 +417,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, PMD_TYPE_TABLE) #define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \ PMD_TYPE_SECT) +#define pmd_large(pmd) pmd_sect(pmd) #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 #define pud_sect(pud) (0) @@ -499,6 +500,7 @@ static inline void pte_unmap(pte_t *pte) { } #define pud_none(pud) (!pud_val(pud)) #define pud_bad(pud) (!(pud_val(pud) & PUD_TABLE_BIT)) #define pud_present(pud) pte_present(pud_pte(pud)) +#define pud_large(pud) pud_sect(pud) #define pud_valid(pud) pte_valid(pud_pte(pud)) static inline void set_pud(pud_t *pudp, pud_t pud) From patchwork Sun Jun 23 09:44:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11011651 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 B464913AF for ; Sun, 23 Jun 2019 09:46:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F35528B08 for ; Sun, 23 Jun 2019 09:46:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9256028B16; Sun, 23 Jun 2019 09:46:37 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3AD9228B08 for ; Sun, 23 Jun 2019 09:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0yZr8Jop4B8gOS212abRQOgwcPAG0HO3YnK1JIK6WEA=; b=GSYz5+Aa0lJ3ix fC7PGt+3m2vVNZiq1DN3CZwVzfcn8yVfOW+beucMEaOOEduZ7lg0UiePSFfXJb/upnm4az4sZyhC/ 5M1VVMdPtU6jUcCXg/s8F1z2BgU2rZi2Nu0QYf443btPK8dS+Bo0vLx+Fq6frRQZGoQpdLtXW8Lnm ppv5T67UzxhQunnQ+OIhfWaONZ8lntYn187Sv0y/0FmTdofUPHjFV9QjWZDbHB+jT2hHzmvfzWkZ9 8hDCAD8TuproFreYHtYd8WHxLCJehTwayK46nENWk6GtpKVX2kK1yx243mSRvmnFb56XHyuLqE3sd U+xmjeQ2Do8cKYbcvnQQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hez4x-0001cW-KD; Sun, 23 Jun 2019 09:46:31 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hez4C-00019q-61 for linux-arm-kernel@lists.infradead.org; Sun, 23 Jun 2019 09:45:45 +0000 Received: by mail-pl1-x644.google.com with SMTP id t7so5185186plr.11 for ; Sun, 23 Jun 2019 02:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8jypfSRuf2tzCnQqgBbeT0KAA5/GWGPe8r0gYwybhoA=; b=MC3FgqhtZqqZOa3fca2etHFPOlAX/zHSptGaJf3qBl/azqwKXvi2ibRnsxz9AQxojg EICGDT1H4meg+DusobPeLFIRimkWAHJJDK/dlKDhDPS57IyazF6sl+ol2f+XRdncSjTx ujEpJ6IHP0e4ia/heO06G73O29JIvv3eBxJ8vsug9U/B1QpbHlPO/jQtEgUyBX1hHmH5 zhJon/QZMy/0r5wuDPk+yXcnBxYz2434lS1tOAZo8EudlMygn0yOCpQ4Q+dnsj6bSIhB TiQ0NJrPR2ggTlL8e/n3bTP2N95KcpYLeCsOcEREJ/hqIDZLZqTrbj00s66H18rrjXqL +jKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8jypfSRuf2tzCnQqgBbeT0KAA5/GWGPe8r0gYwybhoA=; b=mjN0icUCfEsHpcuKPeQFvyqK5TY1ViFZM9f8jsKkY+L1H7yW/UVx5gOqHg3Jc8O4E7 ERXF/FypRBXsoZR22c5Mc/YzpblxYnu8eWWLOEJdoGl9xDu62VE6G+4G8KewxOfY9f1T 9TqBZy+zdr+vsQInFModvOph2rHuuwY2WR00mHFFKZbSH3zk6wgp6Bjb7h6zQVwY7OWC kkD497OUOsYBxlYDXX73o5kySLN//j1xDjH8G3kV/z3jsxcngfadnVW17Kj2l3WbC0GS k9ZLG/92d6c2fnciE3lbFo2Pj7GAvkZGj/QaL6V3liR93+8GHmqotm12cYWNZYA5OZdr 0DTQ== X-Gm-Message-State: APjAAAXEibMEfUzPyJGsFUnvq5EOvr9pj8sBeEdwj8Ah97ikpcO70HHw 7wJJ0AUlvZdKWArRgur9hhc= X-Google-Smtp-Source: APXvYqxG5TUNwj0LFGeB24LqT2Ou4ZDW4mig65P9OQLsMEMD34gg1qObLUiUXmLaNRqELQkQNbwqkg== X-Received: by 2002:a17:902:a517:: with SMTP id s23mr13564230plq.306.1561283142460; Sun, 23 Jun 2019 02:45:42 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([1.129.156.141]) by smtp.gmail.com with ESMTPSA id d26sm6181062pfn.29.2019.06.23.02.45.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 02:45:42 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Subject: [PATCH 2/3] powerpc/64s: Add p?d_large definitions Date: Sun, 23 Jun 2019 19:44:45 +1000 Message-Id: <20190623094446.28722-3-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190623094446.28722-1-npiggin@gmail.com> References: <20190623094446.28722-1-npiggin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190623_024544_328784_14694A24 X-CRM114-Status: GOOD ( 10.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christophe Leroy , Mark Rutland , Anshuman Khandual , Ard Biesheuvel , Nicholas Piggin , Andrew Morton , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The subsequent patch to fix vmalloc_to_page with huge vmap requires HUGE_VMAP archs to provide p?d_large definitions for the non-pgd page table levels they support. Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Nicholas Piggin --- Upstream powerpc code does not enable HUGE_VMAP, but the powerpc next tree has patches, so this patch is required to fix dependency between this series and powerpc tree in linux-next. arch/powerpc/include/asm/book3s/64/pgtable.h | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index ccf00a8b98c6..c19c8396a1bd 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -915,6 +915,11 @@ static inline int pud_present(pud_t pud) return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT)); } +static inline int pud_large(pud_t pud) +{ + return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE)); +} + extern struct page *pud_page(pud_t pud); extern struct page *pmd_page(pmd_t pmd); static inline pte_t pud_pte(pud_t pud) @@ -958,6 +963,11 @@ static inline int pgd_present(pgd_t pgd) return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT)); } +static inline int pgd_large(pgd_t pgd) +{ + return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PTE)); +} + static inline pte_t pgd_pte(pgd_t pgd) { return __pte_raw(pgd_raw(pgd)); @@ -1083,6 +1093,11 @@ static inline pte_t *pmdp_ptep(pmd_t *pmd) #define pmd_mk_savedwrite(pmd) pte_pmd(pte_mk_savedwrite(pmd_pte(pmd))) #define pmd_clear_savedwrite(pmd) pte_pmd(pte_clear_savedwrite(pmd_pte(pmd))) +static inline int pmd_large(pmd_t pmd) +{ + return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); +} + #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY #define pmd_soft_dirty(pmd) pte_soft_dirty(pmd_pte(pmd)) #define pmd_mksoft_dirty(pmd) pte_pmd(pte_mksoft_dirty(pmd_pte(pmd))) @@ -1151,15 +1166,6 @@ pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, return hash__pmd_hugepage_update(mm, addr, pmdp, clr, set); } -/* - * returns true for pmd migration entries, THP, devmap, hugetlb - * But compile time dependent on THP config - */ -static inline int pmd_large(pmd_t pmd) -{ - return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); -} - static inline pmd_t pmd_mknotpresent(pmd_t pmd) { return __pmd(pmd_val(pmd) & ~_PAGE_PRESENT); From patchwork Sun Jun 23 09:44:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11011653 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 B531613AF for ; Sun, 23 Jun 2019 09:46:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A260428B08 for ; Sun, 23 Jun 2019 09:46:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 965FB28B16; Sun, 23 Jun 2019 09:46: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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3353328B08 for ; Sun, 23 Jun 2019 09:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=K17MB4Dibd7M4Dzl3C8O1hyUu9HeCe5ZpT6BsnRs3Os=; b=cj6DE38lT3bpno aCOoHQTKe+/CLzR+7CNe6Spy/ckvrhLqz9BpXOQ4hmPGvHXv3h/+6Z5PaOUsRSrEs7kwE9k7bldis 8MYMViPIdCIPsG4Pyr1TlQ4xN2sQng0AXzHoYEL7tYndSS5qCg2oKoZQuJEtYUc0ia5LnVgQba0yu esWSnglWQbzaegAzS2cdZv5y/OiViQcRei7ATMaNAW4PSULkBmuVg9hrHPwmmgjiq9ZaWjdZlNzpX 4foU9/3d9Qb+U/HYW18uSB0h/T2TQi87Vmp7y28hJuwgbnfyx5EVD3LhSe5i+h8W+0px/LRBkfs0Y RWDXp1Pi9pQaWjvSlIEA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hez5E-0001tx-0J; Sun, 23 Jun 2019 09:46:48 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hez4G-0001DC-8j for linux-arm-kernel@lists.infradead.org; Sun, 23 Jun 2019 09:45:50 +0000 Received: by mail-pf1-x442.google.com with SMTP id r1so5800110pfq.12 for ; Sun, 23 Jun 2019 02:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BUni308L4TNZcRdWweuUiutx4ej146UezPXSv2fRAeU=; b=JqeYVSNxIoqFzu0xK2z/Z3ztnBfVaDvdJ4jBDcTZwl1ZZSzJpb4XVAqFLNcvsicZQx 8azD+7/r8TB6Xe4GCrMf2HyZfHSfUYK9qHQtKFQhT72bYJ5DCjJKYW0muFytZdbqa87K C4bitxQYLZlwTNsjcupbcQlpamUux3vetpFGshSj8TWe5rPmtnBH77PG9DeEGbtuVAlg hcFCbqVaJ5nfQFVZKN55i3/+v0EylIZXr82F3dOYsbZrBaddGQETYoJ3hPGwQwMDgiaF hhN2431E96e1zXHj299iMvvgry3NSb6UH8u1MpCg5ujVQm+BqSQj0GWssD6TTCp7Ci3I 5cVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BUni308L4TNZcRdWweuUiutx4ej146UezPXSv2fRAeU=; b=jmhXL415fXEqtG+O5nM1mlBcirHOceNaY00immIHa8+TPnQDJ5AUlcM68P/ra+JW4u 3GuJNoccZMn/T6e4Vxarfe2NJ7MV0iVksitV3bEi8fF3XrXOsP66Hmy9z0K7G9i1lrHj yRy6NV4CFGptU1Vd5Mdaa4czQIdZV0Bgm2DOdUGqFDOlnOxPk1i3+FSbHUvB+YDnxjbu m7vlyVejRgaAfRuHTBvSxc4ZuQkiSE4EwmXysn9VpQZK9wYRjp7jRNdXAYjXIomwlAKJ l5EewwV1iHmRzMW+uOP7li8KgX98e+newsEFHJMXIFsWDjbB6cw4iVH17lTHDjlmti8m /UTg== X-Gm-Message-State: APjAAAXW9h1/kdToHdT4ZCK3PBy/z2Lu99AA2m4N+r1SfXw+kmUo4Fsz AOF2RyUwXps/tUd/dxpsG6M= X-Google-Smtp-Source: APXvYqzXhmFEsFsp6pqN+TP8Jn+x9XMVyMY/SjTnneXCEg7e318qlarpEXN25vv1DI0lY9gT+msajA== X-Received: by 2002:a17:90a:be0a:: with SMTP id a10mr16827730pjs.112.1561283147081; Sun, 23 Jun 2019 02:45:47 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([1.129.156.141]) by smtp.gmail.com with ESMTPSA id d26sm6181062pfn.29.2019.06.23.02.45.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 02:45:46 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Subject: [PATCH 3/3] mm/vmalloc: fix vmalloc_to_page for huge vmap mappings Date: Sun, 23 Jun 2019 19:44:46 +1000 Message-Id: <20190623094446.28722-4-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190623094446.28722-1-npiggin@gmail.com> References: <20190623094446.28722-1-npiggin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190623_024548_698709_4C3E3F2F X-CRM114-Status: GOOD ( 13.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christophe Leroy , Mark Rutland , Anshuman Khandual , Ard Biesheuvel , Nicholas Piggin , Andrew Morton , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP vmalloc_to_page returns NULL for addresses mapped by larger pages[*]. Whether or not a vmap is huge depends on the architecture details, alignments, boot options, etc., which the caller can not be expected to know. Therefore HUGE_VMAP is a regression for vmalloc_to_page. This change teaches vmalloc_to_page about larger pages, and returns the struct page that corresponds to the offset within the large page. This makes the API agnostic to mapping implementation details. [*] As explained by commit 029c54b095995 ("mm/vmalloc.c: huge-vmap: fail gracefully on unexpected huge vmap mappings") Signed-off-by: Nicholas Piggin --- include/asm-generic/4level-fixup.h | 1 + include/asm-generic/5level-fixup.h | 1 + mm/vmalloc.c | 37 +++++++++++++++++++----------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h index e3667c9a33a5..3cc65a4dd093 100644 --- a/include/asm-generic/4level-fixup.h +++ b/include/asm-generic/4level-fixup.h @@ -20,6 +20,7 @@ #define pud_none(pud) 0 #define pud_bad(pud) 0 #define pud_present(pud) 1 +#define pud_large(pud) 0 #define pud_ERROR(pud) do { } while (0) #define pud_clear(pud) pgd_clear(pud) #define pud_val(pud) pgd_val(pud) diff --git a/include/asm-generic/5level-fixup.h b/include/asm-generic/5level-fixup.h index bb6cb347018c..c4377db09a4f 100644 --- a/include/asm-generic/5level-fixup.h +++ b/include/asm-generic/5level-fixup.h @@ -22,6 +22,7 @@ #define p4d_none(p4d) 0 #define p4d_bad(p4d) 0 #define p4d_present(p4d) 1 +#define p4d_large(p4d) 0 #define p4d_ERROR(p4d) do { } while (0) #define p4d_clear(p4d) pgd_clear(p4d) #define p4d_val(p4d) pgd_val(p4d) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 4c9e150e5ad3..4be98f700862 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -284,26 +285,36 @@ struct page *vmalloc_to_page(const void *vmalloc_addr) if (pgd_none(*pgd)) return NULL; + p4d = p4d_offset(pgd, addr); if (p4d_none(*p4d)) return NULL; - pud = pud_offset(p4d, addr); + if (WARN_ON_ONCE(p4d_bad(*p4d))) + return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (p4d_large(*p4d)) + return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT); +#endif - /* - * Don't dereference bad PUD or PMD (below) entries. This will also - * identify huge mappings, which we may encounter on architectures - * that define CONFIG_HAVE_ARCH_HUGE_VMAP=y. Such regions will be - * identified as vmalloc addresses by is_vmalloc_addr(), but are - * not [unambiguously] associated with a struct page, so there is - * no correct value to return for them. - */ - WARN_ON_ONCE(pud_bad(*pud)); - if (pud_none(*pud) || pud_bad(*pud)) + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) + return NULL; + if (WARN_ON_ONCE(pud_bad(*pud))) return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (pud_large(*pud)) + return pud_page(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); +#endif + pmd = pmd_offset(pud, addr); - WARN_ON_ONCE(pmd_bad(*pmd)); - if (pmd_none(*pmd) || pmd_bad(*pmd)) + if (pmd_none(*pmd)) + return NULL; + if (WARN_ON_ONCE(pmd_bad(*pmd))) return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (pmd_large(*pmd)) + return pmd_page(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); +#endif ptep = pte_offset_map(pmd, addr); pte = *ptep;