Re: [PATCH 4.19 36/63] locking/lockdep: Add debug_locks check in __lock_downgrade()

From: Waiman Long
Date: Wed Oct 02 2019 - 09:16:55 EST


On 10/1/19 6:20 PM, Sasha Levin wrote:
> On Mon, Sep 30, 2019 at 10:00:35AM -0400, Waiman Long wrote:
>> On 9/29/19 9:46 PM, Tetsuo Handa wrote:
>>> On 2019/09/30 9:28, Sasha Levin wrote:
>>>> On Sun, Sep 29, 2019 at 11:43:38PM +0900, Tetsuo Handa wrote:
>>>>> On 2019/09/29 22:54, Greg Kroah-Hartman wrote:
>>>>>> From: Waiman Long <longman@xxxxxxxxxx>
>>>>>>
>>>>>> [ Upstream commit 513e1073d52e55b8024b4f238a48de7587c64ccf ]
>>>>>>
>>>>>> Tetsuo Handa had reported he saw an incorrect "downgrading a read
>>>>>> lock"
>>>>>> warning right after a previous lockdep warning. It is likely that
>>>>>> the
>>>>>> previous warning turned off lock debugging causing the lockdep to
>>>>>> have
>>>>>> inconsistency states leading to the lock downgrade warning.
>>>>>>
>>>>>> Fix that by add a check for debug_locks at the beginning of
>>>>>> __lock_downgrade().
>>>>> Please drop "[PATCH 4.19 36/63] locking/lockdep: Add debug_locks
>>>>> check in __lock_downgrade()".
>>>>> We had a revert patch shown below in the past.
>>>> We had a revert in the stable trees, but that revert was incorrect.
>>>>
>>>> Take a look at commit 513e1073d52e55 upstream, it patches
>>>> __lock_set_class() (even though the subject line says
>>>> __lock_downgrade()). So this is not a backporting error as the revert
>>>> said it is, but is rather the intended location to be patched.
>>>>
>>>> If this is actually wrong, then it should be addressed upstream first.
>>>>
>>> Hmm, upstream has two commits with same author, same date, same
>>> subject, different hash, different content.
>>> I couldn't find from
>>> https://lkml.kernel.org/r/1547093005-26085-1-git-send-email-longman@xxxxxxxxxx
>>> that
>>> we want to patch both __lock_set_class() and __lock_downgrade(), but
>>> I found that the tip-bot has patched
>>> __lock_downgrade() on "2019-01-21 11:29" and __lock_set_class() on
>>> "2019-02-04Â 8:56".
>>> Seems that we by error patched both functions, though patching both
>>> functions should be harmless...
>>>
>>> 64aa348ed kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-08-11 09:30:21 +0200 4115) static int
>>> 00ef9f734 kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-12-04 09:00:17 +0100 4116) __lock_set_class(struct lockdep_map
>>> *lock, const char *name,
>>> 00ef9f734 kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-12-04 09:00:17 +0100 4117)ÂÂÂÂÂÂÂÂÂÂÂ struct lock_class_key
>>> *key, unsigned int subclass,
>>> 00ef9f734 kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-12-04 09:00:17 +0100 4118)ÂÂÂÂÂÂÂÂÂÂÂ unsigned long ip)
>>> 64aa348ed kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-08-11 09:30:21 +0200 4119) {
>>> 64aa348ed kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-08-11 09:30:21 +0200 4120)ÂÂ struct task_struct *curr = current;
>>> 8c8889d8e kernel/locking/lockdep.c (Imre DeakÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-05-24 23:15:08 +0300 4121)ÂÂ unsigned int depth, merged = 0;
>>> 41c2c5b86 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:15 +0900 4122)ÂÂ struct held_lock *hlock;
>>> 64aa348ed kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-08-11 09:30:21 +0200 4123)ÂÂ struct lock_class *class;
>>> 64aa348ed kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-08-11 09:30:21 +0200 4124)ÂÂ int i;
>>> 64aa348ed kernel/lockdep.cÂÂÂÂÂÂÂÂ (Peter ZijlstraÂÂÂÂÂÂÂÂÂÂÂ
>>> 2008-08-11 09:30:21 +0200 4125)
>>> 513e1073d kernel/locking/lockdep.c (Waiman LongÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-01-09 23:03:25 -0500 4126)ÂÂ if (unlikely(!debug_locks))
>>> 513e1073d kernel/locking/lockdep.c (Waiman LongÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-01-09 23:03:25 -0500 4127)ÂÂÂÂÂÂÂÂÂÂ return 0;
>>> 513e1073d kernel/locking/lockdep.c (Waiman LongÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-01-09 23:03:25 -0500 4128)
>>>
>>> 6419c4af7 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:17 +0900 4162) static int __lock_downgrade(struct
>>> lockdep_map *lock, unsigned long ip)
>>> 6419c4af7 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:17 +0900 4163) {
>>> 6419c4af7 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:17 +0900 4164)ÂÂ struct task_struct *curr = current;
>>> 8c8889d8e kernel/locking/lockdep.c (Imre DeakÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-05-24 23:15:08 +0300 4165)ÂÂ unsigned int depth, merged = 0;
>>> 6419c4af7 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:17 +0900 4166)ÂÂ struct held_lock *hlock;
>>> 6419c4af7 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:17 +0900 4167)ÂÂ int i;
>>> 6419c4af7 kernel/locking/lockdep.c (J. R. OkajimaÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2017-02-03 01:38:17 +0900 4168)
>>> 714925805 kernel/locking/lockdep.c (Waiman LongÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-01-09 23:03:25 -0500 4169)ÂÂ if (unlikely(!debug_locks))
>>> 714925805 kernel/locking/lockdep.c (Waiman LongÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-01-09 23:03:25 -0500 4170)ÂÂÂÂÂÂÂÂÂÂ return 0;
>>> 714925805 kernel/locking/lockdep.c (Waiman LongÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
>>> 2019-01-09 23:03:25 -0500 4171)
>>>
>>> commit 513e1073d52e55b8024b4f238a48de7587c64ccf
>>> Author: Waiman Long <longman@xxxxxxxxxx>
>>> Date:ÂÂ Wed Jan 9 23:03:25 2019 -0500
>>>
>>> ÂÂÂ locking/lockdep: Add debug_locks check in __lock_downgrade()
>>>
>>> commit 71492580571467fb7177aade19c18ce7486267f5
>>> Author: Waiman Long <longman@xxxxxxxxxx>
>>> Date:ÂÂ Wed Jan 9 23:03:25 2019 -0500
>>>
>>> ÂÂÂ locking/lockdep: Add debug_locks check in __lock_downgrade()
>>>
>> As I had said before, it looks like the git-apply mixed up the location
>> due to the fact that the hunks are exactly the same for both locations.
>> So if the patch to be applied does not have the right line number, it
>> will get applied to the wrong location first.
>
> I very much agree, my point is that *both* patches are upstream right
> now, and if one of those patches is wrong then it should be reverted
> upstream, and we'd be happy to take the revert.

The patch itself shouldn't do any harm even if it is applied to the
wrong function. So there is no urgency to revert it.

Cheers,
Longman