Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp157837pxb; Tue, 12 Jan 2021 23:38:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0D+21bSSzldAElKNPqClagK2E8BSEShISDe7yFKWKY9TaV0pUHjBWhhZD7oWbrJTt0al7 X-Received: by 2002:a17:906:5fc9:: with SMTP id k9mr628348ejv.70.1610523524552; Tue, 12 Jan 2021 23:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610523524; cv=none; d=google.com; s=arc-20160816; b=LWgcqao+CcjsGS8ARhuwh2gozTI1ofkQhb3bjkWoI0YJ5MqO3yATS+wKVCqBFcXrlH G8o6jUlGC9jRCJMh7JklTbrVjKKNuCuxCeukw+8uAhQqMfToXHYJvD7QfkuNLR4PgmpT LOTNtNLxA0lKNyL8jfyX2KpWBzjziju+AW5OKWmlpCUhWKS3lgz9gdpSDYtME3cbBoqx 2ppE5QfNYlv6RJiuzoUphDqYSN0NsjFHw6RfdGgBGj8SLjmeHFZZAt3nmIeN5+PlxhAE laNHeiJBDRmjYIoiFkc7y8C4Gs46lB5zP8iHqSM8lm3Nv3hp8YFaYz48uDl2csA0/F+D ivlA== 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=M4kZsho2BrXtwBe3kI/f/ecIlyy+uuXeKnv8OTas7Qg=; b=lFUk99feIK9arcmAdifOsS8teuM5GBB+fQa+sf474V7bOuYc+QRiNJZxvj0VSTfi/a yQI6vs5VODJbpauTkJx++RSUfAYsJG6WWaUABeGS5Cszx4RbXkEmEH3dxUMlqG91wob5 CCCaXxKV5swA0yyHq8J1qhmlEnjGCk+n+A0nBLVSiQVqUJAm8vhL6y8Nm8nfEhxHqzio R7UEye2ZaFS8Odyax4Ci1RxX3da25n6VNvBM4WcT4wEo4h7CWz4hNRjUXIl1hUTLB0zA it6GeJaQyubqdWvUR3tROBeUlLzXegj7Tf8EiUEyGDTLM29cX6aHKhj/o76wJQ564Fji ZyVg== 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 bx4si568848edb.137.2021.01.12.23.38.21; Tue, 12 Jan 2021 23:38:44 -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 S1726584AbhAMHgZ (ORCPT + 99 others); Wed, 13 Jan 2021 02:36:25 -0500 Received: from mga01.intel.com ([192.55.52.88]:51022 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725998AbhAMHgY (ORCPT ); Wed, 13 Jan 2021 02:36:24 -0500 IronPort-SDR: z62sIIfSwKnvnT74uLslIcc3VWzWnTOPsU4U88SEPOcDDnT3H/rZlrw3RnnPGL/l1tq+F7oD8b Rpa/eDNE92fA== X-IronPort-AV: E=McAfee;i="6000,8403,9862"; a="196799249" X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="196799249" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:43 -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 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 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; }