From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144932; b=fMCM+BKcItO3cz71wWjWmFziNKPrWUNiFaovwFwXG5zaZnWxQqJXUyBPozPAhz+5khrn g0M659dBf14UzSAkOOv/tt8voJxaZpSX1hiL/dZzUHASTNO9mhDUwXtW4nCjGmpiYj7T+ lr6uqpoOWNhOvBQ2AB8CCHOJTcKSzekLWc0wQNhwpEer/xFYPGvwvv8ncTvqTOwChvUiC kB6hJ6OVnSs8U0iqPMXmlAnt4o7u9yW1rXmXoKkswCKS8DXQBnCy6dOXrLIhpxQ2ZRGT/ OW5TjU0AUKHny62yM8qF74hZqBbJ1U0qQkTpH/C7DH2zPwF+43vA3JuNrNvIcc3WlLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144932; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=OVi1Y8oGwuMRmslxoa5rBZoeT4nHiPho8v5/pIEoZyc=; b=yKpLVN57Sh7qMCplP+++SRbXc44wPjU6UAWdM6XWZlbirABy0tq/QrTbsF8wxYqRDSuw 6Ee2EGDgjfhMlRm23yaf6WPqQufarGzOUWTGWHniZ+pgnC+XJUUBK7wk5MouI9TDmC/7W X1xbvVY/WTyzSx0bNYxiWQaoKRkl5UAzeuOAigL7Ln0GY8qqxHCm4aPlZx+4x46n7Ve7c 7u1EoZl4PmUrsdUo3nCYojjABRu6zd7If7/0GS3y5R25XBoRi/BS+EdubcgazWO1ijRH4 8oFX+FqWJfw3InYg3k0HrfcoyItTxfkTkXgIRndVobt79i5Mpvtk61+Z76kECFZNKUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=AUjBMJqF; arc=none smtp.remote-ip=209.85.214.200 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CA3B606A689 for ; Tue, 1 Dec 2026 17:08:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CA3B606A689 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=AUjBMJqF Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2ee2d612733so90327285ad.0 for ; Tue, 01 Dec 2026 09:08:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796144931; x=1796749731; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OVi1Y8oGwuMRmslxoa5rBZoeT4nHiPho8v5/pIEoZyc=; b=AUjBMJqFWPnF9snOZiu14ayTSaJIzxg7QdH2LoUybH8MDrfiGFdT+I9uEf5p70Jl9k I8D8mcAig+wajHd0hiTqVW3PNtVaD+kt3DRbcXiJtK/KVr54bjEKAw6gb4D4vPo2f76G JKkdchtPqYbbLrWvtgdDD6QS3u4x4J4ii+GMaCfRSbMGm6pjwFmaoLQaDuW3QpOaBl8t vSaFjR+biaYDZY3IPW7BbHfrGXtOwGjl1ic1qbnggPEC1z/4j0H+wAcjonVFDwZ9Q312 19Y7kknZRK+7VB7yUxABHP5U2aOPwhM2+17KFOGuUE4iQvw+rJ4kSmZbPTbp2mVAdQcX AG3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796144931; x=1796749731; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OVi1Y8oGwuMRmslxoa5rBZoeT4nHiPho8v5/pIEoZyc=; b=Azgr//0bm3NddR8JF7aXUdMzxj2v6y01o/k48nGFbMpePmfgzNWyY8NXZmrc33TaR/ ZfuzGD/lwaR5wtDNezukFUDB4+WfC7HyIduOyLgZZMtvjXqBH20n8ntN4lsj7SfGCPZw 9holWGd7h1xqGadWOjZkth6DpXp80FLOpmF4HBWtIrIMkM1TJPVFz9GgD/t5bn3Cg8Bg bXgdcV2gOVfKxxjYyxBq2oIxazbJY4b4oCcvybzXCSuVBCcaH/sJF2hpoNs0llL4wGLK rl6rVG/Zyis76frpTKAVkZYNy1Qx2GKWigFHULR2sx96ep+v91cNnamg8ny89aEEAmH+ FsIw== X-Forwarded-Encrypted: i=1; AL+hErFT3lIXk+2SC3KnsLjaIpPpIrOpuBIPtpzQOD4PXN35DdPok7lKh3PTX4uZQ3BDNOfqrsQR01CN+dVXoes=@vger.kernel.org X-Gm-Message-State: APuU4Z98kLD8f3uaSgNfn/0mgRYhlxtDxPwpNx8Qozq3UWlmvgPZy82q suY5N9QR/fePFQZ20bhOSPuNndP9KWO8t2JN/p2htUoDWLs+SfisVr8xdY8TnXkspnlPfvBbb9a 3TKwJ77Kz X-Received: from plbmb6.prod.google.com ([2002:a17:903:986:b0:2e9:84f0:65ba]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e80a:b0:2ea:1079:e518 with SMTP id d9443c01a7336-2f03ee64ac4mr287183215ad.0.1796144931303; Tue, 01 Dec 2026 09:08:51 -0800 (PST) Date: Tue, 1 Dec 2026 17:08:48 +0000 In-Reply-To: <20261201170849.296378-1-jrhilke@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261201170849.296378-1-jrhilke@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201170849.296378-2-jrhilke@google.com> Subject: [PATCH v10 1/2] vfio: selftests: Require -f in setup.sh to unbind a bound device From: Josh Hilke To: Alex Williamson Cc: Josh Hilke , David Matlack , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Vipin Sharma Content-Type: text/plain; charset="UTF-8" Make setup.sh refuse to set up a device that is currently bound to a driver other than vfio-pci unless -f is passed. Devices that are unbound or already bound to vfio-pci do not require -f. Validate all device arguments before modifying any device so a refused device does not leave partial state behind. Also add -h to print usage and exit 0, and document -f in Documentation/driver-api/vfio-selftests.rst. Suggested-by: David Matlack Signed-off-by: Josh Hilke --- Documentation/driver-api/vfio-selftests.rst | 9 ++-- tools/testing/selftests/vfio/scripts/setup.sh | 41 +++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Documentation/driver-api/vfio-selftests.rst b/Documentation/driver-api/vfio-selftests.rst index 9d39a22519d6..cfe7a3a06602 100644 --- a/Documentation/driver-api/vfio-selftests.rst +++ b/Documentation/driver-api/vfio-selftests.rst @@ -48,12 +48,13 @@ Setting up Devices .. code-block:: sh - tools/testing/selftests/vfio/scripts/setup.sh 0000:01:00.0 + tools/testing/selftests/vfio/scripts/setup.sh [-f] 0000:01:00.0 The script handles unbinding the device from its current driver and binding it -to ``vfio-pci``. Metadata about this device is stored in -``/tmp/vfio-selftests-devices`` so that the device can be cleaned up later -(bound back to its original driver). +to ``vfio-pci``. If a device is currently bound to a driver other than +``vfio-pci``, ``setup.sh`` refuses to unbind it unless ``-f`` is passed. +Metadata about this device is stored in ``/tmp/vfio-selftests-devices`` so that +the device can be cleaned up later (bound back to its original driver). Execution --------- diff --git a/tools/testing/selftests/vfio/scripts/setup.sh b/tools/testing/selftests/vfio/scripts/setup.sh index 49a499e51cbe..7eacd301f0c7 100755 --- a/tools/testing/selftests/vfio/scripts/setup.sh +++ b/tools/testing/selftests/vfio/scripts/setup.sh @@ -3,20 +3,55 @@ set -e source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh +function usage() { + cat >&2 <&2 + while getopts "fh" opt; do + case "${opt}" in + f) force="true" ;; + h) usage; exit 0 ;; + *) usage; exit 1 ;; + esac + done + shift $((OPTIND - 1)) + + device_bdfs=("$@") + if [ ${#device_bdfs[@]} -eq 0 ]; then + usage exit 1 fi - for device_bdf in "$@"; do + for device_bdf in "${device_bdfs[@]}"; do test -d /sys/bus/pci/devices/${device_bdf} + if [ "${force}" ]; then + continue + fi + + driver=$(get_driver ${device_bdf}) + if [ "${driver}" ] && [ "${driver}" != "vfio-pci" ]; then + echo "${device_bdf} is bound to ${driver}, pass -f to unbind it." >&2 + exit 1 + fi + done + + for device_bdf in "${device_bdfs[@]}"; do device_dir=${DEVICES_DIR}/${device_bdf} if [ -d "${device_dir}" ]; then echo "${device_bdf} has already been set up, exiting." -- 2.56.1.839.g22a8290db9-goog