Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2105918pxa; Mon, 17 Aug 2020 00:20:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHJln1TwDdQZFIWyxBIK36mWYWkB/LS7BSaWCJNRbxhN0vnKNfNwIm94JZrQHElNCpAyY6 X-Received: by 2002:a17:906:e0d:: with SMTP id l13mr14547938eji.434.1597648855284; Mon, 17 Aug 2020 00:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597648855; cv=none; d=google.com; s=arc-20160816; b=fvdLpgYxz0hDlcywBMWFgxe96KkZ1iv2gy+QxMXmr2za8XNeycfQeYAM0RPcTp14aX y0ds3LLbhvtz9cfoxxrsTbu5O0gLP2OCDBrLoFVXN1bRGH9HF0INganHcckpVRLfHkQC 4vhskhJ6O5HV87l1EpML9qWq429EkFzJIES0HBMFalRKVGsMmbFUD5Sa6N9r/xtYsXLU ULReUtwyHDMNmjl0a54MgE157hcvLWIHUq6D1oJnat2vL2iGxNR62rAuWpjZctfYyB1t Ke14eYzwmhbo8BKPLN9ERA9dCjk8LHcTpsObm0R3XCNRvVYNg8J5o6l4+znbmz1Ji7Np EbEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=/Set//dgm7G/XdtiNNP38eYsEDsXQCMaAkbmzasEPMg=; b=BAT4niL5zps/xclApxlXTkZBhk5OipzV5z/FahSFturR20/Fzs7MSMPOyEcE2wSszn MrHl+Ps7aVYzBPkdtCM9QfGfhBgeHk9Q+yH/8WRvpD5oDoIYL4bLNYeFobB8+2l1gFYy 9V06UeWOkCKAufi4B3nycJimViAFwRZCIU7VAoJuePt3QVFMloemtDcOs3PeDWKgYAbr sXGm7kltYfVM7I+FJeCTDecg6BsOqq4FP766iYqZMdezuOM1nG4JkMVyM6gXOrfIBWHJ kZBBgsTcGWTdkuNKt7yee8zdeg62ltFez/RnY4/h1+zliWb3Z4kQejX600SddGcBSjiW FKvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JdBgyG4W; 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 qc4si10412638ejb.712.2020.08.17.00.20.32; Mon, 17 Aug 2020 00:20:55 -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=JdBgyG4W; 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 S1726633AbgHQHSJ (ORCPT + 99 others); Mon, 17 Aug 2020 03:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725765AbgHQHSI (ORCPT ); Mon, 17 Aug 2020 03:18:08 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C899BC061388 for ; Mon, 17 Aug 2020 00:18:07 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id d14so14124442qke.13 for ; Mon, 17 Aug 2020 00:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=/Set//dgm7G/XdtiNNP38eYsEDsXQCMaAkbmzasEPMg=; b=JdBgyG4W1iyFfmRRasE/WxCe+QioC2gKjz2BHSMl7Mow6xxBfhSXol7QKLgheZht1F DCP89xzuke3Sm08FZLbNOchZ6zcVdgyjGxrQvFUAex9B0thU/DTSkHj4VuCOriaw+0BA F8vW+w84c7DQPmVSRTBWs1SE2R4Ii17eZwzyepJKanQZQIiR23vJ6J3doVGopNqc8Dmh IzgN3x1rlXiMnMaCCLNUDrRptOHoWc/4whQuHkVAM5RuSkDe+AbSD87BPWofVBE2le1c 3omWdmBJa8cVa3g0KiG0+gAZNxEnsOtHDL7XsdndPbfhfd1rlNabtWjsdl3QZ29vOxx7 k5Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=/Set//dgm7G/XdtiNNP38eYsEDsXQCMaAkbmzasEPMg=; b=Cy9NJqT1tItvk2XJOSmy/uLY1m2qUJ5k+KAtNhyn6CWxiUCWAfc0i5Re97AVJ7WaBy CfKpJZ3k7DX2+Zd3rgof3yuSjXj98bdU78q6V10WFUaml1wtC8y0qVQJ+m5QS2Y8H3uI OYpzqyd0L9y94KcPYHEWjmVB2YFVuRv7kuIb45feniHD5qtn33CuViDasfAOj0hjK57X xJNr5P2HOzDnKdkmCPIlVn01UAmu8BnEMvc7iqoxcrUIJGGrNuxS8oYYMA8DkWernhK6 eNuXd0XrEvNRvDtuZTOAV+gfvBiMVHDWwhLu5RWwHzqBixEE90I3O2qKne/eGOiZP8uz IrYA== X-Gm-Message-State: AOAM531xbVvYGX6Mxioa6kBtGj/K4qgo3mH3czvPm5IxvzNUkOTDEwig 2s0vkFjnOdwyL2FRWGMpI9d4P94t5q5QJw== X-Received: by 2002:a05:620a:152d:: with SMTP id n13mr10980555qkk.43.1597648686064; Mon, 17 Aug 2020 00:18:06 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id b187sm15642131qkd.107.2020.08.17.00.18.02 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Mon, 17 Aug 2020 00:18:04 -0700 (PDT) Date: Mon, 17 Aug 2020 00:17:49 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Song Liu cc: Hugh Dickins , Andrew Morton , "Kirill A. Shutemov" , Srikar Dronamraju , Oleg Nesterov , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" Subject: Re: [PATCH] uprobes: __replace_page() avoid BUG in munlock_vma_page() In-Reply-To: <852258AE-75B6-404A-B236-9EEF37AEE43F@fb.com> Message-ID: References: <852258AE-75B6-404A-B236-9EEF37AEE43F@fb.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Aug 2020, Song Liu wrote: > > On Aug 16, 2020, at 1:44 PM, Hugh Dickins wrote: > > > > syzbot crashed on the VM_BUG_ON_PAGE(PageTail) in munlock_vma_page(), > > when called from uprobes __replace_page(). Which of many ways to fix it? > > Settled on not calling when PageCompound (since Head and Tail are equals > > in this context, PageCompound the usual check in uprobes.c, and the prior > > use of FOLL_SPLIT_PMD will have cleared PageMlocked already). > > > > Reported-by: syzbot > > Fixes: 5a52c9df62b4 ("uprobe: use FOLL_SPLIT_PMD instead of FOLL_SPLIT") > > Signed-off-by: Hugh Dickins > > Cc: stable@vger.kernel.org # v5.4+ > > --- > > This one is not a 5.9-rc regression, but still good to fix. > > > > kernel/events/uprobes.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > --- v5.9-rc/kernel/events/uprobes.c 2020-08-12 19:46:50.851196584 -0700 > > +++ linux/kernel/events/uprobes.c 2020-08-16 13:18:35.292821674 -0700 > > @@ -205,7 +205,7 @@ static int __replace_page(struct vm_area > > try_to_free_swap(old_page); > > page_vma_mapped_walk_done(&pvmw); > > > > - if (vma->vm_flags & VM_LOCKED) > > + if ((vma->vm_flags & VM_LOCKED) && !PageCompound(old_page)) > > Do we need munlock_vma_page() for THP page head? No: as the commit message says "the prior use of FOLL_SPLIT_PMD will have cleared PageMlocked already" - our THP implementation has difficulty supporting Mlocked consistently when the huge page is somewhere mapped by ptes, so one of the things that __split_huge_pmd() does is clear_page_mlock(), then PageDoubleMap will prevent Mlocked being set again once GUP has brought the old_page pte back in. But if you'd prefer us to munlock_vma_page(compound_head(old_page)) instead, I can certainly change the patch: it's one of the options I considered, but couldn't quite bring myself to do it that way, knowing that actually it would never find PageMlocked set. (If PageMlocked were allowed on tail pages, I'd have used a PageMlocked test instead of the PageCompound one: I spent nearly an hour bikeshedding the alternatives here!) (One day I must remind myself of when munlock_vma_page() should be used, versus when clear_page_mlock() should be used: I think it comes down to a choice of which stats get incremented, but I may also be forgetting something more important: anyway, no obvious reason to depart from the munlock_vma_page() that's always been used here.) Hugh