Linux-rt-users archive on lore.kernel.org
 help / color / Atom feed
* [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked
@ 2019-11-12 16:16 Mikulas Patocka
  2019-11-13 10:29 ` Nikos Tsironis
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mikulas Patocka @ 2019-11-12 16:16 UTC (permalink / raw)
  To: tglx, linux-rt-users
  Cc: Mike Snitzer, Nikos Tsironis, Scott Wood, Ilias Tsitsimpis,
	dm-devel, linux-kernel, linux-fsdevel, Daniel Wagner,
	Sebastian Andrzej Siewior

list_bl would crash with BUG() if we used it without locking. dm-snapshot 
uses its own locking on realtime kernels (it can't use list_bl because 
list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks 
while holding bl_lock).

To avoid this BUG, we must set LIST_BL_LOCKMASK = 0.

This patch is intended only for the realtime kernel patchset, not for the 
upstream kernel.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

Index: linux-rt-devel/include/linux/list_bl.h
===================================================================
--- linux-rt-devel.orig/include/linux/list_bl.h	2019-11-07 14:01:51.000000000 +0100
+++ linux-rt-devel/include/linux/list_bl.h	2019-11-08 10:12:49.000000000 +0100
@@ -19,7 +19,7 @@
  * some fast and compact auxiliary data.
  */
 
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
+#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE)
 #define LIST_BL_LOCKMASK	1UL
 #else
 #define LIST_BL_LOCKMASK	0UL
@@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct
 	bit_spin_lock(0, (unsigned long *)b);
 #else
 	raw_spin_lock(&b->lock);
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
-	__set_bit(0, (unsigned long *)b);
-#endif
 #endif
 }
 
@@ -172,9 +169,6 @@ static inline void hlist_bl_unlock(struc
 #ifndef CONFIG_PREEMPT_RT_BASE
 	__bit_spin_unlock(0, (unsigned long *)b);
 #else
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
-	__clear_bit(0, (unsigned long *)b);
-#endif
 	raw_spin_unlock(&b->lock);
 #endif
 }


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked
  2019-11-12 16:16 [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked Mikulas Patocka
@ 2019-11-13 10:29 ` Nikos Tsironis
  2019-11-13 11:16   ` Mikulas Patocka
  2019-11-13 11:18 ` [PATCH RT 2/2 v3] " Mikulas Patocka
  2019-11-13 13:10 ` [PATCH RT 2/2 v4] " Nikos Tsironis
  2 siblings, 1 reply; 7+ messages in thread
From: Nikos Tsironis @ 2019-11-13 10:29 UTC (permalink / raw)
  To: Mikulas Patocka, tglx, linux-rt-users
  Cc: Mike Snitzer, Scott Wood, Ilias Tsitsimpis, dm-devel,
	linux-kernel, linux-fsdevel, Daniel Wagner,
	Sebastian Andrzej Siewior

On 11/12/19 6:16 PM, Mikulas Patocka wrote:
> list_bl would crash with BUG() if we used it without locking. dm-snapshot 
> uses its own locking on realtime kernels (it can't use list_bl because 
> list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks 
> while holding bl_lock).
> 
> To avoid this BUG, we must set LIST_BL_LOCKMASK = 0.
> 
> This patch is intended only for the realtime kernel patchset, not for the 
> upstream kernel.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> 
> Index: linux-rt-devel/include/linux/list_bl.h
> ===================================================================
> --- linux-rt-devel.orig/include/linux/list_bl.h	2019-11-07 14:01:51.000000000 +0100
> +++ linux-rt-devel/include/linux/list_bl.h	2019-11-08 10:12:49.000000000 +0100
> @@ -19,7 +19,7 @@
>   * some fast and compact auxiliary data.
>   */
>  
> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE)
>  #define LIST_BL_LOCKMASK	1UL
>  #else
>  #define LIST_BL_LOCKMASK	0UL
> @@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct
>  	bit_spin_lock(0, (unsigned long *)b);
>  #else
>  	raw_spin_lock(&b->lock);
> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> -	__set_bit(0, (unsigned long *)b);
> -#endif
>  #endif
>  }
>  

Hi Mikulas,

I think removing __set_bit()/__clear_bit() breaks hlist_bl_is_locked(),
which is used by the RCU variant of list_bl.

Nikos

> @@ -172,9 +169,6 @@ static inline void hlist_bl_unlock(struc
>  #ifndef CONFIG_PREEMPT_RT_BASE
>  	__bit_spin_unlock(0, (unsigned long *)b);
>  #else
> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> -	__clear_bit(0, (unsigned long *)b);
> -#endif
>  	raw_spin_unlock(&b->lock);
>  #endif
>  }
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked
  2019-11-13 10:29 ` Nikos Tsironis
@ 2019-11-13 11:16   ` Mikulas Patocka
  2019-11-13 11:50     ` Nikos Tsironis
  0 siblings, 1 reply; 7+ messages in thread
From: Mikulas Patocka @ 2019-11-13 11:16 UTC (permalink / raw)
  To: Nikos Tsironis
  Cc: tglx, linux-rt-users, Mike Snitzer, Scott Wood, Ilias Tsitsimpis,
	dm-devel, linux-kernel, linux-fsdevel, Daniel Wagner,
	Sebastian Andrzej Siewior



On Wed, 13 Nov 2019, Nikos Tsironis wrote:

> On 11/12/19 6:16 PM, Mikulas Patocka wrote:
> > list_bl would crash with BUG() if we used it without locking. dm-snapshot 
> > uses its own locking on realtime kernels (it can't use list_bl because 
> > list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks 
> > while holding bl_lock).
> > 
> > To avoid this BUG, we must set LIST_BL_LOCKMASK = 0.
> > 
> > This patch is intended only for the realtime kernel patchset, not for the 
> > upstream kernel.
> > 
> > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > 
> > Index: linux-rt-devel/include/linux/list_bl.h
> > ===================================================================
> > --- linux-rt-devel.orig/include/linux/list_bl.h	2019-11-07 14:01:51.000000000 +0100
> > +++ linux-rt-devel/include/linux/list_bl.h	2019-11-08 10:12:49.000000000 +0100
> > @@ -19,7 +19,7 @@
> >   * some fast and compact auxiliary data.
> >   */
> >  
> > -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> > +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE)
> >  #define LIST_BL_LOCKMASK	1UL
> >  #else
> >  #define LIST_BL_LOCKMASK	0UL
> > @@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct
> >  	bit_spin_lock(0, (unsigned long *)b);
> >  #else
> >  	raw_spin_lock(&b->lock);
> > -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> > -	__set_bit(0, (unsigned long *)b);
> > -#endif
> >  #endif
> >  }
> >  
> 
> Hi Mikulas,
> 
> I think removing __set_bit()/__clear_bit() breaks hlist_bl_is_locked(),
> which is used by the RCU variant of list_bl.
> 
> Nikos

OK. so I can remove this part of the patch.

Mikulas

> > @@ -172,9 +169,6 @@ static inline void hlist_bl_unlock(struc
> >  #ifndef CONFIG_PREEMPT_RT_BASE
> >  	__bit_spin_unlock(0, (unsigned long *)b);
> >  #else
> > -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> > -	__clear_bit(0, (unsigned long *)b);
> > -#endif
> >  	raw_spin_unlock(&b->lock);
> >  #endif
> >  }
> > 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH RT 2/2 v3] list_bl: avoid BUG when the list is not locked
  2019-11-12 16:16 [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked Mikulas Patocka
  2019-11-13 10:29 ` Nikos Tsironis
@ 2019-11-13 11:18 ` " Mikulas Patocka
  2019-11-13 13:10 ` [PATCH RT 2/2 v4] " Nikos Tsironis
  2 siblings, 0 replies; 7+ messages in thread
From: Mikulas Patocka @ 2019-11-13 11:18 UTC (permalink / raw)
  To: tglx, linux-rt-users
  Cc: Mike Snitzer, Nikos Tsironis, Scott Wood, Ilias Tsitsimpis,
	dm-devel, linux-kernel, linux-fsdevel, Daniel Wagner,
	Sebastian Andrzej Siewior

list_bl would crash with BUG() if we used it without locking. dm-snapshot 
uses its own locking on realtime kernels (it can't use list_bl because 
list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks 
while holding bl_lock).

To avoid this BUG, we must set LIST_BL_LOCKMASK = 0.

This patch is intended only for the realtime kernel patchset, not for the 
upstream kernel.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 include/linux/list_bl.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-rt-devel/include/linux/list_bl.h
===================================================================
--- linux-rt-devel.orig/include/linux/list_bl.h	2019-11-13 12:15:50.000000000 +0100
+++ linux-rt-devel/include/linux/list_bl.h	2019-11-13 12:15:50.000000000 +0100
@@ -19,7 +19,7 @@
  * some fast and compact auxiliary data.
  */
 
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
+#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE)
 #define LIST_BL_LOCKMASK	1UL
 #else
 #define LIST_BL_LOCKMASK	0UL


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked
  2019-11-13 11:16   ` Mikulas Patocka
@ 2019-11-13 11:50     ` Nikos Tsironis
  2019-11-13 12:05       ` Mikulas Patocka
  0 siblings, 1 reply; 7+ messages in thread
From: Nikos Tsironis @ 2019-11-13 11:50 UTC (permalink / raw)
  To: Mikulas Patocka
  Cc: tglx, linux-rt-users, Mike Snitzer, Scott Wood, Ilias Tsitsimpis,
	dm-devel, linux-kernel, linux-fsdevel, Daniel Wagner,
	Sebastian Andrzej Siewior

On 11/13/19 1:16 PM, Mikulas Patocka wrote:
> 
> 
> On Wed, 13 Nov 2019, Nikos Tsironis wrote:
> 
>> On 11/12/19 6:16 PM, Mikulas Patocka wrote:
>>> list_bl would crash with BUG() if we used it without locking. dm-snapshot 
>>> uses its own locking on realtime kernels (it can't use list_bl because 
>>> list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks 
>>> while holding bl_lock).
>>>
>>> To avoid this BUG, we must set LIST_BL_LOCKMASK = 0.
>>>
>>> This patch is intended only for the realtime kernel patchset, not for the 
>>> upstream kernel.
>>>
>>> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
>>>
>>> Index: linux-rt-devel/include/linux/list_bl.h
>>> ===================================================================
>>> --- linux-rt-devel.orig/include/linux/list_bl.h	2019-11-07 14:01:51.000000000 +0100
>>> +++ linux-rt-devel/include/linux/list_bl.h	2019-11-08 10:12:49.000000000 +0100
>>> @@ -19,7 +19,7 @@
>>>   * some fast and compact auxiliary data.
>>>   */
>>>  
>>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
>>> +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE)
>>>  #define LIST_BL_LOCKMASK	1UL
>>>  #else
>>>  #define LIST_BL_LOCKMASK	0UL
>>> @@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct
>>>  	bit_spin_lock(0, (unsigned long *)b);
>>>  #else
>>>  	raw_spin_lock(&b->lock);
>>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
>>> -	__set_bit(0, (unsigned long *)b);
>>> -#endif
>>>  #endif
>>>  }
>>>  
>>
>> Hi Mikulas,
>>
>> I think removing __set_bit()/__clear_bit() breaks hlist_bl_is_locked(),
>> which is used by the RCU variant of list_bl.
>>
>> Nikos
> 
> OK. so I can remove this part of the patch.
> 

I think this causes another problem. LIST_BL_LOCKMASK is used in various
functions to set/clear the lock bit, e.g. in hlist_bl_first(). So, if we
lock the list through hlist_bl_lock(), thus setting the lock bit with
__set_bit(), and then call hlist_bl_first() to get the first element,
the returned pointer will be invalid. As LIST_BL_LOCKMASK is zero the
least significant bit of the pointer will be 1.

I think for dm-snapshot to work using its own locking, and without
list_bl complaining, the following is sufficient:

--- a/include/linux/list_bl.h
+++ b/include/linux/list_bl.h
@@ -25,7 +25,7 @@
 #define LIST_BL_LOCKMASK       0UL
 #endif

-#ifdef CONFIG_DEBUG_LIST
+#if defined(CONFIG_DEBUG_LIST) && !defined(CONFIG_PREEMPT_RT_BASE)
 #define LIST_BL_BUG_ON(x) BUG_ON(x)
 #else
 #define LIST_BL_BUG_ON(x)

Nikos

> Mikulas
> 
>>> @@ -172,9 +169,6 @@ static inline void hlist_bl_unlock(struc
>>>  #ifndef CONFIG_PREEMPT_RT_BASE
>>>  	__bit_spin_unlock(0, (unsigned long *)b);
>>>  #else
>>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
>>> -	__clear_bit(0, (unsigned long *)b);
>>> -#endif
>>>  	raw_spin_unlock(&b->lock);
>>>  #endif
>>>  }
>>>
>>
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked
  2019-11-13 11:50     ` Nikos Tsironis
@ 2019-11-13 12:05       ` Mikulas Patocka
  0 siblings, 0 replies; 7+ messages in thread
From: Mikulas Patocka @ 2019-11-13 12:05 UTC (permalink / raw)
  To: Nikos Tsironis
  Cc: tglx, linux-rt-users, Mike Snitzer, Scott Wood, Ilias Tsitsimpis,
	dm-devel, linux-kernel, linux-fsdevel, Daniel Wagner,
	Sebastian Andrzej Siewior



On Wed, 13 Nov 2019, Nikos Tsironis wrote:

> On 11/13/19 1:16 PM, Mikulas Patocka wrote:
> > 
> > 
> > On Wed, 13 Nov 2019, Nikos Tsironis wrote:
> > 
> >> On 11/12/19 6:16 PM, Mikulas Patocka wrote:
> >>> list_bl would crash with BUG() if we used it without locking. dm-snapshot 
> >>> uses its own locking on realtime kernels (it can't use list_bl because 
> >>> list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks 
> >>> while holding bl_lock).
> >>>
> >>> To avoid this BUG, we must set LIST_BL_LOCKMASK = 0.
> >>>
> >>> This patch is intended only for the realtime kernel patchset, not for the 
> >>> upstream kernel.
> >>>
> >>> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> >>>
> >>> Index: linux-rt-devel/include/linux/list_bl.h
> >>> ===================================================================
> >>> --- linux-rt-devel.orig/include/linux/list_bl.h	2019-11-07 14:01:51.000000000 +0100
> >>> +++ linux-rt-devel/include/linux/list_bl.h	2019-11-08 10:12:49.000000000 +0100
> >>> @@ -19,7 +19,7 @@
> >>>   * some fast and compact auxiliary data.
> >>>   */
> >>>  
> >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> >>> +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE)
> >>>  #define LIST_BL_LOCKMASK	1UL
> >>>  #else
> >>>  #define LIST_BL_LOCKMASK	0UL
> >>> @@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct
> >>>  	bit_spin_lock(0, (unsigned long *)b);
> >>>  #else
> >>>  	raw_spin_lock(&b->lock);
> >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
> >>> -	__set_bit(0, (unsigned long *)b);
> >>> -#endif
> >>>  #endif
> >>>  }
> >>>  
> >>
> >> Hi Mikulas,
> >>
> >> I think removing __set_bit()/__clear_bit() breaks hlist_bl_is_locked(),
> >> which is used by the RCU variant of list_bl.
> >>
> >> Nikos
> > 
> > OK. so I can remove this part of the patch.
> > 
> 
> I think this causes another problem. LIST_BL_LOCKMASK is used in various
> functions to set/clear the lock bit, e.g. in hlist_bl_first(). So, if we
> lock the list through hlist_bl_lock(), thus setting the lock bit with
> __set_bit(), and then call hlist_bl_first() to get the first element,
> the returned pointer will be invalid. As LIST_BL_LOCKMASK is zero the
> least significant bit of the pointer will be 1.
> 
> I think for dm-snapshot to work using its own locking, and without
> list_bl complaining, the following is sufficient:
> 
> --- a/include/linux/list_bl.h
> +++ b/include/linux/list_bl.h
> @@ -25,7 +25,7 @@
>  #define LIST_BL_LOCKMASK       0UL
>  #endif
> 
> -#ifdef CONFIG_DEBUG_LIST
> +#if defined(CONFIG_DEBUG_LIST) && !defined(CONFIG_PREEMPT_RT_BASE)
>  #define LIST_BL_BUG_ON(x) BUG_ON(x)
>  #else
>  #define LIST_BL_BUG_ON(x)
> 
> Nikos

Yes - so, submit this.

Reviewed-by: Mikulas Patocka <mpatocka@redhat.com>

Mikulas


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH RT 2/2 v4] list_bl: avoid BUG when the list is not locked
  2019-11-12 16:16 [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked Mikulas Patocka
  2019-11-13 10:29 ` Nikos Tsironis
  2019-11-13 11:18 ` [PATCH RT 2/2 v3] " Mikulas Patocka
@ 2019-11-13 13:10 ` " Nikos Tsironis
  2 siblings, 0 replies; 7+ messages in thread
From: Nikos Tsironis @ 2019-11-13 13:10 UTC (permalink / raw)
  To: mpatocka, tglx, linux-rt-users, msnitzer, dm-devel, linux-kernel
  Cc: swood, linux-fsdevel, dwagner, bigeasy, iliastsi, ntsironis

list_bl would crash with BUG() if we used it without locking.
dm-snapshot uses its own locking on realtime kernels (it can't use
list_bl because list_bl uses raw spinlock and dm-snapshot takes other
non-raw spinlocks while holding bl_lock).

To avoid this BUG we deactivate the list debug checks for list_bl on
realtime kernels.

This patch is intended only for the realtime kernel patchset, not for
the upstream kernel.

Signed-off-by: Nikos Tsironis <ntsironis@arrikto.com>
Reviewed-by: Mikulas Patocka <mpatocka@redhat.com>
---
 include/linux/list_bl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/list_bl.h b/include/linux/list_bl.h
index da38433240f5..3585b2f6b948 100644
--- a/include/linux/list_bl.h
+++ b/include/linux/list_bl.h
@@ -25,7 +25,7 @@
 #define LIST_BL_LOCKMASK	0UL
 #endif
 
-#ifdef CONFIG_DEBUG_LIST
+#if defined(CONFIG_DEBUG_LIST) && !defined(CONFIG_PREEMPT_RT_BASE)
 #define LIST_BL_BUG_ON(x) BUG_ON(x)
 #else
 #define LIST_BL_BUG_ON(x)
-- 
2.11.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 16:16 [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked Mikulas Patocka
2019-11-13 10:29 ` Nikos Tsironis
2019-11-13 11:16   ` Mikulas Patocka
2019-11-13 11:50     ` Nikos Tsironis
2019-11-13 12:05       ` Mikulas Patocka
2019-11-13 11:18 ` [PATCH RT 2/2 v3] " Mikulas Patocka
2019-11-13 13:10 ` [PATCH RT 2/2 v4] " Nikos Tsironis

Linux-rt-users archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rt-users/0 linux-rt-users/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rt-users linux-rt-users/ https://lore.kernel.org/linux-rt-users \
		linux-rt-users@vger.kernel.org
	public-inbox-index linux-rt-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rt-users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git