From patchwork Tue Sep 3 14:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13788803 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 512E4CD343A for ; Tue, 3 Sep 2024 14:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3691E8D0151; Tue, 3 Sep 2024 10:25:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B98E8D018C; Tue, 3 Sep 2024 10:25:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4FEA8D0151; Tue, 3 Sep 2024 10:25:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BB1978D018A for ; Tue, 3 Sep 2024 10:25:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76225C03DB for ; Tue, 3 Sep 2024 14:25:44 +0000 (UTC) X-FDA: 82523650608.09.064D8BB Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 4CFD21C0008 for ; Tue, 3 Sep 2024 14:25:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=XBJDv5Ca; spf=pass (imf18.hostedemail.com: domain of steven.sistare@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=steven.sistare@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725373448; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=FzV8EX4BQiwM4vVwOQ334d+6m0RyMfcpZu8PckWd74g=; b=HgRJt3NAkzXxuvqvTcH3ibBK34pxiZOyAbLubqVYI6ut76F6UlXrfZmfclZzUUUbbJa5iF A/uYKx9ETmHckY+EpSZ5Yyo/oMxxIal1DPJ0ZUtg/U06tDzR4vpCDv/8FetxXNx06xHCgs Jr5Xfe9BveK4/L8bqeIkaoorTW74txQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725373448; a=rsa-sha256; cv=none; b=tIdrWy1GsPIpsmIqSHJZ6nEcBZFTXuE1DVivVpCOt/IhvXLNxnHe5KLx5vZ1XPSvzo6kWE 3CVX9EPpYVDfM/2Kdf1d06BPkkxvEzExDd618qn0ptQFEGipZzpQpmBbQOIIuwzOFkCdZD J3cM2u1MEJFk3v9C8doFXPKzxVJmoZU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=XBJDv5Ca; spf=pass (imf18.hostedemail.com: domain of steven.sistare@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=steven.sistare@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4837fYmS026699; Tue, 3 Sep 2024 14:25:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= corp-2023-11-20; bh=FzV8EX4BQiwM4vVwOQ334d+6m0RyMfcpZu8PckWd74g=; b= XBJDv5CaWEn2t67eUkMMb+7Wp3p6gKOBzRsAm6sOBTsuheYvS3dcYN0PRFxRw0fS KSNjFDAveduGo5TNiSy/HU2Ltg0dcbn0tDU/A1OT4qxXoxcX//QqiOjrvdTtafWY 9WmTycXLfQDBs8jeJiK/a5yrh5LF2CZHojeb4FxMnqGLkqawcgWYTheHjMINqMiE Gy5inScSoYB5f98PDiYyrbQU9AHIlHlMSm4y0w4GuTkobz6bHfB6EzU2Jmx+LbRK 7nBA0cQ+qU9d2uLljklTqeLzpVCrFvdHh33WfhgxRfqazqzTG5zfiWiGDd7+3MPR waeVEeKHsb67Quk8y9JW/g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dr0jsb95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 14:25:30 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 483EMN1o001737; Tue, 3 Sep 2024 14:25:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmf1mf4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 14:25:28 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 483EPN4Q023489; Tue, 3 Sep 2024 14:25:28 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmf1maj-5; Tue, 03 Sep 2024 14:25:28 +0000 From: Steve Sistare To: linux-mm@kvack.org Cc: Vivek Kasireddy , Muchun Song , Andrew Morton , Matthew Wilcox , Peter Xu , David Hildenbrand , Jason Gunthorpe , Steve Sistare Subject: [PATCH V1 4/5] mm/gup: fix memfd_pin_folios hugetlb page allocation Date: Tue, 3 Sep 2024 07:25:20 -0700 Message-Id: <1725373521-451395-5-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1725373521-451395-1-git-send-email-steven.sistare@oracle.com> References: <1725373521-451395-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-03_02,2024-09-03_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409030117 X-Proofpoint-GUID: RSGcJb7xOCIx7vID57sAgnj-AvsO56kQ X-Proofpoint-ORIG-GUID: RSGcJb7xOCIx7vID57sAgnj-AvsO56kQ X-Rspamd-Queue-Id: 4CFD21C0008 X-Stat-Signature: uuq1nuuhephohc85w5odt4jr5dxryqrf X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725373542-432258 X-HE-Meta: U2FsdGVkX1/g7ZEBi4kidCXlcpsi0e4AE68KAroKAyJCmxAfpaEskXmlo794w3ys9E3blLhRtw5EJUvRRxnA/O9BwVRk8cr8bVgokAHoL60kY8nNXGC/xH2/kQAO1EymyQKKxZFbStDj3CDalOLJ69uYEfn9yNOTk8uIDxMLkUn/cpJRMhdStLZ1U4gGVSyQ67DBvi4nJ8qG6eHkAREvQ+9moD+/u8ySQ3kd6HJTy+M14joGd37G1bBOg60CzomytrJ0vtJYnMvANgla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List-ID: List-Subscribe: List-Unsubscribe: When memfd_pin_folios -> memfd_alloc_folio creates a hugetlb page, the index is wrong. The subsequent call to filemap_get_folios_contig thus cannot find it, and fails, and memfd_pin_folios loops forever. To fix, adjust the index for the huge_page_order. memfd_alloc_folio also forgets to unlock the folio, so the next touch of the page calls hugetlb_fault which blocks forever trying to take the lock. Unlock it. Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios") Signed-off-by: Steve Sistare Acked-by: Vivek Kasireddy --- mm/memfd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/memfd.c b/mm/memfd.c index bfe0e71..bcb131d 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -79,10 +79,13 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) * alloc from. Also, the folio will be pinned for an indefinite * amount of time, so it is not expected to be migrated away. */ - gfp_mask = htlb_alloc_mask(hstate_file(memfd)); + struct hstate *h = hstate_file(memfd); + + gfp_mask = htlb_alloc_mask(h); gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE); + idx >>= huge_page_order(h); - folio = alloc_hugetlb_folio_reserve(hstate_file(memfd), + folio = alloc_hugetlb_folio_reserve(h, numa_node_id(), NULL, gfp_mask); @@ -95,6 +98,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) free_huge_folio(folio); return ERR_PTR(err); } + folio_unlock(folio); return folio; } return ERR_PTR(-ENOMEM);