From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144932; b=GF+VF7dKk9LYO4wheRCnF7YEVU2usuNRehOE91v9hZeu5a6aQY3XQ6dV3L+qi1k0Pqdw azlAgvQw3d4kUAZZ/jugME4KLO/lwnLjwf4BsfWuU5ZgvBoInvXAeevzyi+S5qzUZ4p79 1On+kTS4vyNga04b2VDYcGu1LRPSmDfpVNljzqIfHhCtCnTFV/8BReBzHzT/jPdHx74he 5t4icpTfMkWLIjj0KFH045h09CAdrlKYRcmgSyrmJ9DyJaIW0tCvhrHbgaoKMv35FS6um 2dxQoqsD89A3taPg5jrTIFvhAl4lPaSang8ziPFSwsGeAgMNwnxoUHCGK6MTBCpzCIQ== 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=E4N6NcL9FnmzrQEnSZZp9a4HiPMvejWPlim0Iuix62SlTSEFmuNUGrwu0UhQixXpnDV+ pxTzteq0XcOxucAkGX6VJWKiH8tQlaG2t+XEeqKu8lED/phZF+z4vnpqDXVrG8yX4fB9a MrrRMOB5iFhxbVcGcaRWeBns1iBlGWtPLD2XfDgT1wmkiPHYLCYX1WP6dNUGGw5Ci7ZZ6 zCoiYppmnVYdODehtwVtcfclm4r/L2ssFYer3xRWXRAi112hcguLm+4hgTqQUG9Hr8ZlZ bgc481cyfBqq4E5W3u5KglUlANRFRFfBJ6Olf31w4og/AmIv+vHxOdskRD9TQwBtu7w== 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.199 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 6133F606A327 for ; Tue, 1 Dec 2026 17:08:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6133F606A327 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-f199.google.com with SMTP id d9443c01a7336-2f022026e60so129363435ad.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=U/YAkptx80iOBh4FTbQNrT3MqNS/EmLHZjYvoIfO1DTLQCTjG7UmpPZkfjdSzYamFy jb6J70uLQqhDfuXJjAfzkFpuKhsO5ogBL86LtDXFtpiw9SsPQTrMRfWbfO4OEj1LwhRg Fsr7VN0jWFY1f4pN2GbvULn1aGEML+tjdhj2wZ8d9bGyEAWZRUyHfJTZ7ViN3g1N3Tt9 QmTKrtNbWjgxFSU3/TCKt733CxMAe+/w/8EojEWXIScVLgxls1hcllJb+kICcsdHFltB GJGV/jGjs5YRaK/3O4ZxN0Tj10LqfuUNOQjXvDA5T0ZsBZ8o7faEToOpjghsv4oOb8cP 3Q8g== X-Forwarded-Encrypted: i=1; AL+hErEvdQIxAE4MPz9YM30jWFRhaxpPNm3v7Tk0OraGSv24VS+cLsDdLTdnLjYJWkmmFWDU0Dc=@vger.kernel.org X-Gm-Message-State: APuU4Z9DebJCrgi2jFD8hean+kDq2j0C3OjqMgBA/tJ2tEcWZYEGvPa2 SDAXXGamibOBeIYHbA0AyRlv4wNe3X+crCVzzHM/rtUFZdu5zoB9oP8gsGnjKtGkM/2QjMrBFu7 +0WKY6mFA 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: kvm@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