From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEC293B52F5 for ; Thu, 26 Feb 2026 14:16:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772115418; cv=none; b=usG9HF6ywfdMbm/UBe6ybnX5BWpHjXp8ZYJvzgBwqPwqlFzwctiZilz5TUCTnIbL9AwyuAv5aHZ+JNPBOlKE+UH9vzg5y3uGHpMAifAbwgHYjBndJYrDOi0OiJfvc6AZIeX/fSMQzRfj5+/TMdkbpnpZcX7FAwxoB6z/T4nIgLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772115418; c=relaxed/simple; bh=L9aKGOPdtAWsjsZS+OCQqYtLmBuOWxIu8s84aw62qLA=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=q3U8XFVbubiKtoLl9RMmxR1EddivTYRMzIzkzgif74q7yF9Jk1o0qrGTno0GjS6tuHLb3rLTgLafCtOW7ydDNRABW4gwTEE3haxrVWMSlxyfr+vI+r0T28Iw02EVELqE0YnYRsiK5crP3MofO0G/4BXJNjaMDZSJtTET2FLRDb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=GihduFFX; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="GihduFFX" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-827270d50d4so984774b3a.3 for ; Thu, 26 Feb 2026 06:16:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1772115417; x=1772720217; darn=vger.kernel.org; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jNAD0DboxzMSBQ7MXxoHQ/ZEV45aIr2CHYOKdSDYsjc=; b=GihduFFXF6Y6kLyPgB5OT219gbA/DCULyrfXNqGSkcHzCikDomBGS9IdBbJPdYCpmY mPJUgAu7GLt8FX97DCIBRtVVrGDGiZ+HngfDRLr1mt2oL4ddQ+38/9UjV1pq9lUGV4vp iYKDiXicAGiM+JkRCvgoVnQwiSnl17MnPSBao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772115417; x=1772720217; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jNAD0DboxzMSBQ7MXxoHQ/ZEV45aIr2CHYOKdSDYsjc=; b=UWy/o225BQhIhmDgd+imJtFapt0ZsJ3u2XENZYFW64vUrL3CvgewuPlG2lcU+W0Ri8 482Qeedk58ndyOjjnAOvNgFtNRFWh/aEOgiQcpYxvSn6vWX2lMKEIBm80iIGDqsgUZlD drLm0QUhGPALbkMdQmDsLM4IRG678qyBeHrhx90svygOR9QL7a5ppxtg/2Q61JYbAKk2 19Wnebq680Muw4KyexIPognw70rLjUuR4lXlZcHkeXaN2SXTm2eNuNKZEreZVbKUDCgM s65QgWqju9eZRUnL5mPuFqbbNMvouc60yfnPxLAf1uJJjKc9g8RaJL5+Ec1OnIOv+xo1 2XAw== X-Forwarded-Encrypted: i=1; AJvYcCVx4IX4Dh6NQjr1l/qeJXL5FrdwP+zeMmdOBINMi4Q3gcZv1VWmiJX6peleI8iAuTuc6aMcwXkkt/E4Ops=@vger.kernel.org X-Gm-Message-State: AOJu0Yxo/YTZbt5ODAHlzDAWQ7/S3FjIByNEZ/3Fvjm/RHvvnJV6qdzl fefNEgd8ue2XDf6fNNVZOdy2V9rbJ7bS4Do5oh450AYGRt+JKwnS3Rrs5qEWmJjba4U= X-Gm-Gg: ATEYQzzglqidmPZhTOCZr4JXSBoD4r29UF2Ys1v8fiawZLmhsi1XqZOr7wV9mTLxWl7 /lNiaGXD3fTvL51hlQOi7YJoq10FuaDBw2QftMHCu/BaK4ii2ygr6nVNkFCLK11F1W0bm9Y+tQA FKTjlEPi0tpBvK/kvof+1kce73sKl0dnEmQ5Dd4w4Nf+JArDi9OvOD93fhU2V1ToD3No5h+1W+f JjcG1LdryviYUVKm/a2E1+f/o94ox9PgKJD8HtWSADbEVLNl16KnLyiHs66O9Ne6iGym/Vkoyin OPcBcyV5OlX49cXqY8xiTffF7US13MQfKXXevsEGJ2HYc1PcSjZtMOyVJk6SUNT1xO6w1hT/3rW LW1RL0t3MrIkBmJGXA+JYMFqbS/pihw4FpmQxd6wVZQU745rrkSCifiJxXwJ4IWyAB1NUzg6Qut 1Wb/HhdmQRe0tr0SstC6tEnyZFKJGR X-Received: by 2002:a05:6a00:4503:b0:823:1212:8e87 with SMTP id d2e1a72fcca58-8273bfa1f7bmr1954788b3a.32.1772115417192; Thu, 26 Feb 2026 06:16:57 -0800 (PST) Received: from localhost ([154.47.23.70]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82739ba6275sm3012040b3a.0.2026.02.26.06.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 06:16:56 -0800 (PST) Date: Thu, 26 Feb 2026 22:16:47 +0800 From: Chris Down To: Andrew Morton Cc: David Hildenbrand , Matthew Wilcox , kernel-team@fb.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/3] mm/huge_memory: Prevent huge zeropage refcount corruption in PMD move Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) After commit d82d09e48219 ("mm/huge_memory: mark PMD mappings of the huge zero folio special"), moved huge zero PMDs must remain special so vm_normal_page_pmd() continues to treat them as special mappings. move_pages_huge_pmd() currently reconstructs the destination PMD in the huge zero page branch, which drops PMD state such as pmd_special() on architectures with CONFIG_ARCH_HAS_PTE_SPECIAL. As a result, vm_normal_page_pmd() can treat the moved huge zero PMD as a normal page and corrupt its refcount. Instead of reconstructing the PMD from the folio, derive the destination entry from src_pmdval after pmdp_huge_clear_flush(), then handle the PMD metadata the same way move_huge_pmd() does for moved entries by marking it soft-dirty and clearing uffd-wp. Fixes: d82d09e48219 ("mm/huge_memory: mark PMD mappings of the huge zero folio special") Cc: stable@vger.kernel.org Signed-off-by: Chris Down --- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index fed57951a7cd..8166b5e871ad 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2794,7 +2794,8 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm _dst_pmd = pmd_mkwrite(pmd_mkdirty(_dst_pmd), dst_vma); } else { src_pmdval = pmdp_huge_clear_flush(src_vma, src_addr, src_pmd); - _dst_pmd = folio_mk_pmd(page_folio(src_page), dst_vma->vm_page_prot); + _dst_pmd = move_soft_dirty_pmd(src_pmdval); + _dst_pmd = clear_uffd_wp_pmd(_dst_pmd); } set_pmd_at(mm, dst_addr, dst_pmd, _dst_pmd); -- 2.51.2