mm: migration: Use rcu_dereference_protected when dereferencing the radix tree slot during file page migration
Subsystems (2)
PATCH 1/1 mm: migration: Use rcu_dereference_protected when dereferencing the radix tree slot during file page migration
migrate_pages() -> unmap_and_move() only calls rcu_read_lock() for anonymous pages, as introduced by git commit 989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference to anon_vma and is only held for anon pages as file pages are locked which is sufficient protection against freeing.
However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses radix_tree_deref_slot() -> rcu_dereference() without the RCU lock held triggering the following warning under CONFIG_PROVE_RCU.
[ 173.674290] ===================================================
[ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ]
[ 173.676016] ---------------------------------------------------
[ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection!
[ 173.676016]
[ 173.676016] other info that might help us debug this:
[ 173.676016]
[ 173.676016]
[ 173.676016] rcu_scheduler_active = 1, debug_locks = 0
[ 173.676016] 1 lock held by hugeadm/2899:
[ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab
[ 173.676016]
[ 173.676016] stack backtrace:
[ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild
[ 173.676016] Call Trace:
[ 173.676016] [<c128cc01>] ? printk+0x14/0x1b
[ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86
[ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab
[ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39
[ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107
[ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107
[ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae
[ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces radix_tree_deref_slot_protected() which calls rcu_dereference_protected(). Users of it must pass in the mapping->tree_lock that is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning that rcu_dereference_protected is allowable.
--- include/linux/radix-tree.h | 17 +++++++++++++++++ mm/migrate.c | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-)
include/linux/radix-tree.h +17 -0
@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, +spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ()); +return rcu_dereference_protected (*pslot,lockdep_is_held (treelock)); +} + +/** * radix_tree_deref_retry - check radix_tree_deref_slot * @arg: pointer returned by radix_tree_deref_slot * Returns: 0 if retry is not required, otherwise retry is required
mm/migrate.c +2 -2
@@ -244,7 +244,7 @@ static int migrate_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }
@@ -316,7 +316,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 58 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>--- include/linux/radix-tree.h | 17 +++++++++++++++++ mm/migrate.c | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +3
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 10 lines
include/linux/radix-tree.h +10
-0+* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, +spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ());
This was a bad idea. After some extended testing, it was obvious that this function can be called for swapcache pages with the RCU lock held. Paul, is it still permissible to use rcu_dereference_protected() or must the RCU read lock not be held?
Quoted 30 lines
include/linux/radix-tree.h +4
-0+return rcu_dereference_protected (*pslot,lockdep_is_held (treelock)); +} + +/** * radix_tree_deref_retry - check radix_tree_deref_slot * @arg: pointer returned by radix_tree_deref_slot * Returns: 0 if retry is not required, otherwise retry is required mm/migrate.c +2
-2@@ -244,7 +244,7 @@ static int migrate_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }@@ -316,7 +316,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }
Signature · 3 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab
Quoted 55 lines · Mel Gorman
Quoted 54 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] ===================================================
[ 173.676016] [ INFO: suspiciousrcu_dereference_check()usage. ]
[ 173.676016] ---------------------------------------------------
[ 173.676016]include/linux/radix-tree.h:145invokedrcu_dereference_check()without protection!
[ 173.676016]
[ 173.676016] other info that might help us debug this:
[ 173.676016]
[ 173.676016]
[ 173.676016]rcu_scheduler_active= 1,debug_locks= 0
[ 173.676016] 1 lock held by hugeadm/2899:
[ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>]migrate_page_move_mapping+0x40/0x1ab[ 173.676016]
[ 173.676016] stack backtrace:
[ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild
[ 173.676016] Call Trace:
[ 173.676016] [<c128cc01>] ?printk+0x14/0x1b
[ 173.676016] [<c1063502>]lockdep_rcu_dereference+0x7d/0x86
[ 173.676016] [<c10e3db5>]migrate_page_move_mapping+0xca/0x1ab
[ 173.676016] [<c10e41ad>]migrate_page+0x23/0x39
[ 173.676016] [<c10e491b>]buffer_migrate_page+0x22/0x107
[ 173.676016] [<c10e48f9>] ?buffer_migrate_page+0x0/0x107
[ 173.676016] [<c10e425d>]move_to_new_page+0x9a/0x1ae
[ 173.676016] [<c10e47e6>]migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>---
include/linux/radix-tree.h | 17 +++++++++++++++++mm/migrate.c| 4 ++--2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +0
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }
Quoted 14 lines
Quoted 4 lines
include/linux/radix-tree.h +3
-0/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 10 lines
include/linux/radix-tree.h +10
-0+* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, + spinlock_t *treelock) +{ + BUG_ON(rcu_read_lock_held());
Hmm.. Why did you add the check?
If rcu_read_lock were already held, we wouldn't need this new API.
Quoted 4 lines
This was a bad idea. After some extended testing, it was obvious that this function can be called for swapcache pages with the RCU lock held. Paul, is it still permissible to use
rcu_dereference_protected()or must
I guess has no problem.
Quoted 2 lines
the RCU read lock not be held?
Signature · 2 lines
Kind regards, Minchan Kim
[ Add Paul back to the CC list, and also Dipankar.
Hopefully I killed the mime encodings correctly ]
Quoted 65 lines · Minchan Kim
Quoted 64 lines · Mel Gorman
Quoted 63 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.},at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>---
include/linux/radix-tree.h| 17 +++++++++++++++++mm/migrate.c| 4 ++--2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +8
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCUlock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates.
Quoted 8 lines
Quoted 5 lines
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 5 lines
include/linux/radix-tree.h +5
-0+*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, +spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ());Hmm.. Why did you add the check?
Ifrcu_read_lockwere already held, we wouldn't need this new API.
I'm not Paul but I can read the code in include/linux/rcuupdate.h.
Holding rcu_read_lock_held isn't a problem, but using protected with just the read lock is.
Quoted 7 lines
Quoted 5 lines
This was a bad idea. After some extended testing, it was obvious that this function can be called for swapcache pages with the RCU lock held. Paul, is it still permissible to use
rcu_dereference_protected()or mustI guess has no problem.
No this is a problem
.. because __rcu_dereference_protected doesn't include the smp_read_barrier_depends() that is needed in the rcu only reference path.
Either we need two helpers, one for when the tree is write locked and one when the tree is only rcu read locked, or we use __rcu_dereference_check with check = 1.
Quoted 5 lines
Quoted 3 lines
the RCU read lock not be held?
Minchan Kim
milton
Quoted 79 lines · Milton Miller
[ Add Paul back to the CC list, and also Dipankar.
Hopefully I killed the mime encodings correctly ]Quoted 65 lines · Minchan Kim
Quoted 64 lines · Mel Gorman
Quoted 63 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.},at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>---
include/linux/radix-tree.h| 17 +++++++++++++++++mm/migrate.c| 4 ++--2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +8
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCUlock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. Quoted 8 lines
Quoted 5 lines
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 5 lines
include/linux/radix-tree.h +5
-0+*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, +spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ());Hmm.. Why did you add the check?
Ifrcu_read_lockwere already held, we wouldn't need this new API.
Quoted 5 lines
I'm not Paul but I can read the code in
include/linux/rcuupdate.h.Holding
rcu_read_lock_heldisn't a problem, but using protected with just the read lock is.
Bah, this was extremely careless of me as it's even written in teh documentation. In this specific case, it's simply allowed to ignore whether the RCU read lock is held or not and the BUG_ON check was unnecessary. The tree lock protects against parallel updaters which is what we really care about for using _protected.
In a later cycle, I should look at reducing the RCU read lock hold time in migration. The main thing it's protecting is getting a stable reference to anon_vma and it's held longer than is necessary for that. In the meantime, can anyone spot a problem with this patch?
==== CUT HERE ====
mm: migration: Use rcu_dereference_protected when dereferencing the radix tree slot during file page migration
migrate_pages() -> unmap_and_move() only calls rcu_read_lock() for anonymous pages, as introduced by git commit 989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference to anon_vma and is only held for anon pages as file pages are locked which is sufficient protection against freeing.
However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses radix_tree_deref_slot() -> rcu_dereference() without the RCU lock held triggering the following warning.
[ 173.674290] ===================================================
[ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ]
[ 173.676016] ---------------------------------------------------
[ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection!
[ 173.676016]
[ 173.676016] other info that might help us debug this:
[ 173.676016]
[ 173.676016]
[ 173.676016] rcu_scheduler_active = 1, debug_locks = 0
[ 173.676016] 1 lock held by hugeadm/2899:
[ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab
[ 173.676016]
[ 173.676016] stack backtrace:
[ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild
[ 173.676016] Call Trace:
[ 173.676016] [<c128cc01>] ? printk+0x14/0x1b
[ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86
[ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab
[ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39
[ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107
[ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107
[ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae
[ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces radix_tree_deref_slot_protected() which calls rcu_dereference_protected(). Users of it must pass in the mapping->tree_lock that is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning that rcu_dereference_protected is allowable.
--- include/linux/radix-tree.h | 16 ++++++++++++++++ mm/migrate.c | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-)
include/linux/radix-tree.h +16 -0
@@ -146,6 +146,22 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, +spinlock_t *treelock) +{ +return rcu_dereference_protected (*pslot,lockdep_is_held (treelock)); +} + +/** * radix_tree_deref_retry - check radix_tree_deref_slot * @arg: pointer returned by radix_tree_deref_slot * Returns: 0 if retry is not required, otherwise retry is required
mm/migrate.c +2 -2
@@ -244,7 +244,7 @@ static int migrate_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }
@@ -316,7 +316,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }
Minchan Kim
Reviewed-byQuoted 92 lines · Mel Gorman
Quoted 79 lines · Milton Miller
[ Add Paul back to the CC list, and also Dipankar. Hopefully I killed the mime encodings correctly ]
Quoted 65 lines · Minchan Kim
Quoted 64 lines · Mel Gorman
Quoted 63 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.},at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>---
include/linux/radix-tree.h| 17 +++++++++++++++++mm/migrate.c| 4 ++--2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +8
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCUlock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. Quoted 8 lines
Quoted 5 lines
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot)
Quoted 5 lines
include/linux/radix-tree.h +5
-0+*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, + spinlock_t *treelock) +{ + BUG_ON(rcu_read_lock_held());Hmm.. Why did you add the check?
Ifrcu_read_lockwere already held, we wouldn't need this new API.Quoted 5 lines
I'm not Paul but I can read the code in
include/linux/rcuupdate.h.Holding
rcu_read_lock_heldisn't a problem, but using protected with just the read lock is.Bah, this was extremely careless of me as it's even written in teh documentation. In this specific case, it's simply allowed to ignore whether the RCU read lock is held or not and the
BUG_ONcheck was unnecessary. The tree lock protects against parallel updaters which is what we really care about for using_protected.
Quoted 3 lines
In a later cycle, I should look at reducing the RCU read lock hold time in migration. The main thing it's protecting is getting a stable reference to
anon_vmaand it's held longer than is necessary for that.
Yes.
I think if we want to reduce RCU read lock hold time, we should look unmap_and_move in case of anon page.
After we hold a reference of anon_vma->external_refcount, anon_vma would be stable so we can release rcu_read_unlock.
It can save many time.
Quoted 40 lines
In the meantime, can anyone spot a problem with this patch?
==== CUT HERE ====
mm: migration: Usercu_dereference_protectedwhen dereferencing the radix tree slot during file page migration
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning.[ 173.674290] ===================================================
[ 173.676016] [ INFO: suspiciousrcu_dereference_check()usage. ]
[ 173.676016] ---------------------------------------------------
[ 173.676016]include/linux/radix-tree.h:145invokedrcu_dereference_check()without protection!
[ 173.676016]
[ 173.676016] other info that might help us debug this:
[ 173.676016]
[ 173.676016]
[ 173.676016]rcu_scheduler_active= 1,debug_locks= 0
[ 173.676016] 1 lock held by hugeadm/2899:
[ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>]migrate_page_move_mapping+0x40/0x1ab[ 173.676016]
[ 173.676016] stack backtrace:
[ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild
[ 173.676016] Call Trace:
[ 173.676016] [<c128cc01>] ?printk+0x14/0x1b
[ 173.676016] [<c1063502>]lockdep_rcu_dereference+0x7d/0x86
[ 173.676016] [<c10e3db5>]migrate_page_move_mapping+0xca/0x1ab
[ 173.676016] [<c10e41ad>]migrate_page+0x23/0x39
[ 173.676016] [<c10e491b>]buffer_migrate_page+0x22/0x107
[ 173.676016] [<c10e48f9>] ?buffer_migrate_page+0x0/0x107
[ 173.676016] [<c10e425d>]move_to_new_page+0x9a/0x1ae
[ 173.676016] [<c10e47e6>]migrate_pages+0x1e7/0x2fa
Quoted 7 lines
This patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>
This is what I want.
Thanks.
Signature · 6 lines
Kind regards, Minchan Kim -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 65 lines · Minchan Kim
Quoted 64 lines · Mel Gorman
Quoted 63 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] ===================================================
[ 173.676016] [ INFO: suspiciousrcu_dereference_check()usage. ]
[ 173.676016] ---------------------------------------------------
[ 173.676016]include/linux/radix-tree.h:145invokedrcu_dereference_check()without protection!
[ 173.676016]
[ 173.676016] other info that might help us debug this:
[ 173.676016]
[ 173.676016]
[ 173.676016]rcu_scheduler_active= 1,debug_locks= 0
[ 173.676016] 1 lock held by hugeadm/2899:
[ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>]migrate_page_move_mapping+0x40/0x1ab[ 173.676016]
[ 173.676016] stack backtrace:
[ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild
[ 173.676016] Call Trace:
[ 173.676016] [<c128cc01>] ?printk+0x14/0x1b
[ 173.676016] [<c1063502>]lockdep_rcu_dereference+0x7d/0x86
[ 173.676016] [<c10e3db5>]migrate_page_move_mapping+0xca/0x1ab
[ 173.676016] [<c10e41ad>]migrate_page+0x23/0x39
[ 173.676016] [<c10e491b>]buffer_migrate_page+0x22/0x107
[ 173.676016] [<c10e48f9>] ?buffer_migrate_page+0x0/0x107
[ 173.676016] [<c10e425d>]move_to_new_page+0x9a/0x1ae
[ 173.676016] [<c10e47e6>]migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>---
include/linux/radix-tree.h | 17 +++++++++++++++++mm/migrate.c| 4 ++--2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +8
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) } /** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates.
Quoted 9 lines
Quoted 5 lines
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 5 lines
include/linux/radix-tree.h +5
-0+*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, + spinlock_t *treelock) +{ + BUG_ON(rcu_read_lock_held());Hmm.. Why did you add the check?
Ifrcu_read_lockwere already held, we wouldn't need this new API.
Because our earlier discussions assumed that RCU read lock was not held in this path. The check was added to ensure that assumption was correct, it wasn't.
Quoted 16 lines
Quoted 4 lines
This was a bad idea. After some extended testing, it was obvious that this function can be called for swapcache pages with the RCU lock held. Paul, is it still permissible to use
rcu_dereference_protected()or mustI guess has no problem.
Quoted 2 lines
the RCU read lock not be held?
Signature · 2 lines
Kind regards, Minchan Kim
Signature · 7 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 66 lines · Mel Gorman
Quoted 65 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>--- include/linux/radix-tree.h | 17 +++++++++++++++++ mm/migrate.c | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +10
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected(void **pslot,
Quoted 8 lines
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 3 lines
include/linux/radix-tree.h +3
-0+ spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ());This was a bad idea. After some extended testing, it was obvious that this function can be called for swapcache pages with the RCU lock held. Paul, is it still permissible to use
rcu_dereference_protected()or must the RCU read lock not be held?
Apologies for the late reply!
It is OK to call rcu_dereference_protected() with rcu_read_lock() held, but -only- if updates are somehow blocked -- for example, the treelock being held as below.
It is OK to have extra protection, at least in this case. ;-)
Quoted 40 lines
Quoted 30 lines
include/linux/radix-tree.h +4
-0+return rcu_dereference_protected (*pslot,lockdep_is_held (treelock)); +} + +/** * radix_tree_deref_retry - check radix_tree_deref_slot * @arg: pointer returned by radix_tree_deref_slot * Returns: 0 if retry is not required, otherwise retry is required mm/migrate.c +2
-2@@ -244,7 +244,7 @@ static int migrate_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }@@ -316,7 +316,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }Signature · 8 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Quoted 76 lines · Paul E. McKenney
Quoted 66 lines · Mel Gorman
Quoted 65 lines · Mel Gorman
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2faThis patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>--- include/linux/radix-tree.h | 17 +++++++++++++++++ mm/migrate.c | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +10
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected(void **pslot,Quoted 8 lines
include/linux/radix-tree.h static inline void *radix_tree_deref_slot(void **pslot) · line 161
Quoted 3 lines
include/linux/radix-tree.h +3
-0+ spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ());This was a bad idea. After some extended testing, it was obvious that this function can be called for swapcache pages with the RCU lock held. Paul, is it still permissible to use
rcu_dereference_protected()or must the RCU read lock not be held?
Quoted 8 lines
Apologies for the late reply!
It is OK to call
rcu_dereference_protected()withrcu_read_lock()held, but -only- if updates are somehow blocked -- for example, the treelock being held as below.It is OK to have extra protection, at least in this case. ;-)
Thanks for the clarification Paul.
Signature · 10 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 35 lines · On Mon, 20 Dec 2010 15:23:36 +0000 Mel Gorman <[email protected]> wrote:
migrate_pages()->unmap_and_move()only callsrcu_read_lock()for anonymous pages, as introduced by git commit989f89c57e6361e7d16fbd9572b5da7d313b073d. The point of the RCU protection there is part of getting a stable reference toanon_vmaand is only held for anon pages as file pages are locked which is sufficient protection against freeing.However, while a file page's mapping is being migrated, the radix tree is double checked to ensure it is the expected page. This uses
radix_tree_deref_slot()->rcu_dereference()without the RCU lock held triggering the following warning underCONFIG_PROVE_RCU.[ 173.674290] =================================================== [ 173.676016] [ INFO: suspicious rcu_dereference_check() usage. ] [ 173.676016] --------------------------------------------------- [ 173.676016] include/linux/radix-tree.h:145 invoked rcu_dereference_check() without protection! [ 173.676016] [ 173.676016] other info that might help us debug this: [ 173.676016] [ 173.676016] [ 173.676016] rcu_scheduler_active = 1, debug_locks = 0 [ 173.676016] 1 lock held by hugeadm/2899: [ 173.676016] #0: (&(&inode->i_data.tree_lock)->rlock){..-.-.}, at: [<c10e3d2b>] migrate_page_move_mapping+0x40/0x1ab [ 173.676016] [ 173.676016] stack backtrace: [ 173.676016] Pid: 2899, comm: hugeadm Not tainted 2.6.37-rc5-autobuild [ 173.676016] Call Trace: [ 173.676016] [<c128cc01>] ? printk+0x14/0x1b [ 173.676016] [<c1063502>] lockdep_rcu_dereference+0x7d/0x86 [ 173.676016] [<c10e3db5>] migrate_page_move_mapping+0xca/0x1ab [ 173.676016] [<c10e41ad>] migrate_page+0x23/0x39 [ 173.676016] [<c10e491b>] buffer_migrate_page+0x22/0x107 [ 173.676016] [<c10e48f9>] ? buffer_migrate_page+0x0/0x107 [ 173.676016] [<c10e425d>] move_to_new_page+0x9a/0x1ae [ 173.676016] [<c10e47e6>] migrate_pages+0x1e7/0x2fa
Quoted 7 lines
This patch introduces
radix_tree_deref_slot_protected()which callsrcu_dereference_protected(). Users of it must pass in themapping->tree_lockthat is protecting this dereference. Holding the tree lock protects against parallel updaters of the radix tree meaning thatrcu_dereference_protectedis allowable.Signed-off-by Mel Gorman <[email protected]>
Thank you for fixing.
Quoted 56 lines
--- include/linux/radix-tree.h | 17 +++++++++++++++++ mm/migrate.c | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-)include/linux/radix-tree.h +17
-0@@ -146,6 +146,23 @@ static inline void *radix_tree_deref_slot(void **pslot) }/** +* radix_tree_deref_slot_protected - dereference a slot without RCU lock but with tree lock held +* @pslot: pointer to slot, returned by radix_tree_lookup_slot +* Returns: item that was stored in that slot with any direct pointer flag +* removed. +* +* Similar to radix_tree_deref_slot but only used during migration when a pages +* mapping is being moved. The caller does not hold the RCU read lock but it +* must hold the tree lock to prevent parallel updates. +*/ +static inline void *radix_tree_deref_slot_protected (void **pslot, +spinlock_t *treelock) +{ +BUG_ON (rcu_read_lock_held ()); +return rcu_dereference_protected (*pslot,lockdep_is_held (treelock)); +} + +/** * radix_tree_deref_retry - check radix_tree_deref_slot * @arg: pointer returned by radix_tree_deref_slot * Returns: 0 if retry is not required, otherwise retry is required mm/migrate.c +2
-3@@ -244,7 +244,7 @@ static int migrate_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }@@ -316,7 +316,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, expected_count =2 +page_has_private (page);if (page_count (page) != expected_count || - (struct page *)radix_tree_deref_slot (pslot) != page) { + (struct page *)radix_tree_deref_slot_protected (pslot, &mapping->tree_lock) != page) {spin_unlock_irq (&mapping->tree_lock);return -EAGAIN ; } --
Quoted 5 lines
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>