From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4280C43613 for ; Sun, 23 Jun 2019 09:45:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8AFDE20679 for ; Sun, 23 Jun 2019 09:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JqeYVSNx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AFDE20679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3DFD26B0008; Sun, 23 Jun 2019 05:45:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 390BC8E0002; Sun, 23 Jun 2019 05:45:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27FAD8E0001; Sun, 23 Jun 2019 05:45:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id E59C56B0008 for ; Sun, 23 Jun 2019 05:45:48 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id a13so7114312pgw.19 for ; Sun, 23 Jun 2019 02:45:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BUni308L4TNZcRdWweuUiutx4ej146UezPXSv2fRAeU=; b=dnGEh2Fq0CiYg/mxwRW1SZEoOUXxAPHNeJI/pwm7OORU/nV5MOb+Uucf4AI67zd8iM i2BSz0T/pnu5/LwHfoGyoxmACvOJgjQ6O1odyMF66rPq3Y/H5yV3g21p4bzFr/o1zsbF y1yH4nqzduEBZCPg4PULRILGgAtfncqpN61AUn6IUmHHVpWsrjnjD7JzmUfh1GUNbPFs HMV/o3mz/CirFC532dQu0uqsY7Hwa70Vy4weksHDD8KRwaoKnWBcfyZiTHh5mxy5k6Xm x7VqmLSmlSDB5I55FapKtPKfjt8OcT9vT48B7Op04ccfJWFM/VuVfVBjcliLgy2ElneN 9YmA== X-Gm-Message-State: APjAAAVs4I92t/zgAcsY/SPhkWHBBsg5HpMMnheDQpTS5F8QaeB36sdw Wv+igBq924ql2+xexPaStu62Ik22ROiULDb9HO86pGe9jTfL3bHbkwrEtKFHvo/GIySX4pVH28j hO8MIEHNvTvp9okZRYcXbSK92T/vHtWR+NQkk07/0R2BdxVIpTGZ/2w39Ogt0GbXZOA== X-Received: by 2002:a63:289:: with SMTP id 131mr21270725pgc.211.1561283148446; Sun, 23 Jun 2019 02:45:48 -0700 (PDT) X-Received: by 2002:a63:289:: with SMTP id 131mr21270664pgc.211.1561283147520; Sun, 23 Jun 2019 02:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561283147; cv=none; d=google.com; s=arc-20160816; b=Gxa0WETME/UaRPP1SDhR/B1szPhPqXyq2H0KerATPXhxQjiPwypSXc8IyYLyW4EbK7 Ke2OFuRXfebB8DjtcAd9TjvOVbrRmAGgUAE3bpdWrdnWn9Cpt2izM9YSHJLVaoY3JZwv sPQhryXlD4i+uIncHuolpRyQZlRulKRYZGADNe2+3VAQU4kKzcUHjHv5TE/vMBv7sXUy 0JNIl0MQPiZYegzIrkcjIVwpFH/+Yc66hmQwZPZf1C268WQcoe38USUdhRnt0kRjAJPR JbfThCAydCQXrDiSBNuBJoJ7bU5HIkKIUTRwgbiSYMAWgzENFVN87/5iVB8Cw3PSDxrh fIYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=BUni308L4TNZcRdWweuUiutx4ej146UezPXSv2fRAeU=; b=zWqALFj+1cy98W8yPZ1HtUO37XHP2q+RxNS1lXJPANDidI9hCoGY0Vy8XGlG4ERQnt MHOntsIBc5Pr464/d2m+5pB2ITNz6qDPuEqV/L3IEb7XJ51bbRXFVYADP2ntkNvVV56Z VWl2XAlHmQPbta0oKJxl/+kBVWe8Y6u9wcoK7f5QRcP947qIsvBBYPy4+zkjozlAVRGR zBHU7E9MqEz9WnX0HhCrn/eGzBgG8ypXXWNHf4vnP/+cOlLpTauW0t/It/sVQjXpD7X4 ZJ86vewsBERshbQwv7ZldwvDPdpkgDtAhhJHEegYiOs8RisJE2FT3nBlb0COkENQSwPY G++A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JqeYVSNx; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o5sor10736630pjp.20.2019.06.23.02.45.47 for (Google Transport Security); Sun, 23 Jun 2019 02:45:47 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JqeYVSNx; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-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 Cc: Nicholas Piggin , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Andrew Morton , Anshuman Khandual , Christophe Leroy , Ard Biesheuvel , Mark Rutland 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 Content-Transfer-Encoding: 8bit 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: 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; -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ACFAC43613 for ; Sun, 23 Jun 2019 09:52:40 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E67D920645 for ; Sun, 23 Jun 2019 09:52:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JqeYVSNx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E67D920645 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45Wnln5qm5zDqYp for ; Sun, 23 Jun 2019 19:52:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JqeYVSNx"; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45Wnbx72PDzDqXD for ; Sun, 23 Jun 2019 19:45:49 +1000 (AEST) Received: by mail-pg1-x541.google.com with SMTP id y72so5485765pgd.8 for ; Sun, 23 Jun 2019 02:45:49 -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=UolUyje79OCGcVc384yrJowiHyRhPJpUXGHbZ3oQKOb9XqbbPNRnVcy8HSQtS0n9ph pGnoCN3smUWEvQxqq2r67hQo7gAHF3uYhrUGSMQIUpg4+3gsWl4ZHWyPRHVcWutLG6Qz uBDcH7OXNMjgYbeukb/EoNwM0aTYQoHvV6pUuFFgZrdgeuXlikeBKcNfXu5cByLPHcKw H2Bk+Sz5RRUL2A6zEdvpZivlqEcMF9rjmiPNeff88xPeY8mrOaUBlA6jCqN2YUcM0bBl zrebDYc8HX2Ha6k9CbA80xSD10HQfruyrdMKclKNX4ZGXH5WjhasE1AQrj4il/HmQHxN SF9w== X-Gm-Message-State: APjAAAXixAAect0BehMEQo/z/etCKl0o33NhT5ZDi3qplbhBJ70ImVej UGVOrdbzS/rrasQ/PYKLkL8= 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 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Anshuman Khandual , Ard Biesheuvel , Nicholas Piggin , Andrew Morton , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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; -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44ACDC43613 for ; Sun, 23 Jun 2019 09:46:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA15920679 for ; Sun, 23 Jun 2019 09:46:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cj6DE38l"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JqeYVSNx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA15920679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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-In; 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel