From patchwork Wed Sep 4 19:41:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 13791306 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 888CBCD4F23 for ; Wed, 4 Sep 2024 19:41:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCDE38D0009; Wed, 4 Sep 2024 15:41:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7D318D0006; Wed, 4 Sep 2024 15:41:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF7F48D0009; Wed, 4 Sep 2024 15:41:19 -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 8E22C8D0006 for ; Wed, 4 Sep 2024 15:41:19 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3D4B9AAE72 for ; Wed, 4 Sep 2024 19:41:19 +0000 (UTC) X-FDA: 82528074678.15.ADC833B Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf04.hostedemail.com (Postfix) with ESMTP id 7426940006 for ; Wed, 4 Sep 2024 19:41:17 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Fc6AIwdP; spf=pass (imf04.hostedemail.com: domain of steven.sistare@oracle.com designates 205.220.177.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=1725478853; 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:references:dkim-signature; bh=3OrwKIIgh3fUSi7RvpVQLFayAllsAgxPBfOrLwLXfIM=; b=qsUAfwNOjds81o3gM7tB6g3887cF1gNw2nbhLuGMlBp5ZFdYKiZULCPi+e494RF5LynSmW W+5NCjIbry3oSAe/odyvhMsbWiJkhkG0LyYZbnIZifbQYO40P3bit6x7cOmwEcjP3eY7FP hIn7/RBlRKzdehxQ4ZjMCBH47A9m4Sk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Fc6AIwdP; spf=pass (imf04.hostedemail.com: domain of steven.sistare@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=steven.sistare@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725478853; a=rsa-sha256; cv=none; b=bltMDrybHLqGWFFvad3rloIg6ok9uH7+cWNZMqBhEr6z1lqzOVaatXGTuQVUZ5LIXxvhIQ gT3x3ZPuVd4Tgmjp+fLTtXJ0yJ9dfBCQws5M+BD+w0y2aPq3w5sCw4JP9TvvAE1vDDVBQx ETNpKWiR3vU0QdckyUFdpSmisNbWbCk= Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 484I0Wd3013437; Wed, 4 Sep 2024 19:41:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id; s=corp-2023-11-20; bh=3OrwKI Igh3fUSi7RvpVQLFayAllsAgxPBfOrLwLXfIM=; b=Fc6AIwdP2W2kd652LrVueG vZG8rSteHjTwiEDt2WBxp4WZSFxggyhCDoKhDA4XILYn2NHr1ynvdQeoe5oKvceK FJYQo2/OP9WaBmZ7vXELk6SCiP+xEyjGtYZOr8WVa/ZiSj0tj3iejFXgS0XQ/rBF XOH4BiwQUDLmzLqsy1J2qrx0DhBG9jzL9bX8gFovj+pEQAe3U0PFDsvxIaUbMyB1 t3zpG8gFym9yqQE0p5jb1X7vL0TS96CNBPB50J16MBEH4fPNUZ5fWvGOMYStVzKh D2G7hgIQH3HdK+j+ntd0G05K6PyA9FS2nkERrBOGLtwo2zgjE0UpawySE/UDk2mA == Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41dwndm9e5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Sep 2024 19:41:12 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 484J9nTZ018422; Wed, 4 Sep 2024 19:41:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41bsmgjv11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Sep 2024 19:41:11 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 484JfAbw032832; Wed, 4 Sep 2024 19:41:10 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 41bsmgjv0c-1; Wed, 04 Sep 2024 19:41:10 +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] mm/hugetlb: simplify refs in memfd_alloc_folio Date: Wed, 4 Sep 2024 12:41:08 -0700 Message-Id: <1725478868-61732-1-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 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-04_17,2024-09-04_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2409040148 X-Proofpoint-GUID: 2Swj5p-Ave8LF9biUx4asGHk2ugzOQ3x X-Proofpoint-ORIG-GUID: 2Swj5p-Ave8LF9biUx4asGHk2ugzOQ3x X-Rspam-User: X-Stat-Signature: q6dndj6rkqhqx3gpu6i6kzzx6tgx6t3j X-Rspamd-Queue-Id: 7426940006 X-Rspamd-Server: rspam11 X-HE-Tag: 1725478877-21628 X-HE-Meta: U2FsdGVkX18yBBKWBlh2cW0uE8YK3hvFRPaUsNElnC50JSL4K/e3s83FMvkUR/LRReiiAWNxZByqZhGnahrHma6ryDl4bnbp3Xe0ESaZ/jL7lQD1BJ7tZYRoavgYX+Eqm407bf6Ndqp6LPagOohhATUirlukU9cRCkZEZyE9QuIPti40Sc5aVizrSw3NXLNOoC+htzeoL7HTi9aRH48g7Fvz/P30FSjTHlhHUUkhx3PpkamadmiP+Y97PzPX0zbopIiB71hBOUOBtxi8gTAmdCzirf0mh/Wu+BRqz2Je557x5PisdK5EuG074ZwX7nLqKnoXWuKIpghxpKvhCGFGDcvZXeEbAalx5wRdDM3BvDpq3ATFdDRqjCzPNnJelLRNL1VOOitpqNYBLVqhEIbx3kf3OOu5nMEnHTsbUY9oO7EqBffDe3gIfA/OrnLO9d7RYWC2bS6flTHkxgRyZWkIzQSAAiZKjUKlx+ThEg3eXtTpk72cP6SpKpr2blMHQbqPvkgVpDSBfnA82M9cKbz9+8C2Xg3/QSXUNlxbriY0RyEsgXkGv6antPwt121/MKuZ6KY26Uoy8S7Fhk2UErhOpyorWoyNVG/firzisqRCwMNsXr7OHDbHVvn9hyjVka2VtnwNUpK9UMlbYSyWx7YFLOaMuXiL99rIoRGxESSv76gTRUQ4nZf6FEQuCHDeH6RQgMe2F+yXOKD4lhBkfI+6oeSS2Am+XhYq6Uu7hm9hrhfPv7s/q+ZvS9cExy3C55PUjVWGiG6wQfwR6Vk1mHkxTIVtfPDLan0EC93pYAw4ufm+Ncv2zJpjCBvchK6N6m1Oia1vOCpvSOz+IVnSE+0R7e/QCGYb8DlgbHQD013XKxXTCChqaTLiPg/Zen3rIX3qA+qlKJGOIQM3uK1PebGEYgdSKDYSdbGZRA8eBleGvNd/CwDr9Nz43eUYSaS4U/FmD3em9A5GJw2GK1zg8DL PWyWU2hJ br8t1BWeBASutSPZtpDvLnXh+0YZ/7v9DeJtVvXbRt9F2GY+SSZQMi6fGbIxPcM7qoh9Rcsu/tTtgQwTiWI92tia8YRq33GOW63JzDvHrC2TazP8WzeR4hcXOK15mLWSniyn26+NsWHGZNKyMa5/O8PvVqNqx9avoZJqmUmHxTJoIGbOb1p8VA5AU8HIa7z9aBB4zJ4v3Xwr0HUwus7yU8ZM8BgK9T8Wsi7QiHEaJOc/tbDr3D6mnUoGnJ6BX3ur6SfF10eohGmhOS94= 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: The folio_try_get in memfd_alloc_folio is not necessary. Delete it, and delete the matching folio_put in memfd_pin_folios. This also avoids leaking a ref if the memfd_alloc_folio call to hugetlb_add_to_page_cache fails, which would otherwise need an additional folio_put. This is a continuation of the fix "mm/hugetlb: fix memfd_pin_folios free_huge_pages leak" Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios") Suggested-by: Vivek Kasireddy Signed-off-by: Steve Sistare --- mm/gup.c | 4 +--- mm/memfd.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index bccabaa..947881ff 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3618,7 +3618,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, pgoff_t start_idx, end_idx, next_idx; struct folio *folio = NULL; struct folio_batch fbatch; - struct hstate *h = NULL; + struct hstate *h; long ret = -EINVAL; if (start < 0 || start > end || !max_folios) @@ -3662,8 +3662,6 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, &fbatch); if (folio) { folio_put(folio); - if (h) - folio_put(folio); folio = NULL; } diff --git a/mm/memfd.c b/mm/memfd.c index bcb131d..f715301 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -89,7 +89,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) numa_node_id(), NULL, gfp_mask); - if (folio && folio_try_get(folio)) { + if (folio) { err = hugetlb_add_to_page_cache(folio, memfd->f_mapping, idx);