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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 93FECC43613 for ; Mon, 24 Jun 2019 06:52:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B69A20665 for ; Mon, 24 Jun 2019 06:52:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B69A20665 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8DD428E0002; Mon, 24 Jun 2019 02:52:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88E2D8E0001; Mon, 24 Jun 2019 02:52:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 757398E0002; Mon, 24 Jun 2019 02:52:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 285808E0001 for ; Mon, 24 Jun 2019 02:52:41 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id s7so18994678edb.19 for ; Sun, 23 Jun 2019 23:52:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :references:from:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=ravRVdrefX3LmEH8E9wTic6GQVrIv9Dyv6IzjGnHH0A=; b=NRO2/cqUW/rN9qh6hEuQdzBQ+JzEOK+axQavfewiSSWj4Vx9G4rpNsvNtDwwBTmOme fycWo7OBwwQ4yU0HUZOTm1/2a6ogfFAL+STndCPFlxoNvJth8N6INhSedjKdaTRAXNcn mB2GEiKhqO6dHUZHy9HeP5L/6xCaMdzmwHQTSuwJBHHTMJTsNR3snmyXrrGNsfPFYVTm J4wdOyc1j+m/a9coLSoPEZILirnhtX/Osk69iX8CF5+C1ZWx6bTfBBfZU04iG7lKBzni uJntem6TOtIvwHnmYrwtToYbecDZgqPhS/p5chJmHCoF6ZMy7ANRx9sVa/rHiTi/uZWr fgXg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com X-Gm-Message-State: APjAAAUfpr/Lu4RQ1aPvrQIDAfewV7KBQB5TAjJ/kdFMxXDje4P0Ef3e oDB0kdoFBhdItfqgHwP8eUPAOrbaoM2fgDnqaDqNtxQ1/xKNdcWlSdrycQRyT2l7lh9K7npXHFP exJctTeeKnNV0GtBhuHw/0j/DHeCT3ISUE6zZOPAMh6nGFXEKjja+NWUwH9gAjMFaqA== X-Received: by 2002:a05:6402:134c:: with SMTP id y12mr61522953edw.96.1561359160620; Sun, 23 Jun 2019 23:52:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqy45gRmCDJdkqZdEPlYDG+ZyPpJpkZn/fmhhRD5sjUCdU1zxAsGsCErvQmicX2/Tg7/kJK1 X-Received: by 2002:a05:6402:134c:: with SMTP id y12mr61522907edw.96.1561359159728; Sun, 23 Jun 2019 23:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561359159; cv=none; d=google.com; s=arc-20160816; b=lyDQ+EhD/7cWtdg9VoAdkVdAdFzyGEX8IZr6zX3fkGxUrEUjuyhJE5F5qC0LAOC+8E KDlHRSVr215wwYUA5FrVdlEPjLWWYY/bAt+nZpzMwV8XokADxz1dHI/lw7smPEtXdJf5 DyWZQoxZNd/fPcOGdqUXTs80p1T1mW278pzCPHHOVx++1fR9fXpaa+jUaQ1xABKpCLn5 XH6Ebh8gQwtIf6udA2Mj1oko4P8DG/xyhzh7fL0BitSV/qaXM3xDmgmQHEOi5HxpE6rf wU8r/0w+6aRhnhX7CgjMK4bu9Ajrz32f6frf6NfipInJllUCEZiu/7fqNuBDkGTabBQr rH9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject; bh=ravRVdrefX3LmEH8E9wTic6GQVrIv9Dyv6IzjGnHH0A=; b=Czr/n6EWT3dR0NUN333Idm3l//HbrDaROrqjRnr+S08Rn8KHhAh4M4GuIxaDYHJkx0 dE9gZN5QWbmcKqbaNTUJyA8av/gtFoPjL0xLPXYF1HhZ7CR7QONc7AyZn4E70CVdpd0q +ccIaHSMMnO2Dpx4rWzhol6C/6LceaHIivOL9uXKp4/CQsPr3WDjDB0/qNl8gAKMmbpn dI2duPg5edi8nkM5vgbGV3qf/QUc8erKvBUszHwIXUDJ0WmyBH7LGx6f48YpChpmPwLq qWPYh1my8c6BDWpAVZ7xuDtVWikBXtfcMkXjuEfJUgRnjF/JOb9YL441CDPBIT2clyHN 0OXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.110.172]) by mx.google.com with ESMTP id s13si8947268edb.309.2019.06.23.23.52.39 for ; Sun, 23 Jun 2019 23:52:39 -0700 (PDT) Received-SPF: pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) client-ip=217.140.110.172; Authentication-Results: mx.google.com; spf=pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7C6152B; Sun, 23 Jun 2019 23:52:38 -0700 (PDT) Received: from [10.162.41.123] (p8cg001049571a15.blr.arm.com [10.162.41.123]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 61E2B3F246; Sun, 23 Jun 2019 23:54:24 -0700 (PDT) Subject: Re: [PATCH 3/3] mm/vmalloc: fix vmalloc_to_page for huge vmap mappings To: Nicholas Piggin , linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Andrew Morton , Christophe Leroy , Ard Biesheuvel , Mark Rutland References: <20190623094446.28722-1-npiggin@gmail.com> <20190623094446.28722-4-npiggin@gmail.com> From: Anshuman Khandual Message-ID: <8668f76d-faad-4e57-2f7b-f2b8969b1026@arm.com> Date: Mon, 24 Jun 2019 12:22:59 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190623094446.28722-4-npiggin@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 06/23/2019 03:14 PM, Nicholas Piggin wrote: > 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; The warning here is a required addition but it needs to be moved after p4d_large() check. Please see the next comment below. > +#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 > + pud_bad() on arm64 returns true when the PUD does not point to a next page table page implying the fact that it might be a large/huge entry. I am not sure if the semantics holds good for other architectures too. But on arm64 if pud_large() is true, then pud_bad() will be true as well. So pud_bad() check must happen after pud_large() check. So the sequence here should be 1. pud_none() --> Nothing is in here, return NULL 2. pud_large() --> Return offset page address from the huge page mapping 3. pud_bad() --> Return NULL as there is no more page table level left Checking pud_bad() first can return NULL for a valid huge mapping. > 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 Ditto. I see that your previous proposal had this right which got changed in this manner after my comments. Sorry about it. It was recently when I learned (correctly) that expected semantics of pxx_bad() is that - It does not point to the next page table page. Hence I wonder why is this not renamed as pxx_table() instead to make it absolutely clear.