From nobody Wed Dec 17 20:39:02 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 849928F47 for ; Fri, 3 May 2024 01:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714698586; cv=none; b=ZRzO2hs6WW0PxOX7W+HlvDVYI1RT+QWKqNnj/52oJWt4Vdz2D/HQ7VL6GdMe4UNgRPaBF/XbS81UFReyF+AD+TnrUrjtEdae5zmFWwRQ1R+wcNjqYeZR2IPIzdFutcnh2RitSH3cnQi3V06GKL0WCrGWvili0gUaldSCLLYGshs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714698586; c=relaxed/simple; bh=iayp5Ymt2FvhKu1bwN6Su6tiRmvTOj7tvklDVbpEaAo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=LMHewpoKhEqE0LvOIfgJ5LXy9PvL/TBAdRVJC1txBwEwVz+A2vwnZUQQ13uhE1uycsKzBj7T8loIwGK6zHwUhz1hyFTWlEXgCFm4BaNkR4o/e24DPZ8MeAsAVMPHOP7dS4JLE65sJGuAr9QY3jFGIOxQnum2FprZM+0Iv/p1Fw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Jarkgbdv; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Jarkgbdv" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; }; =20 int sysctl_hugetlb_shm_group; @@ -70,6 +71,7 @@ enum hugetlb_param { Opt_pagesize, Opt_size, Opt_uid, + Opt_nommapfilesz, }; =20 static const struct fs_parameter_spec hugetlb_fs_parameters[] =3D { @@ -80,6 +82,7 @@ static const struct fs_parameter_spec hugetlb_fs_paramete= rs[] =3D { fsparam_string("pagesize", Opt_pagesize), fsparam_string("size", Opt_size), fsparam_u32 ("uid", Opt_uid), + fsparam_flag ("nommapfilesz", Opt_nommapfilesz), {} }; =20 @@ -159,7 +162,12 @@ static int hugetlbfs_file_mmap(struct file *file, stru= ct vm_area_struct *vma) goto out; =20 ret =3D 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=3D%o", sbinfo->mode); if (sbinfo->max_inodes !=3D -1) seq_printf(m, ",nr_inodes=3D%lu", sbinfo->max_inodes); + if (sbinfo->nommapfilesz) + seq_puts(m, ",nommapfilesz"); =20 hpage_size /=3D 1024; mod =3D 'K'; @@ -1430,6 +1440,11 @@ static int hugetlbfs_parse_param(struct fs_context *= fc, struct fs_parameter *par ctx->min_val_type =3D SIZE_PERCENT; return 0; =20 + case Opt_nommapfilesz: + /* don't update file size in mmap call */ + ctx->nommapfilesz =3D 1; + return 0; + default: return -EINVAL; } @@ -1487,6 +1502,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct f= s_context *fc) sbinfo->uid =3D ctx->uid; sbinfo->gid =3D ctx->gid; sbinfo->mode =3D ctx->mode; + sbinfo->nommapfilesz =3D ctx->nommapfilesz; =20 /* * Allocate and initialize subpool if maximum or minimum size is @@ -1558,6 +1574,7 @@ static int hugetlbfs_init_fs_context(struct fs_contex= t *fc) ctx->min_hpages =3D -1; /* No default minimum size */ ctx->max_val_type =3D NO_SIZE; ctx->min_val_type =3D NO_SIZE; + ctx->nommapfilesz =3D 0; /* allows file size update in mmap call */ fc->fs_private =3D ctx; fc->ops =3D &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; }; =20 static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *s= b) --=20 2.7.4