Commit d795a90
mm/swapfile.c: move inode_lock out of claim_swapfile
claim_swapfile() currently keeps the inode locked when it is successful,
or the file is already swapfile (with -EBUSY). And, on the other error
cases, it does not lock the inode.
This inconsistency of the lock state and return value is quite confusing
and actually causing a bad unlock balance as below in the "bad_swap"
section of __do_sys_swapon().
This commit fixes this issue by moving the inode_lock() and IS_SWAPFILE
check out of claim_swapfile(). The inode is unlocked in
"bad_swap_unlock_inode" section, so that the inode is ensured to be
unlocked at "bad_swap". Thus, error handling codes after the locking now
jumps to "bad_swap_unlock_inode" instead of "bad_swap".
=====================================
WARNING: bad unlock balance detected!
5.5.0-rc7+ #176 Not tainted
-------------------------------------
swapon/4294 is trying to release lock (&sb->s_type->i_mutex_key) at: __do_sys_swapon+0x94b/0x3550
but there are no more locks to release!
other info that might help us debug this:
no locks held by swapon/4294.
stack backtrace:
CPU: 5 PID: 4294 Comm: swapon Not tainted 5.5.0-rc7-BTRFS-ZNS+ #176
Hardware name: ASUS All Series/H87-PRO, BIOS 2102 07/29/2014
Call Trace:
dump_stack+0xa1/0xea
print_unlock_imbalance_bug.cold+0x114/0x123
lock_release+0x562/0xed0
up_write+0x2d/0x490
__do_sys_swapon+0x94b/0x3550
__x64_sys_swapon+0x54/0x80
do_syscall_64+0xa4/0x4b0
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f15da0a0dc7
Fixes: 1638045 ("mm: set S_SWAPFILE on blockdev swap devices")
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Tested-by: Qais Youef <qais.yousef@arm.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/20200206090132.154869-1-naohiro.aota@wdc.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>1 parent 83fd69c commit d795a90
1 file changed
Lines changed: 20 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2899 | 2899 | | |
2900 | 2900 | | |
2901 | 2901 | | |
2902 | | - | |
2903 | | - | |
2904 | | - | |
2905 | | - | |
2906 | 2902 | | |
2907 | 2903 | | |
2908 | 2904 | | |
| |||
3157 | 3153 | | |
3158 | 3154 | | |
3159 | 3155 | | |
3160 | | - | |
3161 | 3156 | | |
3162 | 3157 | | |
3163 | 3158 | | |
3164 | 3159 | | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
3165 | 3166 | | |
3166 | 3167 | | |
3167 | 3168 | | |
3168 | 3169 | | |
3169 | 3170 | | |
3170 | | - | |
| 3171 | + | |
3171 | 3172 | | |
3172 | 3173 | | |
3173 | 3174 | | |
3174 | 3175 | | |
3175 | | - | |
| 3176 | + | |
3176 | 3177 | | |
3177 | 3178 | | |
3178 | 3179 | | |
3179 | 3180 | | |
3180 | 3181 | | |
3181 | 3182 | | |
3182 | | - | |
| 3183 | + | |
3183 | 3184 | | |
3184 | 3185 | | |
3185 | 3186 | | |
3186 | 3187 | | |
3187 | 3188 | | |
3188 | 3189 | | |
3189 | | - | |
| 3190 | + | |
3190 | 3191 | | |
3191 | 3192 | | |
3192 | 3193 | | |
| |||
3211 | 3212 | | |
3212 | 3213 | | |
3213 | 3214 | | |
3214 | | - | |
| 3215 | + | |
3215 | 3216 | | |
3216 | 3217 | | |
3217 | 3218 | | |
| |||
3220 | 3221 | | |
3221 | 3222 | | |
3222 | 3223 | | |
3223 | | - | |
| 3224 | + | |
3224 | 3225 | | |
3225 | 3226 | | |
3226 | 3227 | | |
| |||
3234 | 3235 | | |
3235 | 3236 | | |
3236 | 3237 | | |
3237 | | - | |
| 3238 | + | |
3238 | 3239 | | |
3239 | 3240 | | |
3240 | 3241 | | |
3241 | 3242 | | |
3242 | 3243 | | |
3243 | | - | |
| 3244 | + | |
3244 | 3245 | | |
3245 | 3246 | | |
3246 | 3247 | | |
| |||
3280 | 3281 | | |
3281 | 3282 | | |
3282 | 3283 | | |
3283 | | - | |
| 3284 | + | |
3284 | 3285 | | |
3285 | 3286 | | |
3286 | 3287 | | |
| |||
3290 | 3291 | | |
3291 | 3292 | | |
3292 | 3293 | | |
3293 | | - | |
| 3294 | + | |
3294 | 3295 | | |
3295 | 3296 | | |
3296 | 3297 | | |
| |||
3315 | 3316 | | |
3316 | 3317 | | |
3317 | 3318 | | |
| 3319 | + | |
| 3320 | + | |
3318 | 3321 | | |
3319 | 3322 | | |
3320 | 3323 | | |
3321 | 3324 | | |
3322 | 3325 | | |
3323 | 3326 | | |
3324 | 3327 | | |
| 3328 | + | |
3325 | 3329 | | |
3326 | 3330 | | |
3327 | 3331 | | |
| |||
3333 | 3337 | | |
3334 | 3338 | | |
3335 | 3339 | | |
3336 | | - | |
3337 | | - | |
3338 | | - | |
3339 | | - | |
3340 | | - | |
| 3340 | + | |
3341 | 3341 | | |
3342 | | - | |
3343 | 3342 | | |
3344 | 3343 | | |
3345 | 3344 | | |
| |||
0 commit comments