Received: by 10.213.65.68 with SMTP id h4csp1158782imn; Wed, 14 Mar 2018 11:17:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELvsDFY3Ocq0jSieOxIpEFdV//sfItFdUxclg6xBSmjxMV0Xikk2OqaR1/ZwYr95a/fSuu4y X-Received: by 2002:a17:902:a607:: with SMTP id u7-v6mr4875088plq.367.1521051474497; Wed, 14 Mar 2018 11:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521051474; cv=none; d=google.com; s=arc-20160816; b=HGdRBDB/q9HAEw+iVBXpnUErFTZ18PgLng2AChwfvlG9ComEsEwnlNzxrKwBdsboIy 4rpsCUJrfW65ZuUaBtOsOyjaDd4oYANL6xCMgykHIrEeV5pIDkFdwBLWQQMzF83fQK3O oStcDMBEKnFOr2Zxk/zUeW/lfOpBbl1WuI+BxvA5GXCLco2LzP9gresTlOlCtWrVV2PF Nk85oEhSMyFv7uOQTGikuwLPqDwkWFZSAGesNAJeNfi1DzoIykWLH5h3j+ya6M6W9OE7 FM8sQWi+k3T4UNF1cOD2mKfHdQYRC8hRRMlP+8dzb6oRm/rZzik4nANyASCPrIb65O+l CdMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=UClwCy4Czc7JTjeITKkO970GO8A1sKHGZfO8wt2zgKw=; b=j+wfMg8AA3JcNvE47dL6/7vM1emP8R9kKzQqyAZwKO3z/F8A0AfVNe1PvU8R8bVD/M 8bzuHVcqtGUeHZdJnnn3W86dScXt40gs4xeG/odgj3htWD/s+ub4CduVlRY2sso8gzG+ 6Uq7Do2vG9WguCT1XIw40Txd4aWRJeSlzR0PJfG2lUH91cZuQixmy99uF0o00Kv8+JSF 5/kTw86+fhFLsES7DbGs3eo3L13GBxyduN/MxnBRRCkFIDoU6PZmEQyuEjq50VwFZmmf 6UPEoRr7hPnSHY1R21/yRsVagtZVPqvGtEMlnm3aONSjUQ+5jYMUzeB7/ZiMw8RlySUg 6Row== 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 h2si2185895pgv.201.2018.03.14.11.17.08; Wed, 14 Mar 2018 11:17:54 -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; 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 S1752572AbeCNSL3 (ORCPT + 99 others); Wed, 14 Mar 2018 14:11:29 -0400 Received: from g4t3426.houston.hpe.com ([15.241.140.75]:41495 "EHLO g4t3426.houston.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752212AbeCNSL2 (ORCPT ); Wed, 14 Mar 2018 14:11:28 -0400 Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id 672178B; Wed, 14 Mar 2018 18:11:27 +0000 (UTC) Received: from misato.americas.hpqcorp.net (misato.americas.hpqcorp.net [10.34.81.122]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id CD517863; Wed, 14 Mar 2018 18:02:02 +0000 (UTC) From: Toshi Kani To: mhocko@suse.com, akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, bp@suse.de, catalin.marinas@arm.com Cc: guohanjun@huawei.com, will.deacon@arm.com, wxf.wang@hisilicon.com, willy@infradead.org, cpandya@codeaurora.org, linux-mm@kvack.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Toshi Kani , stable@vger.kernel.org Subject: [PATCH v2 2/2] x86/mm: implement free pmd/pte page interfaces Date: Wed, 14 Mar 2018 12:01:55 -0600 Message-Id: <20180314180155.19492-3-toshi.kani@hpe.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180314180155.19492-1-toshi.kani@hpe.com> References: <20180314180155.19492-1-toshi.kani@hpe.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement pud_free_pmd_page() and pmd_free_pte_page() on x86, which clear a given pud/pmd entry and free up lower level page table(s). Address range associated with the pud/pmd entry must have been purged by INVLPG. fixes: e61ce6ade404e ("mm: change ioremap to set up huge I/O mappings") Signed-off-by: Toshi Kani Cc: Michal Hocko Cc: Andrew Morton Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Borislav Petkov Cc: Matthew Wilcox Cc: --- arch/x86/mm/pgtable.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 1eed7ed518e6..34cda7e0551b 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -712,7 +712,22 @@ int pmd_clear_huge(pmd_t *pmd) */ int pud_free_pmd_page(pud_t *pud) { - return pud_none(*pud); + pmd_t *pmd; + int i; + + if (pud_none(*pud)) + return 1; + + pmd = (pmd_t *)pud_page_vaddr(*pud); + + for (i = 0; i < PTRS_PER_PMD; i++) + if (!pmd_free_pte_page(&pmd[i])) + return 0; + + pud_clear(pud); + free_page((unsigned long)pmd); + + return 1; } /** @@ -724,6 +739,15 @@ int pud_free_pmd_page(pud_t *pud) */ int pmd_free_pte_page(pmd_t *pmd) { - return pmd_none(*pmd); + pte_t *pte; + + if (pmd_none(*pmd)) + return 1; + + pte = (pte_t *)pmd_page_vaddr(*pmd); + pmd_clear(pmd); + free_page((unsigned long)pte); + + return 1; } #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */