This is a note to let you know that I've just added the patch titled mbcache: Avoid nesting of cache->c_list_lock under bit locks to the 5.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mbcache-avoid-nesting-of-cache-c_list_lock-under-bit-locks.patch and it can be found in the queue-5.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 5fc4cbd9fde5d4630494fd6ffc884148fb618087 Mon Sep 17 00:00:00 2001 From: Jan Kara <jack@xxxxxxx> Date: Thu, 8 Sep 2022 11:10:32 +0200 Subject: mbcache: Avoid nesting of cache->c_list_lock under bit locks From: Jan Kara <jack@xxxxxxx> commit 5fc4cbd9fde5d4630494fd6ffc884148fb618087 upstream. Commit 307af6c87937 ("mbcache: automatically delete entries from cache on freeing") started nesting cache->c_list_lock under the bit locks protecting hash buckets of the mbcache hash table in mb_cache_entry_create(). This causes problems for real-time kernels because there spinlocks are sleeping locks while bitlocks stay atomic. Luckily the nesting is easy to avoid by holding entry reference until the entry is added to the LRU list. This makes sure we cannot race with entry deletion. Cc: stable@xxxxxxxxxx Fixes: 307af6c87937 ("mbcache: automatically delete entries from cache on freeing") Reported-by: Mike Galbraith <efault@xxxxxx> Signed-off-by: Jan Kara <jack@xxxxxxx> Link: https://lore.kernel.org/r/20220908091032.10513-1-jack@xxxxxxx Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/mbcache.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) --- a/fs/mbcache.c +++ b/fs/mbcache.c @@ -90,8 +90,14 @@ int mb_cache_entry_create(struct mb_cach return -ENOMEM; INIT_LIST_HEAD(&entry->e_list); - /* Initial hash reference */ - atomic_set(&entry->e_refcnt, 1); + /* + * We create entry with two references. One reference is kept by the + * hash table, the other reference is used to protect us from + * mb_cache_entry_delete_or_get() until the entry is fully setup. This + * avoids nesting of cache->c_list_lock into hash table bit locks which + * is problematic for RT. + */ + atomic_set(&entry->e_refcnt, 2); entry->e_key = key; entry->e_value = value; entry->e_flags = 0; @@ -107,15 +113,12 @@ int mb_cache_entry_create(struct mb_cach } } hlist_bl_add_head(&entry->e_hash_list, head); - /* - * Add entry to LRU list before it can be found by - * mb_cache_entry_delete() to avoid races - */ + hlist_bl_unlock(head); spin_lock(&cache->c_list_lock); list_add_tail(&entry->e_list, &cache->c_list); cache->c_entry_count++; spin_unlock(&cache->c_list_lock); - hlist_bl_unlock(head); + mb_cache_entry_put(cache, entry); return 0; } Patches currently in stable-queue which might be from jack@xxxxxxx are queue-5.4/udf-avoid-double-brelse-in-udf_rename.patch queue-5.4/ext4-fix-deadlock-due-to-mbcache-entry-corruption.patch queue-5.4/mbcache-automatically-delete-entries-from-cache-on-f.patch queue-5.4/mbcache-avoid-nesting-of-cache-c_list_lock-under-bit-locks.patch queue-5.4/ext4-avoid-unaccounted-block-allocation-when-expanding-inode.patch queue-5.4/ext4-unindent-codeblock-in-ext4_xattr_block_set.patch queue-5.4/ext4-correct-inconsistent-error-msg-in-nojournal-mod.patch queue-5.4/udf-do-not-bother-looking-for-prealloc-extents-if-i_lenextents-matches-i_size.patch queue-5.4/ext4-fix-bug_on-in-__es_tree_search-caused-by-bad-boot-loader-inode.patch queue-5.4/ext4-fix-race-when-reusing-xattr-blocks.patch queue-5.4/ext4-goto-right-label-failed_mount3a.patch queue-5.4/ext4-fix-inode-leak-in-ext4_xattr_inode_create-on-an-error-path.patch queue-5.4/ext4-add-helper-to-check-quota-inums.patch queue-5.4/udf-fix-extending-file-within-last-block.patch queue-5.4/ext4-fix-corruption-when-online-resizing-a-1k-bigalloc-fs.patch queue-5.4/ext4-allocate-extended-attribute-value-in-vmalloc-area.patch queue-5.4/ext4-remove-ea-inode-entry-from-mbcache-on-inode-evi.patch queue-5.4/ext4-init-quota-for-old.inode-in-ext4_rename.patch queue-5.4/udf-fix-extension-of-the-last-extent-in-the-file.patch queue-5.4/mbcache-add-functions-to-delete-entry-if-unused.patch queue-5.4/ext4-add-ext4_iget_bad-flag-to-prevent-unexpected-bad-inode.patch queue-5.4/mbcache-don-t-reclaim-used-entries.patch queue-5.4/udf-fix-preallocation-discarding-at-indirect-extent-boundary.patch queue-5.4/ext4-avoid-bug_on-when-creating-xattrs.patch queue-5.4/hfs-hfsplus-use-warn_on-for-sanity-check.patch queue-5.4/udf-discard-preallocation-before-extending-file-with-a-hole.patch queue-5.4/ext4-initialize-quota-before-expanding-inode-in-setproject-ioctl.patch