From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3D583F0AA8 for ; Tue, 2 Jun 2026 14:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780410384; cv=none; b=nm2xF44oHumtkF/AmyabRFZrva1uaIm/rGbNmC6McwXV2QtGuSu9KV3I8lh4PCuybIg014Myuz787tGCUBoQN1p9Y9FU0iLFJ4anZ+WUPPVGQGn1PcUIDIe7+2X9TyBH4ODaAJTUm3uTdGgnyQNFclWz42sZVVFAU55ux70W03I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780410384; c=relaxed/simple; bh=hKT+qTsdPyhdE4sNVeEYAAj2+MvGbcPWZN74/zC1yUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BppBDCDkbeMrV2eAtGrNDE8MUvnvYGICU1ihFfCyy+K6YvGoGIh01hyVk/zKAfN+mMiE2ypJUv/fn3X6RsoxSjGZ1TmAzGoZTVlgrtYI6PMgmv1pN0iYKI0lr2vh2u09zf48Y7LOAS9xC7TYB1pxLdoBD21wRvxwLkkbUd3weaw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=AVOw/ISZ; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="AVOw/ISZ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780410380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pGQmOJINkpIXV0ZvH+Jm+oHlVpPUGDMIu+1lnED7ios=; b=AVOw/ISZBXBVizlZbXDxSwTDf5thD0B0csl6a/y8G+wGupAGChJXkHLIGLsqpfvmoTOG+8 Q3FV+EKJhJemeJmLl/oGWv99F4ur3FR3ki4VDol7GJazVUxtrOB3GhUn6HIcNDFrBL1j8M Z2+/d+F9J03eBO8eXdsx7Fdn62LZij4= From: Usama Arif To: Andrew Morton , david@kernel.org, chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com Cc: ying.huang@linux.alibaba.com, Baoquan He , willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, npache@redhat.com, Liam R. Howlett , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, kernel-team@meta.com, Usama Arif Subject: [v2 04/16] mm/huge_memory: move softleaf_to_folio() inside migration branch Date: Tue, 2 Jun 2026 07:24:12 -0700 Message-ID: <20260602142537.198755-5-usama.arif@linux.dev> In-Reply-To: <20260602142537.198755-1-usama.arif@linux.dev> References: <20260602142537.198755-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT change_non_present_huge_pmd() calls softleaf_to_folio() unconditionally at the top of the function. softleaf_to_folio() extracts a PFN from the entry and converts it to a folio pointer, which is only meaningful for migration and device_private entries that encode a real PFN. A swap entry encodes a swap offset instead, so softleaf_to_folio() would produce a bogus pointer and crash on mprotect() when a PMD swap entry is present. Move the call into the migration_write branch where the folio is actually used, so the function is safe for any non-present PMD type. Acked-by: David Hildenbrand (Arm) Reviewed-by: Dev Jain Signed-off-by: Usama Arif --- 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 15913a37b6df..b7b76eef6617 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2558,11 +2558,12 @@ static void change_non_present_huge_pmd(struct mm_struct *mm, bool uffd_wp_resolve) { softleaf_t entry = softleaf_from_pmd(*pmd); - const struct folio *folio = softleaf_to_folio(entry); pmd_t newpmd; VM_WARN_ON(!pmd_is_valid_softleaf(*pmd)); if (softleaf_is_migration_write(entry)) { + const struct folio *folio = softleaf_to_folio(entry); + /* * A protection check is difficult so * just be safe and disable write -- 2.52.0