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.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no 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 62E9AC48BE5 for ; Sat, 12 Jun 2021 01:50:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC35E61181 for ; Sat, 12 Jun 2021 01:50:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC35E61181 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1BF696B006C; Fri, 11 Jun 2021 21:50:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 148676B006E; Fri, 11 Jun 2021 21:50:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE8BA6B0070; Fri, 11 Jun 2021 21:50:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id B696C6B006C for ; Fri, 11 Jun 2021 21:50:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 263C48249980 for ; Sat, 12 Jun 2021 01:50:26 +0000 (UTC) X-FDA: 78243392052.29.0CB20E0 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf26.hostedemail.com (Postfix) with ESMTP id 1D00040002C1 for ; Sat, 12 Jun 2021 01:50:21 +0000 (UTC) Received: by mail-lf1-f45.google.com with SMTP id r5so11269711lfr.5 for ; Fri, 11 Jun 2021 18:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DgJgazWwZm0ckWV47NnxvUxfq3HmV/tC3J+ues9bgWY=; b=WW2lJdYvuofDnZh5w550dcy8GMpYI9IhckSnmIxxkuBNem7Q0OEW33tDJvZEmTXCLu 1ALyesAwRvJtyGFGSx3geqH7paIHx+//ODWMarr34VG4dIBcDcQl2GIkZtIwblVN77QO z260GdbH+lBBJ9VxwNGFvWUF1O8mwUc2JF5pw34IFHXQdpTVbZGrxRjPy86uTMbGdDQ/ 0zF78+L+uwQdrx+YsfzW7BkA1Bbp0iAwRoPO55h6bow9p5FO3Gw+8llkJhHLGiSot2wK D5cu25C69T6AYglJjVPQKLnEyzqxwbg7M3yaaTuTsvxkEgKTIokFCTJ8NeNeuc8XOST0 DpoQ== 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=DgJgazWwZm0ckWV47NnxvUxfq3HmV/tC3J+ues9bgWY=; b=NK4BTDEDB6hvuvEvEPTLGN9xwRD78WfLpkk1/OvnfH40/RITN7fc1b39dWQtwqBFfM qWZueybpeHt+sarCIwUwxnogoL2utzvFImPA6c7CJiXSH+NEKsGQKCpd9WhhGVyI8QvR vL5Fx+z491oZXXvKrmsuT1bWJLNCq4sXA5HWgPhFPSqaZNxtHi3pUfX+FCzpQU1vpN+H HKSQW2jX5+EBD37kutNtIifTdxCAJioGGfUpzYSq60ZY7PN++tUc9zsPqY6AJFN8Zx3V SzngB6Sm7OFrkk8S2B8HJzJ/0zdPfT1HX6mtStq4mS85DkRFn5dV6tnjLWeWIxI85wgn SwzA== X-Gm-Message-State: AOAM531GKiRnyMXMI3HWI16FAsYXzNuwrVccetydXoXa/XerbQaMaXMu b78rzMMDHDJpITLiwcQqLsSGCH80N7Jz60KZpWdx4w== X-Google-Smtp-Source: ABdhPJwmAeFAI2/1QIPU5vaMZ1EtDuuYIQRqOvmFo5GQ1bmPA8XfQYh7lbkkpnNfNay5cEQGVaVuf7mi6/+5G/8fGxE= X-Received: by 2002:a05:6512:754:: with SMTP id c20mr4359735lfs.356.1623462624060; Fri, 11 Jun 2021 18:50:24 -0700 (PDT) MIME-Version: 1.0 References: <20210611161545.998858-1-jannh@google.com> <20210611153624.65badf761078f86f76365ab9@linux-foundation.org> In-Reply-To: <20210611153624.65badf761078f86f76365ab9@linux-foundation.org> From: Jann Horn Date: Sat, 12 Jun 2021 03:49:57 +0200 Message-ID: Subject: Re: [PATCH resend] mm/gup: fix try_grab_compound_head() race with split_huge_page() To: Andrew Morton Cc: Linux-MM , kernel list , Matthew Wilcox , "Kirill A . Shutemov" , John Hubbard , Jan Kara , stable Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=WW2lJdYv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of jannh@google.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=jannh@google.com X-Rspamd-Server: rspam02 X-Stat-Signature: cjwu7mjcieg7a3e1fc85te7p8xi6j7p7 X-Rspamd-Queue-Id: 1D00040002C1 X-HE-Tag: 1623462621-568785 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 Sat, Jun 12, 2021 at 12:36 AM Andrew Morton wrote: > On Fri, 11 Jun 2021 18:15:45 +0200 Jann Horn wrote: > > +/* Equivalent to calling put_page() @refs times. */ > > +static void put_page_refs(struct page *page, int refs) > > +{ > > + VM_BUG_ON_PAGE(page_ref_count(page) < refs, page); > > I don't think there's a need to nuke the whole kernel in this case. > Can we warn then simply leak the page? That way we have a much better > chance of getting a good bug report. Ah, yeah, I guess that makes sense. I had just copied this over from put_compound_head(), and figured it was fine to keep it as-is, but I guess changing it would be reasonable. I'm not quite sure what the best way to do that would be though. I guess the check should go away in !DEBUG_VM builds? Should I just explicitly put the check in an ifdef block? Like so: #ifdef CONFIG_DEBUG_VM if (VM_WARN_ON_ONCE_PAGE(...)) return; #endif Or, since inline ifdeffery looks ugly, get rid of the explicit ifdef, and change the !DEBUG_VM definition of VM_WARN_ON_ONCE_PAGE() as follows so that the branch is compiled away? #define VM_WARN_ON_ONCE_PAGE(cond, page) (BUILD_BUG_ON_INVALID(cond), false) That would look kinda neat, but it would be different from the behavior of WARN_ON(), which still returns the original condition even in !BUG builds, so that could be confusing... > > + /* > > + * Calling put_page() for each ref is unnecessarily slow. Only the last > > + * ref needs a put_page(). > > + */ > > + if (refs > 1) > > + page_ref_sub(page, refs - 1); > > + put_page(page); > > +} >