From patchwork Mon Nov 26 23:19:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 10699327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9780C13BB for ; Mon, 26 Nov 2018 23:20:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 842382A50E for ; Mon, 26 Nov 2018 23:20:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 715BC2A51A; Mon, 26 Nov 2018 23:20:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 810CD2A50E for ; Mon, 26 Nov 2018 23:20:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C8896B4455; Mon, 26 Nov 2018 18:20:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 853146B4457; Mon, 26 Nov 2018 18:20:01 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F3E06B4458; Mon, 26 Nov 2018 18:20:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 245186B4455 for ; Mon, 26 Nov 2018 18:20:01 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id q62so8793654pgq.9 for ; Mon, 26 Nov 2018 15:20:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :in-reply-to:message-id:references:user-agent:mime-version; bh=khDn23SWH+VCa5WnDaGtQ9G0p+QCH9yXW3GVZzGGRA8=; b=d/iIXqN3y0wx225xa5ZN0x5TnTa1KlLlntcvRHCFJA/TSLtQD2thnqnLqbFk+p8Uwt QpyPlG2hNHKnhir/KonQfnKxmZAc+LQ4rn5mc0+S3KwkpPcdKEZyKJaVW4ZTGYF597t5 JpqFBkh6CAMKy8BH+ZYeNhRRo8b/4URWU6uMGYJoKIKUT+bTwmksAgxMmVAAdTsr72Es wW8UgqptdVBXwNJBxjdnkCHNRjr8gKA+mk8wgGTenL8APRgsDCmrRF/H0FjtUtsDOksB mS4rpYFJdqTqGSo2AmPIw+kMKGsIinxlSFMlJo1TrpcSuJXoXSec2EMICC290WqkmlDx Oq0Q== X-Gm-Message-State: AA+aEWYUjUSpTe2NIU/IkLjk1FxV16sNgX5FhvcQtHc25tK+gAb7ZFjP MqhVS7TMOYOO8kmbGVun2iZheIBe7arLZrxLUtBJDVVs0sMmTybAlM0gOAJrn4k7ujCqwNjnWWP 4oR5tvL1vDFd1vfLtKWgVq4G2AhiZEeFlzajR4br6IeqCZz104YF+DIzSe3B6k5YjxOY8C5S31o F88Ns7f/ILaEkUhi1k/Y8XTbnAvIN569gyQifer204cRxfgw5G/uGFUqumy/pbM2ALtgyxIA4ja XbDnsZJPExDNtoMsMVewms//mG+qcLTEeiYvwNgNSf7Xr+1RFC5FKY+d2R1yX0WWNUYVcbXv/si 9dZUFISNG7m7PZ33EUfm26JWPW9JV4TZ0iIETCJVctbIzvjo8eyzMJIuyFddyYwrrV7aVnBvgm+ S X-Received: by 2002:a17:902:b60a:: with SMTP id b10mr28284607pls.303.1543274400783; Mon, 26 Nov 2018 15:20:00 -0800 (PST) X-Received: by 2002:a17:902:b60a:: with SMTP id b10mr28284582pls.303.1543274400147; Mon, 26 Nov 2018 15:20:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543274400; cv=none; d=google.com; s=arc-20160816; b=xD1gsGob+mow7BFJa8gSm7XNWTSBAjarb1PbH1g+XPUpLied55bu0B/2LQFek4w30L GZ/PKbtqYAiGKUXmvoimoMkc1+u6FIg3ucxOS9iAR7QcctzuI/6wMUZeucOPsOrkj5dy Q6hp6YoxdU3XpF8DKBJaK9tFDN956sZ7B7be1TKwwdgr76Uo5rPqzkJE1dqG+nFKsCEm ennU1ViXWSD0yvKloRSIRVfd+yatz81ax2EDIpRK+4vjrzp1GMFuicJODlhvYIW/Qn+P 4NKiQF17EUFsFX9t8n/UDufbh1wwzYDK+TUwUqq3bUQD8sBO/h2d53snn5CB9SQ80VZE v3Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:dkim-signature; bh=khDn23SWH+VCa5WnDaGtQ9G0p+QCH9yXW3GVZzGGRA8=; b=r7ki3svttMhQUnzgU+4Ifr7iRWR9X9/56+lP03SNVs3AuGnZNt+C/TO4W8vyXB6QaW 1UfmI1sOtkMONrlpPrYWACg0q75TXO+CGsmlT3GmfQbXftfr0P9EujT0yQ85+Owd0lS7 6O5R5G+L+DXO0VA1XfWCHaPhIw/EQM9XHxVMWM712BGoSjj/wJUA5QKqlkRsvdSeTh12 H/p7yu/E3mj+xcVGcl3f7Lpk9W/jvJcnD2a+TB0Ln6X1w3LRseiHxqgF9RfOaXXqbTF5 y700+cEBqziBtCVq2NDYCusEpkBDX1Z9CLGaaauAHBvgychGcVpNpNzriLZSNfxz+X6A Or1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OKedTm5U; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n13sor2812115pfj.12.2018.11.26.15.20.00 for (Google Transport Security); Mon, 26 Nov 2018 15:20:00 -0800 (PST) Received-SPF: pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OKedTm5U; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=khDn23SWH+VCa5WnDaGtQ9G0p+QCH9yXW3GVZzGGRA8=; b=OKedTm5UXv0BNAxfE+pLCb7261S0fsMpfSMQl9R2MbYMvd/xjMLSD7zEpowCyvENqo h9YJlbHRgkJAZ3QmcUhR8aLtM/DrIAU7oJ1j1fDaQ++7BAD95sPDunJiMx4hB7JaB5V7 bKMY+JtkszjJnHVLj7Zsyl7HQJP8OEMGZ+7OWxA1EQ5Hd5Bfc6i2vEzmG2VTS8va+g7T 2zDICEWeLTPZUA4OusZ3C139AehglM4HPXtl3ilBdLXh7msSLoiLFNFP5FdYoriRIdMt iAiySEZFNE8yWzZMoIPe8iyzrKIxLhElfZ2Pt0rZIwVu1q1TsFDEUicS8QtXOn9Re9vM K7dg== X-Google-Smtp-Source: AJdET5dE8PEPcQo4WzICFBQ3PNPT+VfmhlobQluDLeVMuPdjvAcs17I+LLUfRL+mDeURYK09tE58sg== X-Received: by 2002:a62:c21c:: with SMTP id l28mr30018943pfg.74.1543274399402; Mon, 26 Nov 2018 15:19:59 -0800 (PST) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id x27sm2492472pfe.178.2018.11.26.15.19.58 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Nov 2018 15:19:58 -0800 (PST) Date: Mon, 26 Nov 2018 15:19:57 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , "Kirill A. Shutemov" , Matthew Wilcox , Konstantin Khlebnikov , linux-mm@kvack.org Subject: [PATCH 02/10] mm/huge_memory: splitting set mapping+index before unfreeze In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 Cc: Kirill A. Shutemov Cc: Konstantin Khlebnikov Cc: stable@vger.kernel.org # 4.8+ Acked-by: Kirill A. Shutemov --- 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 30100fac2341..cef2c256e7c4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2402,6 +2402,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(); @@ -2422,12 +2428,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)); /*