From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 3D07E32939C for ; Fri, 27 Mar 2026 02:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774577691; cv=none; b=N8vF+w4jvp72wmbrf//Rqtp5gyAIsDf5LOoCTLe13uIo91fbGzA6qBUSpN8zCK+tvRD0kHIiArQlAGJMwq/Flvp7SUjttKAGEyRCuE7kC3diSHZYNDBQaMXeIoedeziKF6AT6PlzyySRrxqdRSA8/4kjYDSNagVxk2WeREKZpZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774577691; c=relaxed/simple; bh=fxX/sueyUOeg6w1sOy3tLvYGW+Jdk7TL6TnQMxgHOpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pr03F2XbfrgWGhuwlk/fCEIGeBLFKskfMWmHSTChO37V5mt/Z0utSwCm1yleCccs4CMHOitzN9gF2lkap2P0J2Gr55IXswblku5KXF1+wPbPO3jPp0QPkHJ0DI+DvkRFNu3qUUwNrmv0v2zuBGjV9hjGl0uYhdJBU+RM7HdPvME= 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=qCDvFHls; arc=none smtp.client-ip=95.215.58.181 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="qCDvFHls" 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=1774577688; 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=aCI7ssiILkMHWnNEWRqeaTC8kADA5FVp8TNFAvIRw20=; b=qCDvFHlsrwn4BvHyl/OogfK+SU4PjAk/orshzs5oMnmbbYqMdO8VxcJG7SBrE5JnvZqhvW kHDxMSY4i21WqlUHUenbjsbHJeQSPwrgThPtMRU39TVbMcqqZ2CIv39avji+vUki/1rSj8 MrVPi7UsYpHW/i7zFvcn0mt99gsGNQA= From: Usama Arif To: Andrew Morton , david@kernel.org, Lorenzo Stoakes , 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: [v3 06/24] mm: thp: handle split failure in wp_huge_pmd() Date: Thu, 26 Mar 2026 19:08:48 -0700 Message-ID: <20260327021403.214713-7-usama.arif@linux.dev> In-Reply-To: <20260327021403.214713-1-usama.arif@linux.dev> References: <20260327021403.214713-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT wp_huge_pmd() splits the PMD when COW or write-notify must be handled at PTE level (e.g., shared/file VMAs, userfaultfd). It then returns VM_FAULT_FALLBACK so the fault handler retries at PTE granularity. If the split fails, the PMD is still huge. The PTE fault path cannot handle a huge PMD entry. Return VM_FAULT_OOM on split failure, which signals the fault handler to invoke the OOM killer or return -ENOMEM to userspace. This is similar to what __handle_mm_fault would do if p4d_alloc or pud_alloc fails. Signed-off-by: Usama Arif --- mm/memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index caf97c48cb166..b99ec3ffc18d1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6328,8 +6328,13 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) } split: - /* COW or write-notify handled on pte level: split pmd. */ - __split_huge_pmd(vma, vmf->pmd, vmf->address, false); + /* + * COW or write-notify handled on pte level: split pmd. + * If split fails, the PMD is still huge so falling back + * to PTE handling would be incorrect. + */ + if (__split_huge_pmd(vma, vmf->pmd, vmf->address, false)) + return VM_FAULT_OOM; return VM_FAULT_FALLBACK; } -- 2.52.0