History

Merge tag 'vfs-6.13.netfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull netfs updates from Christian Brauner: "Various fixes for the netfs library and related infrastructure: cachefiles: - Fix a dentry leak in cachefiles_open_file() - Fix incorrect length return value in cachefiles_ondemand_fd_write_iter() - Fix missing pos updates in cachefiles_ondemand_fd_write_iter() - Clean up in cachefiles_commit_tmpfile() - Fix NULL pointer dereference in object->file - Add a memory barrier for FSCACHE_VOLUME_CREATING netfs: - Remove call to folio_index() - Fix a few minor bugs in netfs_page_mkwrite() - Remove unnecessary references to pages" * tag 'vfs-6.13.netfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: netfs/fscache: Add a memory barrier for FSCACHE_VOLUME_CREATING cachefiles: Fix NULL pointer dereference in object->file cachefiles: Clean up in cachefiles_commit_tmpfile() cachefiles: Fix missing pos updates in cachefiles_ondemand_fd_write_iter() cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter() netfs: Remove unnecessary references to pages netfs: Fix a few minor bugs in netfs_page_mkwrite() netfs: Remove call to folio_index()

Linus Torvalds committed 1 year ago

Commit 8dcf44f2 parents 56be9aa a4b29237 files · +65 −46Browse files

Unified · Split

7 files
  1. fs/cachefiles/interface.c +10 −4
  2. fs/cachefiles/namei.c +0 −5
  3. fs/cachefiles/ondemand.c +29 −9
  4. fs/netfs/buffered_read.c +4 −4
  5. fs/netfs/buffered_write.c +20 −21
  6. fs/netfs/fscache_volume.c +1 −2
  7. include/trace/events/netfs.h +1 −1
fs/cachefiles/interface.c+10−4
@@ -327,6 +327,8 @@ static void cachefiles_commit_object(struct cachefiles_object *object, · 326 unmodified lines
327static void cachefiles_clean_up_object(struct cachefiles_object *object,327static void cachefiles_clean_up_object(struct cachefiles_object *object,
328 struct cachefiles_cache *cache)328 struct cachefiles_cache *cache)
329{329{
330 struct file *file;
331
330 if (test_bit(FSCACHE_COOKIE_RETIRED, &object->cookie->flags)) {332 if (test_bit(FSCACHE_COOKIE_RETIRED, &object->cookie->flags)) {
331 if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) {333 if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) {
332 cachefiles_see_object(object, cachefiles_obj_see_clean_delete);334 cachefiles_see_object(object, cachefiles_obj_see_clean_delete);
@@ -342,10 +344,14 @@ static void cachefiles_clean_up_object(struct cachefiles_object *object, · 9 unmodified lines
342 }344 }
343 345
344 cachefiles_unmark_inode_in_use(object, object->file);346 cachefiles_unmark_inode_in_use(object, object->file);
345 if (object->file) {347
346 fput(object->file);348 spin_lock(&object->lock);
347 object->file = NULL;349 file = object->file;
348 }350 object->file = NULL;
351 spin_unlock(&object->lock);
352
353 if (file)
354 fput(file);
349}355}
350 356
351/*357/*
fs/cachefiles/namei.c+0−5
@@ -691,11 +691,6 @@ bool cachefiles_commit_tmpfile(struct cachefiles_cache *cache, · 690 unmodified lines
691 }691 }
692 692
693 if (!d_is_negative(dentry)) {693 if (!d_is_negative(dentry)) {
694 if (d_backing_inode(dentry) == file_inode(object->file)) {
695 success = true;
696 goto out_dput;
697 }
698
699 ret = cachefiles_unlink(volume->cache, object, fan, dentry,694 ret = cachefiles_unlink(volume->cache, object, fan, dentry,
700 FSCACHE_OBJECT_IS_STALE);695 FSCACHE_OBJECT_IS_STALE);
701 if (ret < 0)696 if (ret < 0)
fs/cachefiles/ondemand.c+29−9
@@ -60,26 +60,36 @@ static ssize_t cachefiles_ondemand_fd_write_iter(struct kiocb *kiocb, · 59 unmodified lines
60{60{
61 struct cachefiles_object *object = kiocb->ki_filp->private_data;61 struct cachefiles_object *object = kiocb->ki_filp->private_data;
62 struct cachefiles_cache *cache = object->volume->cache;62 struct cachefiles_cache *cache = object->volume->cache;
63 struct file *file = object->file;63 struct file *file;
64 size_t len = iter->count;64 size_t len = iter->count, aligned_len = len;
65 loff_t pos = kiocb->ki_pos;65 loff_t pos = kiocb->ki_pos;
66 const struct cred *saved_cred;66 const struct cred *saved_cred;
67 int ret;67 int ret;
68 68
69 if (!file)69 spin_lock(&object->lock);
70 file = object->file;
71 if (!file) {
72 spin_unlock(&object->lock);
70 return -ENOBUFS;73 return -ENOBUFS;
74 }
75 get_file(file);
76 spin_unlock(&object->lock);
71 77
72 cachefiles_begin_secure(cache, &saved_cred);78 cachefiles_begin_secure(cache, &saved_cred);
73 ret = __cachefiles_prepare_write(object, file, &pos, &len, len, true);79 ret = __cachefiles_prepare_write(object, file, &pos, &aligned_len, len, true);
74 cachefiles_end_secure(cache, saved_cred);80 cachefiles_end_secure(cache, saved_cred);
75 if (ret < 0)81 if (ret < 0)
76 return ret;82 goto out;
77 83
78 trace_cachefiles_ondemand_fd_write(object, file_inode(file), pos, len);84 trace_cachefiles_ondemand_fd_write(object, file_inode(file), pos, len);
79 ret = __cachefiles_write(object, file, pos, iter, NULL, NULL);85 ret = __cachefiles_write(object, file, pos, iter, NULL, NULL);
80 if (!ret)86 if (!ret) {
81 ret = len;87 ret = len;
88 kiocb->ki_pos += ret;
89 }
82 90
91out:
92 fput(file);
83 return ret;93 return ret;
84}94}
85 95
@@ -87,12 +97,22 @@ static loff_t cachefiles_ondemand_fd_llseek(struct file *filp, loff_t pos, · 1 unmodified line
87 int whence)97 int whence)
88{98{
89 struct cachefiles_object *object = filp->private_data;99 struct cachefiles_object *object = filp->private_data;
90 struct file *file = object->file;100 struct file *file;
101 loff_t ret;
91 102
92 if (!file)103 spin_lock(&object->lock);
104 file = object->file;
105 if (!file) {
106 spin_unlock(&object->lock);
93 return -ENOBUFS;107 return -ENOBUFS;
108 }
109 get_file(file);
110 spin_unlock(&object->lock);
94 111
95 return vfs_llseek(file, pos, whence);112 ret = vfs_llseek(file, pos, whence);
113 fput(file);
114
115 return ret;
96}116}
97 117
98static long cachefiles_ondemand_fd_ioctl(struct file *filp, unsigned int ioctl,118static long cachefiles_ondemand_fd_ioctl(struct file *filp, unsigned int ioctl,
fs/netfs/buffered_read.c+4−4
@@ -627,7 +627,7 @@ static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len, · 626 unmodified lines
627 if (unlikely(always_fill)) {627 if (unlikely(always_fill)) {
628 if (pos - offset + len <= i_size)628 if (pos - offset + len <= i_size)
629 return false; /* Page entirely before EOF */629 return false; /* Page entirely before EOF */
630 zero_user_segment(&folio->page, 0, plen);630 folio_zero_segment(folio, 0, plen);
631 folio_mark_uptodate(folio);631 folio_mark_uptodate(folio);
632 return true;632 return true;
633 }633 }
@@ -646,7 +646,7 @@ static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len, · 12 unmodified lines
646 646
647 return false;647 return false;
648zero_out:648zero_out:
649 zero_user_segments(&folio->page, 0, offset, offset + len, plen);649 folio_zero_segments(folio, 0, offset, offset + len, plen);
650 return true;650 return true;
651}651}
652 652
@@ -713,7 +713,7 @@ retry: · 60 unmodified lines
713 if (folio_test_uptodate(folio))713 if (folio_test_uptodate(folio))
714 goto have_folio;714 goto have_folio;
715 715
716 /* If the page is beyond the EOF, we want to clear it - unless it's716 /* If the folio is beyond the EOF, we want to clear it - unless it's
717 * within the cache granule containing the EOF, in which case we need717 * within the cache granule containing the EOF, in which case we need
718 * to preload the granule.718 * to preload the granule.
719 */719 */
@@ -773,7 +773,7 @@ error: · 53 unmodified lines
773EXPORT_SYMBOL(netfs_write_begin);773EXPORT_SYMBOL(netfs_write_begin);
774 774
775/*775/*
776 * Preload the data into a page we're proposing to write into.776 * Preload the data into a folio we're proposing to write into.
777 */777 */
778int netfs_prefetch_for_write(struct file *file, struct folio *folio,778int netfs_prefetch_for_write(struct file *file, struct folio *folio,
779 size_t offset, size_t len)779 size_t offset, size_t len)
fs/netfs/buffered_write.c+20−21
@@ -83,13 +83,13 @@ static void netfs_update_i_size(struct netfs_inode *ctx, struct inode *inode, · 82 unmodified lines
83 * netfs_perform_write - Copy data into the pagecache.83 * netfs_perform_write - Copy data into the pagecache.
84 * @iocb: The operation parameters84 * @iocb: The operation parameters
85 * @iter: The source buffer85 * @iter: The source buffer
86 * @netfs_group: Grouping for dirty pages (eg. ceph snaps).86 * @netfs_group: Grouping for dirty folios (eg. ceph snaps).
87 *87 *
88 * Copy data into pagecache pages attached to the inode specified by @iocb.88 * Copy data into pagecache folios attached to the inode specified by @iocb.
89 * The caller must hold appropriate inode locks.89 * The caller must hold appropriate inode locks.
90 *90 *
91 * Dirty pages are tagged with a netfs_folio struct if they're not up to date91 * Dirty folios are tagged with a netfs_folio struct if they're not up to date
92 * to indicate the range modified. Dirty pages may also be tagged with a92 * to indicate the range modified. Dirty folios may also be tagged with a
93 * netfs-specific grouping such that data from an old group gets flushed before93 * netfs-specific grouping such that data from an old group gets flushed before
94 * a new one is started.94 * a new one is started.
95 */95 */
@@ -223,11 +223,11 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter, · 127 unmodified lines
223 * we try to read it.223 * we try to read it.
224 */224 */
225 if (fpos >= ctx->zero_point) {225 if (fpos >= ctx->zero_point) {
226 zero_user_segment(&folio->page, 0, offset);226 folio_zero_segment(folio, 0, offset);
227 copied = copy_folio_from_iter_atomic(folio, offset, part, iter);227 copied = copy_folio_from_iter_atomic(folio, offset, part, iter);
228 if (unlikely(copied == 0))228 if (unlikely(copied == 0))
229 goto copy_failed;229 goto copy_failed;
230 zero_user_segment(&folio->page, offset + copied, flen);230 folio_zero_segment(folio, offset + copied, flen);
231 __netfs_set_group(folio, netfs_group);231 __netfs_set_group(folio, netfs_group);
232 folio_mark_uptodate(folio);232 folio_mark_uptodate(folio);
233 trace_netfs_folio(folio, netfs_modify_and_clear);233 trace_netfs_folio(folio, netfs_modify_and_clear);
@@ -407,7 +407,7 @@ EXPORT_SYMBOL(netfs_perform_write); · 173 unmodified lines
407 * netfs_buffered_write_iter_locked - write data to a file407 * netfs_buffered_write_iter_locked - write data to a file
408 * @iocb: IO state structure (file, offset, etc.)408 * @iocb: IO state structure (file, offset, etc.)
409 * @from: iov_iter with data to write409 * @from: iov_iter with data to write
410 * @netfs_group: Grouping for dirty pages (eg. ceph snaps).410 * @netfs_group: Grouping for dirty folios (eg. ceph snaps).
411 *411 *
412 * This function does all the work needed for actually writing data to a412 * This function does all the work needed for actually writing data to a
413 * file. It does all basic checks, removes SUID from the file, updates413 * file. It does all basic checks, removes SUID from the file, updates
@@ -491,7 +491,9 @@ EXPORT_SYMBOL(netfs_file_write_iter); · 77 unmodified lines
491 491
492/*492/*
493 * Notification that a previously read-only page is about to become writable.493 * Notification that a previously read-only page is about to become writable.
494 * Note that the caller indicates a single page of a multipage folio.494 * The caller indicates the precise page that needs to be written to, but
495 * we only track group on a per-folio basis, so we block more often than
496 * we might otherwise.
495 */497 */
496vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group)498vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group)
497{499{
@@ -501,7 +503,7 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr · 3 unmodified lines
501 struct address_space *mapping = file->f_mapping;503 struct address_space *mapping = file->f_mapping;
502 struct inode *inode = file_inode(file);504 struct inode *inode = file_inode(file);
503 struct netfs_inode *ictx = netfs_inode(inode);505 struct netfs_inode *ictx = netfs_inode(inode);
504 vm_fault_t ret = VM_FAULT_RETRY;506 vm_fault_t ret = VM_FAULT_NOPAGE;
505 int err;507 int err;
506 508
507 _enter("%lx", folio->index);509 _enter("%lx", folio->index);
@@ -510,21 +512,15 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr · 2 unmodified lines
510 512
511 if (folio_lock_killable(folio) < 0)513 if (folio_lock_killable(folio) < 0)
512 goto out;514 goto out;
513 if (folio->mapping != mapping) {515 if (folio->mapping != mapping)
514 folio_unlock(folio);516 goto unlock;
515 ret = VM_FAULT_NOPAGE;517 if (folio_wait_writeback_killable(folio) < 0)
516 goto out;518 goto unlock;
517 }
518
519 if (folio_wait_writeback_killable(folio)) {
520 ret = VM_FAULT_LOCKED;
521 goto out;
522 }
523 519
524 /* Can we see a streaming write here? */520 /* Can we see a streaming write here? */
525 if (WARN_ON(!folio_test_uptodate(folio))) {521 if (WARN_ON(!folio_test_uptodate(folio))) {
526 ret = VM_FAULT_SIGBUS | VM_FAULT_LOCKED;522 ret = VM_FAULT_SIGBUS;
527 goto out;523 goto unlock;
528 }524 }
529 525
530 group = netfs_folio_group(folio);526 group = netfs_folio_group(folio);
@@ -559,5 +555,8 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr · 28 unmodified lines
559out:555out:
560 sb_end_pagefault(inode->i_sb);556 sb_end_pagefault(inode->i_sb);
561 return ret;557 return ret;
558unlock:
559 folio_unlock(folio);
560 goto out;
562}561}
563EXPORT_SYMBOL(netfs_page_mkwrite);562EXPORT_SYMBOL(netfs_page_mkwrite);
fs/netfs/fscache_volume.c+1−2
@@ -322,8 +322,7 @@ maybe_wait: · 321 unmodified lines
322 }322 }
323 return;323 return;
324no_wait:324no_wait:
325 clear_bit_unlock(FSCACHE_VOLUME_CREATING, &volume->flags);325 clear_and_wake_up_bit(FSCACHE_VOLUME_CREATING, &volume->flags);
326 wake_up_bit(&volume->flags, FSCACHE_VOLUME_CREATING);
327}326}
328 327
329/*328/*
include/trace/events/netfs.h+1−1
@@ -450,7 +450,7 @@ TRACE_EVENT(netfs_folio, · 449 unmodified lines
450 struct address_space *__m = READ_ONCE(folio->mapping);450 struct address_space *__m = READ_ONCE(folio->mapping);
451 __entry->ino = __m ? __m->host->i_ino : 0;451 __entry->ino = __m ? __m->host->i_ino : 0;
452 __entry->why = why;452 __entry->why = why;
453 __entry->index = folio_index(folio);453 __entry->index = folio->index;
454 __entry->nr = folio_nr_pages(folio);454 __entry->nr = folio_nr_pages(folio);
455 ),455 ),
456 456

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t