From patchwork Thu Apr 22 00:37:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12217205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B68ACC43460 for ; Thu, 22 Apr 2021 00:37:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 784D861445 for ; Thu, 22 Apr 2021 00:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343936AbhDVAiM (ORCPT ); Wed, 21 Apr 2021 20:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234856AbhDVAiM (ORCPT ); Wed, 21 Apr 2021 20:38:12 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D466FC06174A for ; Wed, 21 Apr 2021 17:37:36 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id 8so11037896qkv.8 for ; Wed, 21 Apr 2021 17:37:36 -0700 (PDT) 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=zQ3oRqFEaYwUupWBz0Ob+9p/m78IpqRSVRzOwl1NExU=; b=YA4YGWCqTJFmMsrOHxlI/UdbFCODBETZ0PKicjaq8W+MO7k74dvfKTRVJ5blFY7Bat i4hOjfxV+MY28sfBh7CZQ2S4mSLZcTJzzwU5phkRvU0O95Qp8gQvGugTxKyjvJOTEZ/4 vYnaIZGmMbA1ipt0DA1S73cMSVJRkDXPuK3n2oFOkJI7QjXuQVL9NNaBxfT3GSKYDU1h THOWkOTIgOZnvrWCMm3JEH/LYbRfEoVLD6GZib4mLzDzIvE8WRoIKI7csn9sKv8qET9b wuHpi3aE4SL8MkROICgmJxe7MRbe0q72Zyp7h8cUbriKNb5YqtAekLueCKKnBVBzNGPt AV/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=zQ3oRqFEaYwUupWBz0Ob+9p/m78IpqRSVRzOwl1NExU=; b=enDqZwgI6RcR8N/RCVJU1vFImd+UzuN83L3+MJRj7In4xt6jW/CAk4OSRutC4P6A95 5XcJnvN/pzS6acyRg0BMKfzqlMJtlmaJyquqaEnjTnHl0tEIm5O6rwkMNYY6cjemL7jz T9DJNDa58pz4J8Srros1l4lN4Y8WFJEVnhrOpxOInPSCX8nQR/Zlo2/7kYYXW1ZCtRFV 20agFYxufrYTHJ2MuJsNiiKlUbSt60eAKfPRPHgYeqEHpaD7Cj8MTwOFhXAl3s+o8HsY D+7IznMhYi9cIKt09fAMe0e5pOfvHunV/0ehrCs2EBflZy8eRDgymH6wFZMdaRwWfSu/ g7CQ== X-Gm-Message-State: AOAM531Gjovl3rY4Bw9q3bejgJg2V5SM/AKkUvD13N6qyGWyN2yRX4sO YvM+CudQY05wYjYxvobt/tI52w== X-Google-Smtp-Source: ABdhPJxhPr50cgrqI2sPQlTusR7MLgOC52sKYJ/5T1GklWlbSpBpN1INHypgW+5A+R7wJBx4RtPRvg== X-Received: by 2002:a37:8bc1:: with SMTP id n184mr1021888qkd.268.1619051855892; Wed, 21 Apr 2021 17:37:35 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id h65sm933294qkc.128.2021.04.21.17.37.34 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Wed, 21 Apr 2021 17:37:35 -0700 (PDT) Date: Wed, 21 Apr 2021 17:37:33 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Hugh Dickins , Matthew Wilcox , William Kucharski , Christoph Hellwig , Jan Kara , Dave Chinner , Johannes Weiner , "Kirill A. Shutemov" , Yang Shi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] mm/filemap: fix find_lock_entries hang on 32-bit THP In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No problem on 64-bit, or without huge pages, but xfstests generic/308 hung uninterruptibly on 32-bit huge tmpfs. Since 4.13's 0cc3b0ec23ce ("Clarify (and fix) MAX_LFS_FILESIZE macros"), MAX_LFS_FILESIZE is only a PAGE_SIZE away from wrapping 32-bit xa_index to 0, so the new find_lock_entries() has to be extra careful when handling a THP. Fixes: 5c211ba29deb ("mm: add and use find_lock_entries") Signed-off-by: Hugh Dickins --- mm/filemap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- 5.12-rc8/mm/filemap.c 2021-02-26 19:42:39.812156085 -0800 +++ linux/mm/filemap.c 2021-04-20 23:20:20.509464440 -0700 @@ -1969,8 +1969,14 @@ unlock: put: put_page(page); next: - if (!xa_is_value(page) && PageTransHuge(page)) - xas_set(&xas, page->index + thp_nr_pages(page)); + if (!xa_is_value(page) && PageTransHuge(page)) { + unsigned int nr_pages = thp_nr_pages(page); + + /* Final THP may cross MAX_LFS_FILESIZE on 32-bit */ + xas_set(&xas, page->index + nr_pages); + if (xas.xa_index < nr_pages) + break; + } } rcu_read_unlock();