Index | Thread | Search

From:
Yamasaki Yuu <miagetegorann@gmail.com>
Subject:
Re: need help with test: sys/vfs: stop checkalias replacing vnodes
To:
tech@openbsd.org
Date:
Wed, 11 Nov 2026 11:46:40 +0900

Download raw body.

Thread
Since "sys/vfs: stop checkalias replacing vnodes" (9274ed7885f in the
git mirror, 2026-11-08), the root swap partition is configured twice
at boot.  swapctl -A in rc now adds it a second time:

  swapctl: adding 0b85468de71a22af.b as swap device at priority 0

  $ pstat -s
  Device      512-blocks     Used    Avail Capacity  Priority
  /dev/sd0b       524256        0   524256     0%    0
  /dev/sd0b       524256        0   524256     0%    0
  Total          1048512        0  1048512     0%

GENERIC.MP built from the parent commit lists sd0b once, and
swapctl -A gets EBUSY there as before.  The duplicate is still there
at 6afb24b0786.  Seen on amd64 under QEMU with an AHCI disk.

swapmount() gets its vnode from bdevvp(), swapctl -A gets one through
namei(), and swaplist_find() compares vnode pointers.  ffs_vinit()
used to replace its vnode with the VT_NON alias returned by
checkalias(), so both were the same vnode and SWAP_ON failed with
EBUSY.  Now they are two vnodes for the same dev_t.

The same lookup is used by SWAP_OFF and SWAP_CTL, so the partition the
kernel configured can't be removed by path any more.  Of two SWAP_OFF
calls on /dev/sd0b, the first removes the entry rc added and the
second fails with ENXIO; sd0b stays in the list.  swapctl -d makes
the same call.

Both entries cover the same blocks, so paging corrupts memory.  Under
QEMU with 512 MB of RAM, a pattern test that fills and checks 560 MB
finished with no bad words on the parent commit.  On 9274ed7885f the
test program and sshd crashed during the same test.

The diff below makes swaplist_find() match block devices on swd_dev as
well.  With it on top of 6afb24b0786 (amd64 GENERIC.MP, QEMU, 512 MB of
RAM): rc no longer adds sd0b and pstat -s lists it once; a second
SWAP_ON fails with EBUSY; the pattern test finishes with no bad words;
SWAP_OFF of /dev/sd0b, SWAP_ON and SWAP_ON again (EBUSY) work.

diff --git sys/uvm/uvm_swap.c sys/uvm/uvm_swap.c
index 6c89f175f78..86021518b2e 100644
--- sys/uvm/uvm_swap.c
+++ sys/uvm/uvm_swap.c
@@ -471,7 +471,13 @@ swaplist_find(struct vnode *vp, boolean_t remove)
 	 */
 	LIST_FOREACH(spp, &swap_priority, spi_swappri) {
 		TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) {
-			if (sdp->swd_vp != vp)
+			/*
+			 * A block device can be reached through more than
+			 * one vnode, e.g. the one swapmount() got from
+			 * bdevvp() and one from namei(); match the device.
+			 */
+			if (sdp->swd_vp != vp && (vp->v_type != VBLK ||
+			    sdp->swd_dev != vp->v_rdev))
 				continue;
 			if (remove) {
 				TAILQ_REMOVE(&spp->spi_swapdev, sdp, swd_next);