Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1572078pxa; Sun, 2 Aug 2020 12:23:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoc4h2kCJ+RAvyTqjcZBbjEn3/2bJoJ0KQqHDPRQdlpanHMbcA9LvWMIPh1cjpG599vNW9 X-Received: by 2002:a17:906:6b87:: with SMTP id l7mr12953786ejr.198.1596396207796; Sun, 02 Aug 2020 12:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596396207; cv=none; d=google.com; s=arc-20160816; b=MUGwaLnQnZnSajAW2UiEvI3N4uINCAMsDS1T5ZgheHFm7Jk7GRfOXmUvU+IQdKdf5T 0eKFJRY8A5KnwUgfROdTRXgGgprNK/A9HgJASQy5Ki3UdxAHfCaa/+aIj2+4ywh6xJhH pMPhXgz2E6GPjPRote/YfnbntdKcct4aTjcJ13/zl6qTrL0CwtOWk8qk1FK9zDF4fTIx q629m8rnr9PpDcpLMOEGIudMr5uyBgYwD8yL3dtIphlOv+PfjpV12tOv29masxiIJ0y1 mI9UWqAS5iSgdTCVE8AqaUjtcF8NkO9NUEgCkahgK68eTZaGxJeRD6Nm2jgVbhAaH+4+ 21vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=HdJ+2t0gL5zUBULh0wxTvXD/jJHQMjRu5f/2scMrQFs=; b=vCHS2Hq3ev5RjbRKucjLxosRgN1+2s8Fi9oeE+/SLhldG/waV79R3Lykl1+5/9d6Kc oCFd/EwkMfwaZOX+U40m+eMV5YshdYNnynrWRgwp8XgAKJpKefCRSvWB9ehENz8+DCBp znyAuL/+Rh1wqC1TqKWFblT42uObXONnIKXAeK7BMTwLpipMkn+OG7XL1HZ55Fst8Shn QXKXW4JMB6IL35lL/4aqopOHFRs4IH8cRzRBOxpD+rpy6SYa5mFOEYC7v+hBno33ATqE s3QSaTtDTZ0fCGNq1cdRf00wYSOOoqBD5gAOFAPCG9ouoaNvJs6O4vX4Apdp+LMeVBAj AIyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sHovUWig; 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 x8si720097edl.249.2020.08.02.12.23.05; Sun, 02 Aug 2020 12:23:27 -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=sHovUWig; 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 S1727059AbgHBTSj (ORCPT + 99 others); Sun, 2 Aug 2020 15:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbgHBTSj (ORCPT ); Sun, 2 Aug 2020 15:18:39 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3ED6C06174A for ; Sun, 2 Aug 2020 12:18:38 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id b2so5866614qvp.9 for ; Sun, 02 Aug 2020 12:18:38 -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=HdJ+2t0gL5zUBULh0wxTvXD/jJHQMjRu5f/2scMrQFs=; b=sHovUWigi9DH0ehaFjjuGyHBmXdsFFLTcVQ4mg1yJa8XdTlENu9heMa9cUZgyVHH+o uKZUe44Y7JLsGccne7YggSTfxEF99wHr9fYnjCdsYYRX53w+SL0cjr63sTjQchuFQ5xe WbqnyIdd1Gb7nz7ykp21L2j8v82z96hxm42keMtf+6U3u3pW3x2HSxBWi3ZXJ8Z5zSjd NHjPQpnqydpPofRIFF2H1kTxNhd6LbjBpohrhwWVyZtAvFa7/0ZClkBufNnAi9kaaeZe ttxVNKCUGxkI/CxlC4Uc8TeZMcRvw2Rf2c0kkSEZKnOODOM4fm+SEy5oiiLwqnNwZSM0 WLVQ== 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=HdJ+2t0gL5zUBULh0wxTvXD/jJHQMjRu5f/2scMrQFs=; b=toHDc6l5Q+jQu9NE9Bpay6J1XCuNwJAv4/i43haZFC5AttSMOqMuFB6mEUrL5Jt6Ro 0y9VKj11x5fiYlufAHvKeEJhZeU0U/bz6h/Gk+BMJQ6iQEycalI/owrF4BmaU89w74Uq vFVt5ecd2VDN7Cb/XDO3YL49M41aeBTpjESP+NLguLqH8zPIbIqqcPx0WDUStrgw2nZE 3eu838pgqBxVTx0qEfketRPsUgHiOzKK1TrkhWp+0Z9ZO7pDihEsCoVcdT4g9a5VgKhs zDyTav8UUAZANxRoUsoxPdHaJI2Y+vlo6vrga1hnOxwItGeFtTlWk1jd01u4Bf0ASTd0 a1uA== X-Gm-Message-State: AOAM530w0j0ATnpQRjz1H+hWSboV5DhFSWijb67Fue+3Zz8lxZhBn8Mc 4SDBIDA0+mVNxN3Ivpx/2WlcRA== X-Received: by 2002:ad4:470f:: with SMTP id k15mr13640963qvz.216.1596395918016; Sun, 02 Aug 2020 12:18:38 -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 t35sm19789974qth.79.2020.08.02.12.18.36 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 02 Aug 2020 12:18:37 -0700 (PDT) Date: Sun, 2 Aug 2020 12:18:35 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , Andrea Arcangeli , Song Liu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] khugepaged: khugepaged_test_exit() check mmget_still_valid() 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move collapse_huge_page()'s mmget_still_valid() check into khugepaged_test_exit() itself. collapse_huge_page() is used for anon THP only, and earned its mmget_still_valid() check because it inserts a huge pmd entry in place of the page table's pmd entry; whereas collapse_file()'s retract_page_tables() or collapse_pte_mapped_thp() merely clears the page table's pmd entry. But core dumping without mmap lock must have been as open to mistaking a racily cleared pmd entry for a page table at physical page 0, as exit_mmap() was. And we certainly have no interest in mapping as a THP once dumping core. Fixes: 59ea6d06cfa9 ("coredump: fix race condition between collapse_huge_page() and core dumping") Signed-off-by: Hugh Dickins Cc: stable@vger.kernel.org # v4.8+ --- Note on stable backporting: the coredump fix was backported as far as v3.16, but this extension only needed where shmem or file THP supported. mm/khugepaged.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- 5.8-rc7/mm/khugepaged.c 2020-07-26 16:58:02.189038680 -0700 +++ linux/mm/khugepaged.c 2020-08-02 10:56:11.105617241 -0700 @@ -431,7 +431,7 @@ static void insert_to_mm_slots_hash(stru static inline int khugepaged_test_exit(struct mm_struct *mm) { - return atomic_read(&mm->mm_users) == 0; + return atomic_read(&mm->mm_users) == 0 || !mmget_still_valid(mm); } static bool hugepage_vma_check(struct vm_area_struct *vma, @@ -1100,9 +1100,6 @@ static void collapse_huge_page(struct mm * handled by the anon_vma lock + PG_lock. */ mmap_write_lock(mm); - result = SCAN_ANY_PROCESS; - if (!mmget_still_valid(mm)) - goto out; result = hugepage_vma_revalidate(mm, address, &vma); if (result) goto out;