linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: cgxu519@mykernel.net
Cc: linux-mm <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	David Howells <dhowells@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] hugetlbfs: fix error handling in init_hugetlbfs_fs()
Date: Tue, 29 Oct 2019 13:47:38 -0700	[thread overview]
Message-ID: <94b6244d-2c24-e269-b12c-e3ba694b242d@oracle.com> (raw)
In-Reply-To: <16e15cd0096.1068d5c9f40168.8315245997167313680@mykernel.net>

On 10/28/19 9:36 PM, Chengguang Xu wrote:
>  ---- 在 星期二, 2019-10-29 05:27:01 Mike Kravetz <mike.kravetz@oracle.com> 撰写 ----
>  > 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.
>  > 
>  > Reported-by: Chengguang Xu <cgxu519@mykernel.net>
>  > Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context")
>  > Cc: stable@vger.kernel.org
>  > Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
>  > ---
>  >  fs/hugetlbfs/inode.c | 10 ++++++----
>  >  1 file changed, 6 insertions(+), 4 deletions(-)
>  > 
>  > 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 = 0;
>  >      for_each_hstate(h) {
>  >          mnt = mount_one_hugetlbfs(h);
>  > -        if (IS_ERR(mnt) && i == 0) {
>  > +        if (IS_ERR(mnt)) {
>  > +            hugetlbfs_vfsmount[i] = NULL;
>  >              error = PTR_ERR(mnt);
>  > -            goto out;
>  > +        } else {
>  > +            hugetlbfs_vfsmount[i] = mnt;
>  >          }
>  > -        hugetlbfs_vfsmount[i] = mnt;
>  >          i++;
>  >      }
>  >  
>  > -    return 0;
>  > +    if (hugetlbfs_vfsmount[default_hstate_idx] != NULL)
>  > +        return 0;
> 
> 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 <mike.kravetz@oracle.com>
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 <cgxu519@mykernel.net>
Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context")
Cc: stable@vger.kernel.org
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 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 == NULL)
-		goto out2;
+		goto out;
 
 	error = register_filesystem(&hugetlbfs_fs_type);
 	if (error)
-		goto out;
+		goto out_free;
 
+	/* default hstate mount is required */
+	mnt = mount_one_hugetlbfs(&hstates[default_hstate_idx]);
+	if (IS_ERR(mnt)) {
+		error = PTR_ERR(mnt);
+		goto out_unreg;
+	}
+	hugetlbfs_vfsmount[default_hstate_idx] = mnt;
+
+	/* other hstates are optional */
 	i = 0;
 	for_each_hstate(h) {
+		if (i == default_hstate_idx)
+			continue;
+
 		mnt = mount_one_hugetlbfs(h);
-		if (IS_ERR(mnt) && i == 0) {
-			error = PTR_ERR(mnt);
-			goto out;
-		}
-		hugetlbfs_vfsmount[i] = mnt;
+		if (IS_ERR(mnt))
+			hugetlbfs_vfsmount[i] = NULL;
+		else
+			hugetlbfs_vfsmount[i] = mnt;
 		i++;
 	}
 
 	return 0;
 
- 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)
-- 
2.20.1




  reply	other threads:[~2019-10-29 20:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 10:38 [PATCH] hugetlbfs: fix error handling in init_hugetlbfs_fs() Chengguang Xu
2019-10-18  0:08 ` Mike Kravetz
2019-10-18  0:47   ` Mike Kravetz
2019-10-28 21:27 ` Mike Kravetz
2019-10-29  4:36   ` Chengguang Xu
2019-10-29 20:47     ` Mike Kravetz [this message]
2019-10-29 22:24       ` Andrew Morton
2019-10-29 22:36         ` Mike Kravetz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94b6244d-2c24-e269-b12c-e3ba694b242d@oracle.com \
    --to=mike.kravetz@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgxu519@mykernel.net \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).