From: Hou Tao <houtao1@huawei.com>
fscache_create_volume_work() uses wake_up_bit() to wake up the processes
which are waiting for the completion of volume creation. According to
comments in wake_up_bit() and waitqueue_active(), an extra smp_mb() is
needed to guarantee the memory order between FSCACHE_VOLUME_CREATING
flag and waitqueue_active() before invoking wake_up_bit().
Considering clear_bit_unlock() before wake_up_bit() is an atomic
operation, use smp_mb__after_atomic() instead of smp_mb() to provide
such guarantee.
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
fs/fscache/volume.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/fscache/volume.c b/fs/fscache/volume.c
index fc3dd3bc851d..734d17f404e7 100644
--- a/fs/fscache/volume.c
+++ b/fs/fscache/volume.c
@@ -281,6 +281,11 @@ static void fscache_create_volume_work(struct work_struct *work)
fscache_access_acquire_volume_end);
clear_bit_unlock(FSCACHE_VOLUME_CREATING, &volume->flags);
+ /*
+ * Paired with barrier in wait_on_bit(). Check wake_up_bit() and
+ * waitqueue_active() for details.
+ */
+ smp_mb__after_atomic();
wake_up_bit(&volume->flags, FSCACHE_VOLUME_CREATING);
fscache_put_volume(volume, fscache_volume_put_create_work);
}
--
2.29.2
On 12/26/22 6:33 PM, Hou Tao wrote: > From: Hou Tao <houtao1@huawei.com> > > fscache_create_volume_work() uses wake_up_bit() to wake up the processes > which are waiting for the completion of volume creation. According to > comments in wake_up_bit() and waitqueue_active(), an extra smp_mb() is > needed to guarantee the memory order between FSCACHE_VOLUME_CREATING > flag and waitqueue_active() before invoking wake_up_bit(). > > Considering clear_bit_unlock() before wake_up_bit() is an atomic > operation, use smp_mb__after_atomic() instead of smp_mb() to provide > such guarantee. > > Signed-off-by: Hou Tao <houtao1@huawei.com> > --- > fs/fscache/volume.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/fs/fscache/volume.c b/fs/fscache/volume.c > index fc3dd3bc851d..734d17f404e7 100644 > --- a/fs/fscache/volume.c > +++ b/fs/fscache/volume.c > @@ -281,6 +281,11 @@ static void fscache_create_volume_work(struct work_struct *work) > fscache_access_acquire_volume_end); > > clear_bit_unlock(FSCACHE_VOLUME_CREATING, &volume->flags); > + /* > + * Paired with barrier in wait_on_bit(). Check wake_up_bit() and > + * waitqueue_active() for details. > + */ > + smp_mb__after_atomic(); > wake_up_bit(&volume->flags, FSCACHE_VOLUME_CREATING); > fscache_put_volume(volume, fscache_volume_put_create_work); > } LGTM. Actually I'm thinking if clear_and_wake_up_bit() could be used here. Ditto for patch 1. -- Thanks, Jingbo
Hi, On 1/12/2023 12:34 PM, Jingbo Xu wrote: > > On 12/26/22 6:33 PM, Hou Tao wrote: >> From: Hou Tao <houtao1@huawei.com> >> >> fscache_create_volume_work() uses wake_up_bit() to wake up the processes >> which are waiting for the completion of volume creation. According to >> comments in wake_up_bit() and waitqueue_active(), an extra smp_mb() is >> needed to guarantee the memory order between FSCACHE_VOLUME_CREATING >> flag and waitqueue_active() before invoking wake_up_bit(). >> >> Considering clear_bit_unlock() before wake_up_bit() is an atomic >> operation, use smp_mb__after_atomic() instead of smp_mb() to provide >> such guarantee. >> >> Signed-off-by: Hou Tao <houtao1@huawei.com> >> --- >> fs/fscache/volume.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/fs/fscache/volume.c b/fs/fscache/volume.c >> index fc3dd3bc851d..734d17f404e7 100644 >> --- a/fs/fscache/volume.c >> +++ b/fs/fscache/volume.c >> @@ -281,6 +281,11 @@ static void fscache_create_volume_work(struct work_struct *work) >> fscache_access_acquire_volume_end); >> >> clear_bit_unlock(FSCACHE_VOLUME_CREATING, &volume->flags); >> + /* >> + * Paired with barrier in wait_on_bit(). Check wake_up_bit() and >> + * waitqueue_active() for details. >> + */ >> + smp_mb__after_atomic(); >> wake_up_bit(&volume->flags, FSCACHE_VOLUME_CREATING); >> fscache_put_volume(volume, fscache_volume_put_create_work); >> } > LGTM. > > Actually I'm thinking if clear_and_wake_up_bit() could be used here. > Ditto for patch 1. Good idea. Just find the presence of clear_and_wake_up_bit(). Will do in v3 for both patch 1 & patch 2. >
Hou Tao <houtao@huaweicloud.com> wrote: > fscache_create_volume_work() uses wake_up_bit() to wake up the processes > which are waiting for the completion of volume creation. According to > comments in wake_up_bit() and waitqueue_active(), an extra smp_mb() is > needed to guarantee the memory order between FSCACHE_VOLUME_CREATING > flag and waitqueue_active() before invoking wake_up_bit(). What two values are you ordering? If we're using this to create a critical section, then yes, we would need a barrier to order the changes inside the critical section before changing the memory location that forms the lock - but this is not a critical section. David
Hi, On 1/12/2023 12:09 AM, David Howells wrote: > Hou Tao <houtao@huaweicloud.com> wrote: > >> fscache_create_volume_work() uses wake_up_bit() to wake up the processes >> which are waiting for the completion of volume creation. According to >> comments in wake_up_bit() and waitqueue_active(), an extra smp_mb() is >> needed to guarantee the memory order between FSCACHE_VOLUME_CREATING >> flag and waitqueue_active() before invoking wake_up_bit(). > What two values are you ordering? > > If we're using this to create a critical section, then yes, we would need a > barrier to order the changes inside the critical section before changing the > memory location that forms the lock - but this is not a critical section. It is similar with patch #1. The smp_mb() is used for order between volume->flags and wq->head. > David >
David Howells <dhowells@redhat.com> wrote: > What two values are you ordering? > > If we're using this to create a critical section, then yes, we would need a > barrier to order the changes inside the critical section before changing the > memory location that forms the lock - but this is not a critical section. Actually, that said, the ordering is probably between the bit being cleared and the task state. David
© 2016 - 2025 Red Hat, Inc.