From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CCD8C433EF for ; Tue, 1 Mar 2022 04:18:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 782958D0002; Mon, 28 Feb 2022 23:18:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7317D8D0001; Mon, 28 Feb 2022 23:18:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 620D18D0002; Mon, 28 Feb 2022 23:18:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 535AC8D0001 for ; Mon, 28 Feb 2022 23:18:43 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E8BC6181958BB for ; Tue, 1 Mar 2022 04:18:42 +0000 (UTC) X-FDA: 79194511284.30.01D8907 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 04A5840008 for ; Tue, 1 Mar 2022 04:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=kWYz8Vj6+e73fhwY2HejnGDpRm1xZpM7chYm13xZiRE=; b=Mj0eHI4ii7CLrujUOqvCZpyP/0 50SRuyQxPPqqWWCcpOI57nW9WFI0+TnRPYh9h5+l4RExlWtuO3W2axrsFhuLS+4bAFb0jk+FybZqw oZC0B2tIj/EMc7smzUjQ6TQNmPYIZ0kCijjX+VZs3psXAgRB9SDprtoCDoYRL3SEN3snzzvgiyWCB 29ZGyoT5nkep3iz6jKKhFd1jf58Ij1Jos7KrBWGym5F04rilKPkatuKWYb+r5G5Sozzr6lV4SgjVL VzOIz+4DU60lEcCjHzgWYho4RM6CSNyvCgcAqV500T7+Kq6SW09QaeIO1og49p8qjw3fAaYTJZKkf s9tjnIxA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nOty9-009E6R-Jl; Tue, 01 Mar 2022 04:18:37 +0000 Date: Tue, 1 Mar 2022 04:18:37 +0000 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH next] mm/thp: fix collapse_file()'s try_to_unmap(folio,) Message-ID: References: <3f187b6c-e5e8-e66d-e0c0-7455ca6abb4c@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3f187b6c-e5e8-e66d-e0c0-7455ca6abb4c@google.com> X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: 7u1b7gbjf84634e1qjw8m877a8b9wyhb Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Mj0eHI4i; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Queue-Id: 04A5840008 X-HE-Tag: 1646108321-319355 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: On Sat, Feb 26, 2022 at 06:22:47PM -0800, Hugh Dickins wrote: > The foliation of THP collapse_file()'s call to try_to_unmap() is > currently wrong, crashing on a test in rmap_walk() when xas_next() > delivered a value (after which page has been loaded independently). Argh. I have a fear of this exact bug, and I must have missed checking for it this time. I hate trying to keep two variables in sync, so my preferred fix for this is to remove it for this merge window: +++ b/mm/khugepaged.c @@ -1699,8 +1699,7 @@ static void collapse_file(struct mm_struct *mm, xas_set(&xas, start); for (index = start; index < end; index++) { - struct folio *folio = xas_next(&xas); - struct page *page = &folio->page; + struct page *page = xas_next(&xas); VM_BUG_ON(index != xas.xa_index); if (is_shmem) { @@ -1835,7 +1834,8 @@ static void collapse_file(struct mm_struct *mm, } if (page_mapped(page)) - try_to_unmap(folio, TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH); + try_to_unmap(page_folio(page), + TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH); xas_lock_irq(&xas); xas_set(&xas, index); (ie revert the first hunk). I'll come back to khugepaged in the next merge window and convert this function properly. It's going to take some surgery to shmem in order to use folios there first ...