Received: by 10.223.185.116 with SMTP id b49csp5323914wrg; Wed, 7 Mar 2018 09:50:32 -0800 (PST) X-Google-Smtp-Source: AG47ELvoUk0HJ1aGB72Md9cpS9nsOPeev2joQ7FZq43+iqDDBSHwnqwqJgGZZaS6U4/09Dl52Po3 X-Received: by 2002:a17:902:9a8d:: with SMTP id w13-v6mr7342075plp.136.1520445032475; Wed, 07 Mar 2018 09:50:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520445032; cv=none; d=google.com; s=arc-20160816; b=FOAxwfkvyMaeUROF861vjSuqcYgq71DBa4KLDQ6arabcdsGgdMR3wBKb413jgCo0eB 4YbfhpS+lVIK55WWoWozbraSVL3Lc597Qg5/hWD9OM7dT1QLWLmJIzz2mqQGDhrfnqOJ CSXKZVhQdTTqo9dBbFiaA6zjsxk/OvzLNnYpsvN8JjJ+mhYYPl0RQc68mZxxUmp2tdrg H1GVpo2LxqGD+2wYxotZYIF/BHA2Yv82WR/uMaIdb/+hLuf5ynGMsG9HIJwJGuK8RN3w /9i3EUH8vhra7Dd8+OcPIducgUkkGDsJwmkRhpoMjO+OegF4P3KkVdQv8o6weOK5ZEvT WBOg== 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=1InIV2+vwPNAIxuMAgGFDXDkvBXgB/wMTKmutR1IK2o=; b=Hwh5tKyRq8qW5A67jnlcRJNeSRp/kavzY8CRmmtHY0waAa/o+F1neMsfYJ6APWiabe hVthWj9FCCE8EnGgjc7Jr85hXD+voZ5v5oFaVAGDLiFHqXXQF6ugjYQCU3ykq+bj41oB iQ1ME34tp9E0GoIebiJXA3UIb05/jNiEmvHKgM9xlmj9ivpm5Ycz8Pgkl1RLritULlQa TbIjHJkBSk8P7Uvyb7kBba2nafK/WHr3gC3pxhm4djcPcbuFKzOjXSShljlYZGci1Pyk 3FNtc0nKi2hQ3V72Sa1NmNu+H0QHoPkknfxH7dbf0G1h2hIV7PMRuerytckmkhxASAGH ACvw== 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 t75si14180513pfe.77.2018.03.07.09.50.17; Wed, 07 Mar 2018 09:50:32 -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 S934032AbeCGRr7 (ORCPT + 99 others); Wed, 7 Mar 2018 12:47:59 -0500 Received: from g2t2352.austin.hpe.com ([15.233.44.25]:54233 "EHLO g2t2352.austin.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932905AbeCGRri (ORCPT ); Wed, 7 Mar 2018 12:47:38 -0500 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 0C666AF; Wed, 7 Mar 2018 17:47:36 +0000 (UTC) Received: from misato.americas.hpqcorp.net (misato.americas.hpqcorp.net [10.34.81.122]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 480D436; Wed, 7 Mar 2018 17:47:36 +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, linux-mm@kvack.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Toshi Kani Subject: [PATCH 2/2] x86/mm: implement free pmd/pte page interfaces Date: Wed, 7 Mar 2018 11:32:27 -0700 Message-Id: <20180307183227.17983-3-toshi.kani@hpe.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180307183227.17983-1-toshi.kani@hpe.com> References: <20180307183227.17983-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. Signed-off-by: Toshi Kani Cc: Michal Hocko Cc: Andrew Morton Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Borislav Petkov --- 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 942f4fa341f1..121c0114439e 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -710,7 +710,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; } /** @@ -720,6 +735,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 */