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 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 1C654C47082 for ; Sat, 5 Jun 2021 08:10:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9A141613D8 for ; Sat, 5 Jun 2021 08:10:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A141613D8 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 1A5CA6B006C; Sat, 5 Jun 2021 04:10:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17C256B006E; Sat, 5 Jun 2021 04:10:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01CEC6B0070; Sat, 5 Jun 2021 04:10:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id C38B86B006C for ; Sat, 5 Jun 2021 04:10:37 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 60D2E180AD804 for ; Sat, 5 Jun 2021 08:10:37 +0000 (UTC) X-FDA: 78218948514.20.7BEAB04 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by imf19.hostedemail.com (Postfix) with ESMTP id B8E009001ED7 for ; Sat, 5 Jun 2021 08:10:36 +0000 (UTC) Received: by mail-lj1-f178.google.com with SMTP id e11so14583724ljn.13 for ; Sat, 05 Jun 2021 01:10:36 -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=pxqXWpOMRKwzgShQLB13AAcIjid8zEdiCw/9s5AYCaI=; b=D/dHG9Vnq2ijnQ3b1ICqDvX320BcdijuRqiTrRIz3ioL/opYdhr7zmaV3ULky8qGQ0 Zt87soWd/Lkhb2tZWNxm8fYnqFMQwAJIi/AO4CdqwVqRCv7BgkOdS2bMd92MowyQH/Vl ptAFLJ9XUDL0dmo3CLOax6LIfjCRb7pE9j1CYtPHwdhbrBzTAueOl7LshYamr0dSzvCQ xfYQEEzGE5GWGmB9oaGUciPjE4ntho6V05YfwTHRhPy61c74fszMPcbIfnTLiuu0IdFz p214mDLMjXo4z3MpTsIl/TKWnqrOi642O9YfAYWwpS3a57WPtUU10BcvyOMmrnoT4lIr 4N3g== 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=pxqXWpOMRKwzgShQLB13AAcIjid8zEdiCw/9s5AYCaI=; b=VoJ/pLErPkWAvHMAuJfC0FPxRSirdMgAdvYqT9WrmNnmeM3hoDemhq6iT6eGCjd4Tq oAW1FnQ9gCqNVlNBtqUncrcogwNdGQ+YzWCWcEh0xRgKhdJa3TCZAEMV/mQEoHFmTGiV sJeYSI+JYsz2Vb/Lj9S/iI9b7Vh7lvCTQAFkfRXXIS2kv7lTHhZK+fKRrVp04IgHFJNK 6blm/AowtDyp9HbBCv02yYx7gn2ITFribg5B6jW6R6uEKfjOv4+ewEOuZs2sYfEh3L9q ZhwqEBXuMd9LUwT4AhoRCxc4TQIMQyJtH3IDqxInO7KypWkppwVD5N/1I9JalApBU3n4 Ah8A== X-Gm-Message-State: AOAM530ZtRCSxtXdYQBPPQDSNCiWxyfA/W9wnq7KtWxqxFHC976mT3kj 5zHUQxpmIPrHCcNuBZrIhAYOiK6hcCI4qg== X-Google-Smtp-Source: ABdhPJwF64JHO79JO+CwXdAObnwrYkDUCZlqqNhd4DWfbD8ng+o3wqj+KJ1Z0kj5Qfdc1NHEafcU2A== X-Received: by 2002:ac2:4acd:: with SMTP id m13mr3037027lfp.620.1622820861219; Fri, 04 Jun 2021 08:34:21 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id f10sm749818ljp.8.2021.06.04.08.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jun 2021 08:34:20 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id F1DD51027A9; Fri, 4 Jun 2021 18:34:32 +0300 (+03) Date: Fri, 4 Jun 2021 18:34:32 +0300 From: "Kirill A. Shutemov" To: Hugh Dickins Cc: 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 Message-ID: <20210604153432.b4lck4q75z5oopym@box.shutemov.name> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b="D/dHG9Vn"; dmarc=none; spf=none (imf19.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.208.178) smtp.mailfrom=kirill@shutemov.name X-Stat-Signature: tnahw7hs7jogwfekwgrbzp8esyyxi833 X-Rspamd-Queue-Id: B8E009001ED7 X-Rspamd-Server: rspam02 X-HE-Tag: 1622880636-119487 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 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? Maybe add VM_BUG_ON(!pmd_present()) in is_huge_zero_pmd()? 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. -- Kirill A. Shutemov