Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8132127imu; Tue, 4 Dec 2018 03:33:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vj4zj6JrcGndAFh+mDLwCDm9CTSw6xPX7czEh8VKjgV25y8WX3adP+WJ9rgrdKDGnDdqzE X-Received: by 2002:a62:3948:: with SMTP id g69mr19978496pfa.114.1543923229002; Tue, 04 Dec 2018 03:33:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923228; cv=none; d=google.com; s=arc-20160816; b=M6ebxasn3rX81mQcEq2S8JsAP/rc1+c5Y6Zrl5BoN4LbcSEL7pAwQ5RNjWt0aTyIzk VlBRHI6aeDrr4kgxeR14NsXbmdN7PA34K7BZgdQ62RGSssAM27GAQzOV7z3ZKpTvQX+9 u+jskIG7JwEif3alJvnk0M7C+gTltv4ti/ImQCERS03DIm0MWBZhXR2TsMUfqGNkplBP nax9/QefcvvZ/MqFe5Ra22yKHJdcjlxKFTOph3BrNwSkAWxQzqq6z0SmS6wHz8+tzpt1 fCushr/fcs+b3t/PYKA3kVuW+Th0Iq/ebkI+2dNGSvIByxsKIRIah5Graag6yXXc1XER IaoA== 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=MRXzx+Bftw65pcjF/sQLejlAM/VE1fyi1OxLKpJv73c=; b=kk1zxLM3syxYjsPbs2zMc/JMp1GpxqgnI83n/4X/DPFPaFWmrwcguJJ8xr3ANbpmyN GMAa0MWGtMWGExp3T79FFwk4r6umjE4e4hFxk2iBZSFbNA1rcK17WUgCU1DL47iuHzWL e6NaI5aJB8SkAC6T98jsO3FRkC6laRBSxQ2xKAwlSOgiziQ0mIqOMrBR4flPzVE26uGQ nJ+KUBsEZoVkz9LJ08GUANcflZrX03/HbL1GKvPwiCuAqu1nvkvQsUrMHlmhmk1PvKS1 EKteeP7LvBMoQyp6Aq8PP8v58X1Q/UfyfYRrOlVUKTTy1VyVF2LNNctDSqv+vVGaG7vo nt2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="j/Qm0+AZ"; 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 b2si15783487pgh.475.2018.12.04.03.33.33; Tue, 04 Dec 2018 03:33:48 -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="j/Qm0+AZ"; 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 S1726564AbeLDLbf (ORCPT + 99 others); Tue, 4 Dec 2018 06:31:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:39808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbeLDK42 (ORCPT ); Tue, 4 Dec 2018 05:56:28 -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 BA139214ED; Tue, 4 Dec 2018 10:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543920988; bh=Zb/Uh5jkgfSc5bzzGsdljo3iPPqEzjWvgolqSAALcgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/Qm0+AZR1dMJMQQHYvE/INUp76oOJdrxBwfKtbUweajMJtpQIkN9OKI5mrKeA96p 5PA/hRKxylJ2IvPNJ653oDYBROoH+UeHrnG7ZuyGMEIQPQmHx2Q/yfRv78X+K0AnMJ 4aQNCHIt2nxjRzz00Y6KKY2zmAP1Zpv0+i2uAsDw= 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.19 004/139] mm/khugepaged: collapse_shmem() stop if punched or truncated Date: Tue, 4 Dec 2018 11:48:05 +0100 Message-Id: <20181204103650.134100005@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@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.19-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 a31d740e6cd1..0378f758b065 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1349,6 +1349,16 @@ static void collapse_shmem(struct mm_struct *mm, radix_tree_for_each_slot(slot, &mapping->i_pages, &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. @@ -1459,6 +1469,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