Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'fscache-fixes-20220413' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs

Pull fscache fixes from David Howells:
"Here's a collection of fscache and cachefiles fixes and misc small
cleanups. The two main fixes are:

- Add a missing unmark of the inode in-use mark in an error path.

- Fix a KASAN slab-out-of-bounds error when setting the xattr on a
cachefiles volume due to the wrong length being given to memcpy().

In addition, there's the removal of an unused parameter, removal of an
unused Kconfig option, conditionalising a bit of procfs-related stuff
and some doc fixes"

* tag 'fscache-fixes-20220413' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
fscache: remove FSCACHE_OLD_API Kconfig option
fscache: Use wrapper fscache_set_cache_state() directly when relinquishing
fscache: Move fscache_cookies_seq_ops specific code under CONFIG_PROC_FS
fscache: Remove the cookie parameter from fscache_clear_page_bits()
docs: filesystems: caching/backend-api.rst: fix an object withdrawn API
docs: filesystems: caching/backend-api.rst: correct two relinquish APIs use
cachefiles: Fix KASAN slab-out-of-bounds in cachefiles_set_volume_xattr
cachefiles: unmark inode in use in error path

+52 -39
+4 -4
Documentation/filesystems/caching/backend-api.rst
··· 73 73 If successful, the cache backend can then start setting up the cache. In the 74 74 event that the initialisation fails, the cache backend should call:: 75 75 76 - void fscache_relinquish_cookie(struct fscache_cache *cache); 76 + void fscache_relinquish_cache(struct fscache_cache *cache); 77 77 78 78 to reset and discard the cookie. 79 79 ··· 110 110 111 111 on the cookie that each object belongs to. This schedules the specified cookie 112 112 for withdrawal. This gets offloaded to a workqueue. The cache backend can 113 - test for completion by calling:: 113 + wait for completion by calling:: 114 114 115 - bool fscache_are_objects_withdrawn(struct fscache_cookie *cache); 115 + void fscache_wait_for_objects(struct fscache_cache *cache); 116 116 117 117 Once all the cookies are withdrawn, a cache backend can withdraw all the 118 118 volumes, calling:: ··· 125 125 When the the cache is completely withdrawn, fscache should be notified by 126 126 calling:: 127 127 128 - void fscache_cache_relinquish(struct fscache_cache *cache); 128 + void fscache_relinquish_cache(struct fscache_cache *cache); 129 129 130 130 to clear fields in the cookie and discard the caller's ref on it. 131 131
+11 -12
Documentation/filesystems/caching/netfs-api.rst
··· 404 404 And if an error occurs before that point is reached, the marks can be removed 405 405 by calling:: 406 406 407 - void fscache_clear_page_bits(struct fscache_cookie *cookie, 408 - struct address_space *mapping, 407 + void fscache_clear_page_bits(struct address_space *mapping, 409 408 loff_t start, size_t len, 410 409 bool caching) 411 410 412 - In both of these functions, the cookie representing the cache object to be 413 - written to and a pointer to the mapping to which the source pages are attached 414 - are passed in; start and len indicate the size of the region that's going to be 415 - written (it doesn't have to align to page boundaries necessarily, but it does 416 - have to align to DIO boundaries on the backing filesystem). The caching 417 - parameter indicates if caching should be skipped, and if false, the functions 418 - do nothing. 411 + In these functions, a pointer to the mapping to which the source pages are 412 + attached is passed in and start and len indicate the size of the region that's 413 + going to be written (it doesn't have to align to page boundaries necessarily, 414 + but it does have to align to DIO boundaries on the backing filesystem). The 415 + caching parameter indicates if caching should be skipped, and if false, the 416 + functions do nothing. 419 417 420 - The write function takes some additional parameters: i_size indicates the size 421 - of the netfs file and term_func indicates an optional completion function, to 422 - which term_func_priv will be passed, along with the error or amount written. 418 + The write function takes some additional parameters: the cookie representing 419 + the cache object to be written to, i_size indicates the size of the netfs file 420 + and term_func indicates an optional completion function, to which 421 + term_func_priv will be passed, along with the error or amount written. 423 422 424 423 Note that the write function will always run asynchronously and will unmark all 425 424 the pages upon completion before calling term_func.
+1 -2
fs/afs/write.c
··· 616 616 _debug("write discard %x @%llx [%llx]", len, start, i_size); 617 617 618 618 /* The dirty region was entirely beyond the EOF. */ 619 - fscache_clear_page_bits(afs_vnode_cache(vnode), 620 - mapping, start, len, caching); 619 + fscache_clear_page_bits(mapping, start, len, caching); 621 620 afs_pages_written_back(vnode, start, len); 622 621 ret = 0; 623 622 }
+24 -9
fs/cachefiles/namei.c
··· 57 57 trace_cachefiles_mark_inactive(object, inode); 58 58 } 59 59 60 + static void cachefiles_do_unmark_inode_in_use(struct cachefiles_object *object, 61 + struct dentry *dentry) 62 + { 63 + struct inode *inode = d_backing_inode(dentry); 64 + 65 + inode_lock(inode); 66 + __cachefiles_unmark_inode_in_use(object, dentry); 67 + inode_unlock(inode); 68 + } 69 + 60 70 /* 61 71 * Unmark a backing inode and tell cachefilesd that there's something that can 62 72 * be culled. ··· 78 68 struct inode *inode = file_inode(file); 79 69 80 70 if (inode) { 81 - inode_lock(inode); 82 - __cachefiles_unmark_inode_in_use(object, file->f_path.dentry); 83 - inode_unlock(inode); 71 + cachefiles_do_unmark_inode_in_use(object, file->f_path.dentry); 84 72 85 73 if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) { 86 74 atomic_long_add(inode->i_blocks, &cache->b_released); ··· 492 484 object, d_backing_inode(path.dentry), ret, 493 485 cachefiles_trace_trunc_error); 494 486 file = ERR_PTR(ret); 495 - goto out_dput; 487 + goto out_unuse; 496 488 } 497 489 } 498 490 ··· 502 494 trace_cachefiles_vfs_error(object, d_backing_inode(path.dentry), 503 495 PTR_ERR(file), 504 496 cachefiles_trace_open_error); 505 - goto out_dput; 497 + goto out_unuse; 506 498 } 507 499 if (unlikely(!file->f_op->read_iter) || 508 500 unlikely(!file->f_op->write_iter)) { 509 501 fput(file); 510 502 pr_notice("Cache does not support read_iter and write_iter\n"); 511 503 file = ERR_PTR(-EINVAL); 504 + goto out_unuse; 512 505 } 513 506 507 + goto out_dput; 508 + 509 + out_unuse: 510 + cachefiles_do_unmark_inode_in_use(object, path.dentry); 514 511 out_dput: 515 512 dput(path.dentry); 516 513 out: ··· 603 590 check_failed: 604 591 fscache_cookie_lookup_negative(object->cookie); 605 592 cachefiles_unmark_inode_in_use(object, file); 606 - if (ret == -ESTALE) { 607 - fput(file); 608 - dput(dentry); 593 + fput(file); 594 + dput(dentry); 595 + if (ret == -ESTALE) 609 596 return cachefiles_create_file(object); 610 - } 597 + return false; 598 + 611 599 error_fput: 612 600 fput(file); 613 601 error: 602 + cachefiles_do_unmark_inode_in_use(object, dentry); 614 603 dput(dentry); 615 604 return false; 616 605 }
+1 -1
fs/cachefiles/xattr.c
··· 203 203 if (!buf) 204 204 return false; 205 205 buf->reserved = cpu_to_be32(0); 206 - memcpy(buf->data, p, len); 206 + memcpy(buf->data, p, volume->vcookie->coherency_len); 207 207 208 208 ret = cachefiles_inject_write_error(); 209 209 if (ret == 0)
-3
fs/fscache/Kconfig
··· 38 38 enabled by setting bits in /sys/modules/fscache/parameter/debug. 39 39 40 40 See Documentation/filesystems/caching/fscache.rst for more information. 41 - 42 - config FSCACHE_OLD_API 43 - bool
+1 -1
fs/fscache/cache.c
··· 214 214 215 215 cache->ops = NULL; 216 216 cache->cache_priv = NULL; 217 - smp_store_release(&cache->state, FSCACHE_CACHE_IS_NOT_PRESENT); 217 + fscache_set_cache_state(cache, FSCACHE_CACHE_IS_NOT_PRESENT); 218 218 fscache_put_cache(cache, where); 219 219 } 220 220 EXPORT_SYMBOL(fscache_relinquish_cache);
+3 -1
fs/fscache/cookie.c
··· 30 30 DEFINE_TIMER(fscache_cookie_lru_timer, fscache_cookie_lru_timed_out); 31 31 static DECLARE_WORK(fscache_cookie_lru_work, fscache_cookie_lru_worker); 32 32 static const char fscache_cookie_states[FSCACHE_COOKIE_STATE__NR] = "-LCAIFUWRD"; 33 - unsigned int fscache_lru_cookie_timeout = 10 * HZ; 33 + static unsigned int fscache_lru_cookie_timeout = 10 * HZ; 34 34 35 35 void fscache_print_cookie(struct fscache_cookie *cookie, char prefix) 36 36 { ··· 1069 1069 } 1070 1070 EXPORT_SYMBOL(__fscache_invalidate); 1071 1071 1072 + #ifdef CONFIG_PROC_FS 1072 1073 /* 1073 1074 * Generate a list of extant cookies in /proc/fs/fscache/cookies 1074 1075 */ ··· 1146 1145 .stop = fscache_cookies_seq_stop, 1147 1146 .show = fscache_cookies_seq_show, 1148 1147 }; 1148 + #endif
+4
fs/fscache/internal.h
··· 56 56 * cookie.c 57 57 */ 58 58 extern struct kmem_cache *fscache_cookie_jar; 59 + #ifdef CONFIG_PROC_FS 59 60 extern const struct seq_operations fscache_cookies_seq_ops; 61 + #endif 60 62 extern struct timer_list fscache_cookie_lru_timer; 61 63 62 64 extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix); ··· 139 137 /* 140 138 * volume.c 141 139 */ 140 + #ifdef CONFIG_PROC_FS 142 141 extern const struct seq_operations fscache_volumes_seq_ops; 142 + #endif 143 143 144 144 struct fscache_volume *fscache_get_volume(struct fscache_volume *volume, 145 145 enum fscache_volume_trace where);
+2 -3
fs/fscache/io.c
··· 235 235 { 236 236 struct fscache_write_request *wreq = priv; 237 237 238 - fscache_clear_page_bits(fscache_cres_cookie(&wreq->cache_resources), 239 - wreq->mapping, wreq->start, wreq->len, 238 + fscache_clear_page_bits(wreq->mapping, wreq->start, wreq->len, 240 239 wreq->set_bits); 241 240 242 241 if (wreq->term_func) ··· 295 296 abandon_free: 296 297 kfree(wreq); 297 298 abandon: 298 - fscache_clear_page_bits(cookie, mapping, start, len, cond); 299 + fscache_clear_page_bits(mapping, start, len, cond); 299 300 if (term_func) 300 301 term_func(term_func_priv, ret, false); 301 302 }
+1 -3
include/linux/fscache.h
··· 573 573 574 574 /** 575 575 * fscache_clear_page_bits - Clear the PG_fscache bits from a set of pages 576 - * @cookie: The cookie representing the cache object 577 576 * @mapping: The netfs inode to use as the source 578 577 * @start: The start position in @mapping 579 578 * @len: The amount of data to unlock ··· 581 582 * Clear the PG_fscache flag from a sequence of pages and wake up anyone who's 582 583 * waiting. 583 584 */ 584 - static inline void fscache_clear_page_bits(struct fscache_cookie *cookie, 585 - struct address_space *mapping, 585 + static inline void fscache_clear_page_bits(struct address_space *mapping, 586 586 loff_t start, size_t len, 587 587 bool caching) 588 588 {