From mboxrd@z Thu Jan 1 00:00:00 1970 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 D7E87C433DB for ; Tue, 12 Jan 2021 10:16:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 622DC23109 for ; Tue, 12 Jan 2021 10:16:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 622DC23109 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9B36B8D008D; Tue, 12 Jan 2021 05:16:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 963528D008C; Tue, 12 Jan 2021 05:16:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 852188D008D; Tue, 12 Jan 2021 05:16:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 713538D008C for ; Tue, 12 Jan 2021 05:16:58 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 37F6A180AD811 for ; Tue, 12 Jan 2021 10:16:58 +0000 (UTC) X-FDA: 77696719716.23.bean74_5c07c2827514 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 1720D37604 for ; Tue, 12 Jan 2021 10:16:58 +0000 (UTC) X-HE-Tag: bean74_5c07c2827514 X-Filterd-Recvd-Size: 4959 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 10:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610446616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U4eg0K2Y42rlDcaFlSc0InWSXj6Mh1nlrY28P8UwpZY=; b=Mxz2pj1Re1yrKZTwOGvFqLDqAFiPwJb9ULYOTIYJjw736yaJkrsWP1r4Es3DAYyLgkt3Vy IHp9hE0PAj64wrSgLqIUwKG369upUh4QsSdMf+rzr3Jo6QIXKUWk1WUycoYn2Q3cBmBQaw x2dqU2RUZd6aywuJqahIUDMwTcNpmE8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-xh76z7DZNvmKh8o0hMopaQ-1; Tue, 12 Jan 2021 05:16:53 -0500 X-MC-Unique: xh76z7DZNvmKh8o0hMopaQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1B37100F340; Tue, 12 Jan 2021 10:16:50 +0000 (UTC) Received: from [10.36.115.140] (ovpn-115-140.ams2.redhat.com [10.36.115.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABB495B4A1; Tue, 12 Jan 2021 10:16:48 +0000 (UTC) Subject: Re: [PATCH v2 4/5] mm: Fix page reference leak in soft_offline_page() To: Dan Williams , linux-mm@kvack.org Cc: Andrew Morton , Naoya Horiguchi , Michal Hocko , Oscar Salvador , stable@vger.kernel.org, vishal.l.verma@intel.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org References: <161044407603.1482714.16630477578392768273.stgit@dwillia2-desk3.amr.corp.intel.com> <161044409809.1482714.11965583624142790079.stgit@dwillia2-desk3.amr.corp.intel.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <95b8c874-7236-dc84-ed36-c29b060ada7a@redhat.com> Date: Tue, 12 Jan 2021 11:16:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <161044409809.1482714.11965583624142790079.stgit@dwillia2-desk3.amr.corp.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: On 12.01.21 10:34, Dan Williams wrote: > 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; > } Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb