From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 F22523B47D7 for ; Mon, 27 Apr 2026 10:06:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284384; cv=none; b=RXK/GTVLZFDYgij6Z9dUdNOKFbKvtvYerOYKWf/m9GdPjeuaR3KqIiwppmBAUbnGxFBbmkx3eXeO6LGtN3nhs+N+p9uugmaSZXUsUnzZXnYXeIaHeR+yCm4lQp0g3UIJQ+dQrBh+FfbW2wa4nCah+x0MZUBzjAPR4C+OmBVtXig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284384; c=relaxed/simple; bh=9KAIy8thvqZKpnV6OfxJbnYJ5Bh3vjrP1RYtnmdGXRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KkaQGW11gUg2DrqBsw5OAncFwh+af1DoDFWFd83O9NPyHu8PeMp+qqYFQ2Rh0hYDDUqmVKnmbfJlsEEkVNlpS8gDzM9IDRQcdzh+yUq4hfOYdJyl456BZPeBqZ3L6xATU/wvzowJwF+N9i7nEoOi4V411cKLLTFbDd094Ow4ncI= 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=oYM28SOd; arc=none smtp.client-ip=91.218.175.173 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="oYM28SOd" 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=1777284381; 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=iKT3s2bKzkz1uMChyisn9mj0jVShOFmoW06LrRHh/5o=; b=oYM28SOd6jCk2WFGRONHf31wS/cpq/FfB7e8tuOsMrqQvmdoJQFc+uRMn41mB35sw6haOH UVqwGYkG7D9x0wjO+YJfw/EhI4CJ/YZtYX1b6W5zCONSIM0SvJKGBFpiYdjXLO1/gTZTii SvM1xzwlBQs/aOGaV2Dch9rMTj9Akco= From: Usama Arif To: Andrew Morton , david@kernel.org, chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com Cc: bhe@redhat.com, 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.Howlett@oracle.com, 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: [PATCH 04/13] mm/huge_memory: move softleaf_to_folio() inside migration branch Date: Mon, 27 Apr 2026 03:01:53 -0700 Message-ID: <20260427100553.2754667-5-usama.arif@linux.dev> In-Reply-To: <20260427100553.2754667-1-usama.arif@linux.dev> References: <20260427100553.2754667-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. 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 49da0746b8ca..d82a19b5e276 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2619,11 +2619,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