Skip to content

Commit ec9c57a

Browse files
committed
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
2 parents a199448 + 61132ce commit ec9c57a

11 files changed

Lines changed: 53 additions & 40 deletions

File tree

Documentation/filesystems/caching/backend-api.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ busy.
7373
If successful, the cache backend can then start setting up the cache. In the
7474
event that the initialisation fails, the cache backend should call::
7575

76-
void fscache_relinquish_cookie(struct fscache_cache *cache);
76+
void fscache_relinquish_cache(struct fscache_cache *cache);
7777

7878
to reset and discard the cookie.
7979

@@ -110,9 +110,9 @@ to withdraw them, calling::
110110

111111
on the cookie that each object belongs to. This schedules the specified cookie
112112
for withdrawal. This gets offloaded to a workqueue. The cache backend can
113-
test for completion by calling::
113+
wait for completion by calling::
114114

115-
bool fscache_are_objects_withdrawn(struct fscache_cookie *cache);
115+
void fscache_wait_for_objects(struct fscache_cache *cache);
116116

117117
Once all the cookies are withdrawn, a cache backend can withdraw all the
118118
volumes, calling::
@@ -125,7 +125,7 @@ outstanding accesses on the volume to complete before returning.
125125
When the the cache is completely withdrawn, fscache should be notified by
126126
calling::
127127

128-
void fscache_cache_relinquish(struct fscache_cache *cache);
128+
void fscache_relinquish_cache(struct fscache_cache *cache);
129129

130130
to clear fields in the cookie and discard the caller's ref on it.
131131

Documentation/filesystems/caching/netfs-api.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,21 @@ schedule a write of that region::
404404
And if an error occurs before that point is reached, the marks can be removed
405405
by calling::
406406

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,
409408
loff_t start, size_t len,
410409
bool caching)
411410

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.
419-
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.
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.
417+
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.
423422

424423
Note that the write function will always run asynchronously and will unmark all
425424
the pages upon completion before calling term_func.

fs/afs/write.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ static ssize_t afs_write_back_from_locked_folio(struct address_space *mapping,
616616
_debug("write discard %x @%llx [%llx]", len, start, i_size);
617617

618618
/* 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);
621620
afs_pages_written_back(vnode, start, len);
622621
ret = 0;
623622
}

fs/cachefiles/namei.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ static void __cachefiles_unmark_inode_in_use(struct cachefiles_object *object,
5757
trace_cachefiles_mark_inactive(object, inode);
5858
}
5959

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+
6070
/*
6171
* Unmark a backing inode and tell cachefilesd that there's something that can
6272
* be culled.
@@ -68,9 +78,7 @@ void cachefiles_unmark_inode_in_use(struct cachefiles_object *object,
6878
struct inode *inode = file_inode(file);
6979

7080
if (inode) {
71-
inode_lock(inode);
72-
__cachefiles_unmark_inode_in_use(object, file->f_path.dentry);
73-
inode_unlock(inode);
81+
cachefiles_do_unmark_inode_in_use(object, file->f_path.dentry);
7482

7583
if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) {
7684
atomic_long_add(inode->i_blocks, &cache->b_released);
@@ -484,7 +492,7 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
484492
object, d_backing_inode(path.dentry), ret,
485493
cachefiles_trace_trunc_error);
486494
file = ERR_PTR(ret);
487-
goto out_dput;
495+
goto out_unuse;
488496
}
489497
}
490498

@@ -494,15 +502,20 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
494502
trace_cachefiles_vfs_error(object, d_backing_inode(path.dentry),
495503
PTR_ERR(file),
496504
cachefiles_trace_open_error);
497-
goto out_dput;
505+
goto out_unuse;
498506
}
499507
if (unlikely(!file->f_op->read_iter) ||
500508
unlikely(!file->f_op->write_iter)) {
501509
fput(file);
502510
pr_notice("Cache does not support read_iter and write_iter\n");
503511
file = ERR_PTR(-EINVAL);
512+
goto out_unuse;
504513
}
505514

515+
goto out_dput;
516+
517+
out_unuse:
518+
cachefiles_do_unmark_inode_in_use(object, path.dentry);
506519
out_dput:
507520
dput(path.dentry);
508521
out:
@@ -590,14 +603,16 @@ static bool cachefiles_open_file(struct cachefiles_object *object,
590603
check_failed:
591604
fscache_cookie_lookup_negative(object->cookie);
592605
cachefiles_unmark_inode_in_use(object, file);
593-
if (ret == -ESTALE) {
594-
fput(file);
595-
dput(dentry);
606+
fput(file);
607+
dput(dentry);
608+
if (ret == -ESTALE)
596609
return cachefiles_create_file(object);
597-
}
610+
return false;
611+
598612
error_fput:
599613
fput(file);
600614
error:
615+
cachefiles_do_unmark_inode_in_use(object, dentry);
601616
dput(dentry);
602617
return false;
603618
}

fs/cachefiles/xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
203203
if (!buf)
204204
return false;
205205
buf->reserved = cpu_to_be32(0);
206-
memcpy(buf->data, p, len);
206+
memcpy(buf->data, p, volume->vcookie->coherency_len);
207207

208208
ret = cachefiles_inject_write_error();
209209
if (ret == 0)

fs/fscache/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,3 @@ config FSCACHE_DEBUG
3838
enabled by setting bits in /sys/modules/fscache/parameter/debug.
3939

4040
See Documentation/filesystems/caching/fscache.rst for more information.
41-
42-
config FSCACHE_OLD_API
43-
bool

fs/fscache/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void fscache_relinquish_cache(struct fscache_cache *cache)
214214

215215
cache->ops = NULL;
216216
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);
218218
fscache_put_cache(cache, where);
219219
}
220220
EXPORT_SYMBOL(fscache_relinquish_cache);

fs/fscache/cookie.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static DEFINE_SPINLOCK(fscache_cookie_lru_lock);
3030
DEFINE_TIMER(fscache_cookie_lru_timer, fscache_cookie_lru_timed_out);
3131
static DECLARE_WORK(fscache_cookie_lru_work, fscache_cookie_lru_worker);
3232
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;
3434

3535
void fscache_print_cookie(struct fscache_cookie *cookie, char prefix)
3636
{
@@ -1069,6 +1069,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie,
10691069
}
10701070
EXPORT_SYMBOL(__fscache_invalidate);
10711071

1072+
#ifdef CONFIG_PROC_FS
10721073
/*
10731074
* Generate a list of extant cookies in /proc/fs/fscache/cookies
10741075
*/
@@ -1145,3 +1146,4 @@ const struct seq_operations fscache_cookies_seq_ops = {
11451146
.stop = fscache_cookies_seq_stop,
11461147
.show = fscache_cookies_seq_show,
11471148
};
1149+
#endif

fs/fscache/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ static inline bool fscache_set_cache_state_maybe(struct fscache_cache *cache,
5656
* cookie.c
5757
*/
5858
extern struct kmem_cache *fscache_cookie_jar;
59+
#ifdef CONFIG_PROC_FS
5960
extern const struct seq_operations fscache_cookies_seq_ops;
61+
#endif
6062
extern struct timer_list fscache_cookie_lru_timer;
6163

6264
extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix);
@@ -137,7 +139,9 @@ int fscache_stats_show(struct seq_file *m, void *v);
137139
/*
138140
* volume.c
139141
*/
142+
#ifdef CONFIG_PROC_FS
140143
extern const struct seq_operations fscache_volumes_seq_ops;
144+
#endif
141145

142146
struct fscache_volume *fscache_get_volume(struct fscache_volume *volume,
143147
enum fscache_volume_trace where);

fs/fscache/io.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ static void fscache_wreq_done(void *priv, ssize_t transferred_or_error,
235235
{
236236
struct fscache_write_request *wreq = priv;
237237

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,
240239
wreq->set_bits);
241240

242241
if (wreq->term_func)
@@ -296,7 +295,7 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie,
296295
abandon_free:
297296
kfree(wreq);
298297
abandon:
299-
fscache_clear_page_bits(cookie, mapping, start, len, cond);
298+
fscache_clear_page_bits(mapping, start, len, cond);
300299
if (term_func)
301300
term_func(term_func_priv, ret, false);
302301
}

0 commit comments

Comments
 (0)