Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp748412pxj; Thu, 3 Jun 2021 19:25:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG9gT3FXmye8L+ytekLE7bfE2uW9V28BkrMsCzUWHawjDGxDMdf7Ne79HPtcm8yO9tDmqA X-Received: by 2002:a05:6402:845:: with SMTP id b5mr2289052edz.266.1622773533858; Thu, 03 Jun 2021 19:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622773533; cv=none; d=google.com; s=arc-20160816; b=jLN/TnPwR/2qPT4FlyqmGBWFRW9diwvLYksRGaJZWdD0TLSZ2h1MO1I8xPQwLO4rGI wt+gR+9HUsTNg5taODPQcw/RsWOPMzUzBrSlaTCOmotBbKMX01LxyhI/3lfgfYjq20N7 kENQj0t6F6twJuV0QWzyvtP0w0aJY3alt1h760mQIhjW44c9uIERhsX0TBg2TJ7ncfCk m8OXEk7fOO/LdLTEPTvRrGgx/xaLCoBUTVuw7kDojHiRuGkFZ+qMCb9JX1fhzNGFxoJF irOB+2S64O72+LD34oATtqelUB6b/nzrEB69J78E9IROfxOCNrLXUflQz29AjvZJR1ga lOzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=6gtl5ml3oidODRLTiq6SWXD7TlK86nyhuDo2wphJy1I=; b=tFCj0xG/QDUClpLIb7CJkKwctop/5uAXZ9tbQ25eZdqafX1winbn9HcBcsocTEfgK5 7D/UxxcClijT0m6fiV6hw5aKpMnrqdh1SZBt8PJCjiVpU7vYINN7ahYKlNfyD9gWXLkX kh1dq/egypNobieUjKgMfuxsQ9Ny928DetyqykqORewOTPGVftCVb6qfAo7pvuMaRKxR hSgpSnUtEYdz/1xv4pnHN9JhhHM+eKPLz2pWNGfbvR/QLGqM+YdTHgO35/8/rBiXZ0+O rt7IJ6nBncnbSTHcQXBOKdI12CVu0gBGMngy8H/QXhRd0crfJQSaX7e+13ZYvuiax3Yi vvMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nieY8GPV; 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 d11si3124054ejo.629.2021.06.03.19.25.10; Thu, 03 Jun 2021 19:25:33 -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=nieY8GPV; 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 S229772AbhFDCZP (ORCPT + 99 others); Thu, 3 Jun 2021 22:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbhFDCZP (ORCPT ); Thu, 3 Jun 2021 22:25:15 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6291C06174A for ; Thu, 3 Jun 2021 19:23:13 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id a7so4255294qvf.11 for ; Thu, 03 Jun 2021 19:23:13 -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=6gtl5ml3oidODRLTiq6SWXD7TlK86nyhuDo2wphJy1I=; b=nieY8GPV5VcbWLx7nkMjysrhPRr8sWODb8bEwy1mMCBVbAMQnmQWWK4pjsrcN5Qaij FGMdxt4G9Q1XxXKzbPskpoeg/Oc4kfvHEaxX2n6HNO57NxA7zbZ4UoUfJfXZf2zYLdDF xQq/1EXKmvYZT8bbuZEY/CxJPtidOGfwfrbpTlGOv9EfebdWtwDO5XcpS1U2PPpe0gtb jTUHlEdetUxRZMMFv0Na+/It04KyHaJfyYhHESYggmFEOjh8T0DT9rUD9ILm9RYLo7m1 3/DsARInKvJlkUyjrYVnAwJLX1HDN19mSsFY/UV2XmziBkYNUyFT97NxN5OwTAaCAcye 0NrA== 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=6gtl5ml3oidODRLTiq6SWXD7TlK86nyhuDo2wphJy1I=; b=h6QDEmqp/S/5te5eOTWCMqjGQ0N9IeJmYYTMxCC0bbkGguHUmFDeKypnOz7BXUhwxG oZqspQybyyN+bzXbSCYho71wzVjGGP6d5UB5qMm84Ie4gpSjluDq0N2nCY3V+qs3xzzP WSzplD/uUSEk9rbLEvPMaUWkFxAi1Njl6Z7kfr7gFGY9Hwvy7rv8P1K8aYbUw4xOndnC /m8RbOuWcH20axoTsnxIjhcdAcAPilbs02HpexMGlAA4HMRImpxd1clcvYwtPKY0m8ZK kS1tbhDQuI+LSeEESMbpTn3hCtptQuXFILLHjhSGvqqZ9k5cZhpqsoVrGxe3izmw1xyK T/fQ== X-Gm-Message-State: AOAM532juaHj28U7P8yEhUvHtqmG4kRtAQbFfqMRvGxfoWPNpCq1febZ OxoyTyHWWrYMRTXXulaz5E3vNA== X-Received: by 2002:a05:6214:260f:: with SMTP id gu15mr2627898qvb.21.1622773392735; Thu, 03 Jun 2021 19:23:12 -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 k13sm3132765qki.24.2021.06.03.19.23.10 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 03 Jun 2021 19:23:12 -0700 (PDT) Date: Thu, 3 Jun 2021 19:22:59 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Yang Shi cc: Hugh Dickins , Andrew Morton , "Kirill A. Shutemov" , Wang Yugui , Matthew Wilcox , Naoya Horiguchi , Alistair Popple , Ralph Campbell , Zi Yan , Miaohe Lin , Minchan Kim , Jue Wang , Peter Xu , Jan Kara , Linux MM , Linux Kernel Mailing List Subject: Re: [PATCH 1/7] mm/thp: fix __split_huge_pmd_locked() on shmem migration entry In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 3 Jun 2021, Yang Shi wrote: > On Tue, Jun 1, 2021 at 2:05 PM Hugh Dickins wrote: > > > > Are there more places that need to be careful about pmd migration entries? > > None hit in practice, but several of those is_huge_zero_pmd() tests were > > done without checking pmd_present() first: I believe a pmd migration entry > > could end up satisfying that test. Ah, the inversion of swap offset, to > > protect against L1TF, makes that impossible on x86; but other arches need > > the pmd_present() check, and even x86 ought not to apply pmd_page() to a > > swap-like pmd. Fix those instances; __split_huge_pmd_locked() was not > > wrong to be checking with pmd_trans_huge() instead, but I think it's > > clearer to use pmd_present() in each instance. ... > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 63ed6b25deaa..9fb7b47da87e 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -1676,7 +1676,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, > > spin_unlock(ptl); > > if (is_huge_zero_pmd(orig_pmd)) > > tlb_remove_page_size(tlb, pmd_page(orig_pmd), HPAGE_PMD_SIZE); > > - } else if (is_huge_zero_pmd(orig_pmd)) { > > + } else if (pmd_present(orig_pmd) && is_huge_zero_pmd(orig_pmd)) { > > If it is a huge zero migration entry, the code would fallback to the > "else". But IIUC the "else" case doesn't handle the huge zero page > correctly. It may mess up the rss counter. A huge zero migration entry? I hope that's not something special that I've missed. Do we ever migrate a huge zero page - and how do we find where it's mapped, to insert the migration entries? But if we do, I thought it would use the usual kind of pmd migration entry; and the first check in is_pmd_migration_entry() is !pmd_present(pmd). (I have to be rather careful to check such details, after getting burnt once by pmd_present(): which includes the "huge" bit even when not otherwise present, to permit races with pmdp_invalidate(). I mentioned in private mail that I'd dropped one of my "fixes" because it was harmless but mistaken: I had misunderstood pmd_present().) The point here (see commit message above) is that some unrelated pmd migration entry could pass the is_huge_zero_pmd() test, which rushes off to use pmd_page() without even checking pmd_present() first. And most of its users have, one way or another, checked pmd_present() first; but this place and a couple of others had not. I'm just verifying that it's really a a huge zero pmd before handling its case; the "else" still does not need to handle the huge zero page. Hugh