From patchwork Wed Jan 13 07:35:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 12015977 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=-13.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 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 867E5C433E0 for ; Wed, 13 Jan 2021 07:35:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16EB923139 for ; Wed, 13 Jan 2021 07:35:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16EB923139 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 910206B00D1; Wed, 13 Jan 2021 02:35:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BE506B00D4; Wed, 13 Jan 2021 02:35:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 788058D0007; Wed, 13 Jan 2021 02:35:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 5EB5C6B00D1 for ; Wed, 13 Jan 2021 02:35:44 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 36F2B3631 for ; Wed, 13 Jan 2021 07:35:43 +0000 (UTC) X-FDA: 77699942166.25.waves71_52112d42751c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id A49411804E3A1 for ; Wed, 13 Jan 2021 07:35:42 +0000 (UTC) X-HE-Tag: waves71_52112d42751c X-Filterd-Recvd-Size: 4108 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 07:35:41 +0000 (UTC) IronPort-SDR: q8gHyqoJp7bKt9+UkG1iYdLg/N4uX665smB0sL4vFcIpcfcV9PodhUkngHjF2LTqzvYsEoLsuN F8/cSuexqyQg== X-IronPort-AV: E=McAfee;i="6000,8403,9862"; a="177387900" X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="177387900" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:40 -0800 IronPort-SDR: ezqcf/6BUl4DeaFj02snXJ1RB3gza6UdaG1mXU+AXURDPOlEORbq7fRGK5E8JXNg2KsddJlPwd vbMgW9RkpGMg== X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="389412785" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:39 -0800 Subject: [PATCH v3 4/6] mm: Fix page reference leak in soft_offline_page() From: Dan Williams To: linux-mm@kvack.org Cc: Andrew Morton , Naoya Horiguchi , Michal Hocko , David Hildenbrand , Oscar Salvador , stable@vger.kernel.org, vishal.l.verma@intel.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jan 2021 23:35:38 -0800 Message-ID: <161052333875.1805594.3046789655044320351.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161052331545.1805594.2356512831689786960.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161052331545.1805594.2356512831689786960.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 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: The conversion to move pfn_to_online_page() internal to soft_offline_page() missed that the get_user_pages() reference taken by the madvise() path needs to be dropped when pfn_to_online_page() fails. Note the direct sysfs-path to soft_offline_page() does not perform a get_user_pages() lookup. When soft_offline_page() is handed a pfn_valid() && !pfn_to_online_page() pfn the kernel hangs at dax-device shutdown due to a leaked reference. Fixes: feec24a6139d ("mm, soft-offline: convert parameter to pfn") Cc: Andrew Morton Cc: Naoya Horiguchi Cc: Michal Hocko Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador Cc: Signed-off-by: Dan Williams --- mm/memory-failure.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 5a38e9eade94..78b173c7190c 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1885,6 +1885,12 @@ static int soft_offline_free_page(struct page *page) return rc; } +static void put_ref_page(struct page *page) +{ + if (page) + put_page(page); +} + /** * soft_offline_page - Soft offline a page. * @pfn: pfn to soft-offline @@ -1910,20 +1916,26 @@ static int soft_offline_free_page(struct page *page) int soft_offline_page(unsigned long pfn, int flags) { int ret; - struct page *page; bool try_again = true; + struct page *page, *ref_page = NULL; + + WARN_ON_ONCE(!pfn_valid(pfn) && (flags & MF_COUNT_INCREASED)); if (!pfn_valid(pfn)) return -ENXIO; + if (flags & MF_COUNT_INCREASED) + ref_page = pfn_to_page(pfn); + /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ page = pfn_to_online_page(pfn); - if (!page) + if (!page) { + put_ref_page(ref_page); return -EIO; + } if (PageHWPoison(page)) { pr_info("%s: %#lx page already poisoned\n", __func__, pfn); - if (flags & MF_COUNT_INCREASED) - put_page(page); + put_ref_page(ref_page); return 0; }