Skip to contentSkip to conversation

staging: erofs: remove rcu_read_lock() in erofs_try_to_free_cached_page

PATCH In review Gao Xiang 3 participants 5 messages Feb 16, 2019 – Feb 20, 2019 Staging

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 staging: erofs: remove rcu_read_lock() in erofs_try_to_free_cached_page

page_private(page) cannot be changed if page lock is taken.

Besides, the corresponding workgroup won't be freed if the page is already protected by page lock, therefore no need to take rcu read lock.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 drivers/staging/erofs/unzip_vle.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/staging/erofs/unzip_vle.c +5 -11
index 2b5951f233db..a127d8db76d8 100644
@@ -238,14 +238,9 @@ int erofs_try_to_free_cached_page(struct address_space *mapping,
 {
 	struct erofs_sb_info *const sbi = EROFS_SB(mapping->host->i_sb);
 	const unsigned int clusterpages = erofs_clusterpages(sbi);
-
-	struct z_erofs_vle_workgroup *grp;
+	struct z_erofs_vle_workgroup *const grp = (void *)page_private(page);
 	int ret = 0;	/* 0 - busy */
 
-	/* prevent the workgroup from being freed */
-	rcu_read_lock();
-	grp = (void *)page_private(page);
-
 	if (erofs_workgroup_try_to_freeze(&grp->obj, 1)) {
 		unsigned int i;
 
@@ -257,12 +252,11 @@ int erofs_try_to_free_cached_page(struct address_space *mapping,
 			}
 		}
 		erofs_workgroup_unfreeze(&grp->obj, 1);
-	}
-	rcu_read_unlock();
 
-	if (ret) {
-		ClearPagePrivate(page);
-		put_page(page);
+		if (ret) {
+			ClearPagePrivate(page);
+			put_page(page);
+		}
 	}
 	return ret;
 }
Signature · 1 line
2.14.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Gao Xiang

page_private(page) cannot be changed if page lock is taken.

Besides, the corresponding workgroup won't be freed if the page is already protected by page lock, therefore no need to take rcu read lock.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Reviewed-by Chao Yu <yuchao0 at huawei.com>

Thanks,

author
#2 lore raw
In reply to Gao Xiang

Hi Greg,

Could you consider take some time on these two patches for linux-5.1-rc1?
1) staging: erofs: fix race of initializing xattrs of a inode at the same time
2) staging: erofs: remove rcu_read_lock() in erofs_try_to_free_cached_page

It will be of great help, especially patch 1 (it could cause potential memleak in the race condition without it).

If something (eg, resend these patches in a new patchset) is needed, I'm happy to do that. :)

Thanks,
Gao Xiang

Quoted 49 lines · Gao Xiang

page_private(page) cannot be changed if page lock is taken.

Besides, the corresponding workgroup won't be freed if the page is already protected by page lock, therefore no need to take rcu read lock.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 drivers/staging/erofs/unzip_vle.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/staging/erofs/unzip_vle.c +5 -11
index 2b5951f233db..a127d8db76d8 100644
@@ -238,14 +238,9 @@ int erofs_try_to_free_cached_page(struct address_space *mapping,
 {
 	struct erofs_sb_info *const sbi = EROFS_SB(mapping->host->i_sb);
 	const unsigned int clusterpages = erofs_clusterpages(sbi);
-
-	struct z_erofs_vle_workgroup *grp;
+	struct z_erofs_vle_workgroup *const grp = (void *)page_private(page);
 	int ret = 0;	/* 0 - busy */
 
-	/* prevent the workgroup from being freed */
-	rcu_read_lock();
-	grp = (void *)page_private(page);
-
 	if (erofs_workgroup_try_to_freeze(&grp->obj, 1)) {
 		unsigned int i;
 
@@ -257,12 +252,11 @@ int erofs_try_to_free_cached_page(struct address_space *mapping,
 			}
 		}
 		erofs_workgroup_unfreeze(&grp->obj, 1);
-	}
-	rcu_read_unlock();
 
-	if (ret) {
-		ClearPagePrivate(page);
-		put_page(page);
+		if (ret) {
+			ClearPagePrivate(page);
+			put_page(page);
+		}
 	}
 	return ret;
 }
#3 lore raw
Quoted 8 lines · Gao Xiang

Hi Greg,

Could you consider take some time on these two patches for linux-5.1-rc1?
1) staging: erofs: fix race of initializing xattrs of a inode at the same time
2) staging: erofs: remove rcu_read_lock() in erofs_try_to_free_cached_page

It will be of great help, especially patch 1 (it could cause potential memleak in the race condition without it).

Ok, I'll queue them up now, I was waiting for reviewed-by tags from others to show up :)

greg k-h

author
#4 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Gao Xiang

Hi Greg,

Could you consider take some time on these two patches for linux-5.1-rc1?
1) staging: erofs: fix race of initializing xattrs of a inode at the same time
2) staging: erofs: remove rcu_read_lock() in erofs_try_to_free_cached_page

Quoted 5 lines
Quoted 2 lines

It will be of great help, especially patch 1 (it could cause potential memleak in the race condition without it).

Ok, I'll queue them up now, I was waiting for reviewed-by tags from others to show up :)

Thanks! :)
Gao Xiang

Quoted 3 lines

greg k-h