Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2816144pxb; Mon, 11 Jan 2021 22:05:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyisGaCKiG6f0LQkd4jQRC/kIexdstgtcWLaZnzjFoT8u8gjj4Q7uCP2FLigv/Aa5fS2pmg X-Received: by 2002:a17:907:d25:: with SMTP id gn37mr1072203ejc.381.1610431542485; Mon, 11 Jan 2021 22:05:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610431542; cv=none; d=google.com; s=arc-20160816; b=tFnhHLLxFazZYLN0AfYDm1suc1OTFhTBWL9zM+UIBF3Lv8AJByj2rIf5vbXloHNCi1 AWT00KKpBTpIEcjZm8OHRGfz/Ax2nk+sToXv6ZPKGT48Hwv6uvgBlW9mFhObpEe/anBg DPWZsjvCrRyHIEHmqxImBKyLmykvxG6ZhUFaFURM5GLKdcyR8ScOQ5IFJa9ogrNXU5Pi mfAkrFOStWU1R8Hn5YbE72MHFljiVkkiRlm+a+eRKVU1seWGwGnw4u48xxS3dt+5pCTl /I7zubGVRVIyLZUetoFe5TrqieG4f3Yx+SkzLBwN9gnGKMPOQR/+kvhZg40cfOG7Rn4q YDQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xMvhFe7bcQ6IOSQ+kphPHhhpuZ2atzznfPdds9sUdmM=; b=R8AeFIbV8ykpq6AQCNESXRIKzWFo1kuWBUuX0MMrXwGr5Fg25Rxj8PTYWEq/j1rgTi nUaQfG8FTUqO7k7d0tMGQJ6oDxHkXfbIcmc33bTzg2XhyI+YouXp5OH6/PO10FIFwz+S bt4PKZKhv3fe5LREksl5Ozwxc7LS56XLGSJ32YPp23Lkh+Si1sdMSyHy8+AGACnxgKuK sCQVtWBqm1kYK56xzfUsEtpSJcK9FNKoh8yBZhZHXn7sGPzMPq5Yn/zdfvk8NXbXwEj0 g3AtmRB6m1jgUcJxUPBTQtw/qUlPk2zg8OYEVTeKez3d4sbjdnDcUhXAf0kxYJW2eSJF pOMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=clltO46t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o23si822868edt.543.2021.01.11.22.05.18; Mon, 11 Jan 2021 22:05:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=clltO46t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731980AbhAKNle (ORCPT + 99 others); Mon, 11 Jan 2021 08:41:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:59308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731012AbhAKNMd (ORCPT ); Mon, 11 Jan 2021 08:12:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8CD9522795; Mon, 11 Jan 2021 13:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370737; bh=maoFeyNVcqarQ+CBTrSqZu7z/+dUHZnwukKGn83MjFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=clltO46tHmPjkY9YqQgZ4gPK+r+WIXcc6j0dh0TQaa30zKjF814NxUxOvO9fUKxlO mBkF3JY76Nol8l4PLVS+Q7Lat0DO2Dq0fM/PTqAWoYqs6eeR/KiMlUfzO4xyzVvrKb UWcAdNFG0GFXPTKcd/PCGA04UNDz3HXtmg22BDF0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams , Borislav Petkov , Yi Zhang , "Peter Zijlstra (Intel)" Subject: [PATCH 5.4 76/92] x86/mm: Fix leak of pmd ptlock Date: Mon, 11 Jan 2021 14:02:20 +0100 Message-Id: <20210111130042.817522329@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130039.165470698@linuxfoundation.org> References: <20210111130039.165470698@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Williams commit d1c5246e08eb64991001d97a3bd119c93edbc79a upstream. Commit 28ee90fe6048 ("x86/mm: implement free pmd/pte page interfaces") introduced a new location where a pmd was released, but neglected to run the pmd page destructor. In fact, this happened previously for a different pmd release path and was fixed by commit: c283610e44ec ("x86, mm: do not leak page->ptl for pmd page tables"). This issue was hidden until recently because the failure mode is silent, but commit: b2b29d6d0119 ("mm: account PMD tables like PTE tables") turns the failure mode into this signature: BUG: Bad page state in process lt-pmem-ns pfn:15943d page:000000007262ed7b refcount:0 mapcount:-1024 mapping:0000000000000000 index:0x0 pfn:0x15943d flags: 0xaffff800000000() raw: 00affff800000000 dead000000000100 0000000000000000 0000000000000000 raw: 0000000000000000 ffff913a029bcc08 00000000fffffbff 0000000000000000 page dumped because: nonzero mapcount [..] dump_stack+0x8b/0xb0 bad_page.cold+0x63/0x94 free_pcp_prepare+0x224/0x270 free_unref_page+0x18/0xd0 pud_free_pmd_page+0x146/0x160 ioremap_pud_range+0xe3/0x350 ioremap_page_range+0x108/0x160 __ioremap_caller.constprop.0+0x174/0x2b0 ? memremap+0x7a/0x110 memremap+0x7a/0x110 devm_memremap+0x53/0xa0 pmem_attach_disk+0x4ed/0x530 [nd_pmem] ? __devm_release_region+0x52/0x80 nvdimm_bus_probe+0x85/0x210 [libnvdimm] Given this is a repeat occurrence it seemed prudent to look for other places where this destructor might be missing and whether a better helper is needed. try_to_free_pmd_page() looks like a candidate, but testing with setting up and tearing down pmd mappings via the dax unit tests is thus far not triggering the failure. As for a better helper pmd_free() is close, but it is a messy fit due to requiring an @mm arg. Also, ___pmd_free_tlb() wants to call paravirt_tlb_remove_table() instead of free_page(), so open-coded pgtable_pmd_page_dtor() seems the best way forward for now. Debugged together with Matthew Wilcox . Fixes: 28ee90fe6048 ("x86/mm: implement free pmd/pte page interfaces") Signed-off-by: Dan Williams Signed-off-by: Borislav Petkov Tested-by: Yi Zhang Acked-by: Peter Zijlstra (Intel) Cc: Link: https://lkml.kernel.org/r/160697689204.605323.17629854984697045602.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pgtable.c | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -826,6 +826,8 @@ int pud_free_pmd_page(pud_t *pud, unsign } free_page((unsigned long)pmd_sv); + + pgtable_pmd_page_dtor(virt_to_page(pmd)); free_page((unsigned long)pmd); return 1;