From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796134767; b=3wIT+vZV9OzgXbDaiumLV8RLG1Pf+k/gyGUZA5BvvK7f1kpr5evidockCJPENa6dXeIx EAGlkoddrbdYmJHXsAODHF2rA9Sz2b0HX2mIqGTuCORW5TUSBfhm/8nfmkcA1PNGU021z 7qBdMOzMQy85aHnXQAC+r3ODBncHzjwVHcx8Ekge7+FZJmnFgxJ9kAuebA8jllQyR4Rqg 5GBEweZ7NVhHpuFNLb2w4qLRdjZtWr5OxyIpslv2gVxOmdkmQ3k8JrxPtGDOwfzqNoItP etsqcuQ5cTCmiDMFLJ6+NqI0vpFhCdrGphLEdXFFAlCoPNgABrr5M+7Nb46c79zc5Nw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796134767; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=kn/aRWqdHkNlPlpcV0vqvmQa0PrKqDsWGvFqsZuEeP0=; b=c3wf1izPZYDrFBSURnNNGyMFhdJTizS3/0Ckr/F61PfbZenQXpV8jRJ9VqmugLZjWQ7E JRxa0qXghYJhbFEm821kA/z/wbzPYO3OaKam86izikpoPJnnE8+QOToEcOKiAd04ALPfk ZqoKwMaKimx1l5r1q7UWeml2Xv4sA4rYDN/4zDH04DBY/Dko29a8TSd1ZrKJz9XRn7rx9 btpWLy7iE8ewANV0gRf/VuP1sSbEebWSTdQsifmCOHYyqo7DEcBhbFm1B7oCcuzxW9fm8 ZY0yYVySy8rMAPq8htgCr3+qQGSgtD9G1UOFTfcdcBVmL5Kkdr9M/xXUbPjI0Hz94YQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="PYpP/tMx"; arc=none smtp.remote-ip=198.175.65.18 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A300B606A6A3; Tue, 1 Dec 2026 14:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A300B606A6A3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=PYpP/tMx DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796134767; x=1827670767; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kn/aRWqdHkNlPlpcV0vqvmQa0PrKqDsWGvFqsZuEeP0=; b=PYpP/tMxPmrDqez0SZmTeBsjcbcJ5iNTMI7WoJqE3kgkKw8SFLlh0nh9 K/cnBOo7G1Da6G9A/9KFNe5z+oR4C184om8qzNA75Nmmp4kRKcT13Me6L 0nqeZffW3Z0IWieNBBI1ORrW5OydelQAubkiChE/frt/n8b7cx4Wq4NOh BuW26XORoWFteTFRG/IXMx0WZeXv5wlQLk6hXgH4XyFB7fANU7RzIbMNn p1Ojr2oeZE2feO5QP4jdhPeZCL5LwLeQWbylfx4gqh5LwS393z0cHNdsu nQiOEQep34lR9+gQF7SHRLM0u4ndGzbOJ9tdoo4MYfGqzO65H/Q/VlPWa g==; X-CSE-ConnectionGUID: namq/lU/SMG1pjW7Uu8QQg== X-CSE-MsgGUID: RPH22n4MQqGWtAGxEq8jJw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5019275" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="5019275" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 06:19:23 -0800 X-CSE-ConnectionGUID: dzh5aglzQ426abkNwJhIQA== X-CSE-MsgGUID: sAveMOrsSXeLFbNNDrIKfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13380733" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by fmviesa005.fm.intel.com with ESMTP; 01 Dec 2026 06:19:20 -0800 From: Daniel Byrne To: Shivank Garg , Ravi Jonnalagadda Cc: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , Yiannis Nikolakopoulos , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , "Aneesh Kumar K.V" , Nathan Lynch , Frank Li , Dan Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Day , dmaengine@vger.kernel.org, Vinicius Costa Gomes , Frank Li , Dave Jiang , Daniel Byrne Subject: [RFC PATCH 06/10] mm/migrate: keep folios with private data off the batch copy Date: Tue, 1 Dec 2026 06:12:55 -0800 Message-ID: <20261201141259.2124188-7-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201141259.2124188-1-daniel1.byrne@intel.com> References: <20261201141259.2124188-1-daniel1.byrne@intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The batch path copies a folio after it is unmapped and before the move phase. Buffer heads are written through without a folio reference, and __buffer_migrate_folio() keeps such writers out only in the move phase, after a batched copy has already run. The destination can then miss a write. Other users of folio->private have migrate_folio() callbacks with checks of their own, and a copy made ahead of them bypasses those too. Refuse the batch copy for a folio that has private data attached, and for one whose mapping migrates through a callback other than migrate_folio(), filemap_migrate_folio() and the two buffer head ones. Such a folio takes the per-folio copy in the move phase, as before the batch path. This is a fix to "mm/migrate: add batch-copy path in migrate_pages_batch" and is meant to be folded into it. Signed-off-by: Daniel Byrne --- A fix to patch 2. For folding into v7. mm/migrate.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index 79970170a53a..e584c3776618 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1722,10 +1722,34 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio, static bool folio_can_batch_copy(struct folio *folio) { + struct address_space *mapping; + /* movable_ops pages have a separate migration path */ if (unlikely(page_has_movable_ops(&folio->page))) return false; + /* + * Buffer heads are written through without a folio reference, and + * __buffer_migrate_folio() keeps such writers out only in the move + * phase, after a batched copy would already have run. Other users + * of folio->private have migrate_folio() callbacks with checks of + * their own that a copy made ahead of them would bypass as well. + */ + if (folio_has_attached_private(folio)) + return false; + + mapping = folio_mapping(folio); + if (mapping) { + const struct address_space_operations *a_ops = mapping->a_ops; + + if (a_ops->migrate_folio && + a_ops->migrate_folio != migrate_folio && + a_ops->migrate_folio != filemap_migrate_folio && + a_ops->migrate_folio != buffer_migrate_folio && + a_ops->migrate_folio != buffer_migrate_folio_norefs) + return false; + } + /* * Only batch when refcount matches the expected refcount. * Otherwise a GUP holder could modify src between the -- 2.43.0