From patchwork Mon Aug 30 23:59:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 12466151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3362C43214 for ; Tue, 31 Aug 2021 00:00:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6BFAE60F4B for ; Tue, 31 Aug 2021 00:00:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6BFAE60F4B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 78A5E94000F; Mon, 30 Aug 2021 20:00:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 739D294000E; Mon, 30 Aug 2021 20:00:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D956940010; Mon, 30 Aug 2021 20:00:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0198.hostedemail.com [216.40.44.198]) by kanga.kvack.org (Postfix) with ESMTP id 48A5B94000F for ; Mon, 30 Aug 2021 20:00:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0569918163977 for ; Tue, 31 Aug 2021 00:00:07 +0000 (UTC) X-FDA: 78533418054.23.57FB539 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf30.hostedemail.com (Postfix) with ESMTP id 7C13FE00198C for ; Tue, 31 Aug 2021 00:00:06 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10092"; a="205504356" X-IronPort-AV: E=Sophos;i="5.84,364,1620716400"; d="scan'208";a="205504356" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2021 17:00:05 -0700 X-IronPort-AV: E=Sophos;i="5.84,364,1620716400"; d="scan'208";a="530712949" Received: from ajinkyak-mobl2.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.212.240.95]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2021 17:00:04 -0700 From: Rick Edgecombe To: dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org, x86@kernel.org, akpm@linux-foundation.org, keescook@chromium.org, shakeelb@google.com, vbabka@suse.cz, rppt@kernel.org Cc: Rick Edgecombe , linux-mm@kvack.org, linux-hardening@vger.kernel.org, kernel-hardening@lists.openwall.com, ira.weiny@intel.com, dan.j.williams@intel.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 12/19] x86/mm: Use free_table in unmap path Date: Mon, 30 Aug 2021 16:59:20 -0700 Message-Id: <20210830235927.6443-13-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210830235927.6443-1-rick.p.edgecombe@intel.com> References: <20210830235927.6443-1-rick.p.edgecombe@intel.com> Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf30.hostedemail.com: domain of rick.p.edgecombe@intel.com has no SPF policy when checking 134.134.136.126) smtp.mailfrom=rick.p.edgecombe@intel.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7C13FE00198C X-Stat-Signature: c7dg8qzforfpb3tndc6zrac5ys39oxgw X-HE-Tag: 1630368006-623500 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Memory hot unplug and memremap unmap paths will free direct map page tables. So use free_table() for this. Signed-off-by: Rick Edgecombe --- arch/x86/mm/init_64.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index de5a785ee89f..c2680a77ca88 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -975,7 +975,7 @@ int arch_add_memory(int nid, u64 start, u64 size, return add_pages(nid, start_pfn, nr_pages, params); } -static void __meminit free_pagetable(struct page *page, int order) +static void __meminit free_pagetable(struct page *page, int order, bool table) { unsigned long magic; unsigned int nr_pages = 1 << order; @@ -991,8 +991,14 @@ static void __meminit free_pagetable(struct page *page, int order) } else while (nr_pages--) free_reserved_page(page++); - } else - free_pages((unsigned long)page_address(page), order); + } else { + if (table) { + /* The page tables will always be order 0. */ + free_table(page); + } else { + free_pages((unsigned long)page_address(page), order); + } + } } static void __meminit gather_table(struct page *page, struct list_head *tables) @@ -1008,7 +1014,7 @@ static void __meminit gather_table_finish(struct list_head *tables) list_for_each_entry_safe(page, next, tables, lru) { list_del(&page->lru); - free_pagetable(page, 0); + free_pagetable(page, 0, true); } } @@ -1018,7 +1024,7 @@ static void __meminit free_hugepage_table(struct page *page, if (altmap) vmem_altmap_free(altmap, PMD_SIZE / PAGE_SIZE); else - free_pagetable(page, get_order(PMD_SIZE)); + free_pagetable(page, get_order(PMD_SIZE), false); } static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd, struct list_head *tables) @@ -1102,7 +1108,7 @@ remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end, return; if (!direct) - free_pagetable(pte_page(*pte), 0); + free_pagetable(pte_page(*pte), 0, false); spin_lock(&init_mm.page_table_lock); pte_clear(&init_mm, addr, pte);