From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794272603; b=pR3BOTVy7INYmAMxjIZK3VN05bBbRM9ljJNVKuydj0uBZMpqQNaK5n5W96HseePP0tHB +bCYgplNMoiazkc7oRjnF5m8sfVR6l1H4yk9Im52cCM/i/Qtba74B5GEd5iCkCp4ZQPkF K/l+BQfALq1fQxr5LonQuvYvZWDO+un6fVL8zNMoBhHBMl8OhHGq3VpK7wD7TK76ia3MF VV/HRJCWqEgREs0rk7bbCrWXOFbo5s/HR86NTBxqz7WEEpVNEOcaVDn3B3kDQmWM+5WJc cUF6bvJ/qYIyryctWpyv9zBcAIpYuBjg32iZ7bU4jR1G86zCGcO3mE97mt25XFyA5yA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794272603; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=uyvHbLRGQPPFja2ykVJhN3okg2R1R88Mo+MFffH/uQ4=; b=B0RyPZvMPrzXqh17nfOJI1RpeK3Y4d/vFGcWYBduqqdfbbFtXH39wdb1DVUbzthyhGjw VzysMZQtpXwCkmV/k96umiKFzWSjp+CYkJ+kJH1YUXx4eD9ruvUP2Yy1mLirdqE0i+GiN POVPbPltS7XpyHFe/OY6rl7A9XkUlamLTQAbV2HKIFZPgIPY6aP4oOVlnfklRHn4JFwe9 5KIFWijyAFLpZ9V2X98mjpku5YbLnvZqvB2WlvpwXPL8ZxfCseBYYI/oTs+4l9m6kVlFg 8E7cJOTa8FIW8QBt0/xyXv0ujmahHZmxxG8+1UM/C0ym9KGF1bJqfRK2H7mbmox+7dQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DmYeMKHV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1626606A31C for ; Tue, 10 Nov 2026 01:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DmYeMKHV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DF201F0089F; Tue, 10 Nov 2026 01:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794272602; bh=uyvHbLRGQPPFja2ykVJhN3okg2R1R88Mo+MFffH/uQ4=; h=From:To:Cc:Subject:Date; b=DmYeMKHVJbzRabMb8XCh4ECzEhzDHrP+rXdMtjHmJ4dDi4rE+EToKX2QVi9LdhIDX F2Vlps/TxQUDp8yOnqUMOCdhye4ihBm7iiqtiDZ4JxwuoQ3tNZosh+/v2Wp9xYbnH2 PKrucHwoiHviouLfwyn8VX/01iEcljOJ1EbgEbPtFw7C2wcTOje/CykZobz8OfDiBY Gp5K45TDi/MUXfzRgFtjff2PtypGC6Kl9ZMZyOLeBtRD4lozbSgv2vjHHQkaDOvbih kArcFupmSFSj8Pp+GlDAYQYxs+LI45rOdXv5+YYjn76e7B4SwW+g3jtIOzZHq7cu/R rOHk9K0orHPDQ== From: Sasha Levin To: david@kernel.org, ljs@kernel.org, josef@toxicpanda.com, harry@kernel.org, baohua@kernel.org, dev.jain@arm.com, usama.anjum@arm.com, baolin.wang@linux.alibaba.com Cc: stable@vger.kernel.org Subject: FAILED: patch "[PATCH] mm/rmap: handle device-exclusive entries in folio_referenced_one()" failed to apply to 6.18-stable tree Date: Mon, 9 Nov 2026 20:03:20 -0500 Message-ID: <20261109200320-failed-6.18-f3c493d2f42b@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.18-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y git checkout FETCH_HEAD git cherry-pick -x f3c493d2f42b5f44a5c134d8d7ea7f960caf5e2c # git commit -s git send-email --to '' --in-reply-to '20261109200320-failed-6.18-f3c493d2f42b@kernel.org' --subject-prefix 'PATCH 6.18.y' 'HEAD^..' Thanks, Sasha ------------------ original commit in Linus's tree ------------------ >From f3c493d2f42b5f44a5c134d8d7ea7f960caf5e2c Mon Sep 17 00:00:00 2001 From: "David Hildenbrand (Arm)" Date: Sat, 31 Oct 2026 10:39:38 +0100 Subject: [PATCH] mm/rmap: handle device-exclusive entries in folio_referenced_one() page_vma_mapped_walk() can return non-present device-exclusive entries, but folio_referenced_one() passes them to PTE young-bit accessors that require present PTEs. We must neither call clear_flush_young_ptes_notify() nor folio_pte_batch() with non-present entries. For example, clearing the young bit on non-present PTEs can corrupt the entry: on arm64 PTE_AF overlaps the swap type, so clearing it turns a device-exclusive entry into an ordinary swap entry. folio_pte_batch() will VM_WARN_ON_FOLIO. Apply the same approach as the previous fixes to e.g., damon_ptep_mkold(): treat these entries as old from the CPU's perspective and obtain their young state through the MMU notifier. Skip PTE batching and MGLRU look-around for non-present entries, and don't modify non-present PTEs. Fixes: b756a3b5e7ea ("mm: device exclusive memory access") Reviewed-by: Lorenzo Stoakes (ARM) Cc: stable@vger.kernel.org Reported-by: Josef Bacik Reviewed-by: Harry Yoo (Meta) Reviewed-by: Barry Song Reviewed-by: Dev Jain Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-9-d6437171ecc3@kernel.org Reviewed-by: Baolin Wang Signed-off-by: David Hildenbrand (Arm) --- mm/rmap.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 1131b76bbbc28..0faef46806e5c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -924,6 +924,7 @@ static bool folio_referenced_one(struct folio *folio, DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0); int ptes = 0, referenced = 0; unsigned int nr; + pte_t pteval; while (page_vma_mapped_walk(&pvmw)) { address = pvmw.address; @@ -968,10 +969,12 @@ static bool folio_referenced_one(struct folio *folio, return false; } - if (pvmw.pte && folio_test_large(folio)) { + if (pvmw.pte) + pteval = ptep_get(pvmw.pte); + + if (pvmw.pte && pte_present(pteval) && folio_test_large(folio)) { const unsigned long end_addr = pmd_addr_end(address, vma->vm_end); const unsigned int max_nr = (end_addr - address) >> PAGE_SHIFT; - pte_t pteval = ptep_get(pvmw.pte); nr = folio_pte_batch(folio, pvmw.pte, pteval, max_nr); } @@ -981,11 +984,23 @@ static bool folio_referenced_one(struct folio *folio, * are. —they could be on active/inactive lists or on MGLRU. So the * simplest approach is to disable this look-around optimization. */ - if (lru_gen_enabled() && !lru_gen_switching() && pvmw.pte) { + if (lru_gen_enabled() && !lru_gen_switching() && pvmw.pte && + pte_present(pteval)) { if (lru_gen_look_around(&pvmw, nr)) referenced++; } else if (pvmw.pte) { - if (clear_flush_young_ptes_notify(vma, address, pvmw.pte, nr)) + bool young = false; + + /* + * PFN swap PTEs, such as device-exclusive ones, that + * actually map pages are "old" from a CPU perspective. + * The MMU notifier takes care of any device aspects. + */ + if (pte_present(pteval)) + young = clear_flush_young_ptes(vma, address, pvmw.pte, nr); + young |= mmu_notifier_clear_flush_young(vma->vm_mm, address, + address + nr * PAGE_SIZE); + if (young) referenced++; } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { if (pmdp_clear_flush_young_notify(vma, address, -- 2.53.0