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=-4.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 8676CC433E0 for ; Mon, 3 Aug 2020 08:59:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 24E4C2070A for ; Mon, 3 Aug 2020 08:59:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="L1FDdB/0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24E4C2070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EEB888D00F2; Mon, 3 Aug 2020 04:59:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9DC78D00E9; Mon, 3 Aug 2020 04:59:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB2A68D00F2; Mon, 3 Aug 2020 04:59:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id C64F58D00E9 for ; Mon, 3 Aug 2020 04:59:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 768814DC1 for ; Mon, 3 Aug 2020 08:59:31 +0000 (UTC) X-FDA: 77108658942.12.brain66_150e9fd26f9c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 49FD41800F728 for ; Mon, 3 Aug 2020 08:59:31 +0000 (UTC) X-HE-Tag: brain66_150e9fd26f9c X-Filterd-Recvd-Size: 5921 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Aug 2020 08:59:30 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id s16so23558008ljc.8 for ; Mon, 03 Aug 2020 01:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=s62jzPsCEGTZMn+EVXZ348Lh5mNmexxLfib8yggDGZY=; b=L1FDdB/0UqpzkcKNpYDJVjyF4usUUoLQ9Drdr0r4FA16I7tt5Gck5JK9DJELrVhPgV Z+v1Qgov2vk3+I6CgWjMnOEOoYMwn4SYAqyCpd2Bk6fINlIDPDLMtlm7Rmys6swsPdJO jdeAhrOvxCRUOCxM6BjOglxgCekVCoZfWosyFwneK/JRVXdafL4uZd6I8Z1w6kTe5Y3T GwDZeMLFUBrWcOb/5pxpSwb503V1otUtIHppqPV62O9y8Ph/ST/xglKZljBGSdFq1V18 ullpest44r03RztYM5f+WCcy8RHOPq+XvFWqM2M4i69Gg1CWw/3dzB7Oc8jeYz+6m2Hu Xjsg== 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=s62jzPsCEGTZMn+EVXZ348Lh5mNmexxLfib8yggDGZY=; b=ZLLWH6weUp/V3dEOu7NcyChWk6re8Wa3JWwv+0VhZWCnAjEgMy0HAfyP4v8g9kglKG bBi4iMQCFfrT6URiseqEh1UTiPFfO9u78bUUA6xVgH56ThN82cGzFYu8SiSTxN/EBHNE vH3lFdhBQzUA5tGvwseeiC60B9SUlaFXBSPjVsryQIEo+vqV623Ey6Ao6xczMDLnUKbD 6oBQ/7807tHmLcGX3ZUlJ4PtK5zAEDcFhyplJsqT1369SOEmRvOHYK27AmhgtWxNKDaG 24y7/rXAPdtl8OQrSa1FB0IlRjOciaNUwQuHowD+ueGimGYMDVai4K9K6kD8zz/l2iyA y2Cg== X-Gm-Message-State: AOAM530r7OuHRLCneejzn9FgtOv6bdaXr59VIo+xujBgAsLEXfo0PSWS livZdKWjguGHv/BUAPDTBU9mjw== X-Google-Smtp-Source: ABdhPJznseuQLxd1dYSrIbwJyxLxvs0jDy38WoloUNa56AdoKBRMbWb9iGAmccZv9gf8nH/1c8HB5g== X-Received: by 2002:a2e:b0c9:: with SMTP id g9mr1807998ljl.65.1596445168995; Mon, 03 Aug 2020 01:59:28 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id n3sm3987391ljj.39.2020.08.03.01.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 01:59:28 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 138AF101674; Mon, 3 Aug 2020 11:59:35 +0300 (+03) Date: Mon, 3 Aug 2020 11:59:35 +0300 From: "Kirill A. Shutemov" To: Hugh Dickins Cc: Andrew Morton , "Kirill A. Shutemov" , Andrea Arcangeli , Song Liu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] khugepaged: retract_page_tables() remember to test exit Message-ID: <20200803085935.aama54aie77pq47b@box> References: <20200802214408.patvlf3sghro3nhi@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 49FD41800F728 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Aug 02, 2020 at 05:35:23PM -0700, Hugh Dickins wrote: > On Mon, 3 Aug 2020, Kirill A. Shutemov wrote: > > On Sun, Aug 02, 2020 at 12:16:53PM -0700, Hugh Dickins wrote: > > > Only once have I seen this scenario (and forgot even to notice what > > > forced the eventual crash): a sequence of "BUG: Bad page map" alerts > > > from vm_normal_page(), from zap_pte_range() servicing exit_mmap(); > > > pmd:00000000, pte values corresponding to data in physical page 0. > > > > > > The pte mappings being zapped in this case were supposed to be from a > > > huge page of ext4 text (but could as well have been shmem): my belief > > > is that it was racing with collapse_file()'s retract_page_tables(), > > > found *pmd pointing to a page table, locked it, but *pmd had become > > > 0 by the time start_pte was decided. > > > > > > In most cases, that possibility is excluded by holding mmap lock; > > > but exit_mmap() proceeds without mmap lock. Most of what's run by > > > khugepaged checks khugepaged_test_exit() after acquiring mmap lock: > > > khugepaged_collapse_pte_mapped_thps() and hugepage_vma_revalidate() > > > do so, for example. But retract_page_tables() did not: fix that > > > (using an mm variable instead of vma->vm_mm repeatedly). > > > > Hm. I'm not sure I follow. vma->vm_mm has to be valid as long as we hold > > i_mmap lock, no? Unlinking a VMA requires it. > > Ah, my wording is misleading, yes. That comment > "(using an mm variable instead of vma->vm_mm repeatedly)" > was nothing more than a note, that the patch is bigger than it could be, > because I decided to use an mm variable, instead of vma->vm_mm repeatedly. > But it looks as if I'm saying there used to be a need for READ_ONCE() or > something, and by using the mm variable I was fixing the problem. > > No, sorry: delete that line now the point is made: the mm variable is > just a patch detail, it's not important. > > The fix (as the subject suggested) is for retract_page_tables() to check > khugepaged_test_exit(), after acquiring mmap lock, before doing anything > to the page table. Getting the mmap lock serializes with __mmput(), > which briefly takes and drops it in __khugepaged_exit(); then the > khugepaged_test_exit() check on mm_users makes sure we don't touch the > page table once exit_mmap() might reach it, since exit_mmap() will be > proceeding without mmap lock, not expecting anyone to be racing with it. Okay, makes sense. Acked-by: Kirill A. Shutemov -- Kirill A. Shutemov