2022-10-19 23:14:24

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

It is not obvious to the casual user why it is absolutely necessary to
acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
a lock in that structure. Therefore, add a comment explaining this point.

Signed-off-by: Paul E. McKenney <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Hyeonggon Yoo <[email protected]>
Cc: <[email protected]>
---
include/linux/slab.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 90877fcde70bd..446303e385265 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -76,6 +76,12 @@
* rcu_read_lock before reading the address, then rcu_read_unlock after
* taking the spinlock within the structure expected at that address.
*
+ * Note that it is not possible to acquire a lock within a structure
+ * allocated with SLAB_DESTROY_BY_RCU without first acquiring a reference
+ * as described above. The reason is that SLAB_DESTROY_BY_RCU pages are
+ * not zeroed before being given to the slab, which means that any locks
+ * must be initialized after each and every kmem_struct_alloc().
+ *
* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
*/
/* Defer freeing slabs to RCU */
--
2.31.1.189.g2e36527f23


2022-10-20 07:58:10

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On 10/20/22 00:46, Paul E. McKenney wrote:
> It is not obvious to the casual user why it is absolutely necessary to
> acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
> a lock in that structure. Therefore, add a comment explaining this point.

s/SLAB_DESTROY_BY_RCU/SLAB_TYPESAFE_BY_RCU/ in subject, commit log and the
added comment? :)

> Signed-off-by: Paul E. McKenney <[email protected]>
> Cc: Christoph Lameter <[email protected]>
> Cc: Pekka Enberg <[email protected]>
> Cc: David Rientjes <[email protected]>
> Cc: Joonsoo Kim <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Vlastimil Babka <[email protected]>
> Cc: Roman Gushchin <[email protected]>
> Cc: Hyeonggon Yoo <[email protected]>
> Cc: <[email protected]>
> ---
> include/linux/slab.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 90877fcde70bd..446303e385265 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -76,6 +76,12 @@
> * rcu_read_lock before reading the address, then rcu_read_unlock after
> * taking the spinlock within the structure expected at that address.
> *
> + * Note that it is not possible to acquire a lock within a structure
> + * allocated with SLAB_DESTROY_BY_RCU without first acquiring a reference
> + * as described above. The reason is that SLAB_DESTROY_BY_RCU pages are
> + * not zeroed before being given to the slab, which means that any locks
> + * must be initialized after each and every kmem_struct_alloc().
> + *

Wonder if slab caches with a constructor should be OK here as AFAIK it
should mean the object has to be in the initialized state both when
allocated and freed?

> * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
> */
> /* Defer freeing slabs to RCU */

2022-10-20 16:49:27

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On Thu, Oct 20, 2022 at 09:10:49AM +0200, Vlastimil Babka wrote:
> On 10/20/22 00:46, Paul E. McKenney wrote:
> > It is not obvious to the casual user why it is absolutely necessary to
> > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
> > a lock in that structure. Therefore, add a comment explaining this point.
>
> s/SLAB_DESTROY_BY_RCU/SLAB_TYPESAFE_BY_RCU/ in subject, commit log and the
> added comment? :)

Boy, I was certainly living in the past when I did this patch, wasn't I?

Thank you, will fix on next rebase.

> > Signed-off-by: Paul E. McKenney <[email protected]>
> > Cc: Christoph Lameter <[email protected]>
> > Cc: Pekka Enberg <[email protected]>
> > Cc: David Rientjes <[email protected]>
> > Cc: Joonsoo Kim <[email protected]>
> > Cc: Andrew Morton <[email protected]>
> > Cc: Vlastimil Babka <[email protected]>
> > Cc: Roman Gushchin <[email protected]>
> > Cc: Hyeonggon Yoo <[email protected]>
> > Cc: <[email protected]>
> > ---
> > include/linux/slab.h | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/include/linux/slab.h b/include/linux/slab.h
> > index 90877fcde70bd..446303e385265 100644
> > --- a/include/linux/slab.h
> > +++ b/include/linux/slab.h
> > @@ -76,6 +76,12 @@
> > * rcu_read_lock before reading the address, then rcu_read_unlock after
> > * taking the spinlock within the structure expected at that address.
> > *
> > + * Note that it is not possible to acquire a lock within a structure
> > + * allocated with SLAB_DESTROY_BY_RCU without first acquiring a reference
> > + * as described above. The reason is that SLAB_DESTROY_BY_RCU pages are
> > + * not zeroed before being given to the slab, which means that any locks
> > + * must be initialized after each and every kmem_struct_alloc().
> > + *
>
> Wonder if slab caches with a constructor should be OK here as AFAIK it
> should mean the object has to be in the initialized state both when
> allocated and freed?

It does look that way, thank you!

And __i915_request_ctor(), sighand_ctor(), and anon_vma_ctor() actually
do this, initializing a lock in the process.

The ctor function could just initialize the locks, and all would be well.
In addition, this makes sequence-lock-like approaches a bit easier, as in
"just use a sequence lock".

I will update with attribution.

Thanx, Paul

> > * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
> > */
> > /* Defer freeing slabs to RCU */
>

2022-10-21 08:18:08

by Christoph Lameter

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On Wed, 19 Oct 2022, Paul E. McKenney wrote:

> It is not obvious to the casual user why it is absolutely necessary to
> acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
> a lock in that structure. Therefore, add a comment explaining this point.

Sorry but this is not correct and difficult to comprehend.

1. You do not need a reference to a slab object after it was allocated.
Objects must be properly protected by rcu_locks.

2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc)

3. Modifying locks at allocation/free is not possible since references to
these objects may still persist after free and before alloc.

4. The old term SLAB_DESTROY_BY_RCU is used here.

2022-10-21 14:56:29

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On 10/21/22 15:43, Paul E. McKenney wrote:
> On Fri, Oct 21, 2022 at 09:44:23AM +0200, Christoph Lameter wrote:
>> On Wed, 19 Oct 2022, Paul E. McKenney wrote:
>>
>> > It is not obvious to the casual user why it is absolutely necessary to
>> > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
>> > a lock in that structure. Therefore, add a comment explaining this point.
>>
>> Sorry but this is not correct and difficult to comprehend.
>>
>> 1. You do not need a reference to a slab object after it was allocated.
>> Objects must be properly protected by rcu_locks.
>>
>> 2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc)
>>
>> 3. Modifying locks at allocation/free is not possible since references to
>> these objects may still persist after free and before alloc.
>>
>> 4. The old term SLAB_DESTROY_BY_RCU is used here.
>
> Thank you for looking this over, but Vlastimil beat you to it. How does
> the update below look?

LGTM.

> Thanx, Paul
>
> ------------------------------------------------------------------------
>
> commit ff4c536e6b44e2e185e38c3653851f92e07139da
> Author: Paul E. McKenney <[email protected]>
> Date: Mon Sep 26 08:57:56 2022 -0700
>
> slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking
>
> It is not obvious to the casual user why it is absolutely necessary to
> acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring
> a lock in that structure. Therefore, add a comment explaining this point.
>
> [ paulmck: Apply Vlastimil Babka feedback. ]
>
> Signed-off-by: Paul E. McKenney <[email protected]>

Acked-by: Vlastimil Babka <[email protected]>

> Cc: Christoph Lameter <[email protected]>
> Cc: Pekka Enberg <[email protected]>
> Cc: David Rientjes <[email protected]>
> Cc: Joonsoo Kim <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Vlastimil Babka <[email protected]>
> Cc: Roman Gushchin <[email protected]>
> Cc: Hyeonggon Yoo <[email protected]>
> Cc: <[email protected]>
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 90877fcde70bd..487418c7ea8cd 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -76,6 +76,17 @@
> * rcu_read_lock before reading the address, then rcu_read_unlock after
> * taking the spinlock within the structure expected at that address.
> *
> + * Note that it is not possible to acquire a lock within a structure
> + * allocated with SLAB_TYPESAFE_BY_RCU without first acquiring a reference
> + * as described above. The reason is that SLAB_TYPESAFE_BY_RCU pages
> + * are not zeroed before being given to the slab, which means that any
> + * locks must be initialized after each and every kmem_struct_alloc().
> + * Alternatively, make the ctor passed to kmem_cache_create() initialize
> + * the locks at page-allocation time, as is done in __i915_request_ctor(),
> + * sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers
> + * to safely acquire those ctor-initialized locks under rcu_read_lock()
> + * protection.
> + *
> * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
> */
> /* Defer freeing slabs to RCU */

2022-10-21 15:00:26

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On Fri, Oct 21, 2022 at 09:44:23AM +0200, Christoph Lameter wrote:
> On Wed, 19 Oct 2022, Paul E. McKenney wrote:
>
> > It is not obvious to the casual user why it is absolutely necessary to
> > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
> > a lock in that structure. Therefore, add a comment explaining this point.
>
> Sorry but this is not correct and difficult to comprehend.
>
> 1. You do not need a reference to a slab object after it was allocated.
> Objects must be properly protected by rcu_locks.
>
> 2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc)
>
> 3. Modifying locks at allocation/free is not possible since references to
> these objects may still persist after free and before alloc.
>
> 4. The old term SLAB_DESTROY_BY_RCU is used here.

Thank you for looking this over, but Vlastimil beat you to it. How does
the update below look?

Thanx, Paul

------------------------------------------------------------------------

commit ff4c536e6b44e2e185e38c3653851f92e07139da
Author: Paul E. McKenney <[email protected]>
Date: Mon Sep 26 08:57:56 2022 -0700

slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking

It is not obvious to the casual user why it is absolutely necessary to
acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring
a lock in that structure. Therefore, add a comment explaining this point.

[ paulmck: Apply Vlastimil Babka feedback. ]

Signed-off-by: Paul E. McKenney <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Hyeonggon Yoo <[email protected]>
Cc: <[email protected]>

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 90877fcde70bd..487418c7ea8cd 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -76,6 +76,17 @@
* rcu_read_lock before reading the address, then rcu_read_unlock after
* taking the spinlock within the structure expected at that address.
*
+ * Note that it is not possible to acquire a lock within a structure
+ * allocated with SLAB_TYPESAFE_BY_RCU without first acquiring a reference
+ * as described above. The reason is that SLAB_TYPESAFE_BY_RCU pages
+ * are not zeroed before being given to the slab, which means that any
+ * locks must be initialized after each and every kmem_struct_alloc().
+ * Alternatively, make the ctor passed to kmem_cache_create() initialize
+ * the locks at page-allocation time, as is done in __i915_request_ctor(),
+ * sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers
+ * to safely acquire those ctor-initialized locks under rcu_read_lock()
+ * protection.
+ *
* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
*/
/* Defer freeing slabs to RCU */

2022-10-21 16:04:07

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On 10/21/22 17:42, Paul E. McKenney wrote:
> On Fri, Oct 21, 2022 at 03:50:17PM +0200, Vlastimil Babka wrote:
>> On 10/21/22 15:43, Paul E. McKenney wrote:
>> > On Fri, Oct 21, 2022 at 09:44:23AM +0200, Christoph Lameter wrote:
>> >> On Wed, 19 Oct 2022, Paul E. McKenney wrote:
>> >>
>> >> > It is not obvious to the casual user why it is absolutely necessary to
>> >> > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
>> >> > a lock in that structure. Therefore, add a comment explaining this point.
>> >>
>> >> Sorry but this is not correct and difficult to comprehend.
>> >>
>> >> 1. You do not need a reference to a slab object after it was allocated.
>> >> Objects must be properly protected by rcu_locks.
>> >>
>> >> 2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc)
>> >>
>> >> 3. Modifying locks at allocation/free is not possible since references to
>> >> these objects may still persist after free and before alloc.
>> >>
>> >> 4. The old term SLAB_DESTROY_BY_RCU is used here.
>> >
>> > Thank you for looking this over, but Vlastimil beat you to it. How does
>> > the update below look?
>>
>> LGTM.
>
> May I please have your ack?
>
> Thanx, Paul
>
>> > ------------------------------------------------------------------------
>> >
>> > commit ff4c536e6b44e2e185e38c3653851f92e07139da
>> > Author: Paul E. McKenney <[email protected]>
>> > Date: Mon Sep 26 08:57:56 2022 -0700
>> >
>> > slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking
>> >
>> > It is not obvious to the casual user why it is absolutely necessary to
>> > acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring
>> > a lock in that structure. Therefore, add a comment explaining this point.
>> >
>> > [ paulmck: Apply Vlastimil Babka feedback. ]
>> >
>> > Signed-off-by: Paul E. McKenney <[email protected]>
>>
>> Acked-by: Vlastimil Babka <[email protected]>

It was there :)

>> > Cc: Christoph Lameter <[email protected]>
>> > Cc: Pekka Enberg <[email protected]>
>> > Cc: David Rientjes <[email protected]>
>> > Cc: Joonsoo Kim <[email protected]>
>> > Cc: Andrew Morton <[email protected]>
>> > Cc: Vlastimil Babka <[email protected]>
>> > Cc: Roman Gushchin <[email protected]>
>> > Cc: Hyeonggon Yoo <[email protected]>
>> > Cc: <[email protected]>
>> >
>> > diff --git a/include/linux/slab.h b/include/linux/slab.h
>> > index 90877fcde70bd..487418c7ea8cd 100644
>> > --- a/include/linux/slab.h
>> > +++ b/include/linux/slab.h
>> > @@ -76,6 +76,17 @@
>> > * rcu_read_lock before reading the address, then rcu_read_unlock after
>> > * taking the spinlock within the structure expected at that address.
>> > *
>> > + * Note that it is not possible to acquire a lock within a structure
>> > + * allocated with SLAB_TYPESAFE_BY_RCU without first acquiring a reference
>> > + * as described above. The reason is that SLAB_TYPESAFE_BY_RCU pages
>> > + * are not zeroed before being given to the slab, which means that any
>> > + * locks must be initialized after each and every kmem_struct_alloc().
>> > + * Alternatively, make the ctor passed to kmem_cache_create() initialize
>> > + * the locks at page-allocation time, as is done in __i915_request_ctor(),
>> > + * sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers
>> > + * to safely acquire those ctor-initialized locks under rcu_read_lock()
>> > + * protection.
>> > + *
>> > * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
>> > */
>> > /* Defer freeing slabs to RCU */
>>

2022-10-21 16:22:18

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On Fri, Oct 21, 2022 at 05:50:39PM +0200, Vlastimil Babka wrote:
> On 10/21/22 17:42, Paul E. McKenney wrote:
> > On Fri, Oct 21, 2022 at 03:50:17PM +0200, Vlastimil Babka wrote:
> >> On 10/21/22 15:43, Paul E. McKenney wrote:
> >> > On Fri, Oct 21, 2022 at 09:44:23AM +0200, Christoph Lameter wrote:
> >> >> On Wed, 19 Oct 2022, Paul E. McKenney wrote:
> >> >>
> >> >> > It is not obvious to the casual user why it is absolutely necessary to
> >> >> > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
> >> >> > a lock in that structure. Therefore, add a comment explaining this point.
> >> >>
> >> >> Sorry but this is not correct and difficult to comprehend.
> >> >>
> >> >> 1. You do not need a reference to a slab object after it was allocated.
> >> >> Objects must be properly protected by rcu_locks.
> >> >>
> >> >> 2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc)
> >> >>
> >> >> 3. Modifying locks at allocation/free is not possible since references to
> >> >> these objects may still persist after free and before alloc.
> >> >>
> >> >> 4. The old term SLAB_DESTROY_BY_RCU is used here.
> >> >
> >> > Thank you for looking this over, but Vlastimil beat you to it. How does
> >> > the update below look?
> >>
> >> LGTM.
> >
> > May I please have your ack?
> >
> > Thanx, Paul
> >
> >> > ------------------------------------------------------------------------
> >> >
> >> > commit ff4c536e6b44e2e185e38c3653851f92e07139da
> >> > Author: Paul E. McKenney <[email protected]>
> >> > Date: Mon Sep 26 08:57:56 2022 -0700
> >> >
> >> > slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking
> >> >
> >> > It is not obvious to the casual user why it is absolutely necessary to
> >> > acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring
> >> > a lock in that structure. Therefore, add a comment explaining this point.
> >> >
> >> > [ paulmck: Apply Vlastimil Babka feedback. ]
> >> >
> >> > Signed-off-by: Paul E. McKenney <[email protected]>
> >>
> >> Acked-by: Vlastimil Babka <[email protected]>
>
> It was there :)

One of those mornings, I guess...

Thank you very much!!!

Thanx, Paul

> >> > Cc: Christoph Lameter <[email protected]>
> >> > Cc: Pekka Enberg <[email protected]>
> >> > Cc: David Rientjes <[email protected]>
> >> > Cc: Joonsoo Kim <[email protected]>
> >> > Cc: Andrew Morton <[email protected]>
> >> > Cc: Vlastimil Babka <[email protected]>
> >> > Cc: Roman Gushchin <[email protected]>
> >> > Cc: Hyeonggon Yoo <[email protected]>
> >> > Cc: <[email protected]>
> >> >
> >> > diff --git a/include/linux/slab.h b/include/linux/slab.h
> >> > index 90877fcde70bd..487418c7ea8cd 100644
> >> > --- a/include/linux/slab.h
> >> > +++ b/include/linux/slab.h
> >> > @@ -76,6 +76,17 @@
> >> > * rcu_read_lock before reading the address, then rcu_read_unlock after
> >> > * taking the spinlock within the structure expected at that address.
> >> > *
> >> > + * Note that it is not possible to acquire a lock within a structure
> >> > + * allocated with SLAB_TYPESAFE_BY_RCU without first acquiring a reference
> >> > + * as described above. The reason is that SLAB_TYPESAFE_BY_RCU pages
> >> > + * are not zeroed before being given to the slab, which means that any
> >> > + * locks must be initialized after each and every kmem_struct_alloc().
> >> > + * Alternatively, make the ctor passed to kmem_cache_create() initialize
> >> > + * the locks at page-allocation time, as is done in __i915_request_ctor(),
> >> > + * sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers
> >> > + * to safely acquire those ctor-initialized locks under rcu_read_lock()
> >> > + * protection.
> >> > + *
> >> > * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
> >> > */
> >> > /* Defer freeing slabs to RCU */
> >>
>

2022-10-21 16:24:15

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking

On Fri, Oct 21, 2022 at 03:50:17PM +0200, Vlastimil Babka wrote:
> On 10/21/22 15:43, Paul E. McKenney wrote:
> > On Fri, Oct 21, 2022 at 09:44:23AM +0200, Christoph Lameter wrote:
> >> On Wed, 19 Oct 2022, Paul E. McKenney wrote:
> >>
> >> > It is not obvious to the casual user why it is absolutely necessary to
> >> > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring
> >> > a lock in that structure. Therefore, add a comment explaining this point.
> >>
> >> Sorry but this is not correct and difficult to comprehend.
> >>
> >> 1. You do not need a reference to a slab object after it was allocated.
> >> Objects must be properly protected by rcu_locks.
> >>
> >> 2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc)
> >>
> >> 3. Modifying locks at allocation/free is not possible since references to
> >> these objects may still persist after free and before alloc.
> >>
> >> 4. The old term SLAB_DESTROY_BY_RCU is used here.
> >
> > Thank you for looking this over, but Vlastimil beat you to it. How does
> > the update below look?
>
> LGTM.

May I please have your ack?

Thanx, Paul

> > ------------------------------------------------------------------------
> >
> > commit ff4c536e6b44e2e185e38c3653851f92e07139da
> > Author: Paul E. McKenney <[email protected]>
> > Date: Mon Sep 26 08:57:56 2022 -0700
> >
> > slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking
> >
> > It is not obvious to the casual user why it is absolutely necessary to
> > acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring
> > a lock in that structure. Therefore, add a comment explaining this point.
> >
> > [ paulmck: Apply Vlastimil Babka feedback. ]
> >
> > Signed-off-by: Paul E. McKenney <[email protected]>
>
> Acked-by: Vlastimil Babka <[email protected]>
>
> > Cc: Christoph Lameter <[email protected]>
> > Cc: Pekka Enberg <[email protected]>
> > Cc: David Rientjes <[email protected]>
> > Cc: Joonsoo Kim <[email protected]>
> > Cc: Andrew Morton <[email protected]>
> > Cc: Vlastimil Babka <[email protected]>
> > Cc: Roman Gushchin <[email protected]>
> > Cc: Hyeonggon Yoo <[email protected]>
> > Cc: <[email protected]>
> >
> > diff --git a/include/linux/slab.h b/include/linux/slab.h
> > index 90877fcde70bd..487418c7ea8cd 100644
> > --- a/include/linux/slab.h
> > +++ b/include/linux/slab.h
> > @@ -76,6 +76,17 @@
> > * rcu_read_lock before reading the address, then rcu_read_unlock after
> > * taking the spinlock within the structure expected at that address.
> > *
> > + * Note that it is not possible to acquire a lock within a structure
> > + * allocated with SLAB_TYPESAFE_BY_RCU without first acquiring a reference
> > + * as described above. The reason is that SLAB_TYPESAFE_BY_RCU pages
> > + * are not zeroed before being given to the slab, which means that any
> > + * locks must be initialized after each and every kmem_struct_alloc().
> > + * Alternatively, make the ctor passed to kmem_cache_create() initialize
> > + * the locks at page-allocation time, as is done in __i915_request_ctor(),
> > + * sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers
> > + * to safely acquire those ctor-initialized locks under rcu_read_lock()
> > + * protection.
> > + *
> > * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
> > */
> > /* Defer freeing slabs to RCU */
>