From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796338868; b=ol2xvpvx/Uc1UgQCdZyDodMyNtciFQQhYZ5tjFkCIoXabLhhfMh6d8eJfCxdxdbw//eC Fmx8KQN4WJvUiAK1allCoD4sE7+MHaWwXFukRtNUerYhBZ8g1hOs1OZ4VgQDF8QGhe0I8 9OnJF/8V3LakX0oQdmxsUvfzhSioC2vZHjaq2w54sw7OLjsztgZEUGI6aVc/o2d6a/7LA eMd8HBg9PlvQZTu41ZgMktO93hrQZcdfgfHLsqdlE9+t1C4QT18e6Q4Y0Y6eKO+2UZzRu e3Tirz/cpBtgN7bj+k6SBtT3cvunznXB2J+l+86oZV4xmanCIxRRb781saiUnwLNHoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796338868; 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=5e5H5LSqszsHJYXAz87CFRemlwS2UUQ7VT0uwHAWamg=; b=CgeeQhUNoRpDUeyU6plfDMUa4ugqjOerd0PrA+yhbaePh2nLgJePqrnTConpOv6cIuRv Vhto7tY2mUipgfMzQbnc01EnbyWq1vB2THLJ206nDrXHRwbMMZAz6v3cjvqrnGcQZTk9f UGPNDKjabTfAocKY15z3VWsH4adp7h3+jFgLckwq4ghunT3kDmJivDU29CgNGcQ5Zbu2x Idx2kPco41JWbsKryz9D+62SJoDjo6bb5CL2+p/hi7fLg2cWrnpvmLe7TZ3Tp1mYUi5b9 WbiEfo+X3+VzAZ7/vu74UUQuDeIDPk2DMPz1zQd5UcB3J2DnJQfjq/1VXrnYreWgtAQ== 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=bXqcgdje; arc=none smtp.remote-ip=209.85.210.199 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.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 39113606A334 for ; Thu, 3 Dec 2026 23:01:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 39113606A334 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=bXqcgdje Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8b930598cf0so627031b3a.1 for ; Thu, 03 Dec 2026 15:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796338867; x=1796943667; 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=5e5H5LSqszsHJYXAz87CFRemlwS2UUQ7VT0uwHAWamg=; b=bXqcgdjeLM6HPQ4qh55KIt5y82SRsH0Zwhrzqun0kTq/eJaJhuww1pmsDrR7e6qwpg HBbCnHXkOF424Yi6cdaEa8k3OrqtKZk58f6tWQy+IiO/5Uwa6j3Be0QnfKkzvgfEo7Ch uRTwhN/YmOOKYKU05Fu7qgyC+EhfHr8lwIsj2gT+7nthhhbc0H7dzTt7pupyjlV1DiDI E4ndDGe3FLtz9BbmL1lidud0oubdTnLeuffWGMGBX5x7W0AzwNkt11SquH/eveBrmVhR vgEz+/rXyYR4XqXJAJtGCcQaaqeohteWIMM5jDJ5/Y5i7mA2m8RzWhQv0HhX77mpYY/f FoUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796338867; x=1796943667; 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=5e5H5LSqszsHJYXAz87CFRemlwS2UUQ7VT0uwHAWamg=; b=22n9HzySeISq50k8OEziCvIOro3HVwSPBtk/I6TbwWYGhhZNXJJAqEAVGyj3snWfZ6 vKzUF36yoVCO99U6+LMI4ISfGDbJIzvNynoCf5VzNGxBNzJCf0mGbLFXFPhDdNe8ZRI/ hfPVf6QktXyjW5X7goUwXv2IqUSuGEacVmR5pmHy4FOjlH80NpKg2Jac1dxjHRPh5Vtw n+yZyU4oPM8jvK7sSTGtXNUzY4L+sE73Rw2KuXl6JIf3bZnVlV+wVWcqEfwTEnZtJNWS +ix4ovD+3zab1CLAf6uioSEXtR9taPydPWC78sg4eBVQdjpFN/FDxjRkXyrAzeU5Ru6e OCyA== X-Forwarded-Encrypted: i=1; AL+hErFueKnqp3sYRWuXDBZ1gtEpC+gWE90XYzzq6OBDXmSGdBV4jKzGBFeX9ruoFb4RB4hHf8kGfalRDzJY7D0=@vger.kernel.org X-Gm-Message-State: APuU4Z8rNdCiC1EmXVqR/4enxWfF6ZvarErK94k9h8ZHLgF6WxilpBe7 fv4+gMvRSL4gKN7nrbO8NXYKuoufPutipvXh13uCoMhvSrde+/vhfKKH/SLAwYAysGEhjKjntLt VNIgE/HVF X-Received: from pfbjf4.prod.google.com ([2002:a05:6a00:6e44:b0:88f:3126:fa44]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:148a:b0:8b5:c1f1:e947 with SMTP id d2e1a72fcca58-8de2dfede06mr326270b3a.50.1796338867213; Thu, 03 Dec 2026 15:01:07 -0800 (PST) Date: Thu, 3 Dec 2026 23:01:05 +0000 In-Reply-To: <20261203230106.32033-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: <20261203230106.32033-1-jrhilke@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261203230106.32033-2-jrhilke@google.com> Subject: [PATCH v11 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.915.g69d5ec7298-goog