Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1022360pxj; Fri, 11 Jun 2021 18:54:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzWIkAqmehUp/G/snIvaCFPnRiiVuL8TcpSiAlJvIR8hg/4lPBCcRDs5yxWmGnhfrj6naF X-Received: by 2002:a05:6402:22d0:: with SMTP id dm16mr6427307edb.123.1623462864466; Fri, 11 Jun 2021 18:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623462864; cv=none; d=google.com; s=arc-20160816; b=s0Ec3p0uv7Qp8J9klXypkfIia6vxsXW17opLj0Qz/ymKorBl59gsikvGA/nrns4EEM IzfjeWQHQtHIOXSjalEKzyCvkbk08aBd/RN4GQ3OIkE31gTaoT30ojtMvXVqOcSaiS81 eVo2k/OI4HMW8sy2324rJTUpYCBeNpaEFt4WKWDl5eggTzJlyv6Ei/Se5t1z4OGQVAoz lRLVRlYaz09s4u3cn36hJOHXtGSFVF5+K0QWodMBvq9oU3A12GkIo6C8C/x2ExogHj5I RPm66E+aqdEOEeVpIfAg12GdPfbdi5voGiQgO/P1Y/bbkycdYx2sKvOFiwAA2fm7jVqi R9XA== 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=DgJgazWwZm0ckWV47NnxvUxfq3HmV/tC3J+ues9bgWY=; b=bxcJShdnCBztmd+sw9zdcWfUdtUuBzXV+qOutYfqFjwK+u3hPnPEyStND4E0ea7Kwr LGqbK5y4Yy4uISKuzdNLZK6q/NOIygbMv415aVTvENqKiwKcWMFIu0Vv/XHirCpfUwLj T95go72Rt1afvHDl1Vl1YRud3md6h+7LqwfBVzGl+0H36RO5s3BKA+O165breh8edkQZ s1Uj5lHbzEocOA7RQ4mSkCWm8MAovc1EsfxhG2Rf6ccIiEEizrS1o3H7L+1PtZjv/dMJ Z66p45QNCek2IUpmAdN+uMqXB67f4Dx4zkRTU/SdckJXrIT7xhZAFAqes3+HybT/2IYc nyvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WW2lJdYv; 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 ar10si2462020ejc.254.2021.06.11.18.54.01; Fri, 11 Jun 2021 18:54:24 -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=WW2lJdYv; 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 S230267AbhFLBxl (ORCPT + 99 others); Fri, 11 Jun 2021 21:53:41 -0400 Received: from mail-lf1-f50.google.com ([209.85.167.50]:33471 "EHLO mail-lf1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbhFLBxj (ORCPT ); Fri, 11 Jun 2021 21:53:39 -0400 Received: by mail-lf1-f50.google.com with SMTP id bp38so11323518lfb.0 for ; Fri, 11 Jun 2021 18:51:24 -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=ZOzTDpsN6qbQGDx5NuUG53lfplhSIsipeJLnuBlUeBauKx6vbiEl4a50+5/nGbT9so aaqb92aqkEmZDhN4LZ2r24DWtDufo3s1Pt35zyg2zlB5omOUmt0mJUYxlmVdgdEAiNjQ 9WOkkntk5ayXWFf2B5O4uD7jE/PduI00miclbJT+sZ1DdxYn9TJYSI61Ht/nrMdaSbrO FjrGkh/IY+eaQLg8OBmdQwQpweheaN7uvqPDK9jclNHvB67zjZVdJYUnwafRgsoi/WIb wo6eswhDE5sBkreOfwcc0hSbsDt2zqWxPTy5n6m5/0Bhu5MN8Cctosnr4oH4gcAB/4V9 kYJg== X-Gm-Message-State: AOAM5337g/IxgZu/wsUYPcngEjiIpCRxV7MWLa62D+9DMQBwDaaDI+/q Dvya/h2r/SDJoKe+F7rmCtZRWLF7KdHx5rQoNOleuebzrVQa4J0K 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > > +} >