Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp366593pxj; Thu, 10 Jun 2021 02:45:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzD9WJnZbUkrri7EzkmcRBLDXCUduchuSS8eeqmETyOnwknDLUyvEqcqcawCy5bZpixDOgQ X-Received: by 2002:a05:6402:3123:: with SMTP id dd3mr3769528edb.113.1623318312216; Thu, 10 Jun 2021 02:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623318312; cv=none; d=google.com; s=arc-20160816; b=tqlOp+vmoZDM8RVIrrhYNA9FiYEMzKSHxBxHo9SKzdQTBhWHg3xP1yEuaIjcay/q5p xrk3QYoY9yuC4vvYi5pLroQCq1bCagJChhfWanINmzTkqTPhogLQwfZtEsoc+WoijHzM aYV3edl2XoBtL3oQ3LUooh9VrRl+uRAsNNBg5wuTrD91fJCYwRqyr2q5O8O/pmJav1Qa yrSIdwvKWRHW5ZApHPOu9Z1e0l7ZUUB6VW7HJ5gtYPrYonCWcQEaPswNuTeAdMchTN/K CYhQInBmCClFL0nAf7uuEXZq8i4YSVWAmMolOF4WRaPeXuMWnbIGRE17DA0BpPruVHEo 7Ejg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BY5gWDPGhOOh05MTbHBqo44JzZHQYM/4bR652Xf+XDw=; b=Uy5mDVNtqIi4wGMRYSL++Ngo3qV/hpefqnl08x0ioh+RlZTUz78we4o2Owbyp0oIbV 9D0t/Ty79QwFF64yTJT5XU603d37DEpt2kJS5avnI1jRhpq0NokaGW2stHQScHulzq5e //p+/kmo2RwD4S+c3ZoeDey1girNwZ4AiGhKcz/+ZXPO81lzlTsS/K31uSCH2SRG5HSJ W0LgSO+rjDJZOnjaLzPeYRvG3NHK7DUmP4RP0lJfNY5AuUtPuHmY6w5IBdq4JE0N4TOM FEnDf3wRfcUz0RJGm0F9Kpoj1hbmzmnx23ks4I69qbDP+QfpwfEgVK66nJsoxux431cX 6caA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=MQJOLlGK; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si1960707edm.79.2021.06.10.02.44.49; Thu, 10 Jun 2021 02:45:12 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=MQJOLlGK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbhFJJoj (ORCPT + 99 others); Thu, 10 Jun 2021 05:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbhFJJoj (ORCPT ); Thu, 10 Jun 2021 05:44:39 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60964C061574 for ; Thu, 10 Jun 2021 02:42:30 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id i10so2233501lfj.2 for ; Thu, 10 Jun 2021 02:42: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=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=ZC2m8yWjtg3S/XidFsVDrJL7vP9eTb/tPgr/nLFHiJr048BQb4JGKEiZCY16e4g/rS CDmpzUrLOnBVgiXYuUhfTmOJ1+E+idvzjIygw0jRygLPCc8Fr//rQ8q+tI5bRB8+rQaF ecp484GcaIUTI3rPqmBI4n1xQMJvb/nvWnv0lKis+igmc6aaoN9GuGkR/koi9nH7Rmit 5N6JuEmwGI4VEyXbpI1yyBiWxVdHOyaoVhX51jLTJtB0oJQ/Z9+MeIKXRcHVTUrZ81hl 4ZxrN+Qs26EVWPBDRKVipLdAeLXevw75xQ1A1F1RvcmWSlg29xFJ3e0kHaDrU9E0Z6Ac 6zLQ== X-Gm-Message-State: AOAM532QKVfmGUEaruUogYbCMBdWI8iF/snZfKS1Aq8uOFTJR2UAGtlW tN/TLEdKbMqjxE53z00QT6g63A== 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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