From patchwork Fri May 3 01:21:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakash Sangappa X-Patchwork-Id: 13652255 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 5F91FC25B10 for ; Fri, 3 May 2024 01:09:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BD6A6B009B; Thu, 2 May 2024 21:09:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76ED46B0098; Thu, 2 May 2024 21:09:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AE0C6B009B; Thu, 2 May 2024 21:09:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 29B346B0099 for ; Thu, 2 May 2024 21:09:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DB1B91A0561 for ; Fri, 3 May 2024 01:09:39 +0000 (UTC) X-FDA: 82075302078.15.7C08714 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf30.hostedemail.com (Postfix) with ESMTP id D717880019 for ; Fri, 3 May 2024 01:09:37 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Jarkgbdv; dmarc=pass (policy=quarantine) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of prakash.sangappa@oracle.com designates 205.220.165.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=1714698578; 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=lQ/aE5r73jz7sAhwozhn5KM1HznG3MJp5ZiMSMgpsgQ=; b=t2z0Wr4XOlsB/VjmGhrdFtKsP8CL1QOTF2a6Hrf8/sCSfmGA5BRhotvQJtx83BahTGCBMB ip6g69CXHp6zKOHClSV1T7ta68mm2ZyX7TjEzdKiNEUXxQy0PQO26N9xkWXN9w1y06CYY+ t82gYBdML7NgYIiEt/5lC+AX6EsNUZA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Jarkgbdv; dmarc=pass (policy=quarantine) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of prakash.sangappa@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=prakash.sangappa@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714698578; a=rsa-sha256; cv=none; b=QMSo0LCm3nhcOZfDW8voK2NwxhG1mPlhu7hcyJPuSIW3OTAH+LhDr7iQj6CaQ30sSTeTYb EOpdkqgAKkyY2qEeE6tKZjWb1NO74d4CVhFDsunqUMymDP9BQ0hqY4bHC+UtTP1MHchrC7 ib5I2ivI9AWUr6ySV8hirP1X5CrmYro= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 442MYFsU008652; Fri, 3 May 2024 01:09:26 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=lQ/aE5r73jz7sAhwozhn5KM1HznG3MJp5ZiMSMgpsgQ=; b=JarkgbdvNrJO/RDmT6uZH+SXL9lcOcakVBGKgVBbzE2TwtbVI1M+tY3FLCFDFxIXd9TQ 8RYep6FKZULQEqT84xeZgRz1qapObZr9zSmAM5dfP5oVas8UfvRr1kXMxY7E/IVJzYCF 55GkmTSc0H+k5gjCreKoRz0NQ+NXEWIh2ttBX85nSskkXrZzKooooMvGYvr3mWRE5JHu f1S6eVOTZZag+SY8PBhsv7HWjEl7KczUKCzkhsAPMIOPoe6GLOHMki1Bl/81ZNqm6cNb 5nOZvslxH2H4TsZTypJ4Yt804LeAyL66An1IgfyJYvMGL2O1uim19sD8+moLue2Z9/ZD FQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr9cyrg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 May 2024 01:09:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 44300JsV006104; Fri, 3 May 2024 01:09:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqtbp7y1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Fri, 03 May 2024 01:09:24 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44319NBq035083; Fri, 3 May 2024 01:09:24 GMT Received: from pp-thinkcentre-m82.us.oracle.com (dhcp-10-132-95-245.usdhcp.oraclecorp.com [10.132.95.245]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqtbp7xd-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Fri, 03 May 2024 01:09:24 +0000 From: Prakash Sangappa To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: muchun.song@linux.dev, akpm@linux-foundation.org, willy@infradead.org, prakash.sangappa@oracle.com Subject: [RFC PATCH 1/1] hugetlbfs: Add mount option to choose normal mmap behavior Date: Thu, 2 May 2024 18:21:10 -0700 Message-Id: <1714699270-7360-2-git-send-email-prakash.sangappa@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1714699270-7360-1-git-send-email-prakash.sangappa@oracle.com> References: <1714699270-7360-1-git-send-email-prakash.sangappa@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_15,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405030006 X-Proofpoint-GUID: FyXI72XEtC_EkyeeYQSoka8OGImmMRXZ X-Proofpoint-ORIG-GUID: FyXI72XEtC_EkyeeYQSoka8OGImmMRXZ X-Stat-Signature: pp3dwbx6uro9z989nboj8dyyaw35bpjg X-Rspamd-Queue-Id: D717880019 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1714698577-762081 X-HE-Meta: U2FsdGVkX1+2eJu1hf2E5M0sQs1AIxoGp+7UcJs0dPxuthPWinWxyMSuL7Itt/mEVz/QOIec+mcDJEUhEpHR1bYYM43xUDV0CYEKR33PFQgS/gt1Nw+3zFsnV6tSTCBnMefoNiD0pV1JT8m7CVYbUYXFwihhJ0v9P7D/+6hoR8ukHjqxLkYOD+PmMuvAYyCoeZhwjt+lScYTgh17l77FsVh3F5wZIDJB8YiJA+7j/gprWA6s78NEKdNzxU/NfbkgCuMYPxDDq8KbOHkYpaDIlDiLGhp3WI8QLcTF4qVpBGRlWE10wHophnAudiuUxTDUx1pEE5OF+kTQFPZehvd5jEw6K7k0bEcSscSiskLyLnW7Jv7qfCIxnnhfUHIp6i7uNEt7n0GKfjhUO/+4Rg+khERJkvO1I6oYqUQ+9Y9VOZ/Zqps8qQ5rXWdY8Hi3emBlFe3qEFJw9qeoZT3uJl3YG2HOjpQPVfAfU6UttbRLQO618daMEKisaru2lvnoshyxCJkxBY4Tr5+frT2TSSJNOUxKQ35KUw9nWnzLuzAylTExln812h3XLwRgBw/CPcQ6Int2GX3SKX0QQD4J7zGisJhLTXcXMQrmxYR/G0jsuYU+PFcDyAsjhXqDVMbjeMy1BZeoqPVFangMZ4n7QqyQS3N8y62uGah98etNwKc+bRfsdcZEy7P1bwZTRjE7gfQqIi5AGeV/NauBEYzlZdT+Nztlsg8d1kBiPXts3lp9teGqCVfZC4kCBrqzfph+TD/UqHts7RE9N8lDyZiTcVB7rOGRU4AMQCB+vNRsMPiDz7lf3K1y+VvANewEbiatVB8BvJvxFEcospt1GX58QFKMZwN0xIMw38YuX0w2yP/EmOlL8pQTMSfoyQVBGwy/tI/VicuJCQpNrZbS8kKskDZ044msJLBLtxF95UtheEYIVP4YuuIMEfLXc6E3i5z2Kat9cX5nm0dTY6CcnFCCJv0 w8sRCEDZ FX/VrHrC3b2hi+S+uWAz+X7XxZgghVAIyII6jBIpxhBOrQiRi91l78W7ehwTalgLdpX5tnCQmcNH68/eekOzaE0owFewC4u5NWg4pFM0/udb5MmSXS4vhY20vuSkpeYQplDuGRIs95CIDKQ+MWAQsiu31DoMJMtGbbWPUX1RMhFcryt4+GWExHq1XfFTMCAP5YZbzpnFjglOKX2nnMg0tDEnG/nG84A++QI0pIyMXDHDLyN4= 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: Currently hugetlbfs file size gets extended in a PROT_WRITE mmap call, if mmap size exceeds the file size. This is not normal filesystem behavior. Some applications expect normal file system behavior for mmap, such that the process would receive a signal when accessing mapped address beyond file size. This will not happen if the file size gets extended by mmap(2). Changing current behavior for hugetlbfs can potentially break existing applications. Therefore provide a mount option "nommapfilesz" to choose normal mmap behavior. Suggested-by: Matthew Wilcox Signed-off-by: Prakash Sangappa --- fs/hugetlbfs/inode.c | 19 ++++++++++++++++++- include/linux/hugetlb.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 6502c7e..e37867a 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -58,6 +58,7 @@ struct hugetlbfs_fs_context { kuid_t uid; kgid_t gid; umode_t mode; + ushort nommapfilesz; }; int sysctl_hugetlb_shm_group; @@ -70,6 +71,7 @@ enum hugetlb_param { Opt_pagesize, Opt_size, Opt_uid, + Opt_nommapfilesz, }; static const struct fs_parameter_spec hugetlb_fs_parameters[] = { @@ -80,6 +82,7 @@ static const struct fs_parameter_spec hugetlb_fs_parameters[] = { fsparam_string("pagesize", Opt_pagesize), fsparam_string("size", Opt_size), fsparam_u32 ("uid", Opt_uid), + fsparam_flag ("nommapfilesz", Opt_nommapfilesz), {} }; @@ -159,7 +162,12 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) goto out; ret = 0; - if (vma->vm_flags & VM_WRITE && inode->i_size < len) + /* + * If filesystem is mounted with 'nommapfilesz' option, then + * don't update file size. + */ + if (!(HUGETLBFS_SB(inode->i_sb)->nommapfilesz) + && vma->vm_flags & VM_WRITE && inode->i_size < len) i_size_write(inode, len); out: inode_unlock(inode); @@ -1169,6 +1177,8 @@ static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root) seq_printf(m, ",mode=%o", sbinfo->mode); if (sbinfo->max_inodes != -1) seq_printf(m, ",nr_inodes=%lu", sbinfo->max_inodes); + if (sbinfo->nommapfilesz) + seq_puts(m, ",nommapfilesz"); hpage_size /= 1024; mod = 'K'; @@ -1430,6 +1440,11 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par ctx->min_val_type = SIZE_PERCENT; return 0; + case Opt_nommapfilesz: + /* don't update file size in mmap call */ + ctx->nommapfilesz = 1; + return 0; + default: return -EINVAL; } @@ -1487,6 +1502,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc) sbinfo->uid = ctx->uid; sbinfo->gid = ctx->gid; sbinfo->mode = ctx->mode; + sbinfo->nommapfilesz = ctx->nommapfilesz; /* * Allocate and initialize subpool if maximum or minimum size is @@ -1558,6 +1574,7 @@ static int hugetlbfs_init_fs_context(struct fs_context *fc) ctx->min_hpages = -1; /* No default minimum size */ ctx->max_val_type = NO_SIZE; ctx->min_val_type = NO_SIZE; + ctx->nommapfilesz = 0; /* allows file size update in mmap call */ fc->fs_private = ctx; fc->ops = &hugetlbfs_fs_context_ops; return 0; diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 77b30a8..282cab5 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -537,6 +537,7 @@ struct hugetlbfs_sb_info { kuid_t uid; kgid_t gid; umode_t mode; + ushort nommapfilesz; }; static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)