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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2DD6EC433DB for ; Tue, 12 Jan 2021 20:04:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B4DEF23125 for ; Tue, 12 Jan 2021 20:04:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4DEF23125 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 E426C6B00BD; Tue, 12 Jan 2021 15:04:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DF3A66B00BF; Tue, 12 Jan 2021 15:04:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D09116B00C0; Tue, 12 Jan 2021 15:04:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id BC8B16B00BD for ; Tue, 12 Jan 2021 15:04:08 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7AD9933C4 for ; Tue, 12 Jan 2021 20:04:08 +0000 (UTC) X-FDA: 77698199376.01.sheep61_540081727518 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 44BD21004BA7F for ; Tue, 12 Jan 2021 20:04:08 +0000 (UTC) X-HE-Tag: sheep61_540081727518 X-Filterd-Recvd-Size: 5678 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 20:04:06 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id g21so1603944edy.0 for ; Tue, 12 Jan 2021 12:04:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zdxtVLMD51rvFAUy0uouYzv2JNuR8PLKzsDJKh3c7Cc=; b=CgpDpWy/pkuZnqaYJDLuySEgBXiA4xKvWHC6DDiTgu764C6H2UCvCPUgHrlwGCzNgn fUPc1JLbqFUNBeCqrSEzGK8bJsHxrYcGVhvWQ61okYi8XBqIFrRUo/7g7pMkXeEDHvCa MyeA+dDYsLk+ftkMn3+9QPWX7bV5ijeBGChWSoAyKPKc9q42zWa9VlQF0vBw0z2xw9f9 vWDACqEUBquj/+PzQCjr+uwpecPRHxBT/oDEcZt5AzrxJ4HfTHhe46p36xDJ/Bp+lxM0 /5mQZHjY9h9MRqM4jAEgXFCkH91me6ItJ+CUCFgE+bTMLqtnIHXlIxnl6dDyQksB2VhH vsBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zdxtVLMD51rvFAUy0uouYzv2JNuR8PLKzsDJKh3c7Cc=; b=dwjY7W6j5jJ0nkJijY29pATKOPaykBV8R7CM7U8H9ZKI93L+umj/IoNVF8FtWW2mdC ou7tMjOrfhyGriD47wT3Ixomrk8Szu/KiS8XFXf8mMEqH3iXTzJZGJsQ8cLq9MGPsJ06 F0fepP9CMWTxI/a4y8K+33l7mmnDP8LE/iuAk0NrYQuEl9Ic0RUOzsNXqXCcIWLM9WBX 7b9Dd/2WRLaINW+qR6oCQRiSlZXwCDyo/smoYJMHTm4WBl6TTsrNE3em9n3Z1TwA8cAL r7rjGJS6Ph/OBcDaGcqTp457j/f9zc5kjwE/rDamIpgdhhCc3YhjK4RhoViycljboX1d iI8A== X-Gm-Message-State: AOAM530NKcO5WFmzIf4dh0JIh+SBypjBKNJaL22ouX6NabYuWlymkpnz 1uU4HTzd7bBaJsdW4uo+5M1EBBt6iiwTXUf5rq6+jA== X-Google-Smtp-Source: ABdhPJx9xG3m3PHJqgK6syqsFY+KpasjAjyzludTeiiipSmlClrjWTgEwzevdI3KyXO0/VPNMVZJDuulLjmGdX6Q/p0= X-Received: by 2002:aa7:c2d8:: with SMTP id m24mr661543edp.300.1610481844483; Tue, 12 Jan 2021 12:04:04 -0800 (PST) MIME-Version: 1.0 References: <161044407603.1482714.16630477578392768273.stgit@dwillia2-desk3.amr.corp.intel.com> <161044409809.1482714.11965583624142790079.stgit@dwillia2-desk3.amr.corp.intel.com> <20210112095345.GA12534@linux> In-Reply-To: <20210112095345.GA12534@linux> From: Dan Williams Date: Tue, 12 Jan 2021 12:03:55 -0800 Message-ID: Subject: Re: [PATCH v2 4/5] mm: Fix page reference leak in soft_offline_page() To: Oscar Salvador Cc: Linux MM , Andrew Morton , Naoya Horiguchi , David Hildenbrand , Michal Hocko , stable , Vishal L Verma , linux-nvdimm , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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 Tue, Jan 12, 2021 at 1:54 AM Oscar Salvador wrote: > > On Tue, Jan 12, 2021 at 01:34:58AM -0800, 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. > > I would be more specific here wrt. get_user_pages (madvise). > soft_offline_page gets called from more places besides madvise_*. Sure. > > > 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 > > LGTM, thanks for catching this: > > Reviewed-by: Oscar Salvador > > A nit below. > > > --- > > 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); > > +} > > I am not sure this warrants a function. > I would probably go with "if (ref_page).." in the two corresponding places, > but not feeling strong here. I'll take another look, it felt cluttered... > > > + > > /** > > * 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)); > > Did you see any scenario where this could happen? I understand that you are > adding this because we will leak a reference in case pfn is not valid anymore. > I did not, more future proofing / documenting against refactoring that fails to consider that case.