cascardo/linux.git
8 years agof2fs: manipulate dirty file inodes when DATA_FLUSH is set
Jaegeuk Kim [Mon, 16 May 2016 17:33:40 +0000 (10:33 -0700)]
f2fs: manipulate dirty file inodes when DATA_FLUSH is set

It needs to maintain dirty file inodes only if DATA_FLUSH is set.
Otherwise, let's avoid its overhead.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: add fault injection to sysfs
Sheng Yong [Mon, 16 May 2016 04:38:50 +0000 (12:38 +0800)]
f2fs: add fault injection to sysfs

This patch introduces a new struct f2fs_fault_info and a global f2fs_fault
to save fault injection status. Fault injection entries are created in
/sys/fs/f2fs/fault_injection/ during initializing f2fs module.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: no need inc dirty pages under inode lock
Yunlei He [Fri, 13 May 2016 06:57:43 +0000 (14:57 +0800)]
f2fs: no need inc dirty pages under inode lock

No need inc dirty pages under inode lock

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix incorrect error path handling in f2fs_move_rehashed_dirents
Chao Yu [Sat, 14 May 2016 11:03:53 +0000 (19:03 +0800)]
f2fs: fix incorrect error path handling in f2fs_move_rehashed_dirents

Fix two bugs in error path of f2fs_move_rehashed_dirents:
 - release dir's inode page if fail to call kmalloc
 - recover i_current_depth if fail to converting

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix i_current_depth during inline dentry conversion
Chao Yu [Sat, 14 May 2016 11:03:52 +0000 (19:03 +0800)]
f2fs: fix i_current_depth during inline dentry conversion

With below steps, we will see that dentry page becoming unaccessable later.
This is because we forget updating i_current_depth in inode during inline
dentry conversion, after that, once we failed at somewhere, it will leave
i_current_depth as 0 in non-inline directory. Then, during ->lookup, the
current_depth value makes all dentry pages in first level invisible. Fix
it.

1) mount f2fs with inline_dentry option
2) mkdir dir
3) touch 180 files named [0-179] in dir
4) touch 180 in dir (fail after inline dir conversion)
5) ll dir

ls: cannot access /mnt/f2fs/dir/0: No such file or directory
ls: cannot access /mnt/f2fs/dir/1: No such file or directory
ls: cannot access /mnt/f2fs/dir/2: No such file or directory
ls: cannot access /mnt/f2fs/dir/3: No such file or directory
ls: cannot access /mnt/f2fs/dir/4: No such file or directory

drwxr-xr-x 2 root root 4096  may 13 21:47 ./
drwxr-xr-x 3 root root 4096  may 13 21:46 ../
-????????? ? ?    ?       ?             ? 0
-????????? ? ?    ?       ?             ? 1
-????????? ? ?    ?       ?             ? 10
-????????? ? ?    ?       ?             ? 100
-????????? ? ?    ?       ?             ? 101
-????????? ? ?    ?       ?             ? 102

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: correct return value type of f2fs_fill_super
Sheng Yong [Wed, 11 May 2016 09:08:14 +0000 (17:08 +0800)]
f2fs: correct return value type of f2fs_fill_super

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix deadlock when flush inline data
Chao Yu [Wed, 11 May 2016 11:48:44 +0000 (19:48 +0800)]
f2fs: fix deadlock when flush inline data

Below backtrace info was reported by Yunlei He:

Call Trace:
 [<ffffffff817a9395>] schedule+0x35/0x80
 [<ffffffff817abb7d>] rwsem_down_read_failed+0xed/0x130
 [<ffffffff813c12a8>] call_rwsem_down_read_failed+0x18/0x
 [<ffffffff817ab1d0>] down_read+0x20/0x30
 [<ffffffffa02a1a12>] f2fs_evict_inode+0x242/0x3a0 [f2fs]
 [<ffffffff81217057>] evict+0xc7/0x1a0
 [<ffffffff81217cd6>] iput+0x196/0x200
 [<ffffffff812134f9>] __dentry_kill+0x179/0x1e0
 [<ffffffff812136f9>] dput+0x199/0x1f0
 [<ffffffff811fe77b>] __fput+0x18b/0x220
 [<ffffffff811fe84e>] ____fput+0xe/0x10
 [<ffffffff81097427>] task_work_run+0x77/0x90
 [<ffffffff81074d62>] exit_to_usermode_loop+0x73/0xa2
 [<ffffffff81003b7a>] do_syscall_64+0xfa/0x110
 [<ffffffff817acf65>] entry_SYSCALL64_slow_path+0x25/0x25

Call Trace:
 [<ffffffff817a9395>] schedule+0x35/0x80
 [<ffffffff81216dc3>] __wait_on_freeing_inode+0xa3/0xd0
 [<ffffffff810bc300>] ? autoremove_wake_function+0x40/0x4
 [<ffffffff8121771d>] find_inode_fast+0x7d/0xb0
 [<ffffffff8121794a>] ilookup+0x6a/0xd0
 [<ffffffffa02bc740>] sync_node_pages+0x210/0x650 [f2fs]
 [<ffffffff8122e690>] ? do_fsync+0x70/0x70
 [<ffffffffa02b085e>] block_operations+0x9e/0xf0 [f2fs]
 [<ffffffff8137b795>] ? bio_endio+0x55/0x60
 [<ffffffffa02b0942>] write_checkpoint+0x92/0xba0 [f2fs]
 [<ffffffff8117da57>] ? mempool_free_slab+0x17/0x20
 [<ffffffff8117de8b>] ? mempool_free+0x2b/0x80
 [<ffffffff8122e690>] ? do_fsync+0x70/0x70
 [<ffffffffa02a53e3>] f2fs_sync_fs+0x63/0xd0 [f2fs]
 [<ffffffff8129630f>] ? ext4_sync_fs+0xbf/0x190
 [<ffffffff8122e6b0>] sync_fs_one_sb+0x20/0x30
 [<ffffffff812002e9>] iterate_supers+0xb9/0x110
 [<ffffffff8122e7b5>] sys_sync+0x55/0x90
 [<ffffffff81003ae9>] do_syscall_64+0x69/0x110
 [<ffffffff817acf65>] entry_SYSCALL64_slow_path+0x25/0x25

With following excuting serials, we will set inline_node in inode page
after inode was unlinked, result in a deadloop described as below:
1. open file
2. write file
3. unlink file
4. write file
5. close file

Thread A Thread B
 - dput
  - iput_final
   - inode->i_state |= I_FREEING
   - evict
    - f2fs_evict_inode
 - f2fs_sync_fs
  - write_checkpoint
   - block_operations
    - f2fs_lock_all (down_write(cp_rwsem))
     - f2fs_lock_op (down_read(cp_rwsem))
    - sync_node_pages
     - ilookup
      - find_inode_fast
       - __wait_on_freeing_inode
         (wait on I_FREEING clear)

Here, we change to set inline_node flag only for linked inode for fixing.

Reported-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Tested-by: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: stable@vger.kernel.org # v4.6
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: avoid f2fs_bug_on during recovery
Jaegeuk Kim [Wed, 11 May 2016 16:13:13 +0000 (09:13 -0700)]
f2fs: avoid f2fs_bug_on during recovery

We don't need to use f2fs_bug_on() to treat with any error case when allocating
a block during recovery.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: show # of orphan inodes
Jaegeuk Kim [Wed, 11 May 2016 02:13:50 +0000 (19:13 -0700)]
f2fs: show # of orphan inodes

This adds debug information for # of orphan inodes.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: support in batch fzero in dnode page
Chao Yu [Mon, 9 May 2016 11:56:31 +0000 (19:56 +0800)]
f2fs: support in batch fzero in dnode page

This patch tries to speedup fzero_range by making space preallocation and
address removal of blocks in one dnode page as in batch operation.

In virtual machine, with zram driver:

dd if=/dev/zero of=/mnt/f2fs/file bs=1M count=4096
time xfs_io -f /mnt/f2fs/file -c "fzero 0 4096M"

Before:
real 0m3.276s
user 0m0.008s
sys 0m3.260s

After:
real 0m1.568s
user 0m0.000s
sys 0m1.564s

Signed-off-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: consider ENOSPC case]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: support in batch multi blocks preallocation
Chao Yu [Mon, 9 May 2016 11:56:30 +0000 (19:56 +0800)]
f2fs: support in batch multi blocks preallocation

This patch introduces reserve_new_blocks to make preallocation of multi
blocks as in batch operation, so it can avoid lots of redundant
operation, result in better performance.

In virtual machine, with rotational device:

time fallocate -l 32G /mnt/f2fs/file

Before:
real 0m4.584s
user 0m0.000s
sys 0m4.580s

After:
real 0m0.292s
user 0m0.000s
sys 0m0.272s

In x86, with SSD:

time fallocate -l 500G $MNT/testfile

Before : 24.758 s
After  :  1.604 s

Signed-off-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: fix bugs and add performance numbers measured in x86.]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: make atomic/volatile operation exclusive
Chao Yu [Mon, 9 May 2016 11:56:33 +0000 (19:56 +0800)]
f2fs: make atomic/volatile operation exclusive

atomic/volatile ioctl interfaces are exposed to user like other file
operation interface, it needs to make them getting exclusion against
to each other to avoid potential conflict among these operations
in concurrent scenario.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: use mnt_{want,drop}_write_file in ioctl
Chao Yu [Mon, 9 May 2016 11:56:32 +0000 (19:56 +0800)]
f2fs: use mnt_{want,drop}_write_file in ioctl

In interfaces of ioctl, mnt_{want,drop}_write_file should be used for:
- get exclusion against file system freezing which may used by lvm
  snapshot.
- do telling filesystem that a write is about to be performed on it, and
  make sure that the writes are permitted.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: do not preallocate block unaligned to 4KB
Jaegeuk Kim [Sat, 7 May 2016 15:52:57 +0000 (08:52 -0700)]
f2fs: do not preallocate block unaligned to 4KB

Previously f2fs_preallocate_blocks() tries to allocate unaligned blocks.
In f2fs_write_begin(), however, prepare_write_begin() does not skip its
allocation due to (len != 4KB).
So, it needs locking node page twice unexpectedly.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: read node blocks ahead when truncating blocks
Jaegeuk Kim [Fri, 6 May 2016 23:19:43 +0000 (16:19 -0700)]
f2fs: read node blocks ahead when truncating blocks

This patch enables reading node blocks in advance when truncating large
data blocks.

 > time rm $MNT/testfile (500GB) after drop_cachees
Before : 9.422 s
After  : 4.821 s

Reported-by: Stephen Bates <stephen.bates@microsemi.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fallocate data blocks in single locked node page
Jaegeuk Kim [Fri, 6 May 2016 22:30:38 +0000 (15:30 -0700)]
f2fs: fallocate data blocks in single locked node page

This patch is to improve the expand_inode speed in fallocate by allocating
data blocks as many as possible in single locked node page.

In SSD,
 # time fallocate -l 500G $MNT/testfile

Before : 1m 33.410 s
After  : 24.758 s

Reported-by: Stephen Bates <stephen.bates@microsemi.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix inode cache leak
Chao Yu [Sat, 7 May 2016 08:15:05 +0000 (16:15 +0800)]
f2fs: fix inode cache leak

When testing f2fs with inline_dentry option, generic/342 reports:
VFS: Busy inodes after unmount of dm-0. Self-destruct in 5 seconds.  Have a nice day...

After rmmod f2fs module, kenrel shows following dmesg:
 =============================================================================
 BUG f2fs_inode_cache (Tainted: G           O   ): Objects remaining in f2fs_inode_cache on __kmem_cache_shutdown()
 -----------------------------------------------------------------------------

 Disabling lock debugging due to kernel taint
 INFO: Slab 0xf51ca0e0 objects=22 used=1 fp=0xd1e6fc60 flags=0x40004080
 CPU: 3 PID: 7455 Comm: rmmod Tainted: G    B      O    4.6.0-rc4+ #16
 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
  00000086 00000086 d062fe18 c13a83a0 f51ca0e0 d062fe38 d062fea4 c11c7276
  c1981040 f51ca0e0 00000016 00000001 d1e6fc60 40004080 656a624f 20737463
  616d6572 6e696e69 6e692067 66326620 6e695f73 5f65646f 68636163 6e6f2065
 Call Trace:
  [<c13a83a0>] dump_stack+0x5f/0x8f
  [<c11c7276>] slab_err+0x76/0x80
  [<c11cbfc0>] ? __kmem_cache_shutdown+0x100/0x2f0
  [<c11cbfc0>] ? __kmem_cache_shutdown+0x100/0x2f0
  [<c11cbfe5>] __kmem_cache_shutdown+0x125/0x2f0
  [<c1198a38>] kmem_cache_destroy+0x158/0x1f0
  [<c176b43d>] ? mutex_unlock+0xd/0x10
  [<f8f15aa3>] exit_f2fs_fs+0x4b/0x5a8 [f2fs]
  [<c10f596c>] SyS_delete_module+0x16c/0x1d0
  [<c1001b10>] ? do_fast_syscall_32+0x30/0x1c0
  [<c13c59bf>] ? __this_cpu_preempt_check+0xf/0x20
  [<c10afa7d>] ? trace_hardirqs_on_caller+0xdd/0x210
  [<c10ad50b>] ? trace_hardirqs_off+0xb/0x10
  [<c1001b81>] do_fast_syscall_32+0xa1/0x1c0
  [<c176d888>] sysenter_past_esp+0x45/0x74
 INFO: Object 0xd1e6d9e0 @offset=6624
 kmem_cache_destroy f2fs_inode_cache: Slab cache still has objects
 CPU: 3 PID: 7455 Comm: rmmod Tainted: G    B      O    4.6.0-rc4+ #16
 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
  00000286 00000286 d062fef4 c13a83a0 f174b000 d062ff14 d062ff28 c1198ac7
  c197fe18 f3c5b980 d062ff20 000d04f2 d062ff0c d062ff0c d062ff14 d062ff14
  f8f20dc0 fffffff5 d062e000 d062ff30 f8f15aa3 d062ff7c c10f596c 73663266
 Call Trace:
  [<c13a83a0>] dump_stack+0x5f/0x8f
  [<c1198ac7>] kmem_cache_destroy+0x1e7/0x1f0
  [<f8f15aa3>] exit_f2fs_fs+0x4b/0x5a8 [f2fs]
  [<c10f596c>] SyS_delete_module+0x16c/0x1d0
  [<c1001b10>] ? do_fast_syscall_32+0x30/0x1c0
  [<c13c59bf>] ? __this_cpu_preempt_check+0xf/0x20
  [<c10afa7d>] ? trace_hardirqs_on_caller+0xdd/0x210
  [<c10ad50b>] ? trace_hardirqs_off+0xb/0x10
  [<c1001b81>] do_fast_syscall_32+0xa1/0x1c0
  [<c176d888>] sysenter_past_esp+0x45/0x74

The reason is: in recovery flow, we use delayed iput mechanism for directory
which has recovered dentry block. It means the reference of inode will be
held until last dirty dentry page being writebacked.

But when we mount f2fs with inline_dentry option, during recovery, dirent
may only be recovered into dir inode page rather than dentry page, so there
are no chance for us to release inode reference in ->writepage when
writebacking last dentry page.

We can call paired iget/iput explicityly for inline_dentry case, but for
non-inline_dentry case, iput will call writeback_single_inode to write all
data pages synchronously, but during recovery, ->writepages of f2fs skips
writing all pages, result in losing dirent.

This patch fixes this issue by obsoleting old mechanism, and introduce a
new dir_list to hold all directory inodes which has recovered datas until
finishing recovery.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agofscrypto/f2fs: allow fs-specific key prefix for fs encryption
Jaegeuk Kim [Thu, 5 May 2016 05:05:01 +0000 (22:05 -0700)]
fscrypto/f2fs: allow fs-specific key prefix for fs encryption

This patch allows fscrypto to handle a second key prefix given by filesystem.
The main reason is to provide backward compatibility, since previously f2fs
used "f2fs:" as a crypto prefix instead of "fscrypt:".
Later, ext4 should also provide key_prefix() to give "ext4:".

One concern decribed by Ted would be kinda double check overhead of prefixes.
In x86, for example, validate_user_key consumes 8 ms after boot-up, which turns
out derive_key_aes() consumed most of the time to load specific crypto module.
After such the cold miss, it shows almost zero latencies, which treats as a
negligible overhead.
Note that request_key() detects wrong prefix in prior to derive_key_aes() even.

Cc: Ted Tso <tytso@mit.edu>
Cc: stable@vger.kernel.org # v4.6
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: avoid panic when truncating to max filesize
Chao Yu [Thu, 5 May 2016 11:13:03 +0000 (19:13 +0800)]
f2fs: avoid panic when truncating to max filesize

The following panic occurs when truncating inode which has inline
xattr to max filesize.

[<ffffffffa013d3be>] get_dnode_of_data+0x4e/0x580 [f2fs]
[<ffffffffa013aca1>] ? read_node_page+0x51/0x90 [f2fs]
[<ffffffffa013ad99>] ? get_node_page.part.34+0xb9/0x170 [f2fs]
[<ffffffffa01235b1>] truncate_blocks+0x131/0x3f0 [f2fs]
[<ffffffffa01238e3>] f2fs_truncate+0x73/0x100 [f2fs]
[<ffffffffa01239d2>] f2fs_setattr+0x62/0x2a0 [f2fs]
[<ffffffff811a72c8>] notify_change+0x158/0x300
[<ffffffff8118a42b>] do_truncate+0x6b/0xa0
[<ffffffff8118e539>] ? __sb_start_write+0x49/0x100
[<ffffffff8118a798>] do_sys_ftruncate.constprop.12+0x118/0x170
[<ffffffff8118a82e>] SyS_ftruncate+0xe/0x10
[<ffffffff8169efcf>] tracesys+0xe1/0xe6
[<ffffffffa0139ae0>] get_node_path+0x210/0x220 [f2fs]
 <ffff880206a89ce8>
--[ end trace 5fea664dfbcc6625 ]---

The reason is truncate_blocks tries to truncate all node and data blocks
start from specified block offset with value of (max filesize / block
size), but actually, our valid max block offset is (max filesize / block
size) - 1, so f2fs detects such invalid block offset with BUG_ON in
truncation path.

This patch lets f2fs skip truncating data which is exceeding max
filesize.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix incorrect mapping in ->bmap
Chao Yu [Thu, 5 May 2016 11:13:02 +0000 (19:13 +0800)]
f2fs: fix incorrect mapping in ->bmap

Currently, generic_block_bmap is used in f2fs_bmap, its semantics is when
the mapping is been found, return position of target physical block,
otherwise return zero.

But, previously, when there is no mapping info for specified logical block,
f2fs_bmap will map target physical block to a uninitialized variable, which
should be wrong. Fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: remove an obsolete variable
Jaegeuk Kim [Wed, 4 May 2016 16:58:10 +0000 (09:58 -0700)]
f2fs: remove an obsolete variable

This patch removes an obsolete variable used in add_free_nid.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: don't worry about inode leak in evict_inode
Jaegeuk Kim [Thu, 5 May 2016 02:48:53 +0000 (19:48 -0700)]
f2fs: don't worry about inode leak in evict_inode

Even if an inode failed to release its blocks, it should be kept in an orphan
inode list, so it will be released later.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: shrink size of struct seg_entry
Chao Yu [Wed, 4 May 2016 15:19:48 +0000 (23:19 +0800)]
f2fs: shrink size of struct seg_entry

Restructure struct seg_entry to eliminate holes in it, after that,
in 32-bits machine, it reduces size from 32 bytes to 24 bytes; in
64-bits machine, it reduces size from 56 bytes to 40 bytes.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: reuse get_extent_info
Chao Yu [Wed, 4 May 2016 15:19:47 +0000 (23:19 +0800)]
f2fs: reuse get_extent_info

Reuse get_extent_info for readability.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: remove unneeded memset when updating xattr
Chao Yu [Wed, 4 May 2016 15:19:46 +0000 (23:19 +0800)]
f2fs: remove unneeded memset when updating xattr

Each of fields in struct f2fs_xattr_entry will be assigned later,
so previously we don't need to memset the struct.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: remove unneeded readahead in find_fsync_dnodes
Chao Yu [Wed, 4 May 2016 15:17:00 +0000 (23:17 +0800)]
f2fs: remove unneeded readahead in find_fsync_dnodes

In find_fsync_dnodes, get_tmp_page will read dnode page synchronously,
previously, ra_meta_page did the same work, which is redundant, remove
it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: retry to truncate blocks in -ENOMEM case
Jaegeuk Kim [Tue, 3 May 2016 16:22:18 +0000 (09:22 -0700)]
f2fs: retry to truncate blocks in -ENOMEM case

This patch modifies to retry truncating node blocks in -ENOMEM case.

Signed-off-by: Hou Pengyang <houpengyang@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix leak of orphan inode objects
Jaegeuk Kim [Tue, 3 May 2016 05:09:56 +0000 (22:09 -0700)]
f2fs: fix leak of orphan inode objects

When unmounting filesystem, we should release all the ino entries.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: revisit error handling flows
Jaegeuk Kim [Mon, 2 May 2016 19:34:48 +0000 (12:34 -0700)]
f2fs: revisit error handling flows

This patch fixes a couple of bugs regarding to orphan inodes when handling
errors.

This tries to
 - call alloc_nid_done with add_orphan_inode in handle_failed_inode
 - let truncate blocks in f2fs_evict_inode
 - not make a bad inode due to i_mode change

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: inject ENOSPC failures
Jaegeuk Kim [Fri, 29 Apr 2016 23:29:22 +0000 (16:29 -0700)]
f2fs: inject ENOSPC failures

This patch injects ENOSPC failures.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: inject page allocation failures
Jaegeuk Kim [Fri, 29 Apr 2016 23:17:09 +0000 (16:17 -0700)]
f2fs: inject page allocation failures

This patch adds page allocation failures.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: inject kmalloc failure
Jaegeuk Kim [Fri, 29 Apr 2016 22:49:56 +0000 (15:49 -0700)]
f2fs: inject kmalloc failure

This patch injects kmalloc failure given a fault injection rate.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: add mount option to select fault injection ratio
Jaegeuk Kim [Fri, 29 Apr 2016 22:34:32 +0000 (15:34 -0700)]
f2fs: add mount option to select fault injection ratio

This patch adds a mount option to select fault ratio.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: use f2fs_grab_cache_page instead of grab_cache_page
Jaegeuk Kim [Fri, 29 Apr 2016 23:11:53 +0000 (16:11 -0700)]
f2fs: use f2fs_grab_cache_page instead of grab_cache_page

This patch converts grab_cache_page to f2fs_grab_cache_page.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: introduce f2fs_kmalloc to wrap kmalloc
Jaegeuk Kim [Fri, 29 Apr 2016 22:16:42 +0000 (15:16 -0700)]
f2fs: introduce f2fs_kmalloc to wrap kmalloc

This patch adds f2fs_kmalloc.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: add proc entry to show valid block bitmap
Jaegeuk Kim [Wed, 27 Apr 2016 23:29:05 +0000 (16:29 -0700)]
f2fs: add proc entry to show valid block bitmap

This patch adds a new proc entry to show segment information in more detail.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: introduce macros for proc entries
Jaegeuk Kim [Wed, 27 Apr 2016 23:07:56 +0000 (16:07 -0700)]
f2fs: introduce macros for proc entries

This adds macros to be used multiple proc entries.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: factor out fsync inode entry operations
Chao Yu [Fri, 29 Apr 2016 12:13:37 +0000 (20:13 +0800)]
f2fs: factor out fsync inode entry operations

Factor out fsync inode entry operations into {add,del}_fsync_inode.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix to clear page private flag
Chao Yu [Fri, 29 Apr 2016 12:13:36 +0000 (20:13 +0800)]
f2fs: fix to clear page private flag

Commit 28bc106b2346 ("f2fs: support revoking atomic written pages")
forgot to clear page private flag correctly, fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix to clear private data in page
Chao Yu [Fri, 29 Apr 2016 12:09:15 +0000 (20:09 +0800)]
f2fs: fix to clear private data in page

Private data in page should be removed during ->releasepage or
->invalidatepage, otherwise garbage data would be remained in that page.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix to return 0 if err == -ENOENT in f2fs_readdir
Yunlong Song [Wed, 27 Apr 2016 12:32:37 +0000 (20:32 +0800)]
f2fs: fix to return 0 if err == -ENOENT in f2fs_readdir

Commit 57b62d29ad5b384775974973087d47755a8c6fcc ("f2fs: fix to report
error in f2fs_readdir") causes f2fs_readdir to return -ENOENT when
get_lock_data_page returns -ENOENT. However, the original logic is to
continue when get_lock_data_page returns -ENOENT, but it forgets to
reset err to 0.

This will cause getdents64 incorretly return -ENOENT when lastdirent is
NULL in getdents64. This will lead to a wrong return value for syscall
caller.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: move node pages only in victim section during GC
Chao Yu [Wed, 27 Apr 2016 13:40:15 +0000 (21:40 +0800)]
f2fs: move node pages only in victim section during GC

For foreground GC, we cache node blocks in victim section and set them
dirty, then we call sync_node_pages to flush these node pages, but
meanwhile, those node pages which does not locate in victim section
will be flushed together, so more bandwidth and continuous free space
would be occupied.

So for this condition, it's better to leave those unrelated node page
in cache for further write hit, and let CP or VM to flush them afterward.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: be aware of invalid filename length
Chao Yu [Wed, 27 Apr 2016 14:22:20 +0000 (22:22 +0800)]
f2fs: be aware of invalid filename length

The filename length in dirent of may become zero-sized after random junk
data injection, once encounter such dirent, find_target_dentry or
f2fs_add_inline_entries will run into an infinite loop. So let f2fs being
aware of that to avoid deadloop.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agoMAINTAINERS: update my email address
Chao Yu [Sun, 24 Apr 2016 13:54:51 +0000 (21:54 +0800)]
MAINTAINERS: update my email address

I've changed employer, update my email address to the new one.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: issue cache flush on direct IO
Jaegeuk Kim [Mon, 18 Apr 2016 21:07:44 +0000 (17:07 -0400)]
f2fs: issue cache flush on direct IO

Under direct IO path with O_(D)SYNC, it needs to set proper APPEND or UPDATE
flags, so taht f2fs_sync_file can make its data safe.

Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: set fsync mark only for the last dnode
Jaegeuk Kim [Fri, 15 Apr 2016 16:43:17 +0000 (09:43 -0700)]
f2fs: set fsync mark only for the last dnode

In order to give atomic writes, we should consider power failure during
sync_node_pages in fsync.
So, this patch marks fsync flag only in the last dnode block.

Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: report unwritten status in fsync_node_pages
Jaegeuk Kim [Fri, 15 Apr 2016 16:25:04 +0000 (09:25 -0700)]
f2fs: report unwritten status in fsync_node_pages

The fsync_node_pages should return pass or failure so that user could know
fsync is completed or not.

Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: split sync_node_pages with fsync_node_pages
Jaegeuk Kim [Wed, 13 Apr 2016 23:24:44 +0000 (16:24 -0700)]
f2fs: split sync_node_pages with fsync_node_pages

This patch splits the existing sync_node_pages into (f)sync_node_pages.
The fsync_node_pages is used for f2fs_sync_file only.

Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: avoid writing 0'th page in volatile writes
Jaegeuk Kim [Thu, 14 Apr 2016 23:48:52 +0000 (16:48 -0700)]
f2fs: avoid writing 0'th page in volatile writes

The first page of volatile writes usually contains a sort of header information
which will be used for recovery.
(e.g., journal header of sqlite)

If this is written without other journal data, user needs to handle the stale
journal information.

Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: avoid needless lock for node pages when fsyncing a file
Jaegeuk Kim [Wed, 13 Apr 2016 23:14:38 +0000 (16:14 -0700)]
f2fs: avoid needless lock for node pages when fsyncing a file

When fsync is called, sync_node_pages finds a proper direct node pages to flush.
But, it locks unrelated direct node pages together unnecessarily.

Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: flush dirty pages before starting atomic writes
Jaegeuk Kim [Tue, 12 Apr 2016 21:36:11 +0000 (14:36 -0700)]
f2fs: flush dirty pages before starting atomic writes

If somebody wrote some data before atomic writes, we should flush them in order
to handle atomic data in a right period.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: don't invalidate atomic page if successful
Jaegeuk Kim [Tue, 12 Apr 2016 21:11:03 +0000 (14:11 -0700)]
f2fs: don't invalidate atomic page if successful

If we committed atomic write successfully, we don't need to invalidate pages.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: give -E2BIG for no space in xattr
Jaegeuk Kim [Tue, 12 Apr 2016 18:52:30 +0000 (11:52 -0700)]
f2fs: give -E2BIG for no space in xattr

This patch returns -E2BIG if there is no space to add an xattr entry.
This should fix generic/026 in xfstests as well.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: remove redundant condition check
Jaegeuk Kim [Wed, 6 Apr 2016 18:27:03 +0000 (11:27 -0700)]
f2fs: remove redundant condition check

This patch resolves the redundant condition check reported by David.

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: unset atomic/volatile flag in f2fs_release_file
Jaegeuk Kim [Mon, 11 Apr 2016 20:15:10 +0000 (13:15 -0700)]
f2fs: unset atomic/volatile flag in f2fs_release_file

The atomic/volatile operation should be done in pair of start and commit
ioctl.
For example, if a killed process remains open-ended atomic operation, we should
drop its flag as well as its atomic data. Otherwise, if sqlite initiates another
operation which doesn't require atomic writes, it will lose every data, since
f2fs still treats with them as atomic writes; nobody will trigger its commit.

Reported-by: Miao Xie <miaoxie@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix dropping inmemory pages in a wrong time
Jaegeuk Kim [Mon, 11 Apr 2016 18:51:51 +0000 (11:51 -0700)]
f2fs: fix dropping inmemory pages in a wrong time

When one reader closes its file while the other writer is doing atomic writes,
f2fs_release_file drops atomic data resulting in an empty commit.
This patch fixes this wrong commit problem by checking openess of the file.

 Process0                       Process1
  open file
 start atomic write
 write data
 read data
close file
f2fs_release_file()
clear atomic data
 commit atomic write

Reported-by: Miao Xie <miaoxie@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: add BUG_ON to avoid unnecessary flow
Jaegeuk Kim [Tue, 29 Mar 2016 23:13:45 +0000 (16:13 -0700)]
f2fs: add BUG_ON to avoid unnecessary flow

This patch adds BUG_ON instead of retrying loop.
In the case of node pages, we already got this inode page, but unlocked it.
By the fact that we don't truncate any node pages in operations, the page's
mapping should be unchangeable.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: use PGP_LOCK to check its truncation
Jaegeuk Kim [Wed, 30 Mar 2016 18:25:31 +0000 (11:25 -0700)]
f2fs: use PGP_LOCK to check its truncation

Previously, after trylock_page is succeeded, it doesn't check its mapping.
In order to fix that, we can just give PGP_LOCK to pagecache_get_page.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: fix to convert inline directory correctly
Chao Yu [Mon, 22 Feb 2016 10:29:18 +0000 (18:29 +0800)]
f2fs: fix to convert inline directory correctly

With below serials, we will lose parts of dirents:

1) mount f2fs with inline_dentry option
2) echo 1 > /sys/fs/f2fs/sdX/dir_level
3) mkdir dir
4) touch 180 files named [1-180] in dir
5) touch 181 in dir
6) echo 3 > /proc/sys/vm/drop_caches
7) ll dir

ls: cannot access 2: No such file or directory
ls: cannot access 4: No such file or directory
ls: cannot access 5: No such file or directory
ls: cannot access 6: No such file or directory
ls: cannot access 8: No such file or directory
ls: cannot access 9: No such file or directory
...
total 360
drwxr-xr-x 2 root root 4096 Feb 19 15:12 ./
drwxr-xr-x 3 root root 4096 Feb 19 15:11 ../
-rw-r--r-- 1 root root    0 Feb 19 15:12 1
-rw-r--r-- 1 root root    0 Feb 19 15:12 10
-rw-r--r-- 1 root root    0 Feb 19 15:12 100
-????????? ? ?    ?       ?            ? 101
-????????? ? ?    ?       ?            ? 102
-????????? ? ?    ?       ?            ? 103
...

The reason is: when doing the inline dir conversion, we didn't consider
that directory has hierarchical hash structure which can be configured
through sysfs interface 'dir_level'.

By default, dir_level of directory inode is 0, it means we have one bucket
in hash table located in first level, all dirents will be hashed in this
bucket, so it has no problem for us to do the duplication simply between
inline dentry page and converted normal dentry page.

However, if we configured dir_level with the value N (greater than 0), it
will expand the bucket number of first level hash table by 2^N - 1, it
hashs dirents into different buckets according their hash value, if we
still move all dirents to first bucket, it makes incorrent locating for
inline dirents, the result is, although we can iterate all dirents through
->readdir, we can't stat some of them in ->lookup which based on hash
table searching.

This patch fixes this issue by rehashing dirents into correct position
when converting inline directory.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: show current mount status
Jaegeuk Kim [Fri, 18 Mar 2016 16:46:10 +0000 (09:46 -0700)]
f2fs: show current mount status

This patch remains the current mount status to f2fs status info.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: treat as a normal umount when remounting ro
Jaegeuk Kim [Thu, 24 Mar 2016 17:29:39 +0000 (10:29 -0700)]
f2fs: treat as a normal umount when remounting ro

When user remounts f2fs as read-only, we can mark the checkpoint as umount.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: give -EINVAL for norecovery and rw mount
Jaegeuk Kim [Wed, 23 Mar 2016 23:12:58 +0000 (16:12 -0700)]
f2fs: give -EINVAL for norecovery and rw mount

Once detecting something to recover, f2fs should stop mounting, given norecovery
and rw mount options.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: recover superblock at RW remounts
Jaegeuk Kim [Thu, 24 Mar 2016 00:05:27 +0000 (17:05 -0700)]
f2fs: recover superblock at RW remounts

This patch adds a sbi flag, SBI_NEED_SB_WRITE, which indicates it needs to
recover superblock when (re)mounting as RW. This is set only when f2fs is
mounted as RO.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: give RO message when recovering superblock
Jaegeuk Kim [Wed, 23 Mar 2016 17:42:01 +0000 (10:42 -0700)]
f2fs: give RO message when recovering superblock

When one of superblocks is missing, f2fs recovers it with the valid one.
But, even if f2fs is mounted as RO, we'd better notify that too.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agoMerge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
Linus Torvalds [Fri, 15 Apr 2016 02:53:46 +0000 (19:53 -0700)]
Merge branch 'x86-urgent-for-linus' of git://git./linux/kernel/git/tip/tip

Pull x86 fixes from Ingo Molnar:
 "Misc fixes: a binutils fix, an lguest fix, an mcelog fix and a missing
  documentation fix"

* 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/mce: Avoid using object after free in genpool
  lguest, x86/entry/32: Fix handling of guest syscalls using interrupt gates
  x86/build: Build compressed x86 kernels as PIE
  x86/mm/pkeys: Add missing Documentation

8 years agoMerge branch 'mm-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
Linus Torvalds [Fri, 15 Apr 2016 02:31:34 +0000 (19:31 -0700)]
Merge branch 'mm-urgent-for-linus' of git://git./linux/kernel/git/tip/tip

Pull mm gup cleanup from Ingo Molnar:
 "This removes the ugly get-user-pages API hack, now that all upstream
  code has been migrated to it"

("ugly" is putting it mildly. But it worked.. - Linus)

* 'mm-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  mm/gup: Remove the macro overload API migration helpers from the get_user*() APIs

8 years agoMerge tag 'dm-4.6-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
Linus Torvalds [Fri, 15 Apr 2016 02:07:45 +0000 (19:07 -0700)]
Merge tag 'dm-4.6-fixes' of git://git./linux/kernel/git/device-mapper/linux-dm

Pull device mapper fixes from Mike Snitzer:

 - fix a 4.6-rc1 bio-based DM 'struct dm_target_io' leak in an error
   path

 - stable@ fix for DM cache metadata's READ_LOCK macros that were
   incorrectly returning error if the block manager was in read-only
   mode; also cleanup multi-statement macros to use do {} while(0)

* tag 'dm-4.6-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
  dm cache metadata: fix READ_LOCK macros and cleanup WRITE_LOCK macros
  dm: fix dm_target_io leak if clone_bio() returns an error

8 years agoMerge tag 'pwm/for-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry...
Linus Torvalds [Fri, 15 Apr 2016 02:02:06 +0000 (19:02 -0700)]
Merge tag 'pwm/for-4.6-rc4' of git://git./linux/kernel/git/thierry.reding/linux-pwm

Pull pwm fix from Thierry Reding:
 "A single one-line fix to turn the regmap cache from an RB-tree to a
  flat cache to avoid lockdep and abort issues"

* tag 'pwm/for-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm:
  pwm: fsl-ftm: Use flat regmap cache

8 years agoMerge tag 'sound-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
Linus Torvalds [Fri, 15 Apr 2016 01:47:51 +0000 (18:47 -0700)]
Merge tag 'sound-4.6-rc4' of git://git./linux/kernel/git/tiwai/sound

Pull sound fixes from Takashi Iwai:
 "We've had a very calm development cycle, so far.  Here are the few
  fixes for HD-audio and USB-audio, all of which are small and easy"

* tag 'sound-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound:
  ALSA: hda - Fix inconsistent monitor_present state until repoll
  ALSA: hda - Fix regression of monitor_present flag in eld proc file
  ALSA: usb-audio: Skip volume controls triggers hangup on Dell USB Dock
  ALSA: hda/realtek - Enable the ALC292 dock fixup on the Thinkpad T460s
  ALSA: sscape: Use correct format identifier for size_t
  ALSA: usb-audio: Add a quirk for Plantronics BT300
  ALSA: usb-audio: Add a sample rate quirk for Phoenix Audio TMX320
  ALSA: hda - Bind with i915 only when Intel graphics is present

8 years agoMerge branch 'mailbox-devel' of git://git.linaro.org/landing-teams/working/fujitsu...
Linus Torvalds [Fri, 15 Apr 2016 01:40:47 +0000 (18:40 -0700)]
Merge branch 'mailbox-devel' of git://git.linaro.org/landing-teams/working/fujitsu/integration

Pull mailbox fixes from Jussi Brar:
 "Misc fixes:

  mailbox-test driver:
   - prevent memory leak and another cosmetic change

  mailbox:
   - change the returned error code

  Xgene driver:
   - return -ENOMEM instead of PTR_ERR for failed devm_kzalloc"

* 'mailbox-devel' of git://git.linaro.org/landing-teams/working/fujitsu/integration:
  mailbox: Stop using ENOSYS for anything other than unimplemented syscalls
  mailbox: mailbox-test: Prevent memory leak
  mailbox: mailbox-test: Use more consistent format for calling copy_from_user()
  mailbox: xgene-slimpro: Fix wrong test for devm_kzalloc

8 years agoMerge tag 'for-linus-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeu...
Linus Torvalds [Fri, 15 Apr 2016 01:22:42 +0000 (18:22 -0700)]
Merge tag 'for-linus-4.6-rc4' of git://git./linux/kernel/git/jaegeuk/f2fs

Pull f2fs/fscrypto fixes from Jaegeuk Kim:
 "In addition to f2fs/fscrypto fixes, I've added one patch which
  prevents RCU mode lookup in d_revalidate, as Al mentioned.

  These patches fix f2fs and fscrypto based on -rc3 bug fixes in ext4
  crypto, which have not yet been fully propagated as follows.

   - use of dget_parent and file_dentry to avoid crashes
   - disallow RCU-mode lookup in d_invalidate
   - disallow -ENOMEM in the core data encryption path"

* tag 'for-linus-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs:
  ext4/fscrypto: avoid RCU lookup in d_revalidate
  fscrypto: don't let data integrity writebacks fail with ENOMEM
  f2fs: use dget_parent and file_dentry in f2fs_file_open
  fscrypto: use dget_parent() in fscrypt_d_revalidate()

8 years agoMerge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Linus Torvalds [Fri, 15 Apr 2016 01:15:40 +0000 (18:15 -0700)]
Merge branch 'linus' of git://git./linux/kernel/git/herbert/crypto-2.6

Pull crypto fixes from Herbert Xu:
 "This fixes an NFS regression caused by the skcipher/hash conversion in
  sunrpc.  It also fixes a build problem in certain configurations with
  bcm63xx"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
  hwrng: bcm63xx - fix device tree compilation
  sunrpc: Fix skcipher/shash conversion

8 years agoMerge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
Linus Torvalds [Fri, 15 Apr 2016 01:03:29 +0000 (18:03 -0700)]
Merge branch 'for-linus' of git://git./linux/kernel/git/jmorris/linux-security

Pull keys bugfixes from James Morris:
 "Two bugfixes for Keys related code"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
  ASN.1: fix open failure check on headername
  assoc_array: don't call compare_object() on a node

8 years agodm cache metadata: fix READ_LOCK macros and cleanup WRITE_LOCK macros
Mike Snitzer [Tue, 12 Apr 2016 16:14:46 +0000 (12:14 -0400)]
dm cache metadata: fix READ_LOCK macros and cleanup WRITE_LOCK macros

The READ_LOCK macro was incorrectly returning -EINVAL if
dm_bm_is_read_only() was true -- it will always be true once the cache
metadata transitions to read-only by dm_cache_metadata_set_read_only().

Wrap READ_LOCK and WRITE_LOCK multi-statement macros in do {} while(0).
Also, all accesses of the 'cmd' argument passed to these related macros
are now encapsulated in parenthesis.

A follow-up patch can be developed to eliminate the use of macros in
favor of pure C code.  Avoiding that now given that this needs to apply
to stable@.

Reported-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Fixes: d14fcf3dd79 ("dm cache: make sure every metadata function checks fail_io")
Cc: stable@vger.kernel.org
8 years ago/proc/iomem: only expose physical resource addresses to privileged users
Linus Torvalds [Thu, 14 Apr 2016 19:05:37 +0000 (12:05 -0700)]
/proc/iomem: only expose physical resource addresses to privileged users

In commit c4004b02f8e5b ("x86: remove the kernel code/data/bss resources
from /proc/iomem") I was hoping to remove the phyiscal kernel address
data from /proc/iomem entirely, but that had to be reverted because some
system programs actually use it.

This limits all the detailed resource information to properly
credentialed users instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8 years agopci-sysfs: use proper file capability helper function
Linus Torvalds [Thu, 14 Apr 2016 19:00:21 +0000 (12:00 -0700)]
pci-sysfs: use proper file capability helper function

The PCI config access checked the file capabilities correctly, but used
the itnernal security capability check rather than the helper function
that is actually meant for that.

The security_capable() has unusual return values and is not meant to be
used elsewhere (the only other use is in the capability checking
functions that we actually intend people to use, and this odd PCI usage
really stood out when looking around the capability code.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8 years agoMake file credentials available to the seqfile interfaces
Linus Torvalds [Thu, 14 Apr 2016 18:22:00 +0000 (11:22 -0700)]
Make file credentials available to the seqfile interfaces

A lot of seqfile users seem to be using things like %pK that uses the
credentials of the current process, but that is actually completely
wrong for filesystem interfaces.

The unix semantics for permission checking files is to check permissions
at _open_ time, not at read or write time, and that is not just a small
detail: passing off stdin/stdout/stderr to a suid application and making
the actual IO happen in privileged context is a classic exploit
technique.

So if we want to be able to look at permissions at read time, we need to
use the file open credentials, not the current ones.  Normal file
accesses can just use "f_cred" (or any of the helper functions that do
that, like file_ns_capable()), but the seqfile interfaces do not have
any such options.

It turns out that seq_file _does_ save away the user_ns information of
the file, though.  Since user_ns is just part of the full credential
information, replace that special case with saving off the cred pointer
instead, and suddenly seq_file has all the permission information it
needs.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8 years agoRevert "x86: remove the kernel code/data/bss resources from /proc/iomem"
Linus Torvalds [Thu, 14 Apr 2016 18:18:57 +0000 (11:18 -0700)]
Revert "x86: remove the kernel code/data/bss resources from /proc/iomem"

This reverts commit c4004b02f8e5b9ce357a0bb1641756cc86962664.

Sadly, my hope that nobody would actually use the special kernel entries
in /proc/iomem were dashed by kexec.  Which reads /proc/iomem explicitly
to find the kernel base address.  Nasty.

Anyway, that means we can't do the sane and simple thing and just remove
the entries, and we'll instead have to mask them out based on permissions.

Reported-by: Zhengyu Zhang <zhezhang@redhat.com>
Reported-by: Dave Young <dyoung@redhat.com>
Reported-by: Freeman Zhang <freeman.zhang1992@gmail.com>
Reported-by: Emrah Demir <ed@abdsec.com>
Reported-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8 years agopwm: fsl-ftm: Use flat regmap cache
Stefan Agner [Thu, 21 Jan 2016 02:56:22 +0000 (18:56 -0800)]
pwm: fsl-ftm: Use flat regmap cache

Use flat regmap cache to avoid lockdep warning at probe:

[    0.697285] WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:2755 lockdep_trace_alloc+0x15c/0x160()
[    0.697449] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))

The RB-tree regmap cache needs to allocate new space on first writes.
However, allocations in an atomic context (e.g. when a spinlock is held)
are not allowed. The function regmap_write calls map->lock, which
acquires a spinlock in the fast_io case. Since the pwm-fsl-ftm driver
uses MMIO, the regmap bus of type regmap_mmio is being used which has
fast_io set to true.

The MMIO space of the pwm-fsl-ftm driver is reasonable condense, hence
using the much faster flat regmap cache is anyway the better choice.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
8 years agoMerge tag 'sh-fixes-4.6-rc1' of git://git.libc.org/linux-sh
Linus Torvalds [Wed, 13 Apr 2016 20:02:06 +0000 (13:02 -0700)]
Merge tag 'sh-fixes-4.6-rc1' of git://git.libc.org/linux-sh

Pull arch/sh fixes from Rich Felker:
 "Fixes for two arch/sh build regressions that appeared in 4.6-rc1, one
  introduced by me, and one caused by changes elsewhere"

* tag 'sh-fixes-4.6-rc1' of git://git.libc.org/linux-sh:
  sh: fix function signature of cpu_coregroup_mask to match pointer type
  sh: fix smp-shx3 build regression from removal of arch localtimer

8 years agoMerge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
Linus Torvalds [Wed, 13 Apr 2016 15:58:32 +0000 (08:58 -0700)]
Merge branch 'for-linus' of git://git./linux/kernel/git/gerg/m68knommu

Pull m68knommu/coldfire fix from Greg Ungerer:
 "Only a single change that removes a local arch specific gpio bus sysfs
  device that now clashes with the generic gpio bus sysfs device
  interface"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu:
  m68k/gpio: remove arch specific sysfs bus device

8 years agoMerge tag 'armsoc-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Linus Torvalds [Wed, 13 Apr 2016 15:57:18 +0000 (08:57 -0700)]
Merge tag 'armsoc-fixes' of git://git./linux/kernel/git/arm/arm-soc

Pull ARM SoC fixes from Olof Johansson:
 "A batch of fixes for -rc4, for various platforms.

  Nothing really substantial and worth pointing out in particular; small
  fixes for various bugs, see shortlog for details"

* tag 'armsoc-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc:
  ARM: sa1100: remove references to the defunct handhelds.org
  bus: uniphier-system-bus: fix condition of overlap check
  ARM: uniphier: drop weird sizeof()
  ARM: dts: am335x-baltos-ir5221: fix cpsw_emac0 link type
  ARM: OMAP: Correct interrupt type for ARM TWD
  ARM: DRA722: Add ID detect for Silicon Rev 2.0
  ARM: dts: am43xx: fix edma memcpy channel allocation
  ARM: dts: AM43x-epos: Fix clk parent for synctimer
  ARM: OMAP2: Fix up interconnect barrier initialization for DRA7
  documentation: Fix pinctrl documentation for Meson8 / Meson8b
  ARM: dts: amlogic: Split pinctrl device for Meson8 / Meson8b
  ARM: mvebu: Correct unit address for linksys
  bus: mvebu-mbus: use %pa to print phys_addr_t
  arm64: dts: vulcan: Update PCI ranges
  ARM: u8500_defconfig: turn on the Synaptics RMI4 driver
  ARM: pxa: fix the number of DMA requestor lines
  ARM: OMAP2+: hwmod: Fix updating of sysconfig register
  ARM: OMAP2+: Use srst_udelay for USB on dm814x

8 years agoMerge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Linus Torvalds [Wed, 13 Apr 2016 15:53:26 +0000 (08:53 -0700)]
Merge tag 'for-linus' of git://git./virt/kvm/kvm

Pull KVM fixes from Radim Krčmář:
 "ARM fixes:
   - Wrong indentation in the PMU code from the merge window
   - A long-time bug occuring with running ntpd on the host, candidate
     for stable
   - Properly handle (and warn about) the unsupported configuration of
     running on systems with less than 40 bits of PA space
   - More fixes to the PM and hotplug notifier stuff from the merge
     window

  x86:
   - leak of guest xcr0 (typically shows up as SIGILL)
   - new maintainer (who is sending the pull request too)
   - fix for merge window regression
   - fix for guest CPUID"

Paolo Bonzini points out:
 "For the record, this tag is signed by me because I prepared the pull
  request.  Further pull requests for 4.6 will be signed and sent out by
  Radim directly"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
  KVM: x86: mask CPUID(0xD,0x1).EAX against host value
  kvm: x86: do not leak guest xcr0 into host interrupt handlers
  KVM: MMU: fix permission_fault()
  KVM: new maintainer on the block
  arm64: KVM: unregister notifiers in hyp mode teardown path
  arm64: KVM: Warn when PARange is less than 40 bits
  KVM: arm/arm64: Handle forward time correction gracefully
  arm64: KVM: Add braces to multi-line if statement in virtual PMU code

8 years agox86/mce: Avoid using object after free in genpool
Tony Luck [Wed, 6 Apr 2016 08:05:16 +0000 (10:05 +0200)]
x86/mce: Avoid using object after free in genpool

When we loop over all queued machine check error records to pass them
to the registered notifiers we use llist_for_each_entry(). But the loop
calls gen_pool_free() for the entry in the body of the loop - and then
the iterator looks at node->next after the free.

Use llist_for_each_entry_safe() instead.

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org>
Cc: Gong Chen <gong.chen@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-edac <linux-edac@vger.kernel.org>
Link: http://lkml.kernel.org/r/0205920@agluck-desk.sc.intel.com
Link: http://lkml.kernel.org/r/1459929916-12852-4-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
8 years agoALSA: hda - Fix inconsistent monitor_present state until repoll
Takashi Iwai [Wed, 13 Apr 2016 07:45:53 +0000 (09:45 +0200)]
ALSA: hda - Fix inconsistent monitor_present state until repoll

While the previous commit fixed the missing monitor_present flag
update, it may be still in an inconsistent state while the driver
repolls: the flag itself is updated, but the eld_valid flag and the
contents don't follow until the repoll finishes (and may be repeated
for a few times).

The basic problem is that pin_eld->monitor_present is updated in the
caller side.  This should have been updated only in update_eld().  So,
the proper fix is to avoid accessing pin_eld but only spec->temp_eld.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
8 years agoALSA: hda - Fix regression of monitor_present flag in eld proc file
Hyungwon Hwang [Wed, 13 Apr 2016 00:27:39 +0000 (09:27 +0900)]
ALSA: hda - Fix regression of monitor_present flag in eld proc file

The commit [bd48128539ab: ALSA: hda - Fix forgotten HDMI
monitor_present update] covered the missing update of monitor_present
flag, but this caused a regression for devices without the i915 eld
notifier.  Since the old code supposed that pin_eld->monitor_present
was updated by the caller side, the hdmi_present_sense_via_verbs()
doesn't update the temporary eld->monitor_present but only
pin_eld->monitor_present, which is now overridden in update_eld().

The fix is to update pin_eld->monitor_present as well before calling
update_eld().

Note that this may still leave monitor_present flag in an inconsistent
state when the driver repolls, but this is at least the old behavior.
More proper fix will follow in the later patch.

Fixes: bd48128539ab ('ALSA: hda - Fix forgotten HDMI monitor_present update')
Signed-off-by: Hyungwon Hwang <hyungwon.hwang7@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
8 years agoext4/fscrypto: avoid RCU lookup in d_revalidate
Jaegeuk Kim [Tue, 12 Apr 2016 23:05:36 +0000 (16:05 -0700)]
ext4/fscrypto: avoid RCU lookup in d_revalidate

As Al pointed, d_revalidate should return RCU lookup before using d_inode.
This was originally introduced by:
commit 34286d666230 ("fs: rcu-walk aware d_revalidate method").

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: stable <stable@vger.kernel.org>
8 years agoMerge tag 'keys-fixes-20160412' of git://git.kernel.org/pub/scm/linux/kernel/git...
James Morris [Wed, 13 Apr 2016 01:06:52 +0000 (11:06 +1000)]
Merge tag 'keys-fixes-20160412' of git://git./linux/kernel/git/dhowells/linux-fs into for-linus

8 years agoMerge tag 'mvebu-fixes-4.6-1' of git://git.infradead.org/linux-mvebu into fixes
Olof Johansson [Tue, 12 Apr 2016 19:35:07 +0000 (12:35 -0700)]
Merge tag 'mvebu-fixes-4.6-1' of git://git.infradead.org/linux-mvebu into fixes

mvebu fixes for 4.6 (part 1)

- fix USB adress register for Linksys Armada 388 based boards
- fix build warning in mvebu-mbus

* tag 'mvebu-fixes-4.6-1' of git://git.infradead.org/linux-mvebu:
  ARM: mvebu: Correct unit address for linksys
  bus: mvebu-mbus: use %pa to print phys_addr_t

Signed-off-by: Olof Johansson <olof@lixom.net>
8 years agoARM: sa1100: remove references to the defunct handhelds.org
Linus Walleij [Mon, 4 Apr 2016 12:43:38 +0000 (14:43 +0200)]
ARM: sa1100: remove references to the defunct handhelds.org

The website handhelds.org has been down for a long time and is
likely never coming back online.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Olof Johansson <olof@lixom.net>
8 years agoMerge tag 'pxa-fixes-v4.6' of https://github.com/rjarzmik/linux into fixes
Olof Johansson [Tue, 12 Apr 2016 19:33:41 +0000 (12:33 -0700)]
Merge tag 'pxa-fixes-v4.6' of https://github.com/rjarzmik/linux into fixes

ARM: pxa: fixes for v4.6

There is only a single fix for dma requestor lines initial
setup, triggered by dmaengine previous fix.

* tag 'pxa-fixes-v4.6' of https://github.com/rjarzmik/linux:
  ARM: pxa: fix the number of DMA requestor lines

Signed-off-by: Olof Johansson <olof@lixom.net>
8 years agoMerge tag 'omap-for-v4.6/fixes-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
Olof Johansson [Tue, 12 Apr 2016 19:32:35 +0000 (12:32 -0700)]
Merge tag 'omap-for-v4.6/fixes-rc1' of git://git./linux/kernel/git/tmlind/linux-omap into fixes

Fixes for omaps against v4.6-rc1. Mostly minor fixes for the newer
SoCs with few board fixes and a fix for a long time hwmod bug:

- Fix cpsw_emac0 link type for baltos-ir5221
- Fix interrupt type for TWD
- Fix edma memcpy channel allocation for am43x
- Fix am43x-epos sycntimer32k by using the correct assigned clock
- Fix interconnect barrier for dra7
- Fix a long time hwmod bug for updating sysconfig register properly
- Fix flakey booting on dm814x where USB reset needs a delay

And there is one minor change that is not strictly a fix, but is
good to have for proper hardware detection:

- Detect dra7 silicon revision 2.0 properly

* tag 'omap-for-v4.6/fixes-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap:
  ARM: dts: am335x-baltos-ir5221: fix cpsw_emac0 link type
  ARM: OMAP: Correct interrupt type for ARM TWD
  ARM: DRA722: Add ID detect for Silicon Rev 2.0
  ARM: dts: am43xx: fix edma memcpy channel allocation
  ARM: dts: AM43x-epos: Fix clk parent for synctimer
  ARM: OMAP2: Fix up interconnect barrier initialization for DRA7
  ARM: OMAP2+: hwmod: Fix updating of sysconfig register
  ARM: OMAP2+: Use srst_udelay for USB on dm814x

Signed-off-by: Olof Johansson <olof@lixom.net>
8 years agobus: uniphier-system-bus: fix condition of overlap check
Kunihiko Hayashi [Fri, 1 Apr 2016 10:32:43 +0000 (19:32 +0900)]
bus: uniphier-system-bus: fix condition of overlap check

This patch fixes condition whether the specified address ranges
overlap each other.

Fixes: 4b7f48d395a7 ("bus: uniphier-system-bus: add UniPhier System Bus driver")
Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Olof Johansson <olof@lixom.net>
8 years agoARM: uniphier: drop weird sizeof()
Masahiro Yamada [Fri, 25 Mar 2016 02:14:02 +0000 (11:14 +0900)]
ARM: uniphier: drop weird sizeof()

My intention was to ioremap a 4-byte register.  Coincidentally enough,
sizeof(SZ_4) equals to SZ_4, but this code is weird anyway.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Olof Johansson <olof@lixom.net>
8 years agofscrypto: don't let data integrity writebacks fail with ENOMEM
Jaegeuk Kim [Mon, 11 Apr 2016 22:51:57 +0000 (15:51 -0700)]
fscrypto: don't let data integrity writebacks fail with ENOMEM

This patch fixes the issue introduced by the ext4 crypto fix in a same manner.
For F2FS, however, we flush the pending IOs and wait for a while to acquire free
memory.

Fixes: c9af28fdd4492 ("ext4 crypto: don't let data integrity writebacks fail with ENOMEM")
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs: use dget_parent and file_dentry in f2fs_file_open
Jaegeuk Kim [Mon, 11 Apr 2016 22:15:38 +0000 (15:15 -0700)]
f2fs: use dget_parent and file_dentry in f2fs_file_open

This patch synced with the below two ext4 crypto fixes together.

In 4.6-rc1, f2fs newly introduced accessing f_path.dentry which crashes
overlayfs. To fix, now we need to use file_dentry() to access that field.

Fixes: c0a37d487884 ("ext4: use file_dentry()")
Fixes: 9dd78d8c9a7b ("ext4: use dget_parent() in ext4_file_open()")
Cc: Miklos Szeredi <mszeredi@redhat.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agofscrypto: use dget_parent() in fscrypt_d_revalidate()
Jaegeuk Kim [Mon, 11 Apr 2016 22:10:11 +0000 (15:10 -0700)]
fscrypto: use dget_parent() in fscrypt_d_revalidate()

This patch updates fscrypto along with the below ext4 crypto change.

Fixes: 3d43bcfef5f0 ("ext4 crypto: use dget_parent() in ext4_d_revalidate()")
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agoALSA: usb-audio: Skip volume controls triggers hangup on Dell USB Dock
Kailang Yang [Tue, 12 Apr 2016 02:55:03 +0000 (10:55 +0800)]
ALSA: usb-audio: Skip volume controls triggers hangup on Dell USB Dock

This is Dell usb dock audio workaround.
It was fixed the master volume keep lower.

[Some background: the patch essentially skips the controls of a couple
 of FU volumes.  Although the firmware exposes the dB and the value
 information via the usb descriptor, changing the values (we set the
 min volume as default) screws up the device.  Although this has been
 fixed in the newer firmware, the devices are shipped with the old
 firmware, thus we need the workaround in the driver side.  -- tiwai]

Signed-off-by: Kailang Yang <kailang@realtek.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
8 years agomailbox: Stop using ENOSYS for anything other than unimplemented syscalls
Lee Jones [Wed, 23 Mar 2016 14:43:43 +0000 (14:43 +0000)]
mailbox: Stop using ENOSYS for anything other than unimplemented syscalls

In accordance with e15f431fe2d5 ("errno.h: Improve ENOSYS's comment") and
91c9afaf97ee ("checkpatch.pl: new instances of ENOSYS are errors") we're
converting from the old meaning of: ENOSYS "Function not implemented" to
a more standard EINVAL.

Reported-by: Seraphin Bonnaffe <seraphin.bonnaffe@st.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
8 years agomailbox: mailbox-test: Prevent memory leak
Lee Jones [Wed, 23 Mar 2016 14:43:42 +0000 (14:43 +0000)]
mailbox: mailbox-test: Prevent memory leak

If we set the Signal twice or more, without using it as part of a message,
memory will be re-allocated and the pointer over-written.  Prevent this
potential leak by only allocating memory when there isn't any already.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>