From patchwork Mon Nov 26 23:21:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 10699329 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 501BC13AD for ; Mon, 26 Nov 2018 23:22:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 328E82A591 for ; Mon, 26 Nov 2018 23:22:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2358A2A63A; Mon, 26 Nov 2018 23:22:05 +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 D62DF2A591 for ; Mon, 26 Nov 2018 23:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03EEC6B445A; Mon, 26 Nov 2018 18:22:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2FDD6B445B; Mon, 26 Nov 2018 18:22:02 -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 DD1276B445C; Mon, 26 Nov 2018 18:22:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 975AF6B445A for ; Mon, 26 Nov 2018 18:22:02 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id p3so2415831plk.9 for ; Mon, 26 Nov 2018 15:22:02 -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=Sd48llQOR4D/qyL1g9Jnl5MHdkb3/UlhYavmB9jv1dY=; b=CAVcEt6IhttbJQu1If2OSmG3mmV55g9G7T+jDDOLfQ4kuTzQxGvi1dRyJjle2OTL3N VJYYpbyStRNMv29LiKzPWhGJlHkAJtr/2/F1EHNLal6VwHJVWoKy2Koxeb7frLbEOIoH xzdU4c9ly3t6cW1dT/y0Eg9WpfyWhwXKa75myon7hau9MzfZsu+JSyuYCLRTGgYVE+BL RQrvfgxbvbrfSKqXOkZ9MlHNqDdOFFPeAkNMYlPmdWwrhvg1JgW6jYBwxldSZhfGJC0i zzXzcyeT1QBeMVsGMhlqoNmBUebE9adsJIoSKWQLVQKsv+pxnx/ioZiquLlgFPbdZZXW uZNA== X-Gm-Message-State: AA+aEWYOAxO65Ep57qt7R9varZbY6lMrUemFWfWmPGx4XJvBZIXeF/kc +QejAFT8eEH8rtFPMkoyefzmfXJYyQBQ9lFxyKpL48sQAAvYu4D9eV2hJLTza3/7Z1d7GeLDymX gVh9cU6ZqLEl/X4p7kUJ/yo0Dufa3+HRmaboWSS2CrkWcvKslp11RsBbbMFx+xqF7tYXQABTOSW FgSf3Lhyc6BpmroIrpUHGOQjX8NsGqk9hVccJfG91L7s4uxwLiLTvTNJ/H9RtZ/QMo4H2JxYGZi Kn4T6jNRsELNwwmmN7M03eWOFwv95sKYXRATNY+kF1R9XBrFn8q8Gn08neDQ86uQpgQu9DLju7b EKCVrqmmuHPl+u7snzc8d1HMqsA99X4Dc1Sglq648pAOUTcCqztuFN2AGLpN+of45G1h+0zwmBa n X-Received: by 2002:a63:f615:: with SMTP id m21mr27574257pgh.428.1543274522269; Mon, 26 Nov 2018 15:22:02 -0800 (PST) X-Received: by 2002:a63:f615:: with SMTP id m21mr27574223pgh.428.1543274521504; Mon, 26 Nov 2018 15:22:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543274521; cv=none; d=google.com; s=arc-20160816; b=IMBFdfZkUn145ApafN26QkLCik3xEKiy9tOJUGTVLNhLJKwgEdSgDfonzuTpp++PpK VAt+Cy0ERSH7IVbzYHTBnc5UxOhBtBd4Y+M1mJrf7yFc573a1yjbjSSsLU8XlrMkMTEi VI+2SE1mgdaxb+7jxayDlW0wUQYIrW4Jmr6Gduas+1BJZDJd8EVGMBEJFcYjQa1jd07V T3AmNk4TM3U9et/dE9PnP4qMTNlddaChucSJYHElPdnDLz4L7U9demM1ZnH4hdKkGlA3 fVNQ2njz2dPtoN1BeO6HCryPRm+7+6e+fJDqyzB3OW54tkXtO9An79lcFD2SlpVHqFAY 2jzw== 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=Sd48llQOR4D/qyL1g9Jnl5MHdkb3/UlhYavmB9jv1dY=; b=xCxj08AssJjt+9MkHvqmx799hzUNp/RUybZXjga+ospoU9Ct1LDcjKzmQSq8RFCIlh 6sN3rpPVfnH2Mv8R6DwtXhipmgoK1smXXk+j/LhMZiJmpQvfSHTBqIKgTaHkp6dVHpg3 jOJpIBUAjkVXSM/4mdN6rJ84Ed1L7wKcS+Nud2nyrwoCGtM0zYyodjc+Tx5L7V5JP9hz UcrnpTy4I8e0NAHVvpnyYHKRN9hFOgSXhdyWQDg9r4DNyNqLA4FP3RQYBxe6P8h8YT/N 8/KAyWQzZWoruJd1xRHsx/OD7S5bS0lD/JEuFvyz/IYXExN/cNwuy/0knekOtCKAO3uP QHxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=l32BeqjW; 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 y73sor2781442pfd.54.2018.11.26.15.22.01 for (Google Transport Security); Mon, 26 Nov 2018 15:22:01 -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=l32BeqjW; 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=Sd48llQOR4D/qyL1g9Jnl5MHdkb3/UlhYavmB9jv1dY=; b=l32BeqjW/6g8fnU+g/0mZEfadbn2Fmd3vxypVj/uXzB2jVkSHupm3+53sy9mKGo1zP 2u7F9sXIJsHzwsl4+a4QYNHv026yTjo6LE5sB0npBN/efc1YNNPcTVDgLnehYg60U+54 KKweQLAV3dOpuFO13GJ5RvxpjbViPFQX5HM+HkWEORSChqaNSfMoGRpD3wZ8S628bpfP 0LBqXH/JSF7HnA5jH05k4CyBE2S1dmanjJ420xyuVhNIkD9tB7X/PMQfaZcW1S02nRQB qjvGV5xrwSqPNbzxGFqOYE2NsfN7kGQe/tpKSgvDbmpyURnazLPrdKpFyVD4dXgdRjpc qokg== X-Google-Smtp-Source: AJdET5f94N7DQav0rdhXNHF8c8uVfneBZ69jde1doHH2ayYG/EVeSeiQb0YsRsxV5b6iVqf1qYGLDg== X-Received: by 2002:a62:798f:: with SMTP id u137mr30481824pfc.168.1543274520560; Mon, 26 Nov 2018 15:22:00 -0800 (PST) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id v76sm2094359pfj.145.2018.11.26.15.21.59 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Nov 2018 15:21:59 -0800 (PST) Date: Mon, 26 Nov 2018 15:21:58 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , "Kirill A. Shutemov" , Matthew Wilcox , linux-mm@kvack.org Subject: [PATCH 03/10] mm/huge_memory: fix lockdep complaint on 32-bit i_size_read() 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 testing, on 32-bit kernel with lockdep enabled, showed that __split_huge_page() was using i_size_read() while holding the irq-safe lru_lock and page tree lock, but the 32-bit i_size_read() uses an irq-unsafe seqlock which should not be nested inside them. Instead, read the i_size earlier in split_huge_page_to_list(), and pass the end offset down to __split_huge_page(): all while holding head page lock, which is enough to prevent truncation of that extent before the page tree lock has been taken. Fixes: baa355fd33142 ("thp: file pages support for split_huge_page()") Signed-off-by: Hugh Dickins Cc: Kirill A. Shutemov Cc: stable@vger.kernel.org # 4.8+ Acked-by: Kirill A. Shutemov --- mm/huge_memory.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index cef2c256e7c4..622cced74fd9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2439,12 +2439,11 @@ static void __split_huge_page_tail(struct page *head, int tail, } static void __split_huge_page(struct page *page, struct list_head *list, - unsigned long flags) + pgoff_t end, unsigned long flags) { struct page *head = compound_head(page); struct zone *zone = page_zone(head); struct lruvec *lruvec; - pgoff_t end = -1; int i; lruvec = mem_cgroup_page_lruvec(head, zone->zone_pgdat); @@ -2452,9 +2451,6 @@ static void __split_huge_page(struct page *page, struct list_head *list, /* complete memcg works before add pages to LRU */ mem_cgroup_split_huge_fixup(head); - if (!PageAnon(page)) - end = DIV_ROUND_UP(i_size_read(head->mapping->host), PAGE_SIZE); - for (i = HPAGE_PMD_NR - 1; i >= 1; i--) { __split_huge_page_tail(head, i, lruvec, list); /* Some pages can be beyond i_size: drop them from page cache */ @@ -2626,6 +2622,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) int count, mapcount, extra_pins, ret; bool mlocked; unsigned long flags; + pgoff_t end; VM_BUG_ON_PAGE(is_huge_zero_page(page), page); VM_BUG_ON_PAGE(!PageLocked(page), page); @@ -2648,6 +2645,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) ret = -EBUSY; goto out; } + end = -1; mapping = NULL; anon_vma_lock_write(anon_vma); } else { @@ -2661,6 +2659,15 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) anon_vma = NULL; i_mmap_lock_read(mapping); + + /* + *__split_huge_page() may need to trim off pages beyond EOF: + * but on 32-bit, i_size_read() takes an irq-unsafe seqlock, + * which cannot be nested inside the page tree lock. So note + * end now: i_size itself may be changed at any moment, but + * head page lock is good enough to serialize the trimming. + */ + end = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE); } /* @@ -2707,7 +2714,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) if (mapping) __dec_node_page_state(page, NR_SHMEM_THPS); spin_unlock(&pgdata->split_queue_lock); - __split_huge_page(page, list, flags); + __split_huge_page(page, list, end, flags); if (PageSwapCache(head)) { swp_entry_t entry = { .val = page_private(head) };