Skip to content
Snippets Groups Projects
  1. Dec 05, 2024
    • Zizhi Wo's avatar
      netfs/fscache: Add a memory barrier for FSCACHE_VOLUME_CREATING · 8cc1df31
      Zizhi Wo authored
      
      [ Upstream commit 22f9400a6f3560629478e0a64247b8fcc811a24d ]
      
      In fscache_create_volume(), there is a missing memory barrier between the
      bit-clearing operation and the wake-up operation. This may cause a
      situation where, after a wake-up, the bit-clearing operation hasn't been
      detected yet, leading to an indefinite wait. The triggering process is as
      follows:
      
        [cookie1]                [cookie2]                  [volume_work]
      fscache_perform_lookup
        fscache_create_volume
                              fscache_perform_lookup
                                fscache_create_volume
      			                        fscache_create_volume_work
                                                        cachefiles_acquire_volume
                                                        clear_and_wake_up_bit
          test_and_set_bit
                                  test_and_set_bit
                                    goto maybe_wait
            goto no_wait
      
      In the above process, cookie1 and cookie2 has the same volume. When cookie1
      enters the -no_wait- process, it will clear the bit and wake up the waiting
      process. If a barrier is missing, it may cause cookie2 to remain in the
      -wait- process indefinitely.
      
      In commit 3288666c ("fscache: Use clear_and_wake_up_bit() in
      fscache_create_volume_work()"), barriers were added to similar operations
      in fscache_create_volume_work(), but fscache_create_volume() was missed.
      
      By combining the clear and wake operations into clear_and_wake_up_bit() to
      fix this issue.
      
      Fixes: bfa22da3 ("fscache: Provide and use cache methods to lookup/create/free a volume")
      Signed-off-by: default avatarZizhi Wo <wozizhi@huawei.com>
      Link: https://lore.kernel.org/r/20241107110649.3980193-6-wozizhi@huawei.com
      
      
      Acked-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8cc1df31
  2. Jul 24, 2024
  3. Jul 03, 2024
  4. Jun 12, 2024
  5. Dec 24, 2023
    • David Howells's avatar
      netfs, fscache: Move fs/fscache/* into fs/netfs/ · 47757ea8
      David Howells authored
      
      There's a problem with dependencies between netfslib and fscache as each
      wants to access some functions of the other.  Deal with this by moving
      fs/fscache/* into fs/netfs/ and renaming those files to begin with
      "fscache-".
      
      For the moment, the moved files are changed as little as possible and an
      fscache module is still built.  A subsequent patch will integrate them.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      cc: Christian Brauner <christian@brauner.io>
      cc: linux-fsdevel@vger.kernel.org
      cc: linux-cachefs@redhat.com
      47757ea8
  6. Jan 30, 2023
    • Hou Tao's avatar
      fscache: Use clear_and_wake_up_bit() in fscache_create_volume_work() · 3288666c
      Hou Tao authored
      
      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().
      
      Fixing it by using clear_and_wake_up_bit() to add the missing memory
      barrier.
      
      Reviewed-by: default avatarJingbo Xu <jefflexu@linux.alibaba.com>
      Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Link: https://lore.kernel.org/r/20230113115211.2895845-3-houtao@huaweicloud.com/ # v3
      3288666c
    • Hou Tao's avatar
      fscache: Use wait_on_bit() to wait for the freeing of relinquished volume · 8226e37d
      Hou Tao authored
      
      The freeing of relinquished volume will wake up the pending volume
      acquisition by using wake_up_bit(), however it is mismatched with
      wait_var_event() used in fscache_wait_on_volume_collision() and it will
      never wake up the waiter in the wait-queue because these two functions
      operate on different wait-queues.
      
      According to the implementation in fscache_wait_on_volume_collision(),
      if the wake-up of pending acquisition is delayed longer than 20 seconds
      (e.g., due to the delay of on-demand fd closing), the first
      wait_var_event_timeout() will timeout and the following wait_var_event()
      will hang forever as shown below:
      
       FS-Cache: Potential volume collision new=00000024 old=00000022
       ......
       INFO: task mount:1148 blocked for more than 122 seconds.
             Not tainted 6.1.0-rc6+ #1
       task:mount           state:D stack:0     pid:1148  ppid:1
       Call Trace:
        <TASK>
        __schedule+0x2f6/0xb80
        schedule+0x67/0xe0
        fscache_wait_on_volume_collision.cold+0x80/0x82
        __fscache_acquire_volume+0x40d/0x4e0
        erofs_fscache_register_volume+0x51/0xe0 [erofs]
        erofs_fscache_register_fs+0x19c/0x240 [erofs]
        erofs_fc_fill_super+0x746/0xaf0 [erofs]
        vfs_get_super+0x7d/0x100
        get_tree_nodev+0x16/0x20
        erofs_fc_get_tree+0x20/0x30 [erofs]
        vfs_get_tree+0x24/0xb0
        path_mount+0x2fa/0xa90
        do_mount+0x7c/0xa0
        __x64_sys_mount+0x8b/0xe0
        do_syscall_64+0x30/0x60
        entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      Considering that wake_up_bit() is more selective, so fix it by using
      wait_on_bit() instead of wait_var_event() to wait for the freeing of
      relinquished volume. In addition because waitqueue_active() is used in
      wake_up_bit() and clear_bit() doesn't imply any memory barrier, use
      clear_and_wake_up_bit() to add the missing memory barrier between
      cursor->flags and waitqueue_active().
      
      Fixes: 62ab6335 ("fscache: Implement volume registration")
      Reviewed-by: default avatarJingbo Xu <jefflexu@linux.alibaba.com>
      Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Link: https://lore.kernel.org/r/20230113115211.2895845-2-houtao@huaweicloud.com/ # v3
      8226e37d
  7. Nov 23, 2022
  8. Jul 05, 2022
  9. Jan 21, 2022
  10. Jan 07, 2022
Loading