From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796338868; b=0FUGODW6x0TMIVdE+VKvuojzP+R6H0F77m0iFCruTEGVJ2u2Yv6ZqqvVIMqB7lZ+D+VC 4B3JVG4buwtHJtq/80kYAhk1t1hIzfNSU5am6ehuXhvPo96f7U1O6EBqIVL6pvZwa3je0 +TS2u1t6uMu17wXZXjIGFl4g5fAIxV2CijO7oWBTT2q+aeRPfgqyYW089oQ6yGnzlp6Z+ moekDgaYfgzOEBxFzFGh/gjZCpiKa0IrW/F42+lo+xcqZD7tvC4NDHO5iVSKvcqxefzh6 MEG+lWY5s7JsyJNpBAyIjIm+a7ArwyuGM//5wj2+Vw1bn+hnpWJAJM+uXBy/9jGWV6w== 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=0vF1LA224qvLMu7Sk49Ys3gcXJ72h+TaAox4BUynRnhpsPs/MkcrXragefAkgx/zgb2u cd9qjc/ncrEnFF/qOYwEZWre34hJnFVhGop4I5zFF4/4qVq6H7e2AMdkaNjiNGunbHOTI v5VLNleCwl3hNCyjpUTJprANIVNTidCYl4X88RxCpiNOY8mnwIiaCOzdmtJPLMVIRQLls jmU21aXB3FZ3bZXNnlwqzf2MFwEn//GEjej0NUpOzDxtGtVKFpxfXSmVUtWttySv1PyT/ e5vFuO02BnPKzy9O/Z6T9MkQ1bms80T6Tp/o7eQ9wfQxT+g10OzE21qDkcRGgFdrXqw== 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.198 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (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 34C19606A333 for ; Thu, 3 Dec 2026 23:01:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34C19606A333 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-f198.google.com with SMTP id d2e1a72fcca58-8b930598cf0so627030b3a.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=nYuJyel7k6hQTUYEsJhwoM/tPtYJl9/TtqY7NEcr3fCFyeR0tj97rCdfb8o2bw7Gv/ 76eSWdM9oeACreEiTrPswfhV41GyZ6R8O9srKO+NNFl7NLlaJltAziBayOmzh4BI+/5E pHu+m2ahIIw6VGCJPqJBG6XiuYHxeOLjyr/Fim0QTu149V65oTAHmc0Rb04eyZ1waK51 4fXMN+ASKURrNLHvRJ8IZLNSeMq/o2RfMQ0uL0eBBq/qnXa17agM4lEOSfcmtZNYG/Dt 7iWv0xLQZjw/69dGEJFQrENdNIw92VaW40pNsn6nOsd3x2G20Cc09YDIszqmY223FOAw FxSA== X-Forwarded-Encrypted: i=1; AL+hErFzomAGohjH8MXcjlQgufW6sJS/8pBvPAC4lpz81CjAjwvlhfgd/7Dfvvxalg0BIcHYy0c=@vger.kernel.org X-Gm-Message-State: APuU4Z/dyxj3K9ViE/8mNYt9BAdPFX2I8t8wlhvB3oPHrupAzdNCuggb /ENC0lQrNNPkclBwwGotbfFENKj2y+OeXjY5odioS4u0qsjJbORnwC+003CE1zf8wMwmVot8igH 5LI4iNGy2 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: kvm@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