Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3019867pxb; Tue, 12 Jan 2021 04:30:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjdoK7P40rHTwybIKByhhSmVvcx9AAelLCJjDmOoILBjjY6GBpIPf6THlY0Nf3DJxtGHM2 X-Received: by 2002:a17:906:a04e:: with SMTP id bg14mr2957409ejb.149.1610454631737; Tue, 12 Jan 2021 04:30:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610454631; cv=none; d=google.com; s=arc-20160816; b=fwXbZqB3yEXCC/HPxsV6a18suQnx/cfESJnXtnJFImpUkttqsXHny3sBJK5mvZQyWK sWzDXlpfzFwH3S30xE49BySSOVuWpHUsEK9CQEvaaHeFfsHp6KibtrpmXRQNkT2+Nf2T sgVcQ1kNDWZePKS10vd8neT1iNlYslBfzNlLOfolZPdn8gcLoGiZaJKGVucj0fTa0GJc vOZyVrR75wcTFUf/IylvwKZKmy293IX7gudqxilQ7KMJ9t/Op4KegNwnlOSFUuuE9FJ7 uL5iQeoG39kmeC44ILmFpPLEvD+cqRR8l+QHRrCbuO3CbLrpdndZ0i/9NmJn6uZ+GzaO BIOA== 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:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=9nZzlE/5c5qNx/3eeOhJRCvUx1xpWXcJ/lyXxPJ2ZT4=; b=yQf0spzP9Lddg7zbSPGKNQe13ZrVEMWtooU5Kbp+dFdLfEX2KwEhC0oCtlFPToO3q3 1mZj7Q5cdF7/Cfhiq8/PKHETA/8XNib/94DrZEfZzJkMu8TUDzxcTe72BW+uyNE4Biy9 GMXA5UHQ12l7ubcWRa0dqlCa/MiA40f5UekQXOnPelzyjIah9EouzqcxNsLkv48x3S3u zJfeN/Q0hOARR7dmrXquwmJEAV/C9eun+mUu9EFRIxUniVY3wKxoePqAx0OjA5ux1Sei 04fJsm9kGeaLY1PUQjgXOt7IeSmlYhznQfsqvC0U+Kt9xBzwx2ZvAB3rdbuMdgLALDM/ v58Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n11si1013939eja.511.2021.01.12.04.30.08; Tue, 12 Jan 2021 04:30:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392721AbhALJfl (ORCPT + 99 others); Tue, 12 Jan 2021 04:35:41 -0500 Received: from mga18.intel.com ([134.134.136.126]:57028 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392715AbhALJfk (ORCPT ); Tue, 12 Jan 2021 04:35:40 -0500 IronPort-SDR: 7L535RC0Cs7jRkuW4IZTaH24Nnh6R5tGbXmrRZgKZKBQEnU09Ifv4pr3Cw5v/yRRfMBxYoNdto 9Shj7uCDeDXQ== X-IronPort-AV: E=McAfee;i="6000,8403,9861"; a="165691367" X-IronPort-AV: E=Sophos;i="5.79,341,1602572400"; d="scan'208";a="165691367" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 01:34:59 -0800 IronPort-SDR: 4TSrFpjxdyLfaLml0thLClygScVZvIKkcaXY0+AZZr2Jl3jmQhCIG29P4PmSL8NQX5bZfRWq/5 4B8qgPvs6sjw== X-IronPort-AV: E=Sophos;i="5.79,341,1602572400"; d="scan'208";a="571641600" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 01:34:58 -0800 Subject: [PATCH v2 4/5] mm: Fix page reference leak in soft_offline_page() From: Dan Williams To: linux-mm@kvack.org Cc: Andrew Morton , Naoya Horiguchi , David Hildenbrand , Michal Hocko , 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 01:34:58 -0800 Message-ID: <161044409809.1482714.11965583624142790079.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161044407603.1482714.16630477578392768273.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161044407603.1482714.16630477578392768273.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The conversion to move pfn_to_online_page() internal to soft_offline_page() missed that the get_user_pages() reference needs to be dropped when pfn_to_online_page() fails. 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: David Hildenbrand Cc: Michal Hocko Cc: 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; }