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 68986C3DA4A for ; Mon, 29 Jul 2024 12:55:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E45416B009D; Mon, 29 Jul 2024 08:55:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF5076B009E; Mon, 29 Jul 2024 08:55:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBC3A6B00A2; Mon, 29 Jul 2024 08:55:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AE4416B009D for ; Mon, 29 Jul 2024 08:55:36 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 576C640331 for ; Mon, 29 Jul 2024 12:55:36 +0000 (UTC) X-FDA: 82392786672.18.C6003E2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 23E6A180036 for ; Mon, 29 Jul 2024 12:55:33 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Z3h2O27S; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722257731; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=opEWLaRlUPPuTcVF9JQV5B1iYQkixzeRREUKAI6824o=; b=1B7MZO7zME85VhxdE6+gZHGtR/u3TP2AbZAB12n4dM+DIh9D9tFAZl045QnpNxTeukNA9/ 9A3BLxDN0zqoDNxGopSO8I1/jbaWeF6q7g8Tg3Iv7Ewqzb9MiBZVMNF5CiOvC6+FfgUaMa J6lsKieVa4OnlVYEZ3efNo28v4RRyFg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Z3h2O27S; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722257731; a=rsa-sha256; cv=none; b=k2p3QQcL9ZqPXbo2pMegMF/QieOPeZt4+wj4ZdRCbbvK2fqhTR5BkkfN7tfa/uNHMpHeZ1 UB1EYlxpCQ+TTE+m9Ow9PJqF/bQdlqF1qT4HEzApOYh61niRlrvgjmzT4KuPqFnTRK7S9n UEF+Gp4yyy+yCwUQjZf0TJv6rHsmA4s= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=opEWLaRlUPPuTcVF9JQV5B1iYQkixzeRREUKAI6824o=; b=Z3h2O27S0fXUvOG/m2g3CSn1iQ s0wXWD8/fD7spO399wDArSxC8+8WM2vk15vnvNiBv6IiUUHSBr7j1wOgH+gyZYk1O+oITdb2j7yeA Rb+Qu/d73aXY3LXHhGv+RKBJV6HVpjKUWVS/8k4EnXlbPw4tY5Jo063WyHGZJL/FFDOf5xZqWnU+r +1ZyDxJgj72Vr/WDgoM2E4Ek4HaXRc8cORZs/E6UJ91+7it71Y2soJiZtzYpZ6wz1DB/qx7BZxCrd H5deqH4KLMRAd6hUqLr5AEhf09bFQHflG8wdayykkjv2OexzpdKaziehGEe5AacQzrxzvgO/7HZlS aicELm1w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYPuN-0000000DZnp-1691; Mon, 29 Jul 2024 12:55:23 +0000 Date: Mon, 29 Jul 2024 13:55:23 +0100 From: Matthew Wilcox To: Chuanhua Han Cc: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org, ying.huang@intel.com, baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, hughd@google.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, mhocko@suse.com, minchan@kernel.org, nphamcs@gmail.com, ryan.roberts@arm.com, senozhatsky@chromium.org, shakeel.butt@linux.dev, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, xiang@kernel.org, yosryahmed@google.com, Chuanhua Han Subject: Re: [PATCH v5 3/4] mm: support large folios swapin as a whole for zRAM-like swapfile Message-ID: References: <20240726094618.401593-1-21cnbao@gmail.com> <20240726094618.401593-4-21cnbao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Stat-Signature: w5m7qfj1hq7qp8qei8hgqgfajh6pm6u3 X-Rspamd-Queue-Id: 23E6A180036 X-Rspamd-Server: rspam11 X-HE-Tag: 1722257733-954355 X-HE-Meta: U2FsdGVkX1/ARgS3YuU4B2cSTcVg8qxK9mLjjKXCvYpRJYWI6n4qwky7bbuZn9HVpWssW6e3MkQA9u0rYqEXhFOUoPCRssFNVd3yM1Q5HoaBKnywkv77yYZlQMaj/0t6tDpn+L8wAyXasIRkmBGhMLrahbdfAbWTmWkZpMPN0b1BSEMLmoohWadSxgWs3T1QEnEkWpKtegiXQ6uryi9Uaz2IzVJPORBKqtACS4IltpCkFGguT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ofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jul 29, 2024 at 02:36:38PM +0800, Chuanhua Han wrote: > Matthew Wilcox 于2024年7月29日周一 11:51写道: > > > > On Fri, Jul 26, 2024 at 09:46:17PM +1200, Barry Song wrote: > > > - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, > > > - vma, vmf->address, false); > > > + folio = alloc_swap_folio(vmf); > > > page = &folio->page; > > > > This is no longer correct. You need to set 'page' to the precise page > > that is being faulted rather than the first page of the folio. It was > > fine before because it always allocated a single-page folio, but now it > > must use folio_page() or folio_file_page() (whichever has the correct > > semantics for you). > > > > Also you need to fix your test suite to notice this bug. I suggest > > doing that first so that you know whether you've got the calculation > > correct. > > > > > > This is no problem now, we support large folios swapin as a whole, so > the head page is used here instead of the page that is being faulted. > You can also refer to the current code context, now support large > folios swapin as a whole, and previously only support small page > swapin is not the same. You have completely failed to understand the problem. Let's try it this way: We take a page fault at address 0x123456789000. If part of a 16KiB folio, that's page 1 of the folio at 0x123456788000. If you now map page 0 of the folio at 0x123456789000, you've given the user the wrong page! That looks like data corruption. The code in if (folio_test_large(folio) && folio_test_swapcache(folio)) { as Barry pointed out will save you -- but what if those conditions fail? What if the mmap has been mremap()ed and the folio now crosses a PMD boundary? mk_pte() will now be called on the wrong page.