Subject: possible deadlock in vhost_chr_write_iter

From: syzbot <[email-masked]>
Date: Mon, 22 Jan 2018 11:58:02 -0800

Hello,

syzbot hit the following crash on linux-next commit
761914dd2975bc443024f0ec10a66a26b7186ec2 (Fri Jan 19 06:51:17 2018 +0000)
Add linux-next specific files for 20180119

So far this crash happened 19364 times on linux-next, mmots, upstream.
C reproducer is attached.
syzkaller reproducer is attached.
Raw console output is attached.
compiler: gcc (GCC) 7.1.1 20170620
.config is attached.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: [email-masked]
It will help syzbot understand when the bug is fixed. See footer for  
details.
If you forward the report, please keep this part and the footer.

audit: type=1400 audit(1516395780.240:7): avc:  denied  { map } for   
pid=3659 comm="syzkaller642612" path="/root/syzkaller642612591" dev="sda1"  
ino=16481 scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023  
tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1

============================================
WARNING: possible recursive locking detected
4.15.0-rc8-next-20180119+ #102 Not tainted
--------------------------------------------
syzkaller642612/3659 is trying to acquire lock:
  (&vq->mutex){+.+.}, at: [<000000002c447cb8>] vhost_dev_lock_vqs  
drivers/vhost/vhost.c:907 [inline]
  (&vq->mutex){+.+.}, at: [<000000002c447cb8>] vhost_process_iotlb_msg  
drivers/vhost/vhost.c:997 [inline]
  (&vq->mutex){+.+.}, at: [<000000002c447cb8>]  
vhost_chr_write_iter+0x278/0x1580 drivers/vhost/vhost.c:1046

but task is already holding lock:
  (&vq->mutex){+.+.}, at: [<000000002c447cb8>] vhost_dev_lock_vqs  
drivers/vhost/vhost.c:907 [inline]
  (&vq->mutex){+.+.}, at: [<000000002c447cb8>] vhost_process_iotlb_msg  
drivers/vhost/vhost.c:997 [inline]
  (&vq->mutex){+.+.}, at: [<000000002c447cb8>]  
vhost_chr_write_iter+0x278/0x1580 drivers/vhost/vhost.c:1046

other info that might help us debug this:
  Possible unsafe locking scenario:

        CPU0
        ----
   lock(&vq->mutex);
   lock(&vq->mutex);

  *** DEADLOCK ***

  May be due to missing lock nesting notation

1 lock held by syzkaller642612/3659:
  #0:  (&vq->mutex){+.+.}, at: [<000000002c447cb8>] vhost_dev_lock_vqs  
drivers/vhost/vhost.c:907 [inline]
  #0:  (&vq->mutex){+.+.}, at: [<000000002c447cb8>] vhost_process_iotlb_msg  
drivers/vhost/vhost.c:997 [inline]
  #0:  (&vq->mutex){+.+.}, at: [<000000002c447cb8>]  
vhost_chr_write_iter+0x278/0x1580 drivers/vhost/vhost.c:1046

stack backtrace:
CPU: 1 PID: 3659 Comm: syzkaller642612 Not tainted  
4.15.0-rc8-next-20180119+ #102
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:17 [inline]
  dump_stack+0x194/0x257 lib/dump_stack.c:53
  print_deadlock_bug kernel/locking/lockdep.c:1760 [inline]
  check_deadlock kernel/locking/lockdep.c:1804 [inline]
  validate_chain kernel/locking/lockdep.c:2400 [inline]
  __lock_acquire+0xe8f/0x3e00 kernel/locking/lockdep.c:3430
  lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:3919
  __mutex_lock_common kernel/locking/mutex.c:756 [inline]
  __mutex_lock+0x16f/0x1a80 kernel/locking/mutex.c:893
  mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:908
  vhost_dev_lock_vqs drivers/vhost/vhost.c:907 [inline]
  vhost_process_iotlb_msg drivers/vhost/vhost.c:997 [inline]
  vhost_chr_write_iter+0x278/0x1580 drivers/vhost/vhost.c:1046
  vhost_net_chr_write_iter+0x59/0x70 drivers/vhost/net.c:1372
  call_write_iter include/linux/fs.h:1775 [inline]
  new_sync_write fs/read_write.c:469 [inline]
  __vfs_write+0x684/0x970 fs/read_write.c:482
  vfs_write+0x189/0x510 fs/read_write.c:544
  SYSC_write fs/read_write.c:589 [inline]
  SyS_write+0xef/0x220 fs/read_write.c:581
  entry_SYSCALL_64_fastpath+0x29/0xa0
RIP: 0033:0x43fd79
RSP: 002b:00007ffc9b885e78 EFLAGS: 00000203 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 000000000043fd79
RDX: 0000000000000068 RSI: 0000000020baff98 RDI: 0000000000000003
RBP: 00000

---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to [email-masked].

syzbot will keep track of this bug report.
If you forgot to add the Reported-by tag, once the fix for this bug is  
merged
into any tree, please reply to this email with:
#syz fix: exact-commit-title
If you want to test a patch for this bug, please reply with:
#syz test: git://repo/address.git branch
and provide the patch inline or as an attachment.
To mark this as a duplicate of another syzbot report, please reply with:
#syz dup: exact-subject-of-another-report
If it's a one-off invalid bug report, please reply with:
#syz invalid
Note: if the crash happens again, it will cause creation of a new bug  
report.
Note: all commands must start from beginning of the line in the email body.