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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 BD303C47094 for ; Thu, 10 Jun 2021 09:42:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4FF08613FE for ; Thu, 10 Jun 2021 09:42:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4FF08613FE 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 DB2E96B0036; Thu, 10 Jun 2021 05:42:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8A4B6B006E; Thu, 10 Jun 2021 05:42:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C51F46B0070; Thu, 10 Jun 2021 05:42:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 953C96B0036 for ; Thu, 10 Jun 2021 05:42:30 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 35112180AD81D for ; Thu, 10 Jun 2021 09:42:30 +0000 (UTC) X-FDA: 78237324060.39.34B210B Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf05.hostedemail.com (Postfix) with ESMTP id B0A6DE000253 for ; Thu, 10 Jun 2021 09:42:23 +0000 (UTC) Received: by mail-lf1-f45.google.com with SMTP id k40so2213699lfv.7 for ; Thu, 10 Jun 2021 02:42:29 -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=BY5gWDPGhOOh05MTbHBqo44JzZHQYM/4bR652Xf+XDw=; b=MQJOLlGKsxYhRQMSTHDQKDS/AVvXuBjwfTv9RCF7lTgYMCjlJXuPv2NB2INM4Y0okK kCZ/AODnXxuPill0Rg9SOsoak10eZ//EuEuFIWPsWI8qWmcxZyjq9UsjjmQngCD9Bv4m j35ZnHt+xDTCPwsfIf225yEnlhYQD7yvZrJIaYQhXKAK/NuzdGpzkh9Dddax7q5Ss2/R IeHsHUGxMx9MSID4VTxqSrX35MfjGsmUD5UBbKULAOzcPK3vi/ZUjJQpNKNuX+1AIsOC CBgXHbYsW7sGSh3pwYPZDQ/s0NNK+XpYKwC+/t+HdV/uRIruWJVapVcjMm8xWN9vN2mi +y1A== 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=BY5gWDPGhOOh05MTbHBqo44JzZHQYM/4bR652Xf+XDw=; b=T/o0m+YbuI/4MPmpTKxJ+X39jJ/3qwM+Jcar1sPed7SBgpJ1AGrTLBbDEWRq3X5Ly6 ov559d4JQQKP2TGZLuYU1QbbPxQ75+LGVA/UYpxKZUCWqAXh2USlgquuFDS/F3/1tXhy 2IxvbC3+pLGv0yPE76VxldmfCk8oNdCOOF3Uy3meLkJ/U3AI/85C73hZl707MEDzv6BN YhyOky1fU/Pcjs2jGoSKMMseZMqUuzaE+7PnBbthrPjWzoYlbmlKx1WWe3J9ezqf2krg Io10RpkbKHkt4QlKsVdJAB63JERg2KSqKcezXtr0zPycX3sBPDjeV70g1dsC8E7MF5ek RFJA== X-Gm-Message-State: AOAM531ySyNcr2Srh7ZLQCGUoqX0E4kZcDh0oXhTHeoSn0LHYcByEAJg /fYr92BWQhiynwGpbH+L1RkDWw== X-Google-Smtp-Source: ABdhPJwhWkdCWL07hD3+jqD/nEThG6Ks4sJk7HAe3z3eTSHsg2KK0YXyQLa/vmRIT3d2XoPH5D96pA== X-Received: by 2002:a19:8645:: with SMTP id i66mr1345707lfd.332.1623318148740; Thu, 10 Jun 2021 02:42:28 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id o21sm246947lfr.253.2021.06.10.02.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 02:42:28 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 23BDF1027EE; Thu, 10 Jun 2021 12:42:44 +0300 (+03) Date: Thu, 10 Jun 2021 12:42:44 +0300 From: "Kirill A. Shutemov" To: Hugh Dickins Cc: Andrew Morton , "Kirill A. Shutemov" , Yang Shi , Wang Yugui , Matthew Wilcox , Alistair Popple , Ralph Campbell , Zi Yan , Peter Xu , Will Deacon , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/11] mm/thp: fix page_vma_mapped_walk() if THP mapped by ptes Message-ID: <20210610094244.ag3gp5pnu3ulhhgu@box.shutemov.name> References: <589b358c-febc-c88e-d4c2-7834b37fa7bf@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=MQJOLlGK; dmarc=none; spf=none (imf05.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.167.45) smtp.mailfrom=kirill@shutemov.name X-Stat-Signature: h848ymkh5eciwiicqykb9gg1yuz85rmd X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B0A6DE000253 X-HE-Tag: 1623318143-106716 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 Wed, Jun 09, 2021 at 11:52:37PM -0700, Hugh Dickins wrote: > Running certain tests with a DEBUG_VM kernel would crash within hours, > on the total_mapcount BUG() in split_huge_page_to_list(), while trying > to free up some memory by punching a hole in a shmem huge page: split's > try_to_unmap() was unable to find all the mappings of the page (which, > on a !DEBUG_VM kernel, would then keep the huge page pinned in memory). > > Crash dumps showed two tail pages of a shmem huge page remained mapped > by pte: ptes in a non-huge-aligned vma of a gVisor process, at the end > of a long unmapped range; and no page table had yet been allocated for > the head of the huge page to be mapped into. > > Although designed to handle these odd misaligned huge-page-mapped-by-pte > cases, page_vma_mapped_walk() falls short by returning false prematurely > when !pmd_present or !pud_present or !p4d_present or !pgd_present: there > are cases when a huge page may span the boundary, with ptes present in > the next. > > Restructure page_vma_mapped_walk() as a loop to continue in these cases, > while keeping its layout much as before. Add a step_forward() helper to > advance pvmw->address across those boundaries: originally I tried to use > mm's standard p?d_addr_end() macros, but hit the same crash 512 times > less often: because of the way redundant levels are folded together, > but folded differently in different configurations, it was just too > difficult to use them correctly; and step_forward() is simpler anyway. > > Fixes: ace71a19cec5 ("mm: introduce page_vma_mapped_walk()") > Signed-off-by: Hugh Dickins > Cc: Acked-by: Kirill A. Shutemov -- Kirill A. Shutemov