2022-12-26 10:58:57

by Hou Tao

[permalink] [raw]
Subject: [PATCH v2 0/2] Fixes for fscache volume operations

From: Hou Tao <[email protected]>

Hi,

The patchset includes two fixes for fscache volume operations: patch 1
fixes the hang problem during volume acquisition when the volume
acquisition process waits for the freeing of relinquished volume, patch
2 adds the missing memory barrier in fscache_create_volume_work() and it
is spotted through code review when checking whether or not these is
missing smp_mb() before invoking wake_up_bit().

Comments are always welcome.

Chang Log:
v2:
* rebased on v6.1-rc1
* Patch 1: use wait_on_bit() instead (Suggested by David)
* Patch 2: add the missing smp_mb() in fscache_create_volume_work()

v1: https://listman.redhat.com/archives/linux-cachefs/2022-December/007384.html

Hou Tao (2):
fscache: Use wait_on_bit() to wait for the freeing of relinquished
volume
fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()

fs/fscache/volume.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

--
2.29.2


2022-12-26 11:18:20

by Hou Tao

[permalink] [raw]
Subject: [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()

From: Hou Tao <[email protected]>

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 <[email protected]>
---
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

2023-01-11 04:30:22

by Hou Tao

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] Fixes for fscache volume operations

ping ?

On 12/26/2022 6:33 PM, Hou Tao wrote:
> From: Hou Tao <[email protected]>
>
> Hi,
>
> The patchset includes two fixes for fscache volume operations: patch 1
> fixes the hang problem during volume acquisition when the volume
> acquisition process waits for the freeing of relinquished volume, patch
> 2 adds the missing memory barrier in fscache_create_volume_work() and it
> is spotted through code review when checking whether or not these is
> missing smp_mb() before invoking wake_up_bit().
>
> Comments are always welcome.
>
> Chang Log:
> v2:
> * rebased on v6.1-rc1
> * Patch 1: use wait_on_bit() instead (Suggested by David)
> * Patch 2: add the missing smp_mb() in fscache_create_volume_work()
>
> v1: https://listman.redhat.com/archives/linux-cachefs/2022-December/007384.html
>
> Hou Tao (2):
> fscache: Use wait_on_bit() to wait for the freeing of relinquished
> volume
> fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()
>
> fs/fscache/volume.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>

2023-01-11 16:34:45

by David Howells

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()

David Howells <[email protected]> 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

2023-01-11 17:09:23

by David Howells

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()

Hou Tao <[email protected]> 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

2023-01-12 01:31:43

by Hou Tao

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()

Hi,

On 1/12/2023 12:09 AM, David Howells wrote:
> Hou Tao <[email protected]> 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
>

2023-01-12 05:01:22

by Jingbo Xu

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()



On 12/26/22 6:33 PM, Hou Tao wrote:
> From: Hou Tao <[email protected]>
>
> 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 <[email protected]>
> ---
> 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

2023-01-12 06:49:38

by Hou Tao

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit()

Hi,

On 1/12/2023 12:34 PM, Jingbo Xu wrote:
>
> On 12/26/22 6:33 PM, Hou Tao wrote:
>> From: Hou Tao <[email protected]>
>>
>> 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 <[email protected]>
>> ---
>> 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.
>