Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp126394ybx; Tue, 5 Nov 2019 20:59:43 -0800 (PST) X-Google-Smtp-Source: APXvYqxy1bXmQdINIuLia+6xmk0groDvBAMTbGtmOFFrYBQd9gnpBZ1TCDrCb84I8AUBaqobiQuA X-Received: by 2002:a05:6402:1397:: with SMTP id b23mr588938edv.196.1573016383039; Tue, 05 Nov 2019 20:59:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573016383; cv=none; d=google.com; s=arc-20160816; b=ok0sL00Sy+JK8c1c8lh/ZZwRG8VzSHe6mtnCWkfFYqFWCpSwjqe+NzCPVeULFHAF7O ICpM+TtrvIz6KYKMj9v/i3S0xvFIAJKJsohCj6GRl37b58fKq7cQW7UqcF2tkPUKw7rs jaromxgJTG5mnkZ4udavr31YIWb8qkgugIxxreT1GH3sZuMRfCmOEdGUWfNNMAsr4AcY sSMqRWhzpa8yl9/OThmetOaSXkCN54UtEC+2im/6BS++pGMoY3YQCcd1lmeXJhMsKVab SbLHcfHiBSEu31jV//6hWTs7S/tM389VFmzBtyEhDkqXMMNB9S/9/DnbSZjPslW0tC3r mLyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=w0Yu3a8UPUhhpzL8PulBRDdFd2rr6sExTV86Crf4bFk=; b=dwvyHvfN735/p2O8SuJwpf0c3mBkjlmvRXoNjl0L/Wl97TGGmzG8ZzeDuYnY2Ic/O8 dk2Tg66PRj6TOKOAYZgkXVScFZaM+ywgLhCAwaYxeJH4gLZaCU19+ZIumdJg+B7BZmJV MWCjxz3ZxIGVfsiPZOt/sMm7BgVPHKQYnYVpqcDZ2PLwaBcOQwXkOa6Y83aZIcWMhacF lQXuHlZxnxfs9Ryj81nRiz8UfAlC2/+1vsx1+HvWDaiuAeSi+hi2IMzdhPw+vHSogU+/ o1HqsDIYPbcXrSEwXEwvFvcCW3KlsCmr4DetdrykjnVG9epfia7cb47I+ZwSYcisb1z8 rJ4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TBhoVGJQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si849960edc.46.2019.11.05.20.59.17; Tue, 05 Nov 2019 20:59:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TBhoVGJQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730995AbfKFE6f (ORCPT + 99 others); Tue, 5 Nov 2019 23:58:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:34594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727266AbfKFE6f (ORCPT ); Tue, 5 Nov 2019 23:58:35 -0500 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6CF8214D8; Wed, 6 Nov 2019 04:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573016315; bh=OYGZe4Y6kWI8ux52zLIbquW9cR6zY7hfuBXqrqwr1wc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TBhoVGJQTZ+E9SIiFJuABeDLvEI/E0N9x+RZWx/Z58ToEhwc4O/fkSZjjtCsQoPNS jnzyWCyPc3f6sracKxKYaehf4aAMtvZW2LISMAi9wwZCHqvWVhQ8NvahdN0QLN4igo Mpaax3WS3XRmlGZo0wqSvu4ccQPNeHIUMgHb7bhw= Date: Tue, 5 Nov 2019 20:58:34 -0800 From: Andrew Morton To: Song Liu Cc: open list , "linux-mm@kvack.org" , "matthew.wilcox@oracle.com" , Kernel Team , "william.kucharski@oracle.com" , "kirill.shutemov@linux.intel.com" , "Johannes Weiner" , Hugh Dickins Subject: Re: [PATCH v3] mm,thp: recheck each page before collapsing file THP Message-Id: <20191105205834.aaebbbfead54637d17a84775@linux-foundation.org> In-Reply-To: <9DC29F5B-1DF5-408F-BEDF-FD1FBAAB1361@fb.com> References: <20191018180345.4188310-1-songliubraving@fb.com> <20191018181712.91dd9e9f9941642300e1b8d9@linux-foundation.org> <9DC29F5B-1DF5-408F-BEDF-FD1FBAAB1361@fb.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 19 Oct 2019 05:24:00 +0000 Song Liu wrote: > > We don't have a ref on that page. After we've released the xarray lock > > we have no business playing with *page at all, correct? > > Yeah, this piece is not just redundant, but also buggy. I am also > including some information about it. > > Updated commit log: > > ============================= 8< ============================= > > In collapse_file(), for !is_shmem case, current check cannot guarantee > the locked page is up-to-date. Specifically, xas_unlock_irq() should not > be called before lock_page() and get_page(); and it is necessary to > recheck PageUptodate() after locking the page. > > With this bug and CONFIG_READ_ONLY_THP_FOR_FS=y, madvise(HUGE)'ed .text > may contain corrupted data. This is because khugepaged mistakenly > collapses some not up-to-date sub pages into a huge page, and assumes the > huge page is up-to-date. This will NOT corrupt data in the disk, because > the page is read-only and never written back. Fix this by properly > checking PageUptodate() after locking the page. This check replaces > "VM_BUG_ON_PAGE(!PageUptodate(page), page);". > > Also, move PageDirty() check after locking the page. Current khugepaged > should not try to collapse dirty file THP, because it is limited to > read-only .text. Add a warning with the PageDirty() check as it should > not happen. This warning is added after page_mapping() check, because > if the page is truncated, it might be dirty. I've lost the plot on this patch. I have the v3 patch plus these fixes: http://lkml.kernel.org/r/20191028221414.3685035-1-songliubraving@fb.com http://lkml.kernel.org/r/20191022191006.411277-1-songliubraving@fb.com http://lkml.kernel.org/r/20191030200736.3455046-1-songliubraving@fb.com and there's a v4 which I can't correlate with the above. And there has been discussion about deferring some of the filemap_flush() changes until later. So I think it's best if we just start again. Can you please prepare and send out a v5 (which might be a 2-patch series)?