sys/dev/disk/dm: Add a comment on race on unload
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 11 Nov 2015 11:46:25 +0000 (20:46 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 12 Nov 2015 14:33:50 +0000 (23:33 +0900)
commit53a07f3ae7313aa58948a60f46428bfc2254dc3c
tree28e5e9c877754d799f0c9ce1c8a94a00af1b0fea
parent3472ce2b8a1bca797802d433bbd411a9aa5f7ac2
sys/dev/disk/dm: Add a comment on race on unload

There is a minor race window in dm_modcmd() after the below
conditional on unloading dm.ko. It's possible to create a new
device after it gets beyond the conditional with 0.

    if (dm_dev_counter > 0)
        return EBUSY;

Running the below a.sh and then b.sh concurrently causes
kernel panic. Avoiding this race seems to be difficult using
the existing locks that are all file local ones. The panic
can be reproduced with or without the previous commit.

===== a.sh
  #!/usr/local/bin/bash
  while [ 1 ]; do
      kldload dm
      kldunload dm
  done

===== b.sh
  #!/usr/local/bin/bash
  kldload dm
  while [ 1 ]; do
      dmsetup create zero1 --table '0 100 zero'
      dmsetup remove /dev/mapper/zero1
  done
sys/dev/disk/dm/device-mapper.c