Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8133378imu; Tue, 4 Dec 2018 03:35:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wd8blcIKpW5/yHJ/3PZfTYPLxlkDXpGv5o5hhuCLnwtS9xAjyUDqJk2IJz7hc8Z7SqZe3s X-Received: by 2002:a63:604f:: with SMTP id u76mr16660658pgb.401.1543923303634; Tue, 04 Dec 2018 03:35:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923303; cv=none; d=google.com; s=arc-20160816; b=KP9n58eGpJuqQLF8ne9sDzYrNHRTjySBlPFj/ytwVRx45n10MvQ+WaDEz7fXU7RA5R g6tCmyLegP9T9L8eryippKUPghz05t+bgrWALQHWJc4YO+Qf2SRzy7jO+QZy+cqUdAFN uIuFuiVpjy/pJMMVvvhbpbqVIrnp3Q1AbBiRiUefgRj3iBHs6GOcDtdyHJxUZe40kI14 zCPBb2LLVx2RoJvv7DJNRT+c+17qNkZSKeQJaZaaAc4cCWIYrPa3YPwpRvmkLZ8pbAY8 souCSnn2uVNfUa7BUxxOKjhyDWk/n2SAyEj7624AYpWPH9eXZ8ndkF/rtrtjHH0o0cib aWvA== 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=8gnAUblCybfIgC0lHRpmXTzjQIfnVfmATceRts3cUKE=; b=TW6EbnWVoxWtPOw97HpVYqUg05ST6o7cNqlI4wRt+iNS7a3AMGEXUSackQbOuXtUr7 jaU939OECzrHTicBqG7nfw9avKwY8D/gS1CgJYwv0fnbTEZKNCcZb/jLyotrAl6lqPQy NlQrLdNuSYBdXQDAGZA+VRxA1Xb6oV04tttBDwkMqT0hIT011lN0DQgsVnfZEQQQHmJQ YudPF63XYb4SdHuK7Ba1d+iOCB/1u+QZ7mYZ9Up935Rf0lznxj3uayIQaE01uwzPKwh1 632TYaFFApgN7mS+ZYf6BL3x6PbQ+y258/aSJ6BzoN5KxIXp6ufKyJCCxnfQdSv+TPXY LLSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z3OWu3r2; 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 s19si16243783plp.151.2018.12.04.03.34.48; Tue, 04 Dec 2018 03:35:03 -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=z3OWu3r2; 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 S1726325AbeLDKzq (ORCPT + 99 others); Tue, 4 Dec 2018 05:55:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:38628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbeLDKzn (ORCPT ); Tue, 4 Dec 2018 05:55:43 -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 C39D82146D; Tue, 4 Dec 2018 10:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543920942; bh=vm/x5S6HsiAquvIAiDNLEIGC6+8LxWzJ0Bgj6Rn71+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z3OWu3r2wnBca25wHo+0tm+akCzTEYBYKxDx7Ggi+KhDfXiEG6eSjefHO9n3qDAko QEufMvGtmqm5I9p9FmS6s/xUighttPBB+vl52Nb3Zn+djUITC/R18zCG1XIClZuNL6 0MbdSTRc/AE0UM0vA7qnXACzhnRMlihhrji+THuk= 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.19 002/139] mm/huge_memory: splitting set mapping+index before unfreeze Date: Tue, 4 Dec 2018 11:48:03 +0100 Message-Id: <20181204103650.049827290@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 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 ef573d719eb4..c12b441a99f9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2373,6 +2373,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(); @@ -2393,12 +2399,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)); /* -- 2.17.1