Received: by 10.223.185.116 with SMTP id b49csp5605231wrg; Wed, 7 Mar 2018 14:56:07 -0800 (PST) X-Google-Smtp-Source: AG47ELs8Koh9ogRzIitNa+cMrXbDNJMoCkanZjEfqtcr0CPhEYJPz5hyCVUh4p/R6JP5THUn4r3r X-Received: by 10.98.210.70 with SMTP id c67mr24025489pfg.164.1520463367773; Wed, 07 Mar 2018 14:56:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520463367; cv=none; d=google.com; s=arc-20160816; b=g3wpALgGL+OJGeA5M9q7oXUtzmCbQcMSw0Zmu5b4HL3Knh6YKwu3Uv0EiNACYbtfBP x9lN0Hhgspzth6j40/kdTDpoqjuLRd20f3u/4Tw5+R4l61wLF9iqwmLnjNJtwmKvWvTK abRGDxw+DCg46uVXWuFUQHn6PKI68ZWnuspvzGCV7hjQ8ewy9EIfb0ylup+gWtdDWmuS LWYsL710KQbDpdjgxqhzAS+vMSHEMnWYTkQYvoFxUNjMkITYALsqEN/8UCjxi6HU4t52 42AOccOSAwq0C/vTOxobIhhz4iCBqP6jaLdCRZFtODaG+9Lsn1llXBGHKoMTh02xI8lM HZbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=DLhUps0dVmdGSsCAwt/UD6JDsW0Y30OQp1xCA6g3iRM=; b=fxjyTLeQ0Omg9znLpgoidsBiFDOov9UkAAPNFC6HExOxUDps7BhZmOOVoInyc+NFHT 5XVMwl+Z0XT6gAE0E3pHi3FHI6F3KtOdIDboNb3RgqfPlG0d3hXBJXSKYNCxYWqtMngo 1XcYAxmuVgAtz0Sjn6PLYZq7w2RyvTlcm7J182kjgg5LecsQh1syx6fqnG6DGED/Pk+L JZESYKtdiMhKMi9jDpm0cynNI/RV6aOu/OkHmkZnfyHf8HlWNPwlTeuQqPLCqM276QHE afl5bIfwLFEd3jSLWKtBRJInJJ46Ttq6C2Y6YFT+qSNHA/DUwX5w9GApq8vLJ27DqjMm 3apw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si14531194pfk.292.2018.03.07.14.55.53; Wed, 07 Mar 2018 14:56:07 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934362AbeCGWy5 (ORCPT + 99 others); Wed, 7 Mar 2018 17:54:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38428 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933533AbeCGWy4 (ORCPT ); Wed, 7 Mar 2018 17:54:56 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BD1F5103C; Wed, 7 Mar 2018 22:54:55 +0000 (UTC) Date: Wed, 7 Mar 2018 14:54:54 -0800 From: Andrew Morton To: Toshi Kani Cc: mhocko@suse.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, bp@suse.de, catalin.marinas@arm.com, guohanjun@huawei.com, will.deacon@arm.com, wxf.wang@hisilicon.com, linux-mm@kvack.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm/vmalloc: Add interfaces to free unused page table Message-Id: <20180307145454.d3df4bed6d6431c52bcf271e@linux-foundation.org> In-Reply-To: <20180307183227.17983-2-toshi.kani@hpe.com> References: <20180307183227.17983-1-toshi.kani@hpe.com> <20180307183227.17983-2-toshi.kani@hpe.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 7 Mar 2018 11:32:26 -0700 Toshi Kani wrote: > On architectures with CONFIG_HAVE_ARCH_HUGE_VMAP set, ioremap() > may create pud/pmd mappings. 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. > > 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. > > index 004abf9ebf12..942f4fa341f1 100644 > --- a/arch/x86/mm/pgtable.c > +++ b/arch/x86/mm/pgtable.c > @@ -702,4 +702,24 @@ int pmd_clear_huge(pmd_t *pmd) > > return 0; > } > + > +/** > + * pud_free_pmd_page - clear pud entry and free pmd page > + * > + * Returns 1 on success and 0 on failure (pud not cleared). > + */ > +int pud_free_pmd_page(pud_t *pud) > +{ > + return pud_none(*pud); > +} > + > +/** > + * pmd_free_pte_page - clear pmd entry and free pte page > + * > + * Returns 1 on success and 0 on failure (pmd not cleared). > + */ > +int pmd_free_pte_page(pmd_t *pmd) > +{ > + return pmd_none(*pmd); > +} Are these functions well named? I mean, the comment says "clear pud entry and free pmd page" but the implementatin does neither of those things. The name implies that the function frees a pmd_page but the callsites use the function as a way of querying state.