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=-19.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 D2755C47082 for ; Sat, 5 Jun 2021 06:15:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 76C8161205 for ; Sat, 5 Jun 2021 06:15:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76C8161205 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 078396B0036; Sat, 5 Jun 2021 02:15:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 001536B006E; Sat, 5 Jun 2021 02:15:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC84D6B0036; Sat, 5 Jun 2021 02:15:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id A0DA66B0036 for ; Sat, 5 Jun 2021 02:15:51 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 45098365A for ; Sat, 5 Jun 2021 06:15:51 +0000 (UTC) X-FDA: 78218659302.30.5575D20 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf05.hostedemail.com (Postfix) with ESMTP id 600F4E0005B0 for ; Sat, 5 Jun 2021 06:14:13 +0000 (UTC) Received: by mail-oi1-f181.google.com with SMTP id u11so12080539oiv.1 for ; Fri, 04 Jun 2021 23:14: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=XCilaUhmoV4ajw4OBwjUyKW2dscXR1iV+XY/1Kzgmyc=; b=QkkeBjuuRUXrC5bcLPn/znSS6L1suJyev0jGsH/ObLM7ZRYw0FATlwRMlF+tOMsMYl jA+xzbmzCSA/ceeDvLA3vLeSbhewwpofvnaO6Ub2w8cqHT8TGLGTlHwbAamC3wdUgAf1 TcuUtSGjWbOeOqj7cGJ1zSUQrXj5yQtJ71eR5xtm9lN7fVq+x686MEgNmcjQE5sgAVKx Vs23KwsbqMVXjGjgTijzaPX1w28ZxwQBtTCPxRK6SQ6FgFdEfH6xbaJkfenBQX5Xb4Y2 SklLQrL1Gq0z8dPq4JRqnMhpbnq7PYvSqe0f+ReFbYSVfLuFBIZ1NCTSwNJTDeyb9ACd kZRA== 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=XCilaUhmoV4ajw4OBwjUyKW2dscXR1iV+XY/1Kzgmyc=; b=C/7UjXuWjNnz2BpT+50DVQ+uCW/Kia18PKbbyZyhO+QmWcLr+H+MiWHf/2iXFj78t/ 1JYmfTlCRdHUvkWLaETasQYRU6w87sNErqJ49hN07kqTo+WlL1yecNQabu0dQML9RH9p MpboztS0kPJv/3/zZzcHexsXDRJgHh9NHrMmKIw/q4dkgFhhYbpe5RcpBvAm0zwEP0BM b87mwrNV7Kxp0B5oNeyR4liQsacA5zNq0tXCrFV5NRgTMWCU4ZHIm4yHIbW6YR/NPmBp wAQlXgjXnB/flOvsk81xcP0eqyLLOMVK48wgGMEuOmQllwoEVmSGP1JZ8hoPc9mYMje7 EvBA== X-Gm-Message-State: AOAM531p9VtkqL+giwIDPWJIpmW5q6Zozjys0m6XzZFVmNhFtwpwFS05 SzLodkK8trVCYoliowdG/8Cgfr3chy49OQ== X-Google-Smtp-Source: ABdhPJyQ57sys35NWkmseEMkaZ8FSDIEaje0ne/BirGc48zSKFNUnOdunQZg8p8FiLuVJJT4PG1cJQ== X-Received: by 2002:aca:b107:: with SMTP id a7mr12136444oif.170.1622842161037; Fri, 04 Jun 2021 14:29:21 -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 o2sm555662oom.26.2021.06.04.14.29.19 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Fri, 04 Jun 2021 14:29:20 -0700 (PDT) Date: Fri, 4 Jun 2021 14:29:09 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: "Kirill A. Shutemov" cc: Hugh Dickins , Andrew Morton , "Kirill A. Shutemov" , Yang Shi , Wang Yugui , Matthew Wilcox , Naoya Horiguchi , Alistair Popple , Ralph Campbell , Zi Yan , Miaohe Lin , Minchan Kim , Jue Wang , Peter Xu , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/7] mm/thp: fix __split_huge_pmd_locked() on shmem migration entry In-Reply-To: <20210604153432.b4lck4q75z5oopym@box.shutemov.name> Message-ID: References: <20210604153432.b4lck4q75z5oopym@box.shutemov.name> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=QkkeBjuu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of hughd@google.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: jdxwa749ajahj874ojoaxbuprrk34ifs X-Rspamd-Queue-Id: 600F4E0005B0 X-Rspamd-Server: rspam02 X-HE-Tag: 1622873653-403104 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 Fri, 4 Jun 2021, Kirill A. Shutemov wrote: > On Tue, Jun 01, 2021 at 02:05:45PM -0700, Hugh Dickins wrote: > > Stressing huge tmpfs page migration racing hole punch often crashed on the > > VM_BUG_ON(!pmd_present) in pmdp_huge_clear_flush(), with DEBUG_VM=y kernel; > > or shortly afterwards, on a bad dereference in __split_huge_pmd_locked() > > when DEBUG_VM=n. They forgot to allow for pmd migration entries in the > > non-anonymous case. > > > > Full disclosure: those particular experiments were on a kernel with more > > relaxed mmap_lock and i_mmap_rwsem locking, and were not repeated on the > > vanilla kernel: it is conceivable that stricter locking happens to avoid > > those cases, or makes them less likely; but __split_huge_pmd_locked() > > already allowed for pmd migration entries when handling anonymous THPs, > > so this commit brings the shmem and file THP handling into line. > > > > 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. > > > > And while there: make it clearer to the eye that the !vma_is_anonymous() > > and is_huge_zero_pmd() blocks make early returns (and don't return void). > > > > Fixes: e71769ae5260 ("mm: enable thp migration for shmem thp") > > Signed-off-by: Hugh Dickins > > Cc: > > Looks like a two fixes got squashed into one patch. Zero-page fix and > migration entries in __split_huge_pmd_locked() deserve separate patches, > no? Okay, I'll divide in two (and probably lose the "don't return void" cleanup; but still keep the clearer separation of those two blocks). > > Maybe add VM_BUG_ON(!pmd_present()) in is_huge_zero_pmd()? Certainly not as part of any patch I'm aiming at stable! But I've remembered another approach, I'll say in response to Yang. > > Also I wounder how much code we can remove if we would not establish > migration ptes for file pages. We can make these page table entries 'none' > on migration. I'm not sure how far you're wondering to go with that (just in THP case, or file ptes generally?). But you may recall that I disagree, especially on mlocked vmas, where we break the contract by not using migration entries. Anyway, not something to get into here. Thanks a lot for all your reviews, I'll get on with it. Hugh