Skip to content

Commit

Permalink
Merge branch 'mm-nonmm-unstable' into mm-everything
Browse files Browse the repository at this point in the history
  • Loading branch information
akpm00 committed Nov 15, 2023
2 parents 39e9f26 + 1ff947a commit 4c64241
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 198 deletions.
3 changes: 1 addition & 2 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,11 +1578,10 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
* will be able to manipulate the current directory, etc.
* It would be nice to force an unshare instead...
*/
t = p;
n_fs = 1;
spin_lock(&p->fs->lock);
rcu_read_lock();
while_each_thread(p, t) {
for_other_threads(p, t) {
if (t->fs == p->fs)
n_fs++;
}
Expand Down
62 changes: 31 additions & 31 deletions fs/nilfs2/btnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
set_buffer_mapped(bh);
set_buffer_uptodate(bh);

unlock_page(bh->b_page);
put_page(bh->b_page);
folio_unlock(bh->b_folio);
folio_put(bh->b_folio);
return bh;
}

Expand All @@ -75,15 +75,15 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
{
struct buffer_head *bh;
struct inode *inode = btnc->host;
struct page *page;
struct folio *folio;
int err;

bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node));
if (unlikely(!bh))
return -ENOMEM;

err = -EEXIST; /* internal code */
page = bh->b_page;
folio = bh->b_folio;

if (buffer_uptodate(bh) || buffer_dirty(bh))
goto found;
Expand Down Expand Up @@ -130,8 +130,8 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
*pbh = bh;

out_locked:
unlock_page(page);
put_page(page);
folio_unlock(folio);
folio_put(folio);
return err;
}

Expand All @@ -145,19 +145,19 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
void nilfs_btnode_delete(struct buffer_head *bh)
{
struct address_space *mapping;
struct page *page = bh->b_page;
pgoff_t index = page_index(page);
struct folio *folio = bh->b_folio;
pgoff_t index = folio->index;
int still_dirty;

get_page(page);
lock_page(page);
wait_on_page_writeback(page);
folio_get(folio);
folio_lock(folio);
folio_wait_writeback(folio);

nilfs_forget_buffer(bh);
still_dirty = PageDirty(page);
mapping = page->mapping;
unlock_page(page);
put_page(page);
still_dirty = folio_test_dirty(folio);
mapping = folio->mapping;
folio_unlock(folio);
folio_put(folio);

if (!still_dirty && mapping)
invalidate_inode_pages2_range(mapping, index, index);
Expand Down Expand Up @@ -185,23 +185,23 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
ctxt->newbh = NULL;

if (inode->i_blkbits == PAGE_SHIFT) {
struct page *opage = obh->b_page;
lock_page(opage);
struct folio *ofolio = obh->b_folio;
folio_lock(ofolio);
retry:
/* BUG_ON(oldkey != obh->b_folio->index); */
if (unlikely(oldkey != opage->index))
NILFS_PAGE_BUG(opage,
if (unlikely(oldkey != ofolio->index))
NILFS_PAGE_BUG(&ofolio->page,
"invalid oldkey %lld (newkey=%lld)",
(unsigned long long)oldkey,
(unsigned long long)newkey);

xa_lock_irq(&btnc->i_pages);
err = __xa_insert(&btnc->i_pages, newkey, opage, GFP_NOFS);
err = __xa_insert(&btnc->i_pages, newkey, ofolio, GFP_NOFS);
xa_unlock_irq(&btnc->i_pages);
/*
* Note: page->index will not change to newkey until
* Note: folio->index will not change to newkey until
* nilfs_btnode_commit_change_key() will be called.
* To protect the page in intermediate state, the page lock
* To protect the folio in intermediate state, the folio lock
* is held.
*/
if (!err)
Expand All @@ -213,7 +213,7 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
if (!err)
goto retry;
/* fallback to copy mode */
unlock_page(opage);
folio_unlock(ofolio);
}

nbh = nilfs_btnode_create_block(btnc, newkey);
Expand All @@ -225,7 +225,7 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
return 0;

failed_unlock:
unlock_page(obh->b_page);
folio_unlock(obh->b_folio);
return err;
}

Expand All @@ -238,15 +238,15 @@ void nilfs_btnode_commit_change_key(struct address_space *btnc,
{
struct buffer_head *obh = ctxt->bh, *nbh = ctxt->newbh;
__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey;
struct page *opage;
struct folio *ofolio;

if (oldkey == newkey)
return;

if (nbh == NULL) { /* blocksize == pagesize */
opage = obh->b_page;
if (unlikely(oldkey != opage->index))
NILFS_PAGE_BUG(opage,
ofolio = obh->b_folio;
if (unlikely(oldkey != ofolio->index))
NILFS_PAGE_BUG(&ofolio->page,
"invalid oldkey %lld (newkey=%lld)",
(unsigned long long)oldkey,
(unsigned long long)newkey);
Expand All @@ -257,8 +257,8 @@ void nilfs_btnode_commit_change_key(struct address_space *btnc,
__xa_set_mark(&btnc->i_pages, newkey, PAGECACHE_TAG_DIRTY);
xa_unlock_irq(&btnc->i_pages);

opage->index = obh->b_blocknr = newkey;
unlock_page(opage);
ofolio->index = obh->b_blocknr = newkey;
folio_unlock(ofolio);
} else {
nilfs_copy_buffer(nbh, obh);
mark_buffer_dirty(nbh);
Expand All @@ -284,7 +284,7 @@ void nilfs_btnode_abort_change_key(struct address_space *btnc,

if (nbh == NULL) { /* blocksize == pagesize */
xa_erase_irq(&btnc->i_pages, newkey);
unlock_page(ctxt->bh->b_page);
folio_unlock(ctxt->bh->b_folio);
} else {
/*
* When canceling a buffer that a prepare operation has
Expand Down
28 changes: 15 additions & 13 deletions fs/nilfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,36 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
struct page *page = vmf->page;
struct folio *folio = page_folio(vmf->page);
struct inode *inode = file_inode(vma->vm_file);
struct nilfs_transaction_info ti;
struct buffer_head *bh, *head;
int ret = 0;

if (unlikely(nilfs_near_disk_full(inode->i_sb->s_fs_info)))
return VM_FAULT_SIGBUS; /* -ENOSPC */

sb_start_pagefault(inode->i_sb);
lock_page(page);
if (page->mapping != inode->i_mapping ||
page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
unlock_page(page);
folio_lock(folio);
if (folio->mapping != inode->i_mapping ||
folio_pos(folio) >= i_size_read(inode) ||
!folio_test_uptodate(folio)) {
folio_unlock(folio);
ret = -EFAULT; /* make the VM retry the fault */
goto out;
}

/*
* check to see if the page is mapped already (no holes)
* check to see if the folio is mapped already (no holes)
*/
if (PageMappedToDisk(page))
if (folio_test_mappedtodisk(folio))
goto mapped;

if (page_has_buffers(page)) {
struct buffer_head *bh, *head;
head = folio_buffers(folio);
if (head) {
int fully_mapped = 1;

bh = head = page_buffers(page);
bh = head;
do {
if (!buffer_mapped(bh)) {
fully_mapped = 0;
Expand All @@ -81,11 +83,11 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
} while (bh = bh->b_this_page, bh != head);

if (fully_mapped) {
SetPageMappedToDisk(page);
folio_set_mappedtodisk(folio);
goto mapped;
}
}
unlock_page(page);
folio_unlock(folio);

/*
* fill hole blocks
Expand All @@ -105,7 +107,7 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
nilfs_transaction_commit(inode->i_sb);

mapped:
wait_for_stable_page(page);
folio_wait_stable(folio);
out:
sb_end_pagefault(inode->i_sb);
return vmf_fs_error(ret);
Expand Down
4 changes: 2 additions & 2 deletions fs/nilfs2/gcinode.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
*out_bh = bh;

failed:
unlock_page(bh->b_page);
put_page(bh->b_page);
folio_unlock(bh->b_folio);
folio_put(bh->b_folio);
if (unlikely(err))
brelse(bh);
return err;
Expand Down
11 changes: 6 additions & 5 deletions fs/nilfs2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ static int nilfs_writepages(struct address_space *mapping,

static int nilfs_writepage(struct page *page, struct writeback_control *wbc)
{
struct inode *inode = page->mapping->host;
struct folio *folio = page_folio(page);
struct inode *inode = folio->mapping->host;
int err;

if (sb_rdonly(inode->i_sb)) {
Expand All @@ -185,13 +186,13 @@ static int nilfs_writepage(struct page *page, struct writeback_control *wbc)
* have dirty pages that try to be flushed in background.
* So, here we simply discard this dirty page.
*/
nilfs_clear_dirty_page(page, false);
unlock_page(page);
nilfs_clear_folio_dirty(folio, false);
folio_unlock(folio);
return -EROFS;
}

redirty_page_for_writepage(wbc, page);
unlock_page(page);
folio_redirty_for_writepage(wbc, folio);
folio_unlock(folio);

if (wbc->sync_mode == WB_SYNC_ALL) {
err = nilfs_construct_segment(inode->i_sb);
Expand Down
10 changes: 4 additions & 6 deletions fs/nilfs2/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,14 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
nsegs = argv[4].v_nmembs;
if (argv[4].v_size != argsz[4])
goto out;
if (nsegs > UINT_MAX / sizeof(__u64))
goto out;

/*
* argv[4] points to segment numbers this ioctl cleans. We
* use kmalloc() for its buffer because memory used for the
* segment numbers is enough small.
* use kmalloc() for its buffer because the memory used for the
* segment numbers is small enough.
*/
kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base,
nsegs * sizeof(__u64));
kbufs[4] = memdup_array_user((void __user *)(unsigned long)argv[4].v_base,
nsegs, sizeof(__u64));
if (IS_ERR(kbufs[4])) {
ret = PTR_ERR(kbufs[4]);
goto out;
Expand Down
23 changes: 12 additions & 11 deletions fs/nilfs2/mdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
}

failed_bh:
unlock_page(bh->b_page);
put_page(bh->b_page);
folio_unlock(bh->b_folio);
folio_put(bh->b_folio);
brelse(bh);

failed_unlock:
Expand Down Expand Up @@ -158,8 +158,8 @@ nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, blk_opf_t opf,
*out_bh = bh;

failed_bh:
unlock_page(bh->b_page);
put_page(bh->b_page);
folio_unlock(bh->b_folio);
folio_put(bh->b_folio);
brelse(bh);
failed:
return ret;
Expand Down Expand Up @@ -399,24 +399,25 @@ int nilfs_mdt_fetch_dirty(struct inode *inode)
static int
nilfs_mdt_write_page(struct page *page, struct writeback_control *wbc)
{
struct inode *inode = page->mapping->host;
struct folio *folio = page_folio(page);
struct inode *inode = folio->mapping->host;
struct super_block *sb;
int err = 0;

if (inode && sb_rdonly(inode->i_sb)) {
/*
* It means that filesystem was remounted in read-only
* mode because of error or metadata corruption. But we
* have dirty pages that try to be flushed in background.
* So, here we simply discard this dirty page.
* have dirty folios that try to be flushed in background.
* So, here we simply discard this dirty folio.
*/
nilfs_clear_dirty_page(page, false);
unlock_page(page);
nilfs_clear_folio_dirty(folio, false);
folio_unlock(folio);
return -EROFS;
}

redirty_page_for_writepage(wbc, page);
unlock_page(page);
folio_redirty_for_writepage(wbc, folio);
folio_unlock(folio);

if (!inode)
return 0;
Expand Down
Loading

0 comments on commit 4c64241

Please sign in to comment.