Received: by 10.213.65.68 with SMTP id h4csp1027195imn; Tue, 27 Mar 2018 13:18:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx48AnCh+m2OXdC2m1ck32QhvHCKWYGoaDMk8BhSg+ouzXMZ8l4whYTpQqL1vMr2g4QQhVcce X-Received: by 2002:a17:902:a9c4:: with SMTP id b4-v6mr722745plr.333.1522181902263; Tue, 27 Mar 2018 13:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522181902; cv=none; d=google.com; s=arc-20160816; b=BnJ/Q78HZTJBex7PpYvlygYxOMtOeCppHFzh5P3DkbHcI8+WSYNVo7r4tX8cDQHv56 4LSJwz5eDI9kW9e+1f1zOBQa7BLOrePBfG8J2xv45ZbPyWNsWCaPE8HaggN1B2UgijWM ya2y930rrzcPEOmn/svDa1Goxitgxi74Y78mFk8zCxQl2JOTjX3numG9jAxdNO5elozd Wv1vpxpr949WNkxi0W5BMsECsn+RCHqOLz8RiedhkbTJqhHDM0RwJ1h1EEYboadcejYj SbYdhGPlWSuteU8rzwqxOzR944bD0ndTf5B43BcSoh7W4oEQqPcUhbHsrDELO0W8+iwi rxkQ== 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:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=XwB5qzG412DbX0qy53e9vdahl++P9zY5OT7U0vsBTgg=; b=oHHWga1WVCpIA/sVAE3XMJLJpwGMj8QqDN2eZrbKEfw0PhI/vu3tHy9eG3FELELeXV 2nd+822WpJNJnBlMbC8w3ekxo6EuszCz7LPeOlu9XHfD7cHSC+CSnBqp17JmW1ySs0cE bDfUY4b3dXj5309VFSa0oujCx9/CJ/5IuF6V2WKaLY59ihvjBB/QbUyrhjT6rP0jeGaB SjC7KY5UD0B2++NyQJHlO3In9wnmOXABJQPqSE5+HyMUuTUOT6WAufBTkmXTeEA067+8 jyHeGRvMsFSTwLEGxdduxaqIq9p+955lv7Jj3zilnwVTqWnKLSKd085ZsWhOoNCGI64g 2CzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kjTCr+2b; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e12si1365499pgv.507.2018.03.27.13.18.00; Tue, 27 Mar 2018 13:18:22 -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=@linaro.org header.s=google header.b=kjTCr+2b; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219AbeC0URF (ORCPT + 99 others); Tue, 27 Mar 2018 16:17:05 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:35179 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbeC0URC (ORCPT ); Tue, 27 Mar 2018 16:17:02 -0400 Received: by mail-it0-f68.google.com with SMTP id v194-v6so823429itb.0 for ; Tue, 27 Mar 2018 13:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=XwB5qzG412DbX0qy53e9vdahl++P9zY5OT7U0vsBTgg=; b=kjTCr+2bUro+ba2iF5YZxtOBvMM3BvZB2zoWR88Tu93k0ZLvCLihkwJowbxJ7k4/GC GsXvPh0jbYP8vgTxIdDPkasejBpDjp9T2vdor1rqOYoORJMq/9Do49rgTf7VfS3cQLCt XlLD/rzO85F5jODa8/bv5e9IC25dUkg1fSbd4= 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 :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=XwB5qzG412DbX0qy53e9vdahl++P9zY5OT7U0vsBTgg=; b=Mz6Zu+LBs2S8G1Wo0uum4n3fHNKh/KwvlKgWFArJ3S5vjrxqRkJ/t8uJGX8XrTZgZC jjwfcuFg1bRybggA2hF6YmfO8LOz00gONggWiL5mfDwdt2kYrFdEYwYjaOZJ2YUzJ4ru vAq+SQDlAaahBiEGR8pSAiu/YKs++CiZbaFVura5v07NduMRVELAZGZzfhhBs1fVt2g0 qxgQnGmzSqejW3R4N4ZkJI5hEXuaHCOPDdK3w4xX+SWFXjhLyh3Igi92Tsl1ZivALOih y3oT+xexFzDV8u1MCJnMYIRWL6CDjad7UAoS0i5ZliE7bhanU5dCra3yfXoOklX66EcZ 83mw== X-Gm-Message-State: AElRT7GuFYW75Zuju2pGy6h/OV0TFpmegHkYo/VQo/+VFrtQ3AqPx3oF DUyOBwqWXyNsa1LXmc6uiC2ICA== X-Received: by 2002:a24:ac07:: with SMTP id s7-v6mr747062ite.116.1522181821734; Tue, 27 Mar 2018 13:17:01 -0700 (PDT) Received: from localhost (c-68-47-89-210.hsd1.mn.comcast.net. [68.47.89.210]) by smtp.gmail.com with ESMTPSA id j28sm1390739iod.84.2018.03.27.13.17.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Mar 2018 13:17:01 -0700 (PDT) Date: Tue, 27 Mar 2018 15:17:00 -0500 From: Dan Rue To: Greg Kroah-Hartman Cc: 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: <20180327201700.xmgzgqox3sz3z32r@xps> Mail-Followup-To: 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 References: <20180327162716.407986916@linuxfoundation.org> <20180327162717.580646019@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180327162717.580646019@linuxfoundation.org> User-Agent: NeoMutt/20180223 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 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 > > --- > arch/arm64/mm/mmu.c | 10 ++++++++++ > arch/x86/mm/pgtable.c | 24 ++++++++++++++++++++++++ > include/asm-generic/pgtable.h | 10 ++++++++++ > lib/ioremap.c | 6 ++++-- > 4 files changed, 48 insertions(+), 2 deletions(-) > > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -697,3 +697,13 @@ void *__init fixmap_remap_fdt(phys_addr_ > > return dt_virt; > } > + > +int pud_free_pmd_page(pud_t *pud) > +{ > + return pud_none(*pud); > +} > + > +int pmd_free_pte_page(pmd_t *pmd) > +{ > + return pmd_none(*pmd); > +} > --- a/arch/x86/mm/pgtable.c > +++ b/arch/x86/mm/pgtable.c > @@ -666,4 +666,28 @@ int pmd_clear_huge(pmd_t *pmd) > > return 0; > } > + > +/** > + * pud_free_pmd_page - Clear pud entry and free pmd page. > + * @pud: Pointer to a PUD. > + * > + * Context: The pud range has been unmaped and TLB purged. > + * Return: 1 if clearing the entry succeeded. 0 otherwise. > + */ > +int pud_free_pmd_page(pud_t *pud) > +{ > + return pud_none(*pud); > +} > + > +/** > + * pmd_free_pte_page - Clear pmd entry and free pte page. > + * @pmd: Pointer to a PMD. > + * > + * Context: The pmd range has been unmaped and TLB purged. > + * Return: 1 if clearing the entry succeeded. 0 otherwise. > + */ > +int pmd_free_pte_page(pmd_t *pmd) > +{ > + return pmd_none(*pmd); > +} > #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ > --- a/include/asm-generic/pgtable.h > +++ b/include/asm-generic/pgtable.h > @@ -755,6 +755,8 @@ int pud_set_huge(pud_t *pud, phys_addr_t > int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); > int pud_clear_huge(pud_t *pud); > int pmd_clear_huge(pmd_t *pmd); > +int pud_free_pmd_page(pud_t *pud); > +int pmd_free_pte_page(pmd_t *pmd); > #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ > static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) > { > @@ -772,6 +774,14 @@ static inline int pmd_clear_huge(pmd_t * > { > return 0; > } > +static inline int pud_free_pmd_page(pud_t *pud) > +{ > + return 0; > +} > +static inline int pmd_free_pte_page(pmd_t *pmd) > +{ > + return 0; > +} > #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ > > #endif /* !__ASSEMBLY__ */ > --- a/lib/ioremap.c > +++ b/lib/ioremap.c > @@ -83,7 +83,8 @@ static inline int ioremap_pmd_range(pud_ > > if (ioremap_pmd_enabled() && > ((next - addr) == PMD_SIZE) && > - IS_ALIGNED(phys_addr + addr, PMD_SIZE)) { > + IS_ALIGNED(phys_addr + addr, PMD_SIZE) && > + pmd_free_pte_page(pmd)) { > if (pmd_set_huge(pmd, phys_addr + addr, prot)) > continue; > } > @@ -109,7 +110,8 @@ static inline int ioremap_pud_range(pgd_ > > if (ioremap_pud_enabled() && > ((next - addr) == PUD_SIZE) && > - IS_ALIGNED(phys_addr + addr, PUD_SIZE)) { > + IS_ALIGNED(phys_addr + addr, PUD_SIZE) && > + pud_free_pmd_page(pud)) { > if (pud_set_huge(pud, phys_addr + addr, prot)) > continue; > } > >