Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp44720pxb; Wed, 29 Sep 2021 20:38:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA5RD9OuZYArGDvc9vGPFEbp3LxeA06r2xgGioXwKUDaF2tbtDKhRK1e6W3NbQcOvlTVh7 X-Received: by 2002:a50:8163:: with SMTP id 90mr4296647edc.271.1632973133051; Wed, 29 Sep 2021 20:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632973133; cv=none; d=google.com; s=arc-20160816; b=ZtOxU8H6p4uig//0ahm1X/9lYjjxJfU5KG0mK6xWWkqwhl4qGeyhHlMILZ3uAnZilm 7Bzg9WiETtzHM4FlReHfSnivFgG29EcqmAJxZpf/Y7u4difxV5uiLJFw5xNo4mlFFVjw TQu9pIkuAf59aToFafGJACHBzq5/V36kgqAvvJrXkUUsmx6EjfrqZvNmsrMf661P2cjJ 5B/AnOgzNFy2klFe9wVGqh1TAOUACP7ytRhFCEgH80s865WHy7jyIuCQ1TJBWB6byjHa 2YSe/nZogYBjFyd9IomLpIzkS+8zC1zZgEVdDFgJ2arW26EQHOlgLltiR/xbNF9pUX9N 7hoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Z+Sw4eOcX5/Gr3Tfq5+WDtk6j0TCiVbSmBOTAS/pgs0=; b=A0BJe42BcBq3fcwCEwfgSDNnZB9h8a49Ewzesk1LpmcVhK+SVIBXDagJN7ssrwmYhq A1JlkImREEwsnGPZ3S7aJDdQ3Nj9VjwSF4aUnlOyDVV5l9VQd+NyPR9FBvyrqYswImFI wrz1Ra811KbFfGmxyFRp9FmRYu0kuZr6qbgtcpa6G70LPLi0fpcRfCrKuaCyoo0VYWJy pjIahfHsMRdV7WN1XJ2VPXP9Z4awDInzlXt17R79GVIFqn0vH9f/Jn06WEnv45jrpS4d EcWG1IRe+moZqXtIctLgAUjSC2UEV+wjrpEGwsrAfkWlG8a7X8cvXZrvx6kraE+NZuqD iN5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RBmeSUtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n11si2072739edt.358.2021.09.29.20.38.25; Wed, 29 Sep 2021 20:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RBmeSUtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347347AbhI3D2f (ORCPT + 99 others); Wed, 29 Sep 2021 23:28:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:59424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244576AbhI3D2f (ORCPT ); Wed, 29 Sep 2021 23:28:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EDA2A61882 for ; Thu, 30 Sep 2021 03:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632972413; bh=I4z0jgacNAuh06Bh+oxZt59cjKqg+PlYy5urAT22o0k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RBmeSUtrte27QactydYumTPIijrZyXjov0xLLcRJBiKw34/RZpEEWqAshFKdB4J3t s+/oTBViXv4ciu6lJVP7IBlgOWShaqs+uAwzhTQLcHGenZRPpzosEKU1wS6vuFCxor c0lN0vl5Xl7o5MBfWpc0qDuAoT3h7CqJUMRnP/SFxr+m1lxyWKIGhxG1RV7BRsiwmP EusypBRUZGhgcjIuOEvLPy4m/SHaHYu2BXcXjcI5hgbp4Rg5QlHzJahoNp6ltNyTp2 nNh3EyQB0XvB4ZEt61fZMtaeJ3r4HJrmRW/73ypPKI4NC0GNSCSYBwzRCdj0bJ+NKY QiVFz5bm88EAQ== Received: by mail-lf1-f50.google.com with SMTP id m3so19086007lfu.2 for ; Wed, 29 Sep 2021 20:26:52 -0700 (PDT) X-Gm-Message-State: AOAM531f71HsYG90z/LnH+zp6aqepS36YI3bqzVauTeMnc+eiQaS9ryp DhWM1PdwHUdwBDy5slXbI5nIZYS2KtvOwbpv+ak= X-Received: by 2002:ac2:5182:: with SMTP id u2mr3286881lfi.676.1632972411232; Wed, 29 Sep 2021 20:26:51 -0700 (PDT) MIME-Version: 1.0 References: <20210922070645.47345-2-rongwei.wang@linux.alibaba.com> <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> <9e41661d-9919-d556-8c49-610dae157553@linux.alibaba.com> <68737431-01d2-e6e3-5131-7d7c731e49ae@linux.alibaba.com> <67906bf5-4de9-8433-3d70-cc8fc5cc2347@linux.alibaba.com> In-Reply-To: <67906bf5-4de9-8433-3d70-cc8fc5cc2347@linux.alibaba.com> From: Song Liu Date: Wed, 29 Sep 2021 20:26:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] mm, thp: check page mapping when truncating page cache To: Rongwei Wang Cc: Matthew Wilcox , Andrew Morton , Linux MM , Linux Kernel Mailing List , William Kucharski , Hugh Dickins Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 29, 2021 at 6:54 PM Rongwei Wang wrote: > > > > On 9/30/21 7:41 AM, Song Liu wrote: > > On Wed, Sep 29, 2021 at 10:56 AM Matthew Wilcox wrote: > >> > > [...] > >>> Now, I am able to crash the system on > >>> find_lock_entries () { > >>> ... > >>> VM_BUG_ON_PAGE(page->index != xas.xa_index, page); > >>> } > >>> I guess it is related. I will test more. > >> > >> That's a bogus VM_BUG_ON. I have a patch in my tree to delete it. > >> Andrew has it too, but for some reason, he hasn't sent it on to Linus. > >> > >> +++ b/mm/filemap.c > >> @@ -2093,7 +2093,6 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, > >> if (!xa_is_value(page)) { > >> if (page->index < start) > >> goto put; > >> - VM_BUG_ON_PAGE(page->index != xas.xa_index, page); > >> if (page->index + thp_nr_pages(page) - 1 > end) > >> goto put; > >> if (!trylock_page(page)) > > > > Yes, after removing this line, I am able to see the same bug. > > > > Here is my finding so far: > > > > The issue is NOT caused by concurrent khugepaged:collapse_file() and > > truncate_pagecache(inode, 0). With some printks, we can see a clear > > time gap (>2 second ) between collapse_file() finishes, and > > truncate_pagecache() (which crashes soon). Therefore, my earlier > > suggestion that adds deny_write_access() to collapse_file() does NOT > > work. > > > > The crash is actually caused by concurrent truncate_pagecache(inode, 0). > > If I change the number of write thread in stress_madvise_dso.c to one, > > (IOW, one thread_read and one thread_write), I cannot reproduce the > > crash anymore. > Whether CONFIG_DEBUG_VM is enabled in your vm? > > I think the second possibility mentioned above will been found if you > enable CONFIG_DEBUG_VM: > > 1) multiple writers truncate the same page cache concurrently; > 2) collapse_file rolls back when writer truncates the page cache; > > The following log will be print after enable CONFIG_DEBUG_VM: > > [22216.789904] do_idle+0xb4/0x104 > [22216.789906] cpu_startup_entry+0x34/0x9c > [22216.790144] Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS > 0.0.0 02/06/2015 > [22216.790553] secondary_start_kernel+0x104/0x180 > [22216.790778] Call trace: > [22216.791300] Code: d4210000 b0006161 910d4021 94013b45 (d4210000) > [22216.791662] dump_backtrace+0x0/0x1ec > [22216.791664] show_stack+0x24/0x30 > [22216.791956] ---[ end trace dc769a61c1af087b ]--- > [22216.792295] dump_stack+0xd0/0x128 > [22216.792299] bad_page+0xe4/0x110 > [22216.792579] Kernel panic - not syncing: Oops - BUG: Fatal exception > in interrupt > [22216.792937] check_free_page_bad+0x84/0x90 > [22216.792940] free_pcp_prepare+0x1fc/0x21c > [22216.793253] SMP: stopping secondary CPUs > [22216.793525] free_unref_page+0x2c/0xec > [22216.805537] __put_page+0x60/0x70 > [22216.805931] collapse_file+0xdc8/0x12f0 > [22216.806385] khugepaged_scan_file+0x2dc/0x37c > [22216.806900] khugepaged_scan_mm_slot+0x2e0/0x380 > [22216.807450] khugepaged_do_scan+0x2dc/0x2fc > [22216.807946] khugepaged+0x38/0x100 > [22216.808342] kthread+0x11c/0x120 > [22216.808735] Kernel Offset: disabled > [22216.809153] CPU features: 0x0040002,62208238 > [22216.809681] Memory Limit: none > [22216.813477] Starting crashdump kernel... > > So I think the race also exists between collapse_file and > truncate_pagecache. I do have CONFIG_DEBUG_VM, but I haven't hit this issue yet. Thanks, Song