Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8112604imu; Tue, 4 Dec 2018 03:13:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8sekXf3opOWIju8m6tHDcZZqra33k131haaR+rzpAVDAG9b5NY6mSr2poKXiVHiBsWIIw X-Received: by 2002:a17:902:33c2:: with SMTP id b60mr19508182plc.211.1543921980322; Tue, 04 Dec 2018 03:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921980; cv=none; d=google.com; s=arc-20160816; b=avddggerAxA/hEBz0CAMjw1fEFmtjvcjXyo+a1rO3/0zvbDf/RX9syZ4zI8/tbhurH NMi9sL6dwINdaQAe9ZLgJIZVqKau8yz9nU6Nj17ZXJAG1RnVwnKbIZCKdnVL0k12ZQ/H ppvsjHy4mcEplPcnTnTdTPPJWw2GT1gf1pqI9okzK5ZmXQXPIC/15ecMYlRKWDYFxZ10 AZri8mM4qKrqDJVU8DkKVNJPDXDFlxPLDZT50lpjG1BBRNvu5pSNDHJ7JS/O3silWHfI PMhFWaBRRwwW/KBJMWg1dGXLy9f+RLg+9AgdIte2hw3b0W1jaM9cNakFLRiIFV76Pvwk hffA== 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=NZDhHIB4GN9NfHrMbZUJUdWe+GluAZPIr+NkFNXIrok=; b=qWciyLbMZNpuHlo3MVWeyH9cJLGEtn1ZVe9mGdvrVcKbhmsG330LePyEzOBm8+jlHz tqWgdGmVLY4w5TZ4bl7+e0c/mWLQohxcaZtDQD40R2Dp+iaFHeeLOP2yOJ2V+2HmeLIj moAmW1kx+L2Fvx2AsSggJgzWuFgF2Q5H21PW1xq8xNyGf/MbZ4YkUne3wkz4IllLrYRz EvFipOxU/uSpq4jjyel7G6gr4bOXeHf0SwYk0bMRJWSa6Dln/9SfEX3Iowxyu/rVEEdO r8wH6Q5xYUKVQBU+tWRrmgC6ntfD9FvMnmGyGeH/2JDj/jIW9EiK3xMwZRnDonrRQ8cj zXyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CeOJz67k; 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 c21si16555730plo.165.2018.12.04.03.12.45; Tue, 04 Dec 2018 03:13:00 -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=CeOJz67k; 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 S1728088AbeLDLMJ (ORCPT + 99 others); Tue, 4 Dec 2018 06:12:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:57984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728364AbeLDLId (ORCPT ); Tue, 4 Dec 2018 06:08:33 -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 378F22146D; Tue, 4 Dec 2018 11:08:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921712; bh=EPZ3u+u/9by9lg6tqDShXXaXQlxehgo0f/8A39KSmeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CeOJz67kCv2TRnQmFc+qfLeQJPTDrTk116PC0Bf5Y1F5nUxix5WwcTTdqMupojwKX 2h6SMjAWBg2CygZGSVlkS/xqXS/4Ix8aR/aM651WIkY2L544jECEwU6CjjwhyZv1SE sCkfxFmTJ0N6mPtSi167Sxlzr8lX+3TjmXkRmCjg= 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.9 03/50] mm/huge_memory: splitting set mapping+index before unfreeze Date: Tue, 4 Dec 2018 11:49:58 +0100 Message-Id: <20181204103714.652877731@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 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 c14aec110e90..5beb62fa3d30 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1894,6 +1894,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(); @@ -1914,12 +1920,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