Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8122884imu; Tue, 4 Dec 2018 03:23:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/UbOSTqhLcJ74vgFqCIMHbt2UhI6qQjAO06enphdC6VYAM5nUlzgXPmFEBVSDSbl8PbviKy X-Received: by 2002:a63:ef47:: with SMTP id c7mr16640688pgk.386.1543922631532; Tue, 04 Dec 2018 03:23:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543922631; cv=none; d=google.com; s=arc-20160816; b=RKY3zaUQQeZ89vvAG8imuVfGmsuXpjLJe/MYDXXzJ0vwESGDu+yc7sesPZHhlEPk0j 1DVwjRTqpZDzIyQYJ2CFW03Xw6ceh5r/EAHIVZp1dsY/sNtNvyc8Qz+d/U9g9cdLHkZn J39+RxXa9cGYzKwaTdXB9pnJF0daWglfpU0PicZ3/Jq5oSHEni8xhQbDdhmpYXPd3KyZ gU/c21dvtW15G2H32HZr/GtDIWgfnCz6ozm0/fHSGOvlkalsoRJKDS2ug53vH8q6pK0L cKGHn3rFn6prgdTin6Nh58XzhMF85LJNaT1kH9AQrNnEv++d0eL7cwEifwwWz9SUySYv FTTw== 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=fPVHOuUgo/l4p5IwGlkzsKKiUQt4+D9lvADWFoh8tJ4=; b=H+slDn/2BkGxPnMTjm4Kl+LaBxUF4n+7OrAHVQfbI4dofDFQt4lI2IfkkgFYR33Flb ZwIguhcm7reeLbCFHI7diuu2jHefhJo4ccN+j32ZFD0AcanQGjnj47pA3ceiMzkeHe7Q gZp4TUY/MhauhvDQ5ocXYOhJCNhC3MlhUyDLVAHWiLbAa0DgpUGdqHrUO03BSV9whgC+ KvILrSUq4WnVDa+9n7X0mQJwnQhlqB5BzkKevMQnhdPJ5GP5aiAen+TkYqQ7Dl7QCF7b fahRjtCkE2gBU99SzjOHRtUssb9ADTo0P7ceWNzy6KnwT0gp2XYpzdvUbcjR2W+Gh6m9 X0Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=grqE16JZ; 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 n5si16924919plp.294.2018.12.04.03.23.36; Tue, 04 Dec 2018 03:23: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=grqE16JZ; 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 S1727549AbeLDLB7 (ORCPT + 99 others); Tue, 4 Dec 2018 06:01:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:47682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727165AbeLDLB5 (ORCPT ); Tue, 4 Dec 2018 06:01:57 -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 7D982214F1; Tue, 4 Dec 2018 11:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921317; bh=obwpbtnsPaZeUdR0xIeTnpvRnvsl3289Rchk0GOXcEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=grqE16JZOT7aegiwUDSt6Tp3rrDc3BXCWMV2bOr8NKxWxdiq4Nn7T2RqrRrOYYj1Q JHywZrLRvjF/mQwlg7LWcOFTCiJrn4sUFT6EHDAHVFPqur5awy0FcMTv915A8MpVxT CTYCwrmRmkql90HyFYs+skmM+2J3IQdQ4RhVnSSE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hugh Dickins , "Kirill A. Shutemov" , Konstantin Khlebnikov , Jerome Glisse , Matthew Wilcox , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 003/146] mm/huge_memory: splitting set mapping+index before unfreeze Date: Tue, 4 Dec 2018 11:48:09 +0100 Message-Id: <20181204103726.893053610@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 173d9d9fd3ddae84c110fea8aedf1f26af6be9ec upstream. Huge tmpfs stress testing has occasionally hit shmem_undo_range()'s VM_BUG_ON_PAGE(page_to_pgoff(page) != index, page). Move the setting of mapping and index up before the page_ref_unfreeze() in __split_huge_page_tail() to fix this: so that a page cache lookup cannot get a reference while the tail's mapping and index are unstable. In fact, might as well move them up before the smp_wmb(): I don't see an actual need for that, but if I'm missing something, this way round is safer than the other, and no less efficient. You might argue that VM_BUG_ON_PAGE(page_to_pgoff(page) != index, page) is misplaced, and should be left until after the trylock_page(); but left as is has not crashed since, and gives more stringent assurance. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261516380.2275@eggly.anvils Fixes: e9b61f19858a5 ("thp: reintroduce split_huge_page()") Requires: 605ca5ede764 ("mm/huge_memory.c: reorder operations in __split_huge_page_tail()") Signed-off-by: Hugh Dickins Acked-by: Kirill A. Shutemov Cc: Konstantin Khlebnikov Cc: Jerome Glisse Cc: Matthew Wilcox Cc: [4.8+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/huge_memory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8969f5cf3174..69ffeb439b0f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2331,6 +2331,12 @@ static void __split_huge_page_tail(struct page *head, int tail, (1L << PG_unevictable) | (1L << PG_dirty))); + /* ->mapping in first tail page is compound_mapcount */ + VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING, + page_tail); + page_tail->mapping = head->mapping; + page_tail->index = head->index + tail; + /* Page flags must be visible before we make the page non-compound. */ smp_wmb(); @@ -2351,12 +2357,6 @@ static void __split_huge_page_tail(struct page *head, int tail, if (page_is_idle(head)) set_page_idle(page_tail); - /* ->mapping in first tail page is compound_mapcount */ - VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING, - page_tail); - page_tail->mapping = head->mapping; - - page_tail->index = head->index + tail; page_cpupid_xchg_last(page_tail, page_cpupid_last(head)); lru_add_page_tail(head, page_tail, lruvec, list); } -- 2.17.1