From patchwork Sat Jan 20 01:17:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakash Sangappa X-Patchwork-Id: 13524282 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 3C610C47DAF for ; Sat, 20 Jan 2024 01:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A2336B006E; Fri, 19 Jan 2024 20:08:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72B2D6B0071; Fri, 19 Jan 2024 20:08:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CCF36B0072; Fri, 19 Jan 2024 20:08:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 465776B006E for ; Fri, 19 Jan 2024 20:08:16 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BC27CC03CC for ; Sat, 20 Jan 2024 01:08:15 +0000 (UTC) X-FDA: 81697903350.03.8A44139 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf17.hostedemail.com (Postfix) with ESMTP id E980F40006 for ; Sat, 20 Jan 2024 01:08:12 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=RIeAIHmJ; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf17.hostedemail.com: domain of prakash.sangappa@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=prakash.sangappa@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705712893; 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=sltGnzFHEhyuMAYtQh/kNQsctmX5DQoOH2S/S0KV5tQ=; b=FSdc7z++3MvQ/K1y7X22nZHMd/4zgUmCvJ1q2eee+FrpFpTqByZ4QPVHlHYoaRIyQYI4SQ eKL89oxVOpdTmTc8gmcr4CzS/AEXvNZR18S4UwbHOcs86V/+KG7u0y2zCNpPZ7seoyAo8w 1qQazEf3yXKBWlUAEHCuhvk2OPW6c4M= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=RIeAIHmJ; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf17.hostedemail.com: domain of prakash.sangappa@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=prakash.sangappa@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705712893; a=rsa-sha256; cv=none; b=D6IPCJnaTp2mwktrqaQKajpLzx2nXHH4MJO6R0gS9mv6CWnTKYXVtD53Zm2GGJOKk7pa0b 6ishKFn1Fn5kJNbcUz9l177EIR77/q1Qx+YgDLCMy/CtwfCmgvLFX6MobxDu6TouCjP+38 SUQgZFHh7bT+k8Lg/cl2A7e42p8SyJM= Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40JN72gt027918; Sat, 20 Jan 2024 01:08: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=sltGnzFHEhyuMAYtQh/kNQsctmX5DQoOH2S/S0KV5tQ=; b=RIeAIHmJk59QuXsjd/uSRCa7+TWXXg7wNeUshVTjJOI5UQPcwmlNIQT6V1aSVi68mFB1 dAwAOiq1BD2wTjivqFeYKExdrIwCdd9z+nCdZ7jybJA9iTwLNByyxEIx4Gxd3Z/por2Y EDoJQrdsQkrEj5eET3KUc98jgZQkRs9L1sbdVuONdfEoTWzJgHVErw8VBgKLsN+vn/Y+ WAPgo5hYXHJZqJto/DxRR/3ZrsxzSr6SOtuTup6TRmONerrb0AkRv/lKDir9uLDYgwjA +UJlEFpUI9O41J0Ol3MI2OVUGNLOG3imvwvxQreR2NUzmfsTFVGZT0TfknWUVpPYDJZO vA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vkm2hyper-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 Jan 2024 01:08:11 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40JNNUL9010140; Sat, 20 Jan 2024 01:08:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vkgygbmwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Sat, 20 Jan 2024 01:08:10 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40K18Ack027919; Sat, 20 Jan 2024 01:08:10 GMT Received: from pp-thinkcentre-m82.us.oracle.com (dhcp-10-132-95-245.usdhcp.oraclecorp.com [10.132.95.245]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vkgygbmpm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Sat, 20 Jan 2024 01:08:10 +0000 From: Prakash Sangappa To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: muchun.song@linux.dev, mike.kravetz@oracle.com, akpm@linux-foundation.org Subject: [PATCH] Hugetlb pages should not be reserved by shmat() if SHM_NORESERVE Date: Fri, 19 Jan 2024 17:17:52 -0800 Message-Id: <1705713472-3537-1-git-send-email-prakash.sangappa@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_12,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401200007 X-Proofpoint-GUID: cGRV4LHMiZcnQF8uuuu02ldcl0LYJsPZ X-Proofpoint-ORIG-GUID: cGRV4LHMiZcnQF8uuuu02ldcl0LYJsPZ X-Rspamd-Queue-Id: E980F40006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mtxzj6xcnz7nywntc4f3bnsnwozdj7dc X-HE-Tag: 1705712892-286050 X-HE-Meta: U2FsdGVkX18a5uNWzyBsYf9FFSVTzw6a8GOJwIoT6WAb/JTNJyIYDh2yjKGJnqSuK3A32VjrCGCsgFLwjCr9vn2xdZKmlUdFw4BXCBg2Gnf2SUiGVi+8av9hlm0pNlfvpAST8NFBrL7+VB81RMc6XbicriMmfyH8BDerexK4ZJQkzx8DY8s5MiO10+CTyCt9yzZLRxuf7oqZbgb4TDclncEwKrUzJkIvIdAvOR2T7+DkUHqU9Tc4unlIr8KQQjfWKQCDwQEx44wMHTMQkjCFCafApv7gXWyaAEyvhfpkAMQoztKLvV4MfYpM1TqVlgHJqUjf3G/0IaN8bXTUGKOwkR1ndulzICjpEJYFvWxPNSp6jjIZQArCSN3qxCI5xQRTw3sfsROUaqgygFqSU06A422AfDtZDseddFH/CMzGXkkwQEgP9S2rgySG5/wjvLh+be87G8H4zTf8lRDcyL9SlhlfM3UF2flkIGuCGPsLFPPVVRsFmsu0rDDguxMffZQwYVV1WjHwc1P3tzmqMp6beci/2m9eDSVWbl6RUT0R723EQbLK5dDRcked0Mp2uVbNCOvDTViZS3VcNaMNSsXe05cN+bbNsy/E0v/GIqoiMnfnsZSnteWgM2bcS75ZGdVXJwvvSelI6PKvWZp9tgTVn9iKmJccPKqGVFVi1JdFYxhQTIDBcQxSbVrFMy3Q+kY4TbA2x7WCng4qI0M9k+N1PlnvCHLaOto5mGzjWhIgUMdEBkmOC1aDNA9gZ6Ewne+M+92Ktwc58QFTQSa9/7MosXJPhj8FHcFVauwBrTqsu2HFrr68Z2lV3vw2BG1La+J6ATWwYP7/zA1p22r7YblEG07aKai7vOcqj1MU/afyZFFIJerqRmPqSXbE/J84suplrAuA8y0xnoC1okuZgO5hPCq2UaBdlh/MeqlhRsEpM4U4b4pwyDmJbk88p8qIHiDlY1M+YPdtM1aUa2vDN7h /sFQN8uz RRyk2cmyTl0umE/qO4tp/A6taAmOgw4z2xJWd916uP42q9Cz8JHra+JMK+pwnta99kll60BgjNdecuikgS29CoGFNd1rBs0Sz9YQUcpKJ+oehkgLeRWCNX76NuKGwO5zw5uIAnPt1LQQpXNUtzwIJHJSHnyDw0hFSTfQs6xvHolNR/nIKk42iDDkC7BhfbYz2Xi0DoG3f9zjZfDB6Kq6bvtYDZg== 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: For shared memory of type SHM_HUGETLB, hugetlb pages are reserved in shmget() call. If SHM_NORESERVE flags is specified then the hugetlb pages are not reserved. However when the shared memory is attached with the shmat() call the hugetlb pages are getting reserved incorrectly for SHM_HUGETLB shared memory created with SHM_NORESERVE. Ensure that the hugetlb pages are no reserved for SHM_HUGETLB shared memory in the shmat() call. Signed-off-by: Prakash Sangappa --- fs/hugetlbfs/inode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index f757d4f..93cafd2 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -141,7 +141,13 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) file_accessed(file); ret = -ENOMEM; - if (!hugetlb_reserve_pages(inode, + + /* + * for SHM_HUGETLB, the pages are reserved in the shmget() call so skip + * reserving here. Note only for SHM hugetlbfs file, the inode + * flag S_PRIVATE is set. + */ + if (!(inode->i_flags & S_PRIVATE) && !hugetlb_reserve_pages(inode, vma->vm_pgoff >> huge_page_order(h), len >> huge_page_shift(h), vma, vma->vm_flags))