Re: [Ocfs2-devel] [PATCH] ocfs2: ocfs2_inode_lock_tracker does not distinguish lock level
On Fri, 11 May 2018 12:16:51 +0800 Larry Chenwrote: > > Nice changelog, but it gives no information about the severity of the > > bug: how often does it hit and what is the end-user impact. > > > > This info is needed so that I and others can decide which kernel > > version(s) need the patch, so please always include it when fixing a > > bug, thanks. > > Thanks for your review and feel sorry for not providing enough information. > > For the status quo of ocfs2, without this patch, neither a bug nor end-user > impact will be caused because the wrong logic is avoided. > > But I'm afraid this generic interface, may be called by other > developers in future and used in this situation. > > a process > ocfs2_inode_lock_tracker(ex=0) > ocfs2_inode_lock_tracker(ex=1) OK, thanks. > By the way, should I resend this patch with this info included? I pasted the above into my copy of the changelog so we're good. ___ Ocfs2-devel mailing list Ocfs2-devel@oss.oracle.com https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Re: [Ocfs2-devel] [PATCH] ocfs2: ocfs2_inode_lock_tracker does not distinguish lock level
Hello Andrew, On 05/11/2018 05:49 AM, Andrew Morton wrote: > On Thu, 10 May 2018 13:32:30 +0800 Larry Chenwrote: > >> ocfs2_inode_lock_tracker as a variant of ocfs2_inode_lock, >> is used to prevent deadlock due to recursive lock acquisition. >> >> But this function does not distinguish >> whether the requested level is EX or PR. >> >> If a RP lock has been attained, this function >> will immediately return success afterwards even >> an EX lock is requested. >> >> But actually the return value does not mean that >> the process got a EX lock, because ocfs2_inode_lock >> has not been called. >> >> When taking lock levels into account, we face some different situations. >> 1. no lock is held >> In this case, just lock the inode and return 0 >> >> 2. We are holding a lock >> For this situation, things diverges into several cases >> >> wanted holdingwhat to do >> ex ex see 2.1 below >> ex pr see 2.2 below >> pr ex see 2.1 below >> pr pr see 2.1 below >> >> 2.1 lock level that is been held is compatible >> with the wanted level, so no lock action will be tacken. >> >> 2.2 Otherwise, an upgrade is needed, but it is forbidden. >> >> Reason why upgrade within a process is forbidden is that >> lock upgrade may cause dead lock. The following illustrate >> how it happens. >> >> process 1 process 2 >> ocfs2_inode_lock_tracker(ex=0) >> <== ocfs2_inode_lock_tracker(ex=1) >> >> ocfs2_inode_lock_tracker(ex=1) >> > Nice changelog, but it gives no information about the severity of the > bug: how often does it hit and what is the end-user impact. > > This info is needed so that I and others can decide which kernel > version(s) need the patch, so please always include it when fixing a > bug, thanks. Thanks for your review and feel sorry for not providing enough information. For the status quo of ocfs2, without this patch, neither a bug nor end-user impact will be caused because the wrong logic is avoided. But I'm afraid this generic interface, may be called by other developers in future and used in this situation. a process ocfs2_inode_lock_tracker(ex=0) ocfs2_inode_lock_tracker(ex=1) By the way, should I resend this patch with this info included? Thanks Larry > ___ Ocfs2-devel mailing list Ocfs2-devel@oss.oracle.com https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Re: [Ocfs2-devel] [PATCH] ocfs2: ocfs2_inode_lock_tracker does not distinguish lock level
On Thu, 10 May 2018 13:32:30 +0800 Larry Chenwrote: > ocfs2_inode_lock_tracker as a variant of ocfs2_inode_lock, > is used to prevent deadlock due to recursive lock acquisition. > > But this function does not distinguish > whether the requested level is EX or PR. > > If a RP lock has been attained, this function > will immediately return success afterwards even > an EX lock is requested. > > But actually the return value does not mean that > the process got a EX lock, because ocfs2_inode_lock > has not been called. > > When taking lock levels into account, we face some different situations. > 1. no lock is held >In this case, just lock the inode and return 0 > > 2. We are holding a lock >For this situation, things diverges into several cases > >wanted holding what to do >ex ex see 2.1 below >ex pr see 2.2 below >pr ex see 2.1 below >pr pr see 2.1 below > >2.1 lock level that is been held is compatible >with the wanted level, so no lock action will be tacken. > >2.2 Otherwise, an upgrade is needed, but it is forbidden. > > Reason why upgrade within a process is forbidden is that > lock upgrade may cause dead lock. The following illustrate > how it happens. > > process 1 process 2 > ocfs2_inode_lock_tracker(ex=0) ><== ocfs2_inode_lock_tracker(ex=1) > > ocfs2_inode_lock_tracker(ex=1) > Nice changelog, but it gives no information about the severity of the bug: how often does it hit and what is the end-user impact. This info is needed so that I and others can decide which kernel version(s) need the patch, so please always include it when fixing a bug, thanks. ___ Ocfs2-devel mailing list Ocfs2-devel@oss.oracle.com https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Re: [Ocfs2-devel] [PATCH] ocfs2: ocfs2_inode_lock_tracker does not distinguish lock level
Hello Joseph, Changwei and Jun/Alex, Please help to take a look at this patch, since the previous patch really has vulnerability in logic, although our test cases did not hit it. Thanks Gang >>> Larry Chen2018/5/10 13:32 >>> ocfs2_inode_lock_tracker as a variant of ocfs2_inode_lock, is used to prevent deadlock due to recursive lock acquisition. But this function does not distinguish whether the requested level is EX or PR. If a RP lock has been attained, this function will immediately return success afterwards even an EX lock is requested. But actually the return value does not mean that the process got a EX lock, because ocfs2_inode_lock has not been called. When taking lock levels into account, we face some different situations. 1. no lock is held In this case, just lock the inode and return 0 2. We are holding a lock For this situation, things diverges into several cases wanted holdingwhat to do ex ex see 2.1 below ex pr see 2.2 below pr ex see 2.1 below pr pr see 2.1 below 2.1 lock level that is been held is compatible with the wanted level, so no lock action will be tacken. 2.2 Otherwise, an upgrade is needed, but it is forbidden. Reason why upgrade within a process is forbidden is that lock upgrade may cause dead lock. The following illustrate how it happens. process 1 process 2 ocfs2_inode_lock_tracker(ex=0) <== ocfs2_inode_lock_tracker(ex=1) ocfs2_inode_lock_tracker(ex=1) Signed-off-by: Larry Chen Reviewed-by: Gang He --- fs/ocfs2/dlmglue.c | 119 +++-- fs/ocfs2/dlmglue.h | 1 + 2 files changed, 90 insertions(+), 30 deletions(-) diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index 97a972efab83..68728de12864 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -788,35 +788,34 @@ static inline void ocfs2_add_holder(struct ocfs2_lock_res *lockres, spin_unlock(>l_lock); } -static inline void ocfs2_remove_holder(struct ocfs2_lock_res *lockres, - struct ocfs2_lock_holder *oh) -{ - spin_lock(>l_lock); - list_del(>oh_list); - spin_unlock(>l_lock); - - put_pid(oh->oh_owner_pid); -} - -static inline int ocfs2_is_locked_by_me(struct ocfs2_lock_res *lockres) +static struct ocfs2_lock_holder * +ocfs2_pid_holder(struct ocfs2_lock_res *lockres, + struct pid *pid) { struct ocfs2_lock_holder *oh; - struct pid *pid; - /* look in the list of holders for one with the current task as owner */ spin_lock(>l_lock); - pid = task_pid(current); list_for_each_entry(oh, >l_holders, oh_list) { if (oh->oh_owner_pid == pid) { spin_unlock(>l_lock); - return 1; + return oh; } } spin_unlock(>l_lock); + return NULL; +} - return 0; +static inline void ocfs2_remove_holder(struct ocfs2_lock_res *lockres, + struct ocfs2_lock_holder *oh) +{ + spin_lock(>l_lock); + list_del(>oh_list); + spin_unlock(>l_lock); + + put_pid(oh->oh_owner_pid); } + static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres, int level) { @@ -2610,34 +2609,93 @@ void ocfs2_inode_unlock(struct inode *inode, * * return < 0 on error, return == 0 if there's no lock holder on the stack * before this call, return == 1 if this call would be a recursive locking. + * return == -1 if this lock attempt will cause an upgrade which is forbidden. + * + * When taking lock levels into account,we face some different situations. + * + * 1. no lock is held + *In this case, just lock the inode as requested and return 0 + * + * 2. We are holding a lock + *For this situation, things diverges into several cases + * + *wanted holdingwhat to do + *ex ex see 2.1 below + *ex pr see 2.2 below + *pr ex see 2.1 below + *pr pr see 2.1 below + * + *2.1 lock level that is been held is compatible + *with the wanted level, so no lock action will be tacken. + * + *2.2 Otherwise, an upgrade is needed, but it is forbidden. + * + * Reason why upgrade within a process is forbidden is that + * lock upgrade may cause dead lock. The following illustrates + * how it happens. + * + * thread on node1 thread on node2 + * ocfs2_inode_lock_tracker(ex=0) + * + *<== ocfs2_inode_lock_tracker(ex=1) + * + * ocfs2_inode_lock_tracker(ex=1) */ int ocfs2_inode_lock_tracker(struct inode *inode,