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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 223BFC433E0 for ; Sun, 24 Jan 2021 08:23:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 91F7722582 for ; Sun, 24 Jan 2021 08:23:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91F7722582 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 10B826B0008; Sun, 24 Jan 2021 03:23:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BF246B000A; Sun, 24 Jan 2021 03:23:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC44D6B000C; Sun, 24 Jan 2021 03:23:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id D2DE16B0008 for ; Sun, 24 Jan 2021 03:23:00 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8A7121EE6 for ; Sun, 24 Jan 2021 08:23:00 +0000 (UTC) X-FDA: 77739978120.13.birth84_0701d7e2757b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 6D64C18140B7B for ; Sun, 24 Jan 2021 08:23:00 +0000 (UTC) X-HE-Tag: birth84_0701d7e2757b X-Filterd-Recvd-Size: 6529 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Sun, 24 Jan 2021 08:22:59 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id q2so2976025plk.4 for ; Sun, 24 Jan 2021 00:22:59 -0800 (PST) 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=MjsjuAh+yTiFeI37LQ2ROLPGWlcSvFIMmiFEgOfHCAQ=; b=eoMW7GTVmr9o4bjF6Osj2CJExu/gpEdeNUUo1N+H3CelvPOleQu5cGtPoy2hMTKGQO iPWlEV6sb9Bkf/WxuWioVBu/Zf2xX/zuX6ec40GxcYSBHL08MDoqew6msLSgnv1m97Ri IOIwpbwjdWXqZeszC25ZkbyMeRlx+QsLLA90LzSryZnekHySSvJ6OAdJS52ZID+dLvXB olweo3yleJ3Mi97DWIyC5cYehEu80M3+BAU6/TF8bcuZGVZURMpq3XRZd26h8h2LFlun 2PnCuEhsytdNU+gGBrohRKdVTdqfA2ULKM3/9dHO0rWFYGKCvOH4EeA+/AIrVsTECyY2 jq+A== 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=MjsjuAh+yTiFeI37LQ2ROLPGWlcSvFIMmiFEgOfHCAQ=; b=D7bQIUAKE/YXVI8nx9Cqv4c1TEms7+wP/BM1IENFHNwsNn1jTnNVv20PqMbwnj1skV EBqb1fMLQbpTKHlbZjnCwgW2YS/DqwUqPFoGxiP93Mst5BzYMOW7Hjs1nPuvEzV9dbE9 V7vgHnicQgjaRUpj3klXOVKldHBid2anPMakAFYMnv9pe9Cl1EMded4EpNzdxp3SNTZM 6VEk3vRO1Zb6Z0ImV8jaVj3wvcmUwcDTcfEqtbHOmQwb1tLwEkNERL1QnumXW8cPUzHt 11gZN2tl+8PblMgD4QZfONRnpCFvXer210mCG9HYpst5sdTk7vLirUt7SWGWjzPJ1nUu ckig== X-Gm-Message-State: AOAM532Bg8MdDiA9VbojPLNJLex/ntg5NDQab4R3G2DeEv2toKWp/ak8 bZ+6p3iOT+O4u/vl4GLDT1kOIzmGbcw= X-Google-Smtp-Source: ABdhPJw9eMUNU9DyqDg8M16Otuc3OE05frnBZNYjYRp7v9azdMe2JzhBv/W8zetDEcrCuHdciKeZ9A== X-Received: by 2002:a17:90a:d189:: with SMTP id fu9mr15168573pjb.98.1611476578988; Sun, 24 Jan 2021 00:22:58 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([124.170.13.62]) by smtp.gmail.com with ESMTPSA id gb12sm11799757pjb.51.2021.01.24.00.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 00:22:58 -0800 (PST) From: Nicholas Piggin To: linux-mm@kvack.org, Andrew Morton Cc: Nicholas Piggin , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Zefan Li , Jonathan Cameron , Christoph Hellwig , Christophe Leroy , Rick Edgecombe , Ding Tianhong Subject: [PATCH v10 01/12] mm/vmalloc: fix vmalloc_to_page for huge vmap mappings Date: Sun, 24 Jan 2021 18:22:19 +1000 Message-Id: <20210124082230.2118861-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210124082230.2118861-1-npiggin@gmail.com> References: <20210124082230.2118861-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- mm/vmalloc.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index e6f352bf0498..62372f9e0167 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -34,7 +34,7 @@ #include #include #include - +#include #include #include #include @@ -343,7 +343,9 @@ int is_vmalloc_or_module_addr(const void *x) } =20 /* - * Walk a vmap address to the struct page it maps. + * Walk a vmap address to the struct page it maps. Huge vmap mappings wi= ll + * return the tail page that corresponds to the base page address, which + * matches small vmap mappings. */ struct page *vmalloc_to_page(const void *vmalloc_addr) { @@ -363,25 +365,33 @@ struct page *vmalloc_to_page(const void *vmalloc_ad= dr) =20 if (pgd_none(*pgd)) return NULL; + if (WARN_ON_ONCE(pgd_leaf(*pgd))) + return NULL; /* XXX: no allowance for huge pgd */ + if (WARN_ON_ONCE(pgd_bad(*pgd))) + return NULL; + p4d =3D p4d_offset(pgd, addr); if (p4d_none(*p4d)) return NULL; - pud =3D pud_offset(p4d, addr); + if (p4d_leaf(*p4d)) + return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT); + if (WARN_ON_ONCE(p4d_bad(*p4d))) + return NULL; =20 - /* - * 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=3Dy. 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 =3D pud_offset(p4d, addr); + if (pud_none(*pud)) + return NULL; + if (pud_leaf(*pud)) + return pud_page(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); + if (WARN_ON_ONCE(pud_bad(*pud))) return NULL; + pmd =3D pmd_offset(pud, addr); - WARN_ON_ONCE(pmd_bad(*pmd)); - if (pmd_none(*pmd) || pmd_bad(*pmd)) + if (pmd_none(*pmd)) + return NULL; + if (pmd_leaf(*pmd)) + return pmd_page(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); + if (WARN_ON_ONCE(pmd_bad(*pmd))) return NULL; =20 ptep =3D pte_offset_map(pmd, addr); @@ -389,6 +399,7 @@ struct page *vmalloc_to_page(const void *vmalloc_addr= ) if (pte_present(pte)) page =3D pte_page(pte); pte_unmap(ptep); + return page; } EXPORT_SYMBOL(vmalloc_to_page); --=20 2.23.0