From nobody Tue Feb 10 01:31:45 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 169891F0E3E for ; Thu, 23 Oct 2025 01:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761181231; cv=none; b=O0oh4LKFQElEC/Poi+taC15lE6YXBdQO9U7rgcTX2pbqrzdHM/D+K94BtahVK6H/56+A1B8LJLFN7d/gDPw6xy9zYXUjKUgpUBVpE+o8IPrPh+MD4jKqundnu/x4+CnDNJQnKB47sdXUUEC0goZL6EfVHdBVcikryOYqq/99NwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761181231; c=relaxed/simple; bh=FRgbksM3HIGYkwx36Cagrg47zhk41xhggIZrcI5RpEY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ilYZG1IYCfwBrIVPFIu0pJRCezt3xB3i/XMgmlQ8xOcUh9LblPSDv8L/RI2LzEnW/aMQZV/b0Vxy/nyBKv1fvhfv3BCJvbm+lMDbACmmbAt5NwVo2yVjEBFHSHNkQ6yRyT9XhoLY47SY+FRBbfxG8SMNTzhr6wL0fmNdydUea2c= 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=U4ss6YHl; arc=none smtp.client-ip=209.85.210.180 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="U4ss6YHl" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-781ea2cee3fso254183b3a.0 for ; Wed, 22 Oct 2025 18:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761181228; x=1761786028; 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=psdpZrmw9QO6xTkaBDSFoh7/I56QbRl0HPRaHD7JNxQ=; b=U4ss6YHladEgtC7kcVHqZgsO1MZwLwRCELSCBV/nYhsooNEz4GXej5NiogqpDNL62A X5uVsD2p+IMASJHhdPAjFKwrho30ftGsagbh1iABjCajVSqh2a4BRrbwmksEadksiB4q nzsnpaY529coywzXS0OcjjTAj739jZr5dn4N7oC//VpmvqNfE6jI3G7kzGmJoghj0hfx t21MSPqUINE39rRiMGL+FT+UVbqsVmmSF9544GFNiPEP6XwrgMKw7YdDQUAKomc5wzME xrUT8oSSd/w+sIf0WCWkXdQC4NndzTNGyvnCPm5e/JG8fTI/i/FeaL2oHV8OGHapb/RK vU2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761181228; x=1761786028; 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=psdpZrmw9QO6xTkaBDSFoh7/I56QbRl0HPRaHD7JNxQ=; b=Pwf/eN+yQs52L0nUyjy8AJ5GTHJr0UMVAt9axWWJViudmlrUPrWwcKSPaAYEyXfDIs eJ7zAK5PgYXyLVjquh3faq6wave3+WmZ2wAOho1Ef69rE1Ij1f7VGdxkL+9ghzFbydiF nKQLlMkTeqGqoLW3YlsHm8gcwEitVbvge956bAcvmYUmRJTJEcZzu5kNIMNYFmpTFHL3 rYKce6sNnQTBo68riuhZapLMsiQDfepuJPhEThsLwG624X+46ypGl+/R/6TMOp2yKaOc gfJur2n9ElnKyuvjGNDV5H6u9Ms2pYFo+KAXQ+MrnG+UG9hRaOHd54r3rzlIbUs4VNZF XVQQ== X-Forwarded-Encrypted: i=1; AJvYcCUPdSMXz9Y1BhwOqCmSbiZQQYlWJPQQf9YKOdZq8ROdi3aMV33ksEc3bEzJByLLuUOzTq4/ckkQgTKW04Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yxann2hGLFT6wkZf86b7Z9I3maVRUqwczUK3uum6t7lDlKQzkQD t+cIiokdf78xVJfPynLHlUIXxzjC55jmvCIcWEN315njd08eIrrT8Lbs X-Gm-Gg: ASbGncvVpsoRliI1H2OWF4aEAySe+TETCzZNwju/Qhw9PAhsCWf4j8HguRmwUynyQjO U96nFA1rTev3PRaR9n631O32zy/rzU59A71WkRc0eQnlT9Hzbusc28IDtqzsmNfgiM5Cf8MpHsL 5PhjMGhLzDsokgWJRNzg4F8MDeqmAO/lftFkhhLy2ZujeCaGL8wbo4TSSCzb5LpZiDXZjSFJEG6 Rjq8bSFIbS4ZVotFa/rqQPjfXzxaY8k0lKjLUGgtV/IGm5xop1HBc6+L+HAULxD60V8smRE2e6S xbHjoXETOHk3dzL2hiwNJEdEPp7/8MbHj/I48xoCjO7Se8M/Q/IDTv3JNKbfpomSNqvW3FRXSJR 5eTsL0QqeO3fa/tX8jFpMciTRMQ7hXExjz1TToZNs84kSsNVLldmH4pOVuJfZMiEYZsKnt6l2oU 2R8pqrg4k= X-Google-Smtp-Source: AGHT+IG2lMzcFjc7REx0pi6nhktqcdfljQ9tGmdpXH2R81kak7XIbbuULliQHZiUSV0Oy/z29QS5Nw== X-Received: by 2002:a05:6a00:9518:b0:782:ec0f:d273 with SMTP id d2e1a72fcca58-7a2208fe6bfmr25768343b3a.1.1761181228171; Wed, 22 Oct 2025 18:00:28 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:8::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7a274bb3bdesm563096b3a.64.2025.10.22.18.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Oct 2025 18:00:27 -0700 (PDT) From: Bobby Eshleman Date: Wed, 22 Oct 2025 18:00:08 -0700 Subject: [PATCH net-next 04/12] 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: <20251022-vsock-selftests-fixes-and-improvements-v1-4-edeb179d6463@meta.com> References: <20251022-vsock-selftests-fixes-and-improvements-v1-0-edeb179d6463@meta.com> In-Reply-To: <20251022-vsock-selftests-fixes-and-improvements-v1-0-edeb179d6463@meta.com> To: Stefano Garzarella , Shuah Khan , Bobby Eshleman , Jakub Kicinski Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, 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 | 53 +++++++++++++++++++----------= ---- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selfte= sts/vsock/vmtest.sh index 29b36b4d301d..9c72559aa894 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 } @@ -491,8 +497,6 @@ do done shift $((OPTIND-1)) =20 -trap cleanup EXIT - if [[ ${#} -eq 0 ]]; then ARGS=3D("${TEST_NAMES[@]}") else @@ -507,7 +511,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 +536,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