From nobody Mon Feb 9 09:32:41 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1A72505AF for ; Tue, 21 Oct 2025 23:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761090434; cv=none; b=YNjQBMT4VgIHSH821UJmLbpptSvJN4hwcQ9wmCGPcYjH0d5+U+jVBnjxrctmjUxcTpq7JWadzH04hYtpvaBys71aTd89ClDgbgvnbqnmeyqAFiEIQeUuq8+NEUexNgq0aMpJIhe5Yj/VLNkTCAgRJzEZQITZaPpQAiqn95yOKf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761090434; c=relaxed/simple; bh=1TJpetkZxtBQiB7nUe4Rc6HDEslWsfWsLeGiK/zQyW0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sq/1GZEwW6pxDBMlippu0rf6f1zA7ZDf4OB47J/RGAiq2MxmqHEJ2vIUMvYTExPgrwxtdt48skiekDp7eG48RF6jppzZaLEk+l4LgTRyPpLOZnOQLgEMr9067vmRSFWB4VpJQ7myN86WqCnNPSuq01jCLHRsr3NSfMzTN8pM9ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T/25T2Bd; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T/25T2Bd" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-781010ff051so4625449b3a.0 for ; Tue, 21 Oct 2025 16:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761090429; x=1761695229; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bp4Nw6yXc3Wo3rOJsEv9cE/uO6VvL+09gH92ff2ezzc=; b=T/25T2Bdj+e1EgSp8QyZaPBc6GRNHzdwS8hilo/vEDQREmT84YiYUYxl4K9+WjY4rS ZsoElTzdHbxvUMcIi+boXwJqGqzpqTaop95hmNc7uSXn9h/QJBw/MnvRqoXiF5rCkXsn /hG1Jixn+Axlett/YZcVSVz4+IdktVd7h10FBFEdozP6BlBsnKmrGqmJ1Z4VXO+JH/Os hBkKCvN4wOCEM++6PMIy62lhVrRcxdSQ5td3+47692sK4T3lNkmOEisJFK2paNLDuUcr me42/3zOs4jwDSe8/pACiPmpS0ZzBYCNJLoCHJbUqe5Bm6FGhVIC3rDXbqbRHjCWrQfv Lskw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761090429; x=1761695229; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bp4Nw6yXc3Wo3rOJsEv9cE/uO6VvL+09gH92ff2ezzc=; b=b7PWklzsqe9LhdxKZoyNKBdxBdsEQAz7F+rZzsmTxkbzdf/6bUomFMiqPzbGIFyIRL FsuRKZUUT2+cnEY632PLHpY3DID1VL1qSTPHOCIjBaoM2JNkIjExYcCzjkFX+CD6d6IZ 13eB8ZaiHAp1wnXEgNEiXR5uHjxVRRMjFapNdwb/iEEpEMc1ZRo2xTxTsqpKMoomtpbu T1n11R1cS5K9/3a9u4l3otQfjae/IbTF7xLsAgH3LmfoRU579Gx4UjtLYLKVD5nM8Bbc xQlMl37l3BF3wLle/x6zQZkAK4ZxfMEaiG/T4ew3FLOqC8FYPEQUvA9EF8bJrcBo9J/+ neNA== X-Forwarded-Encrypted: i=1; AJvYcCXr4gj+T+VSH+jojO/SczD5foAZ21cOsPogDmHx5wOeGHRYpQ1KYpHGbe5ZiM+zyZ/tQkQ9kmBVt+5qDOk=@vger.kernel.org X-Gm-Message-State: AOJu0YzrYccw7ZbgUsQDnN1E0GadgfcP27BB4ZWjNU99d+KlSeQ9JrSr nVIkdrbOmsaKncHGvsl5oAF7xcss1VAl7OIqJU850pjIOVVISsKtk9xD X-Gm-Gg: ASbGncsPRQIOPSUVJ5JePE+I6EdE8SzqFmk9cKmpwkToBxoiXxct6O+rztDJ7P7OZCF z9V8PDs78QNTiiUH8Mn1Tp/yCdXfPSFJDIqbv3ViwHv4v9TgZvAF2WQ6s+1Xud6AI05rCBh5iHr t50PbxFsdzNV4RwhY8koYc1xjQFbr8KSsOIXAqa3lgzUYuX5c4yu5AoDTRshjFP+ddM/g8ROoGd vWN3Xv6x4biMRaMxGx2dGSZ81v3n1CYxQpT/ZClqeh8DOil49hbyau2/2tGpoeGg886wzYkT0sw mAumd3UNA5sXunlvG4InmcHJjVKD2KDv7GUJJnOzOPhidQmg1+ZLP19+SPK/wR+AGhYAoq0BtGr sf/AwzZfc+0+7fIixqLZlaLmXDZhvlOkEmHgUErapFermyr1NIkKGOmr5PX7PPTHxr7SOgOtU6t WqoIno6jw= X-Google-Smtp-Source: AGHT+IFtE7kUaxGGBCIPvCA5xq+X+CjTxjkLXDamZJvTdeDWKXgLXL+jJ+B0+JzhKzpp/1MhbmJcug== X-Received: by 2002:a05:6a21:7e8a:b0:338:614f:aac4 with SMTP id adf61e73a8af0-338614fab5amr6788012637.29.1761090429512; Tue, 21 Oct 2025 16:47:09 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:5::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7a25f41ad15sm2272286b3a.41.2025.10.21.16.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 16:47:09 -0700 (PDT) From: Bobby Eshleman Date: Tue, 21 Oct 2025 16:46:54 -0700 Subject: [PATCH net-next v7 11/26] selftests/vsock: avoid multi-VM pidfile collisions with QEMU Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251021-vsock-vmtest-v7-11-0661b7b6f081@meta.com> References: <20251021-vsock-vmtest-v7-0-0661b7b6f081@meta.com> In-Reply-To: <20251021-vsock-vmtest-v7-0-0661b7b6f081@meta.com> To: Stefano Garzarella , Shuah Khan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , Broadcom internal kernel review list , Bobby Eshleman Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, berrange@redhat.com, Bobby Eshleman X-Mailer: b4 0.13.0 From: Bobby Eshleman Change QEMU to use generated pidfile names instead of just a single globally-defined pidfile. This allows multiple QEMU instances to co-exist with different pidfiles. This is required for future tests that use multiple VMs to check for CID collissions. Additionally, this also places the burden of killing the QEMU process and cleaning up the pidfile on the caller of vm_start(). To help with this, a function terminate_pidfiles() is introduced that callers use to perform the cleanup. The terminate_pidfiles() function supports multiple pidfile removals because future patches will need to process two pidfiles at a time. Signed-off-by: Bobby Eshleman --- tools/testing/selftests/vsock/vmtest.sh | 51 +++++++++++++++++++----------= ---- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selfte= sts/vsock/vmtest.sh index 29b36b4d301d..9958b3250520 100755 --- a/tools/testing/selftests/vsock/vmtest.sh +++ b/tools/testing/selftests/vsock/vmtest.sh @@ -23,7 +23,7 @@ readonly VSOCK_CID=3D1234 readonly WAIT_PERIOD=3D3 readonly WAIT_PERIOD_MAX=3D60 readonly WAIT_TOTAL=3D$(( WAIT_PERIOD * WAIT_PERIOD_MAX )) -readonly QEMU_PIDFILE=3D$(mktemp /tmp/qemu_vsock_vmtest_XXXX.pid) +readonly PIDFILE_TEMPLATE=3D/tmp/vsock_vmtest_XXXX.pid =20 # virtme-ng offers a netdev for ssh when using "--ssh", but we also need a # control port forwarded for vsock_test. Because virtme-ng doesn't support @@ -33,12 +33,6 @@ readonly QEMU_PIDFILE=3D$(mktemp /tmp/qemu_vsock_vmtest_= XXXX.pid) # add the kernel cmdline options that virtme-init uses to setup the interf= ace. readonly QEMU_TEST_PORT_FWD=3D"hostfwd=3Dtcp::${TEST_HOST_PORT}-:${TEST_GU= EST_PORT}" readonly QEMU_SSH_PORT_FWD=3D"hostfwd=3Dtcp::${SSH_HOST_PORT}-:${SSH_GUEST= _PORT}" -readonly QEMU_OPTS=3D"\ - -netdev user,id=3Dn0,${QEMU_TEST_PORT_FWD},${QEMU_SSH_PORT_FWD} \ - -device virtio-net-pci,netdev=3Dn0 \ - -device vhost-vsock-pci,guest-cid=3D${VSOCK_CID} \ - --pidfile ${QEMU_PIDFILE} \ -" readonly KERNEL_CMDLINE=3D"\ virtme.dhcp net.ifnames=3D0 biosdevname=3D0 \ virtme.ssh virtme_ssh_channel=3Dtcp virtme_ssh_user=3D$USER \ @@ -89,17 +83,6 @@ vm_ssh() { return $? } =20 -cleanup() { - if [[ -s "${QEMU_PIDFILE}" ]]; then - pkill -SIGTERM -F "${QEMU_PIDFILE}" > /dev/null 2>&1 - fi - - # If failure occurred during or before qemu start up, then we need - # to clean this up ourselves. - if [[ -e "${QEMU_PIDFILE}" ]]; then - rm "${QEMU_PIDFILE}" - fi -} =20 check_args() { local found @@ -188,10 +171,26 @@ handle_build() { popd &>/dev/null } =20 +terminate_pidfiles() { + local pidfile + + for pidfile in "$@"; do + if [[ -s "${pidfile}" ]]; then + pkill -SIGTERM -F "${pidfile}" > /dev/null 2>&1 + fi + + if [[ -e "${pidfile}" ]]; then + rm -f "${pidfile}" + fi + done +} + vm_start() { + local pidfile=3D$1 local logfile=3D/dev/null local verbose_opt=3D"" local kernel_opt=3D"" + local qemu_opts=3D"" local qemu =20 qemu=3D$(command -v "${QEMU}") @@ -201,6 +200,13 @@ vm_start() { logfile=3D/dev/stdout fi =20 + qemu_opts=3D"\ + -netdev user,id=3Dn0,${QEMU_TEST_PORT_FWD},${QEMU_SSH_PORT_FWD} \ + -device virtio-net-pci,netdev=3Dn0 \ + -device vhost-vsock-pci,guest-cid=3D${VSOCK_CID} \ + --pidfile ${pidfile} + " + if [[ "${BUILD}" -eq 1 ]]; then kernel_opt=3D"${KERNEL_CHECKOUT}" fi @@ -209,14 +215,14 @@ vm_start() { --run \ ${kernel_opt} \ ${verbose_opt} \ - --qemu-opts=3D"${QEMU_OPTS}" \ + --qemu-opts=3D"${qemu_opts}" \ --qemu=3D"${qemu}" \ --user root \ --append "${KERNEL_CMDLINE}" \ --rw &> ${logfile} & =20 if ! timeout ${WAIT_TOTAL} \ - bash -c 'while [[ ! -s '"${QEMU_PIDFILE}"' ]]; do sleep 1; done; exit 0'= ; then + bash -c 'while [[ ! -s '"${pidfile}"' ]]; do sleep 1; done; exit 0'; then die "failed to boot VM" fi } @@ -507,7 +513,8 @@ handle_build echo "1..${#ARGS[@]}" =20 log_host "Booting up VM" -vm_start +pidfile=3D"$(mktemp -u $PIDFILE_TEMPLATE)" +vm_start "${pidfile}" vm_wait_for_ssh log_host "VM booted up" =20 @@ -531,6 +538,8 @@ for arg in "${ARGS[@]}"; do cnt_total=3D$(( cnt_total + 1 )) done =20 +terminate_pidfiles "${pidfile}" + echo "SUMMARY: PASS=3D${cnt_pass} SKIP=3D${cnt_skip} FAIL=3D${cnt_fail}" echo "Log: ${LOG}" =20 --=20 2.47.3