[Bug 260793] 'swapon -a' can crash the system

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 05 Jan 2022 20:07:35 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260793

Mark Johnston <markj@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|New                         |Open

--- Comment #3 from Mark Johnston <markj@FreeBSD.org> ---
(In reply to Peter Much from comment #2)
I think swapoff should handle this scenario.  swapon -a already silently
ignores EBUSY from swapon(), which occurs when the file is already a swap
device, so it shouldn't also discard blocks in a file that is already a swap
device.  Normally the kernel wouldn't allow this, but we have:
https://github.com/freebsd/freebsd-src/blob/main/sys/vm/swap_pager.c#L3006

Perhaps swapon's swapon_trim() can check to see if a file at the path is
already in use as a swap device.  I don't think we have a good way to do that
though.  For devfs files we can compare the device number with the ones
available from the vm.swap_info sysctl, but this won't work for regular files,
I think.

Perhaps we can extend the swapon() syscall to let the kernel perform the
trimming.  Or add an IS_THIS_A_SWAP_DEVICE ioctl that swapon can check before
trying to erase the file blocks.

-- 
You are receiving this mail because:
You are the assignee for the bug.