Received: by 10.213.65.68 with SMTP id h4csp1039078imn; Tue, 27 Mar 2018 13:34:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+DAvQBNLDhvuS/Tx08sPTPTu4doBCrYxU2wy4TQ//zYDm0UtbavzVqRd4Vacd9+Y/iixpk X-Received: by 2002:a17:902:1665:: with SMTP id g92-v6mr740865plg.195.1522182854193; Tue, 27 Mar 2018 13:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522182854; cv=none; d=google.com; s=arc-20160816; b=Jqd0enzWZaTqTh0PG5WgavX+CjCbDVNrBckmXhNLSqoXy9T1j/9Bubrhsq4aKkwrcR HHl8mkir3csMOT7SDBb3BfiPJuZpf4ETSAdWTfPIFSiIGBARZu8uk8yeFs1N0RP38pOH Tv1pTABhGyFjOz0L6gS14AKAwiDm6nPDC4Xez290mnowqSZ1CnedROa6T+KCK9MvuEq0 qV5h1mDvWoUGJzVUf2HzoCjK7NtGSpBD5IYyjaFABRgQXWmKnnUA10C6C3ES0NG/LlMq 4Od9qmwexhkVGITbWVMhJJePGpf4v77SUEy/NOZpb0fLmW3NCO7CCZxEZm57ZTJEJwOs K+Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=nylL2xF9GIT4GiE6YwsEffiWBnNMlorDG8wQ1O0wZRw=; b=J8tTUNdd3kRYOk7bnlGhpY6gXYHx5Htjm/na0FM/nBgXYsc6gcePTk6KYDS5MjXjKL MM/CMxl1a99vD+DmoU44PQIZ6442lmyIzTf+CY9xKtJub1OavSno9C7uozCBPYF1j8fv Pug09kuDqJwuXLpH+7fvRX05XNx1m8H1PG3Ibsq8RE/+ycD0+NdzYqkiRp/gf6MKB7Q6 9Oag9jbqhVUnrSP/vfOB5465iG+JkYnwxX5PH7kKjqc2sV6hcgiF4sHDatOi5fVX+Otg P5fewe4z/ZcBJ4uBZYNyEPH6BLPFT7qfS9dCCNYFm1saVLjnttY9vJQyH+l0HXk3hwuv HlpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DcRANoek; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e19si1447954pff.275.2018.03.27.13.33.34; Tue, 27 Mar 2018 13:34:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DcRANoek; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751182AbeC0Ubi (ORCPT + 99 others); Tue, 27 Mar 2018 16:31:38 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:36124 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750966AbeC0Ubg (ORCPT ); Tue, 27 Mar 2018 16:31:36 -0400 Received: by mail-pg0-f68.google.com with SMTP id 201so78850pgg.3; Tue, 27 Mar 2018 13:31:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=nylL2xF9GIT4GiE6YwsEffiWBnNMlorDG8wQ1O0wZRw=; b=DcRANoekeZxdHhhr/dywM5+Hm16bpFRyivaie6VK6h6LM4L2/BZGLwRcZWd1NQh3Yw GaC/JtMM3AjqWGP5JR4xH3+YZUoeat8xuO6jKtSp3lfauOfix9zSf8ioKkP6XbB5Ytds RSSCEmLLsV46rqCvEeT6cswUFKg5QfD19PisLha14NyTp11R3NYygrlNxKAXJNZYOWgi z62NY+BEWYeA7w452IO/7oDEbm9n8GFrsXVrZk19aAbwdUD88bDp3lHWwh7Enx7NMaHT eDOpkU5GRpjvoEyk1dHzEMQ9AzpO0bVcjyz88syFA5ULehp2c1RUHsS/XIlpQMxt9WJf fX/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=nylL2xF9GIT4GiE6YwsEffiWBnNMlorDG8wQ1O0wZRw=; b=I544erK4GnXVVjh3I5IjgW1kp3v3Narm+X36h0Utf1dP4FbqBODqRkzbi4buawkStr IzsUVwEsf1S1wNFF8yR0/bXApYLXYVauqLmQU9Ca+YDf10oN50G48JRdXpbnwrMT5QfZ EPvQuS4Otu7v0HHfEhbLw8e3m+MgjhNJl+BkkMS6fH/tDe5P+mepq9Lf3RKdCRDIIcRB 0kBuNbjGU7C2UqqnrY5zU2Zg+tDQI8XdZIVOuUDlhN5JI6byuoQI6NZCOJkLioAvtWjE 43ZYDHti2XKn7irIQe3gezIxuKUi2005i/yLCeKw6qbfr6fvacD0eVV8SqhJla2462AR NTUQ== X-Gm-Message-State: AElRT7E0h9lY15MERvIGg84jR3SWQVw7k/raxDwneiWBScfsTeGYDqLQ b3ntFt+EoKVPIjd14Aq+6bWtgziWfoE= X-Received: by 10.99.168.13 with SMTP id o13mr535294pgf.198.1522182695681; Tue, 27 Mar 2018 13:31:35 -0700 (PDT) Received: from localhost ([4.14.65.228]) by smtp.gmail.com with ESMTPSA id x1sm4969971pfk.144.2018.03.27.13.31.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 13:31:35 -0700 (PDT) Date: Tue, 27 Mar 2018 13:31:30 -0700 From: Nathan Chancellor To: Dan Rue Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Lei Li , Toshi Kani , Catalin Marinas , Wang Xuefeng , Will Deacon , Hanjun Guo , Michal Hocko , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Matthew Wilcox , Chintan Pandya , Andrew Morton , Linus Torvalds Subject: Re: [PATCH 4.4 20/43] mm/vmalloc: add interfaces to free unmapped page table Message-ID: <20180327203130.GA18921@localhost> References: <20180327162716.407986916@linuxfoundation.org> <20180327162717.580646019@linuxfoundation.org> <20180327201700.xmgzgqox3sz3z32r@xps> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180327201700.xmgzgqox3sz3z32r@xps> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 27, 2018 at 03:17:00PM -0500, Dan Rue wrote: > On Tue, Mar 27, 2018 at 06:27:24PM +0200, Greg Kroah-Hartman wrote: > > 4.4-stable review patch. If anyone has any objections, please let me know. > > > > ------------------ > > > > From: Toshi Kani > > > > commit b6bdb7517c3d3f41f20e5c2948d6bc3f8897394e upstream. > > > > On architectures with CONFIG_HAVE_ARCH_HUGE_VMAP set, ioremap() may > > create pud/pmd mappings. A kernel panic was observed on arm64 systems > > with Cortex-A75 in the following steps as described by Hanjun Guo. > > > > 1. ioremap a 4K size, valid page table will build, > > 2. iounmap it, pte0 will set to 0; > > 3. ioremap the same address with 2M size, pgd/pmd is unchanged, > > then set the a new value for pmd; > > 4. pte0 is leaked; > > 5. CPU may meet exception because the old pmd is still in TLB, > > which will lead to kernel panic. > > > > This panic is not reproducible on x86. INVLPG, called from iounmap, > > purges all levels of entries associated with purged address on x86. x86 > > still has memory leak. > > > > The patch changes the ioremap path to free unmapped page table(s) since > > doing so in the unmap path has the following issues: > > > > - The iounmap() path is shared with vunmap(). Since vmap() only > > supports pte mappings, making vunmap() to free a pte page is an > > overhead for regular vmap users as they do not need a pte page freed > > up. > > > > - Checking if all entries in a pte page are cleared in the unmap path > > is racy, and serializing this check is expensive. > > > > - The unmap path calls free_vmap_area_noflush() to do lazy TLB purges. > > Clearing a pud/pmd entry before the lazy TLB purges needs extra TLB > > purge. > > > > Add two interfaces, pud_free_pmd_page() and pmd_free_pte_page(), which > > clear a given pud/pmd entry and free up a page for the lower level > > entries. > > > > This patch implements their stub functions on x86 and arm64, which work > > as workaround. > > > > [akpm@linux-foundation.org: fix typo in pmd_free_pte_page() stub] > > Link: http://lkml.kernel.org/r/20180314180155.19492-2-toshi.kani@hpe.com > > Fixes: e61ce6ade404e ("mm: change ioremap to set up huge I/O mappings") > > Reported-by: Lei Li > > Signed-off-by: Toshi Kani > > Cc: Catalin Marinas > > Cc: Wang Xuefeng > > Cc: Will Deacon > > Cc: Hanjun Guo > > Cc: Michal Hocko > > Cc: Thomas Gleixner > > Cc: Ingo Molnar > > Cc: "H. Peter Anvin" > > Cc: Borislav Petkov > > Cc: Matthew Wilcox > > Cc: Chintan Pandya > > Cc: > > Signed-off-by: Andrew Morton > > Signed-off-by: Linus Torvalds > > Signed-off-by: Greg Kroah-Hartman > > This patch causes the following build error on 4.4 arm64: > > $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=build-arm64 defconfig > $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=build-arm64 > > CC arch/arm64/mm/mmu.o > ../arch/arm64/mm/mmu.c:701:5: error: redefinition of ‘pud_free_pmd_page’ > int pud_free_pmd_page(pud_t *pud) > ^~~~~~~~~~~~~~~~~ > In file included from ../arch/arm64/include/asm/pgtable.h:682:0, > from ../include/linux/mm.h:55, > from ../include/linux/mman.h:4, > from ../arch/arm64/mm/mmu.c:25: > ../include/asm-generic/pgtable.h:777:19: note: previous definition of ‘pud_free_pmd_page’ was here > static inline int pud_free_pmd_page(pud_t *pud) > ^~~~~~~~~~~~~~~~~ > ../arch/arm64/mm/mmu.c:706:5: error: redefinition of ‘pmd_free_pte_page’ > int pmd_free_pte_page(pmd_t *pmd) > ^~~~~~~~~~~~~~~~~ > In file included from ../arch/arm64/include/asm/pgtable.h:682:0, > from ../include/linux/mm.h:55, > from ../include/linux/mman.h:4, > from ../arch/arm64/mm/mmu.c:25: > ../include/asm-generic/pgtable.h:781:19: note: previous definition of ‘pmd_free_pte_page’ was here > static inline int pmd_free_pte_page(pmd_t *pmd) > ^~~~~~~~~~~~~~~~~ > make[2]: *** [../scripts/Makefile.build:270: arch/arm64/mm/mmu.o] Error 1 > make[1]: *** [/home/drue/src/linux/4.4-rc/Makefile:969: arch/arm64/mm] Error 2 > make[1]: Leaving directory '/home/drue/src/linux/4.4-rc/build-arm64' > make: *** [Makefile:152: sub-make] Error 2 > > Both of my arm64 devices built fine with this patch... It seems like the only way to hit that error is if HAVE_ARCH_HUGE_VMAP isn't set, which seems impossible since it is selected by ARM64... Someone smarter than I might have more insight but this patch is unchanged from upstream so I can only assume that this error would manifest there as well. Cheers! Nathan