From patchwork Sun Aug 2 19:18:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11696847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0EE01392 for ; Sun, 2 Aug 2020 19:18:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9DF15206F6 for ; Sun, 2 Aug 2020 19:18:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sHovUWig" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DF15206F6 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 DAE028D00CE; Sun, 2 Aug 2020 15:18:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D5E698D00AA; Sun, 2 Aug 2020 15:18:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C27B38D00CE; Sun, 2 Aug 2020 15:18:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id A8A0C8D00AA for ; Sun, 2 Aug 2020 15:18:39 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 727DF3625 for ; Sun, 2 Aug 2020 19:18:39 +0000 (UTC) X-FDA: 77106590358.19.wire30_4b1467f26f97 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 4C6DF1AD1B0 for ; Sun, 2 Aug 2020 19:18:39 +0000 (UTC) X-Spam-Summary: 1,0,0,00e824c99e64d230,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:4250:4321:5007:6119:6261:6653:7682:7903:10004:10400:11026:11232:11473:11658:11914:12052:12114:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13069:13180:13229:13311:13357:13439:14096:14097:14181:14394:14659:14721:21080:21433:21444:21451:21611:21627:21990:30003:30054:30070,0,RBL:209.85.219.68:@google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04ygpx4tmfhrpaskhbus4cfxi1t3socshct5fcciajwmpfi4d8juzj1qxgpozwp.3j8sqdffeqyhfnxziezf3hsuncyubn38i351uatzzhuc8t7kfem4mcq9hq4mbei.1-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: wire30_4b1467f26f97 X-Filterd-Recvd-Size: 4884 Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Sun, 2 Aug 2020 19:18:38 +0000 (UTC) Received: by mail-qv1-f68.google.com with SMTP id r19so7936135qvw.11 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=P9A+CFym3PK9CyRxZZ1KS4Q80RrjuRzQS1n+ITMqGp5lfL8H9N9lRCYWgjCmAhSQOS 0OdnV64rm6tpiKtzR3r9019ElKHZ0nG/wj3G2ycVwi+YlUaRY9UCDzmZtV4EKvIYlanf 3u5MtJHYrthfveqLekOYZ/kCqKB72UqiuQM9WZIVoPBuH1R9Pb+jLzArixxw1SHX6wNr TQLtzr7BrqncfrB/tnforubbWHLasFw9XloTGGL27yXP4k3Gd3Uj9lkLGFcvCCAuktFH WCXLg5zyoUfagppspbqgYLPiJk96yliDw8yl+G/l0k7in7kF/OWHuk33vmkXRtNWlUei 15Vw== X-Gm-Message-State: AOAM531iL+WQBAcawP0BosstkjN3g7CzRbCRfNjS3MD2cE/M1c4XxFuv JJT4B2spwJKw2f65JVqa62ZDcQ== X-Google-Smtp-Source: ABdhPJytAGLtbvuAcLH2Aa3Pi1q3sHVCTmRRcn9PxMRLN7jSxbGSR0Xa0ZwxElE1+5veRXWQCgyQHQ== 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 X-Rspamd-Queue-Id: 4C6DF1AD1B0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: 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;