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 48D7AFC5930 for ; Thu, 26 Feb 2026 11:34:35 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fM8Vk6p0jz2yqs; Thu, 26 Feb 2026 22:34:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1772105646; cv=none; b=l60PyssZbLoMS9yU3p7hku3wucVNRvLyLxS0zyERbwksylEMKF8pQIxuVoCtdd/toe6nvcix4U6lKD1ur5FVD2I1h1eb6WU34G4Idam+5GEPjS2lp0+k7jzI/ZpfAuNuHSupVfZzC/jfny0aCUt2HgVoSZHsyd0uuN6RZMkib7pCXZ716cNd74UigkqGgKupC6+350+kJhcnlXzJd33P0heIk9026HLXvC2LG4JyTODg7W/LyFxkWzO8eAQZf51uTrPX2/5O9RqlLBIHbvSFGGW3xxcotY9l2Ke555ZeaDVs56Zl72fBvqv/2khmFP2FHeft/xH7dBAhd04NegsvsA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1772105646; c=relaxed/relaxed; bh=voiqUydpep5c50p71jeWeFdopCgnIpO6zR1blEnFY9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gsGPjr/pTUw53yxZ+k6xwja/VUwegMcjhXxOkBZPX4sVcp2kuUHrlDYn4o1QC8ZaopJVCmTt8/nBo2HUI1DM2keN8cb1z1Yd0bWyWjP8w1+IHXuxjwQHyOutXC81GK+NKHwTDVk48I7XVXpMH5L1pOxUqr5ApwP4Fs3ITG5EhBIq+ZVI8Jy+Fd0y/YxmIovrggVfHC9ueS0AO5pKe1nnyicXQ1E8lDu7GO64tbenoCyvV6FJHe34IE1yfKTzRM62ksq3iNVkyxNIhPxcaNoiupKNrTNcK5v+mS6/K7CK6n45FOzNddHZul0tjCOmoR09SMSRo2I3M+r5TeziOeziNA== 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=udE+houD; dkim-atps=neutral; spf=pass (client-ip=91.218.175.173; helo=out-173.mta0.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=udE+houD; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.dev (client-ip=91.218.175.173; helo=out-173.mta0.migadu.com; envelope-from=usama.arif@linux.dev; receiver=lists.ozlabs.org) Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 4fM8Vk1wYzz2yY0 for ; Thu, 26 Feb 2026 22:34:05 +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=1772105626; 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=voiqUydpep5c50p71jeWeFdopCgnIpO6zR1blEnFY9U=; b=udE+houDLGseN1f6IYvibBzYYzpJnrx63S12MifUCk13f0DjLpLexn7cLE+r93BBzXNqZW GMm8b+RjhZzqazJYt7NxsX82x6AVbHVcuPZhuNhuFnkbnvwr1QnAXR2LjKKpKiQSa6Xdhz 62qhsCiwM2CIlMTRP3nK9ID7G97Ovc0= 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 08/21] mm: thp: handle split failure in follow_pmd_mask() Date: Thu, 26 Feb 2026 03:23:37 -0800 Message-ID: <20260226113233.3987674-9-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-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT follow_pmd_mask() splits a huge PMD when FOLL_SPLIT_PMD is set, so GUP can pin individual pages at PTE granularity. If the split fails, the PMD is still huge and follow_page_pte() cannot process it. Return ERR_PTR(-ENOMEM) on split failure, which causes the GUP caller to get -ENOMEM. -ENOMEM is already returned in follow_pmd_mask if pte_alloc_one fails (which is the reason why split_huge_pmd could fail), hence this is a safe change. Signed-off-by: Usama Arif --- mm/gup.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/gup.c b/mm/gup.c index 8e7dc2c6ee738..792b2e7319dd0 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -928,8 +928,16 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, return follow_page_pte(vma, address, pmd, flags); } if (pmd_trans_huge(pmdval) && (flags & FOLL_SPLIT_PMD)) { + int ret; + spin_unlock(ptl); - split_huge_pmd(vma, pmd, address); + /* + * If split fails, the PMD is still huge and + * we cannot proceed to follow_page_pte. + */ + ret = split_huge_pmd(vma, pmd, address); + if (ret) + return ERR_PTR(ret); /* If pmd was left empty, stuff a page table in there quickly */ return pte_alloc(mm, pmd) ? ERR_PTR(-ENOMEM) : follow_page_pte(vma, address, pmd, flags); -- 2.47.3