Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2456746pxj; Sun, 13 Jun 2021 21:49:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTZ+toKD9kV1mHoseUQVCn0k/TE1sDYPXSUg2LkbasWrkLHF+0Q/CDRMRURGvy+Q6eQplp X-Received: by 2002:a17:906:c212:: with SMTP id d18mr13736266ejz.291.1623646193010; Sun, 13 Jun 2021 21:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623646193; cv=none; d=google.com; s=arc-20160816; b=eJ6ppyN1mZy4tIoY6Votc624pXL7+ODmgPt3ICnevh2d+datuu10/G/snrOF1P2AsZ 9O0ijAvP41NGBRoy4Ke1zf6c5nbGMx/NulxzJmWVI9/3OqXCna7RyqappAO77Ispoi7M FCfdPMk7zpjNbAhlkUyVOO+BHdKrUC+SJlvhDXIy2l/KCa4E+Izs62QiIB4B7LOrW1fX BRRsEkr7xQtXA34PZj9vRblX3JuMbkClsv4CurqMmM94ubiSvnHly6PEWAya/h2Are0C FWHUyK00If0pI4EehPkThMPmqJ3Lk3y1cySzKOh0m14bfTvWfd0L3E+ZdhKWn+uCIuaa OGtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DivavMZT0DB2lVtUmC7mfKuI7ok3bEvks33og/PTQuY=; b=JZ+2caHzj6QN2DNvg++IKPnyrNOTYUZfn6aU4e/6nSYBtnW6h/OVq1zIGnSQg/u8QQ v9PvVaysIilZ0P2iHIE2FMOCV8UmmaZSIv8fxoJr1qW5+kypvhBV9VKAv/MDXkbGvmGW AAQ9wD532ZBn/EXmeNg5GFvZ2mCnOmNEX4FwOUb7TmQT1S4g5D16nrqKPOs1Ctl0yMyJ y5BURRV07GFskvJ6K6kVb54EDVQlaYPvbxAjgrD+0Qzc122+91qbozoo4Ob9kpTADV45 ERjCo/V8cZRLyoB4xbahgR0pWbd1RAaiPVlaE7DBTkx5wt9Lxn0O0dyovhkwdFYQDm8c jQ+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Y3A66Aj5; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf26si10691307edb.316.2021.06.13.21.49.29; Sun, 13 Jun 2021 21:49:53 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=Y3A66Aj5; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbhFNEuH (ORCPT + 99 others); Mon, 14 Jun 2021 00:50:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbhFNEuH (ORCPT ); Mon, 14 Jun 2021 00:50:07 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6409C061574 for ; Sun, 13 Jun 2021 21:47:48 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id r198so18831224lff.11 for ; Sun, 13 Jun 2021 21:47:48 -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=DivavMZT0DB2lVtUmC7mfKuI7ok3bEvks33og/PTQuY=; b=Y3A66Aj51d6devffT4DrhfOmQDaaJSZwLeMBQmUZGi0XNSY4n4PmYsEuW6bcb8qukh 7H4Ohj/Vl6bEUCIa05VyiKYnSoyzsRfc2WRik9uYHX0Bv4X8/vcSqmjJeUFuYc92Y6Gk vyLmc3poDD0GGX+/EyWeZoQ+hXaaxGw4YikQeTWKNon7FYicGD3C0z4/hmyZXomxs8l3 y4475d5ROQmeAXL6EAhMJllWd5I+gOWnYsXz21xvSXvUXgcHJOb5ygCk4U21kPEhbBGG 6czLZcgYdWiWaw4D19aFu6MRi6Y2nudO0Chh+/bA7i3MXAlh53Evh0VnRMHQhtiVtTQn KNBA== 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=DivavMZT0DB2lVtUmC7mfKuI7ok3bEvks33og/PTQuY=; b=eCN2Uw87vSLxv1yrgJx32FW6x0OU4FrWTHOK2ZC8YXQM0N4qdKBeazXt49p8vmx2pU omcZySSVOYwCmnZbpGi5Vex5Wwjb6Q9YqQMpKubMZnn/a6Orx5uFIg4h1Jk5ur6Hr0dm D8TNDSfOaA7fTJOPYFZ0FgeOopv0MLBKqwhWevikB1fnAY5eGLrtrrqkWCW3rpRovlcV U0zS8zMBOpqmmSz20UGRTuvat0LiiS2A59+sXFefXtjCbwCkIb/Nc0RGbyWelT4C01fg 9VqBBM99Fb9OxEm/UMZLytxJABeQ9Sf0RkjRIPWACqNJce+3h4jRIb2pzxZFcLBqh77j 3PEQ== X-Gm-Message-State: AOAM5321p1GvWcGW2k9zKNP50Mt5ptwUFEtPl5X9hkGqja+nI5HilspU BdiBFxOxEh1gPZ4B3zHZdyvHPUIgCLmpYCe4caVVGA== X-Received: by 2002:a05:6512:754:: with SMTP id c20mr10540300lfs.356.1623646066877; Sun, 13 Jun 2021 21:47:46 -0700 (PDT) MIME-Version: 1.0 References: <20210611161545.998858-1-jannh@google.com> <20210611153624.65badf761078f86f76365ab9@linux-foundation.org> <9041f85d-515d-576d-21a9-6f10b6e1279e@nvidia.com> In-Reply-To: <9041f85d-515d-576d-21a9-6f10b6e1279e@nvidia.com> From: Jann Horn Date: Mon, 14 Jun 2021 06:47:20 +0200 Message-ID: Subject: Re: [PATCH resend] mm/gup: fix try_grab_compound_head() race with split_huge_page() To: John Hubbard Cc: Andrew Morton , Linux-MM , kernel list , Matthew Wilcox , "Kirill A . Shutemov" , Jan Kara , stable Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 12, 2021 at 12:17 PM John Hubbard wrote: > On 6/11/21 3:49 PM, Jann Horn wrote: > > 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, > > Agreed: VM_WARN_ON_ONCE_PAGE(), at least at the API level, seems like > the best thing to use here. However, as you point out below, it needs a > little something first. > > > 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... > > > > The VM_WARN_ON_ONCE_PAGE() is not implemented exactly right > in the !CONFIG_DEBUG_VM case. IMHO it should follow the WARN*() > behavior, and return the original condition and keep going > in that case. But the point of the existing definition is that the compiler can avoid generating code for the condition in !DEBUG_VM builds, even if it can't prove that the condition is free of side effects, right? If VM_WARN_ON_ONCE_PAGE() was changed as you propose, then I think that in mem_cgroup_page_lruvec(), the compiler would have to generate code for mem_cgroup_disabled(), which calls static_branch_likely(), which ends up in "asm volatile" statements; so the compiler probably won't be able to eliminate the condition. > Then you could use it directly here. Depending on whether the intended behavior here is to skip the check in !DEBUG_VM builds (which was the case before) or also perform the check in DEBUG_VM builds. And if DEBUG_VM is a config option because it might have some performance impact, isn't the cost of the check probably quite large compared to the cost of printing the warning on a codpath that should never execute?