Skip to contentSkip to conversation

vfs iput in inode critical region

PATCH In review FabF 2 participants 5 messages May 14, 2004 – May 15, 2004 VFS

lore
Share & tools
lore

FabF

author
#0 lore raw

PATCH 1/1 vfs iput in inode critical region

Hi,

AFAICS, block_dev.c : do_open calls bdput after an unlock_kernel.bdput
calls iput and iput plays with some parameters and locks in iput final case only.Here's a patch to have a spinlock around the whole iput.

Regards,
FabF

fs/inode.c +5 -1
diff -Naur orig/fs/inode.c edited/fs/inode.c
@@ -1081,16 +1081,20 @@
 void iput(struct inode *inode)
 {
 	if (inode) {
+		spin_lock(&inode_lock);
 		struct super_operations *op = inode->i_sb->s_op;
 
 		if (inode->i_state == I_CLEAR)
 			BUG();
 
+		/*Calling fs relevant put_inode*/
 		if (op && op->put_inode)
 			op->put_inode(inode);
 
-		if (atomic_dec_and_lock(&inode->i_count, &inode_lock))
+		/*finalize if inode is unused*/
+		if (atomic_dec_and_test(&inode->i_count))
 			iput_final(inode);
+		spin_unlock(&inode_lock);
 	}
 }
 
#1 lore raw
Quoted 5 lines · FabF

Hi,

AFAICS, block_dev.c : do_open calls bdput after an unlock_kernel.bdput
calls iput and iput plays with some parameters and locks in iput final case only.Here's a patch to have a spinlock around the whole iput.

Huh? Of course iput() is called without BKL (and in a lot more places than just that, actually), but why does it imply that we suddenly need to hold inode_lock over the entire function?

author
#2 lore raw
Quoted 11 lines · On Sat, 2004-05-15 at 00:47, [email protected] wrote:
Quoted 5 lines · FabF

Hi,

AFAICS, block_dev.c : do_open calls bdput after an unlock_kernel.bdput
calls iput and iput plays with some parameters and locks in iput final case only.Here's a patch to have a spinlock around the whole iput.

Huh? Of course iput() is called without BKL (and in a lot more places than just that, actually), but why does it imply that we suddenly need to hold inode_lock over the entire function?

What can avoid inode->i_state to change during fs put_inode is done plus super_operations get assigned something unprotected as well.

#3 lore raw
Quoted 9 lines · FabF
Quoted 7 lines · On Sat, 2004-05-15 at 00:47, [email protected] wrote:
Quoted 5 lines · FabF

Hi,

AFAICS, block_dev.c : do_open calls bdput after an unlock_kernel.bdput
calls iput and iput plays with some parameters and locks in iput final case only.Here's a patch to have a spinlock around the whole iput.

Quoted 6 lines
Quoted 4 lines

Huh? Of course iput() is called without BKL (and in a lot more places than just that, actually), but why does it imply that we suddenly need to hold inode_lock over the entire function?

What can avoid inode->i_state to change during fs put_inode is done plus super_operations get assigned something unprotected as well.

1) Nothing whatsoever; why does ->put_inode() need protection for ->i_state of all things?
2) ->i_sb never changes through the lifetime of inode; sb->s_op should never change too.

author
#4 lore raw
Quoted 14 lines · On Sat, 2004-05-15 at 08:33, [email protected] wrote:
Quoted 13 lines · FabF
Quoted 11 lines · On Sat, 2004-05-15 at 00:47, [email protected] wrote:
Quoted 5 lines · FabF

Hi,

AFAICS, block_dev.c : do_open calls bdput after an unlock_kernel.bdput
calls iput and iput plays with some parameters and locks in iput final case only.Here's a patch to have a spinlock around the whole iput.

Huh? Of course iput() is called without BKL (and in a lot more places than just that, actually), but why does it imply that we suddenly need to hold inode_lock over the entire function?

Quoted 5 lines
Quoted 2 lines

What can avoid inode->i_state to change during fs put_inode is done plus super_operations get assigned something unprotected as well.

1) Nothing whatsoever; why does ->put_inode() need protection for ->i_state of all things?

Theorical question of atomicity I guess like stat.c set_bytes asking for "sufficient locking" should use atomic_t values or critical region and don't ask sub-layer to process the right locking.Btw set_bytes is used once (in reiser AFAICS).

Quoted 2 lines

2) ->i_sb never changes through the lifetime of inode; sb->s_op should never change too.

Yep, it should'nt ...