From patchwork Tue Sep 3 14:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13788800 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 BEFB0CD343A for ; Tue, 3 Sep 2024 14:25:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2AD48D0188; Tue, 3 Sep 2024 10:25:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D65AF8D0189; Tue, 3 Sep 2024 10:25:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C05B68D0188; Tue, 3 Sep 2024 10:25:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9A9158D0151 for ; Tue, 3 Sep 2024 10:25:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 525F11C418C for ; Tue, 3 Sep 2024 14:25:38 +0000 (UTC) X-FDA: 82523650356.08.CDFCE6F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf05.hostedemail.com (Postfix) with ESMTP id 35F7A10001F for ; Tue, 3 Sep 2024 14:25:34 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=UKPg1mot; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf05.hostedemail.com: domain of steven.sistare@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=steven.sistare@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725373511; a=rsa-sha256; cv=none; b=p3pcLVz/IgqrIBufjIlTKm+cUS5qxf7uVM4Q5B8+nUQBjeVC5AZajf+23K+NodOLATNQzv tvlaj2Nu7sPqFC0vJBIg5XqLegllmkNgd8Oj4v9F02VEzqUldFZDKy4I3y+VyMj5NL7gF5 O8baR5LLhRAjvjqVcT5q+CG5m9FnEAM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=UKPg1mot; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf05.hostedemail.com: domain of steven.sistare@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=steven.sistare@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725373511; 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=Ua1uUMucl8Iy4dE29g80WUno/uFNzfFVhk67xhZQ69M=; b=QJKqw1H/VFf6WVfD33ff39a9CK0DyqVF0mFC/AJVLxotZ21nstokeJLXVNwReEMqRcuwvL txMMH4hmX31Roa7InEPJrbdNpPrGwsBio7dDzAlmXWEw3CmbE0DsVK+KhiWFZxU8BmOIoc iV8gH6Rf+KhDiE/fvmlJjpHnz78ArZI= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4837fWgi009041; Tue, 3 Sep 2024 14:25:31 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=Ua1uUMucl8Iy4dE29g80WUno/uFNzfFVhk67xhZQ69M=; b= UKPg1mot8oIMkXC+Z8Pbmkpr1oQBgPvz6ZSx1xOgcXfMwVUr+gu9gPnxHhkddYB4 8b2Pmosz4gpBbZlCSin+goyuF3+AlUvpbfcp2ChWRAE75evaZ3hYqXNIePUTuh9v aStiDFAasOO5MNsl7i07phHeE6l9ynbNJWHIdjI3o75hbOPyIziCsTKPeYsgLXdK 3e7iBMRe1u2HqINPxkZH7WfT8xF1LyZ1373VbrkzeOqcxuoD+TZP0Ehqj2xikH8/ jrP81ggglNHG5+Ot1ebBB1OoOvzNbw4mQnW4VYmpjPhPk1YzC8geP7rfmdDxGitv Ht5VY3mbpSG/2+gt0GSd8w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41duw7s2c8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 14:25:31 +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 483EBaCh001690; Tue, 3 Sep 2024 14:25:30 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmf1mfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2024 14:25:29 +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 483EPN4S023489; Tue, 3 Sep 2024 14:25:29 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-6; Tue, 03 Sep 2024 14:25:29 +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 5/5] mm/gup: fix memfd_pin_folios alloc race panic Date: Tue, 3 Sep 2024 07:25:21 -0700 Message-Id: <1725373521-451395-6-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: 4auxgC3hOI8BlqtrTgalHvobms0vbYbK X-Proofpoint-ORIG-GUID: 4auxgC3hOI8BlqtrTgalHvobms0vbYbK X-Rspam-User: X-Rspamd-Queue-Id: 35F7A10001F X-Rspamd-Server: rspam01 X-Stat-Signature: rz61e7ntfr3ypbpcp736i63rzmymszkf X-HE-Tag: 1725373534-270154 X-HE-Meta: U2FsdGVkX18cXG5zB1wZdNY6OmB5ivp9WYbHG1a41dMhCYvhtahPyYhb56QARQhRGUnOnPsjXLKW2LZWwomay3vCLiQ1CSgNBO6pZV6HtC/Ith417CwDt2dGpuzu61gL6ac2t5AbNhiakuhRDDOemgRaAl01G2dM3VesqJc+3w7bjtEUddNmg7Ao50pMK9bTQP9HFRAUEOIlv9yz4Jcf1/FqMrvSzd0t3PDzoBg1U92mAt4R3EyVnNqYmOGppcKTomeUZgjozcZ1Eg3VieuFQl0irF3ZXcZS7nf4B5hvEsFObEhRWg/wxxKx8S12/tC6Rq7iWrVgzf0FIrtMr/wSkvKRwzw2gdtNnUf1O2Bo5kPAaqwd8m9ee2cANAy4Znhc1lqZtUMiDMeh6QsGKW4lVBBPiq1z6KX659o0oVpKXJnIiH39JlXMIb6VEDH+6B7+ojTny1enxWwvExGEP5DtkqsujioX5SvDl7aCZUvWpYSlC6a3VhtzbmvU4JZZSB8TaD396xxpEvCfEQ1YtIFGjK4yJWUnKj3IkNemCuQ6eSFkC2AiU6iBkerhNe5QMORy0P2tojuxWnxLUC9vuwBZHAJYObXbYNR9alU9HrnlKNXrZcro4e90+6pkU9BicGP4H0ABOTIn7Wo9OhosMLIblYbkAvHPAvNKwLsfx62P0kvCYiOG7AzEuf+Arl4dlhpVYv0ThRv7Fcoq7OuuZ7aOe8inrdMu2HE7L3EjRHNyR9w+kV4+sNp9NZrVshIqWBRCifr7lf+bT0PYgyNov17O85qFOzqA4Mz+0qeqXo451rrDc0YuODvosjikxJWt6216DvvIAvNnIajfO8qHkBkkODuPDkEf7nhVNgEHCMElZ3OB7mwzl4xFKSkIXzAvlaWwcW5ocUKBXMaOzKRB0ZwsD4tNptTt9RTp+N+kSMy7ww/+TwMc66yFSdy9yR6iPEkOIjn/4BJ/t46IykBiW9j gd5knrH3 vzV5V0BrID7XobUtPnM4PoANl1LNKYxXE5N0zic+cZ3zkV2zEc58FYvZ1z2AFDugda29HxSAHFAeOOCcK3rrF8XtkNTetgTsnDRSTfE/6/L6v9MbLJCNyjxBnidBk8YTN01D0zNPz0LcllJwWERxIxiEPNw1JwnvdxJUr+3no0MC3rReMTLs2hEOo9VTxidthYGpUiuLnNngto93JMuf7MziVy9qvbleAK61T+YKv+UFx9IbIJDVpldpTbw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: If memfd_pin_folios tries to create a hugetlb page, but someone else already did, then folio gets the value -EEXIST here: folio = memfd_alloc_folio(memfd, start_idx); if (IS_ERR(folio)) { ret = PTR_ERR(folio); if (ret != -EEXIST) goto err; then on the next trip through the "while start_idx" loop we panic here: if (folio) { folio_put(folio); To fix, set the folio to NULL on error. Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios") Signed-off-by: Steve Sistare Acked-by: Vivek Kasireddy --- mm/gup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/gup.c b/mm/gup.c index 5b92f1d..bccabaa 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3705,6 +3705,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, ret = PTR_ERR(folio); if (ret != -EEXIST) goto err; + folio = NULL; } } }