Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8112849imu; Tue, 4 Dec 2018 03:13:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/VTfs+Tkle6xTMRW9/tBvmxN2QuahXtQKxRXF79BpcGYfWG/7zEspDRrYHiPyS+BfTOlnFa X-Received: by 2002:a17:902:2e01:: with SMTP id q1mr652253plb.97.1543921996314; Tue, 04 Dec 2018 03:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921996; cv=none; d=google.com; s=arc-20160816; b=mttqzhykkxbHecjf1cptWUxVJbo3n9HBhy7lluVHUFAFloK6P+PgxrFwxz5Kn3ulGi eHOYXGt/uBsXO4ymXLjCa6KPuwP4OW3rdDIbh330oNfH4gjAS6F75V55lfgJuAusmz2p /e/FDs9RP20DuAf9pSZAq2cG2Or2ZlDxb9uJ+Y7wkiQ9eOGVKlQgKg6TufLRLjLVSXTu o2vaa777REQpfsPKunwA1vRW12rEgIDr6aEpuwt4PKdhtP5ErUo9GCjM8vUn3J6iKGYC Qc8FeHdCJF3zwPoCpQIvrW//jPb/Ti6gBNfd0/NY0EBRXqEApLwwtGABoosV287t+jVM hPPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1btaa0SaeQ69XEYJgtsszrMIxQqpoI9xpktBpWqcOu4=; b=bNTWG0TfpOYM7u/JcpqiPP3eeaQQ+GgFwvYksd62HHnpECYI3nNakh6/OCqeuX9Nxb 7ugDQE1GCdkYi/IlVlgTLxMacj5TrGPjhvOsFtsf68boVkMS3S9rZMFSeKpunVVOdUxc RjABvRgrw1LOg7tUkRKPAyxEF1U0X8H7WA4N1mZ3EHCAu9wlF4jpk805sn1bhnZ9HM2F JCat3hCKOEK/57ifAHwm1nsSe1TMPQi9RRePEvb+4Qt7ZG/gJqvz44O+M2tGTg+wmE6a tT0zNRFa6rwMnqJZPuFq7jUnlCoaNEKgGHCUt5F5LAWfJaH441hY2SeMByioYRKJXohB l9QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vzKOi7lo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si14931454pgl.570.2018.12.04.03.13.00; Tue, 04 Dec 2018 03:13:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vzKOi7lo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728515AbeLDLLT (ORCPT + 99 others); Tue, 4 Dec 2018 06:11:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:58610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728507AbeLDLI7 (ORCPT ); Tue, 4 Dec 2018 06:08:59 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E029214DB; Tue, 4 Dec 2018 11:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921738; bh=kSwrj/y6N1gLvfnF3l6UGNZ+cWKblqNB7gBF1VGcL0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vzKOi7loN21ugae9pT1mafJHdtuLx/vrfyh820/Fa/VLgwnpUpZma20//MeRBsRi+ R027LX7Yy3rIOiYroOhHamzn48Q1TuauHa+o/3ZjKnv01Y85q46sKWAckcFo7dicHE MnXjd6BnE4zYBDptVln78Nq6i/9k2TK4Brwqkj8w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hugh Dickins , Matthew Wilcox , "Kirill A. Shutemov" , Jerome Glisse , Konstantin Khlebnikov , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.9 05/50] mm/khugepaged: collapse_shmem() stop if punched or truncated Date: Tue, 4 Dec 2018 11:50:00 +0100 Message-Id: <20181204103714.772372883@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103714.485546262@linuxfoundation.org> References: <20181204103714.485546262@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ commit 701270fa193aadf00bdcf607738f64997275d4c7 upstream. Huge tmpfs testing showed that although collapse_shmem() recognizes a concurrently truncated or hole-punched page correctly, its handling of holes was liable to refill an emptied extent. Add check to stop that. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261522040.2275@eggly.anvils Fixes: f3f0e1d2150b2 ("khugepaged: add support of collapse for tmpfs/shmem pages") Signed-off-by: Hugh Dickins Reviewed-by: Matthew Wilcox Cc: Kirill A. Shutemov Cc: Jerome Glisse Cc: Konstantin Khlebnikov Cc: [4.8+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/khugepaged.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 1df37ee996d5..62de24194f24 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1351,6 +1351,16 @@ static void collapse_shmem(struct mm_struct *mm, radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { int n = min(iter.index, end) - index; + /* + * Stop if extent has been hole-punched, and is now completely + * empty (the more obvious i_size_read() check would take an + * irq-unsafe seqlock on 32-bit). + */ + if (n >= HPAGE_PMD_NR) { + result = SCAN_TRUNCATED; + goto tree_locked; + } + /* * Handle holes in the radix tree: charge it from shmem and * insert relevant subpage of new_page into the radix-tree. @@ -1462,6 +1472,11 @@ static void collapse_shmem(struct mm_struct *mm, if (result == SCAN_SUCCEED && index < end) { int n = end - index; + /* Stop if extent has been truncated, and is now empty */ + if (n >= HPAGE_PMD_NR) { + result = SCAN_TRUNCATED; + goto tree_locked; + } if (!shmem_charge(mapping->host, n)) { result = SCAN_FAIL; goto tree_locked; -- 2.17.1