From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C3AAFC5930 for ; Thu, 26 Feb 2026 11:34:06 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fM8VL697mz2yFd; Thu, 26 Feb 2026 22:33:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1772105626; cv=none; b=kW2EV1Qx/7UWQExE8/CDUYEg2hHnJtqMCkOHPVTqegk8GGkihDWjA/oZUEmsJjiwgGRlA1+L/ixhrrZvQWHxCrE5cWkNxNe3qWK9bNNgNlqQ9A/ruvpjWM2Vusz5AflnshMDYnnHm+Ybty4V+rI0NkO2xQ9r1tqlsAIJ1tWwDZib8UQii8derZi9+dYJ4Z+HTFg1B685qFzVo2LsRkhaUqFWCI4zi/E/k2qWFyNWZJ19ZAUvyVpAA56q18rxRr18LeoQw63D5J1NXH8Ks1pN7px4i2P9BXPCNi0Z+ZqRLQrHICK61XXT7EG103MVxgng5REGj3C1qDDdU0NDX13d2Q== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1772105626; c=relaxed/relaxed; bh=38HBryh3cdm+ftgRS5GbtNG5HBrHnG2TSvjgBx98jPU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HRsxb8O+bDBJ2EdMGWkzQBYxcEE/a6Q3qVDqzoVy8452LCvH7OoF4e1A9Ml++wlTR2YtcDQ9gJHwlctbQAdM0y53NeP9wEJ51U8olB8VQH7mToPD/qZWHmfiHVJtHh+T7t9AGZc5r/Y7vHnEEePiHgGSiDrPx7eWEpD3OfvA4Ch6kxp5KKVkujnojvx/iHj1+yqAmlPKpX/aArn6nKlj4aPbylWSE4nERIhgqGyw1bYe3bV88Jwy9GZFJHGPABFdryrwYeErJcVvryBhucEvrWao3A5GTkk515YvVBKqlJOm//4NPurLRZXjOPZhYepCD4sD/ujy7TswILUpL1ojtw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WHP1wfJE; dkim-atps=neutral; spf=pass (client-ip=95.215.58.174; helo=out-174.mta1.migadu.com; envelope-from=usama.arif@linux.dev; receiver=lists.ozlabs.org) smtp.mailfrom=linux.dev Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WHP1wfJE; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.dev (client-ip=95.215.58.174; helo=out-174.mta1.migadu.com; envelope-from=usama.arif@linux.dev; receiver=lists.ozlabs.org) Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4fM8VL1Z17z2xMt for ; Thu, 26 Feb 2026 22:33:46 +1100 (AEDT) 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=1772105605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=38HBryh3cdm+ftgRS5GbtNG5HBrHnG2TSvjgBx98jPU=; b=WHP1wfJEjiIuo805/CDPw1ZEpoyAmOLPJew54t/Qv6FjvLJsRZl6KQ9zw/ResskmnYgraa 1InmrX9KSZwqmCAV2swDPkNm4ZtR9ljeMBHNos7fGqBRB8m2acYEuuIZAd9e5c3HR9DorB QqjH5/b9k2rgaJpkswdULdkEDYIRqsQ= From: Usama Arif To: Andrew Morton , david@kernel.org, lorenzo.stoakes@oracle.com, willy@infradead.org, linux-mm@kvack.org Cc: fvdl@google.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, 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, kernel-team@meta.com, maddy@linux.ibm.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, linux-s390@vger.kernel.org, Usama Arif Subject: [RFC v2 04/21] mm: thp: handle split failure in do_huge_pmd_wp_page() Date: Thu, 26 Feb 2026 03:23:33 -0800 Message-ID: <20260226113233.3987674-5-usama.arif@linux.dev> In-Reply-To: <20260226113233.3987674-1-usama.arif@linux.dev> References: <20260226113233.3987674-1-usama.arif@linux.dev> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT do_huge_pmd_wp_page() splits the PMD when a COW of the entire huge page fails (e.g., can't allocate a new folio or the folio is pinned). It then returns VM_FAULT_FALLBACK so the fault can be retried at PTE granularity. If the split fails, the PMD is still huge. Returning VM_FAULT_FALLBACK would re-enter the PTE fault path, which expects a PTE page table at the PMD entry — not a huge PMD. Return VM_FAULT_OOM on split failure, which signals the fault handler to invoke the OOM killer or return -ENOMEM to userspace. Signed-off-by: Usama Arif --- mm/huge_memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d9fb5875fa59e..e82b8435a0b7f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2153,7 +2153,13 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf) folio_unlock(folio); spin_unlock(vmf->ptl); fallback: - __split_huge_pmd(vma, vmf->pmd, vmf->address, false); + /* + * Split failure means the PMD is still huge; returning + * VM_FAULT_FALLBACK would re-enter the PTE path with a + * huge PMD, causing incorrect behavior. + */ + if (__split_huge_pmd(vma, vmf->pmd, vmf->address, false)) + return VM_FAULT_OOM; return VM_FAULT_FALLBACK; } -- 2.47.3