Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8104322imu; Tue, 4 Dec 2018 03:04:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/VnSxsd+Pub9eqPMU7D/6kBuK6VTPXOmdwyBnn7yFWfi0dVpIoScOfRdKzH/7PrpIi35B8M X-Received: by 2002:a17:902:3283:: with SMTP id z3mr19945746plb.76.1543921491817; Tue, 04 Dec 2018 03:04:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921491; cv=none; d=google.com; s=arc-20160816; b=sfENkxJSV/dP8QLuw9S27g2e8XOgZ4Pv+A74UBT6mQrxArroPOwVw7fpHo2pghdiSD 7xxM9awkdNQtoe0crVgdaDTMri1Uuqac2ayroUOkACFjNucitmQxiT3i8mqPRDNcR65m 60RTdQ3QJHTKjNJ500PGZxm5I0wqvg5+iYyFIkcxzN1ed+tps3nXYxEuPsZtcjcsBYzO Je7+lpFHDzMtRyJKLr444dkdbs1nDj4grifzoLdKO5PAngl/S1tl3sUIXDVrH8gCfDq9 zLVngCTGnEXMakX9Y4cWFFmydVKTtknt1cTUTEp0QraaWsdDqmA8Ba5RzNXBlISpQJAj va4A== 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=lErpLd5BWs54/6xtSzmQirNzPw1VvEx6P3sUx6fhD4w=; b=FCqq88I0OQijhfWQv/41pSiPuCbQ+qoJvZ2MftYCVEAuuWEIfHPXG0yUPYoQvzQ4B6 mjoJGBf+/drFPZcHAbmz3neBYKyOag9+GwlvFP7HV4RI3nIDNlodnuXNYjU4PjfGExzv t2OSgrfr8enf3J4FHlZkRSbxIDZjd48QVuiF4AR1SlqAVO7zts4+cv5lb+rji5OwNtCy /leqmmi+hEbSstnoS3CnyiWlbgKYNVm6qbjI43UA9N4zffKBGgbvxgccjJzznajwO0pg bTeaxRZ05f5mARer/KnyKgejJew+4BMV0vOMQy55Tl8ALbBTCfJaGAuKuAHAAQt20bgD yIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lb0vtxwz; 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 11si15015839pgs.126.2018.12.04.03.04.35; Tue, 04 Dec 2018 03:04:51 -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=lb0vtxwz; 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 S1727562AbeLDLCE (ORCPT + 99 others); Tue, 4 Dec 2018 06:02:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:47806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726859AbeLDLCC (ORCPT ); Tue, 4 Dec 2018 06:02:02 -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 6D9EE2146D; Tue, 4 Dec 2018 11:02:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921322; bh=4PLHGUQZjxaSpmYXVhH54mUbTEfypfzBk6/jqKmsD38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lb0vtxwz6tDAc/eTfwlpAXRH3jnnsxDM5fYoRuUEm951cc+ntQ+Uhyv4xVv1pOjZ9 1run7RTdZlstuvbyM13xc7gIIZbUn1z8dpdUQpSLmS241BDkDXuXdhYGxvuX4oHJdz ETT1gOjAeclXsTPXL5311K9qiIOKqjnd5R0N6YDk= 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.14 005/146] mm/khugepaged: collapse_shmem() stop if punched or truncated Date: Tue, 4 Dec 2018 11:48:11 +0100 Message-Id: <20181204103726.989837703@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103726.750894136@linuxfoundation.org> References: <20181204103726.750894136@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.14-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 0a5bb3e8a8a3..d4a06afbeda4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1352,6 +1352,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. @@ -1463,6 +1473,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