From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C37CA9EC4 for ; Tue, 29 Oct 2019 20:47:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02D992067D for ; Tue, 29 Oct 2019 20:47:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ZUYU7X1L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02D992067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 721CE6B0005; Tue, 29 Oct 2019 16:47:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AAE96B0006; Tue, 29 Oct 2019 16:47:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5727D6B0007; Tue, 29 Oct 2019 16:47:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 33E6D6B0005 for ; Tue, 29 Oct 2019 16:47:46 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id D050D181AF5C3 for ; Tue, 29 Oct 2019 20:47:45 +0000 (UTC) X-FDA: 76098008490.11.death26_9786f119dd29 X-HE-Tag: death26_9786f119dd29 X-Filterd-Recvd-Size: 7890 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 20:47:44 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9TKiW4O115974; Tue, 29 Oct 2019 20:47:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=pI3ti0ePmGZJmgoJvow9aItPjDGChrv+DSqwfVKgoOU=; b=ZUYU7X1LDu3k1Td4/HmXAjtE5shf0ZSFxtw1I9QgKjkkrrQdeI+h+pi5r0fncHDlKfRu DY2uCVSY5nwCiKkMUhH40iPEBjuSoM5U0ggGY8O5jnaWkv42KMGU/LfpKUNK7aAets2P 2hXzix2oEGaCTS2y8EXKMAaYWGs+BgQLP9OTNyvHax28BLp5B6kXWvj3eOBxcG0i8spe heGo4+e0rYlKMOaTDNMXqUEd3oOxURXVV6mVFF76bRQqm+9dZR/T/+BRjsCciypuUo10 wj8kB0OLPMyAnkSIfa+F6SHmH04XojpdVu8eVZNUc6uf3TcMtElcjd2wpK6Mi39m7KIh /w== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vvdjuc1jg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2019 20:47:43 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9TKhZgd177368; Tue, 29 Oct 2019 20:47:42 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2vxpenx5w4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2019 20:47:42 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9TKldLr021831; Tue, 29 Oct 2019 20:47:40 GMT Received: from [192.168.1.222] (/71.63.128.209) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 29 Oct 2019 13:47:39 -0700 Subject: Re: [PATCH] hugetlbfs: fix error handling in init_hugetlbfs_fs() To: cgxu519@mykernel.net Cc: linux-mm , linux-kernel , David Howells , Andrew Morton References: <20191017103822.8610-1-cgxu519@mykernel.net> <16e15cd0096.1068d5c9f40168.8315245997167313680@mykernel.net> From: Mike Kravetz Message-ID: <94b6244d-2c24-e269-b12c-e3ba694b242d@oracle.com> Date: Tue, 29 Oct 2019 13:47:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <16e15cd0096.1068d5c9f40168.8315245997167313680@mykernel.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9425 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910290180 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9425 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910290181 Content-Transfer-Encoding: quoted-printable 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: On 10/28/19 9:36 PM, Chengguang Xu wrote: > ---- =E5=9C=A8 =E6=98=9F=E6=9C=9F=E4=BA=8C, 2019-10-29 05:27:01 Mike K= ravetz =E6=92=B0=E5=86=99 ---- > > Subject: [PATCH] mm/hugetlbfs: fix error handling when setting up mo= unts > >=20 > > It is assumed that the hugetlbfs_vfsmount[] array will contain > > either a valid vfsmount pointer or NULL for each hstate after > > initialization. Changes made while converting to use fs_context > > broke this assumption. > >=20 > > Reported-by: Chengguang Xu > > Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context") > > Cc: stable@vger.kernel.org > > Signed-off-by: Mike Kravetz > > --- > > fs/hugetlbfs/inode.c | 10 ++++++---- > > 1 file changed, 6 insertions(+), 4 deletions(-) > >=20 > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > > index a478df035651..178389209561 100644 > > --- a/fs/hugetlbfs/inode.c > > +++ b/fs/hugetlbfs/inode.c > > @@ -1470,15 +1470,17 @@ static int __init init_hugetlbfs_fs(void) > > i =3D 0; > > for_each_hstate(h) { > > mnt =3D mount_one_hugetlbfs(h); > > - if (IS_ERR(mnt) && i =3D=3D 0) { > > + if (IS_ERR(mnt)) { > > + hugetlbfs_vfsmount[i] =3D NULL; > > error =3D PTR_ERR(mnt); > > - goto out; > > + } else { > > + hugetlbfs_vfsmount[i] =3D mnt; > > } > > - hugetlbfs_vfsmount[i] =3D mnt; > > i++; > > } > > =20 > > - return 0; > > + if (hugetlbfs_vfsmount[default_hstate_idx] !=3D NULL) > > + return 0; >=20 > Maybe we should umount other non-null entries and release > used inodes for safety in error case. Yes, even the original code did not clean up properly in the case of all mount errors. This will explicitly mount the default_hstate_idx hstate first. Then, optionally mount other hstates. It will make the error handling and cleanup more explicit. >From 7291f1da0d494cb64f6d219943c59a02e6d4fca7 Mon Sep 17 00:00:00 2001 From: Mike Kravetz Date: Mon, 28 Oct 2019 14:08:42 -0700 Subject: [PATCH] mm/hugetlbfs: fix error handling when setting up mounts It is assumed that the hugetlbfs_vfsmount[] array will contain either a valid vfsmount pointer or NULL for each hstate after initialization. Changes made while converting to use fs_context broke this assumption. While fixing the hugetlbfs_vfsmount issue, it was discovered that init_hugetlbfs_fs never did correctly clean up when encountering a vfs mount error. Reported-by: Chengguang Xu Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context") Cc: stable@vger.kernel.org Signed-off-by: Mike Kravetz --- fs/hugetlbfs/inode.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a478df035651..26e3906c18fe 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1461,28 +1461,41 @@ static int __init init_hugetlbfs_fs(void) sizeof(struct hugetlbfs_inode_info), 0, SLAB_ACCOUNT, init_once); if (hugetlbfs_inode_cachep =3D=3D NULL) - goto out2; + goto out; =20 error =3D register_filesystem(&hugetlbfs_fs_type); if (error) - goto out; + goto out_free; =20 + /* default hstate mount is required */ + mnt =3D mount_one_hugetlbfs(&hstates[default_hstate_idx]); + if (IS_ERR(mnt)) { + error =3D PTR_ERR(mnt); + goto out_unreg; + } + hugetlbfs_vfsmount[default_hstate_idx] =3D mnt; + + /* other hstates are optional */ i =3D 0; for_each_hstate(h) { + if (i =3D=3D default_hstate_idx) + continue; + mnt =3D mount_one_hugetlbfs(h); - if (IS_ERR(mnt) && i =3D=3D 0) { - error =3D PTR_ERR(mnt); - goto out; - } - hugetlbfs_vfsmount[i] =3D mnt; + if (IS_ERR(mnt)) + hugetlbfs_vfsmount[i] =3D NULL; + else + hugetlbfs_vfsmount[i] =3D mnt; i++; } =20 return 0; =20 - out: + out_unreg: + (void)unregister_filesystem(&hugetlbfs_fs_type); + out_free: kmem_cache_destroy(hugetlbfs_inode_cachep); - out2: + out: return error; } fs_initcall(init_hugetlbfs_fs) --=20 2.20.1