From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 3C97634CFBA for ; Wed, 29 Apr 2026 13:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777471083; cv=none; b=Afh6FvL/eJxSnYyTVShoiuN43utRo1cLhBSzoAAAA6x76+aO4IN2aGe/KfurwH5XTXsmn5ndlXEnRXzaAqwxD/tP7qoGHFCVuqQz804HHIJYRWdcCIWYlSZGAKjigVZYDjfIKiZS++AA2vqwaY08rXRnkejerNLBqZZyCAPYoEY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777471083; c=relaxed/simple; bh=o4O58H0ZGeMt4V3P8tjk3QfVGS9Kf3VFG+pAg5emku4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TFxb9kl2Za2sg3Hr4T5WKn74HAsfzaQVZv33BZWgP0asRxKKH6BTfP1mZNZL+RlPA1Jx0IPv+rYfzRXvf/Lm3aoIr4W+z+6sysNky1uZVVKe3hCWETY+PflB7ylZsCaZhSD2hd4m1XiP0RnW30ve1HvuMDf28wn0OZO6MbkiDMA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=SVWZxGpq; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="SVWZxGpq" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-8ee9ec26edaso946214385a.2 for ; Wed, 29 Apr 2026 06:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1777471078; x=1778075878; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=J6W1snzMfnG2kF8GHWkTZnhxIV7cNBkRRyyxoL8MT8M=; b=SVWZxGpqR3DJlrYfXH442PQicZd9yIjAmDRRCuCRQbvMZqMPIG1RhmX7nLcwxZ8eZA R2Lif7IKicCBVrVz6q3g6dOyPJ9g/HVZXsVuC/tzm/coXBf07JFSGI+t4OKfe7BMPgIa 1+yVfhIeopml7CTObzE64ppoLQQwAjN/WqZgHr0RkURSgXvqQobTNhqAnQmYVnJwXTbT Af4wNLvHZwf9NLm+8t1Z8oimtzqDggiA7ucXaR1nXqB1BHbMCc3Olh2BMZQaqX7tYvq6 oa9GF7WSV9S1f2MzNfDw2dCCXM+NlYNEtXswVNTyDVBaWOZweDchykLM3YMnQ9/7BCEA f1IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777471078; x=1778075878; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J6W1snzMfnG2kF8GHWkTZnhxIV7cNBkRRyyxoL8MT8M=; b=edDiZI/ao8OuKksBFkJO0tKlC/Hn1UiLLyrv4ZFmWq271YFBn1mVr80S75aYb9H9bL cKppJvaNzHTI7VvWd/mCcgGN1WwqJLWg44nIoFRXcgyi0f3R0eJYWMp9gedQ+blNLVcI QVGTlzyAVNpIW98yiEyKJzAiiJe2vj/ZF3snS0xiC5aqPkkNa7ZlDHR2v561S5jKup1Y pZngmbmU4lQvfboXi0IJ/p/8w5tWGtSCFmpLjbrvI7Hwwzcu2BNEidT9yv8BBXVRiN8J jFvzCe23o8wx5oJdjhhLGZUeNH+PuNSjVyE/fwWlR4nv674/uDKtQs0/yxgZW+qf57+X AYBg== X-Forwarded-Encrypted: i=1; AFNElJ/qjN7E6EUpQLEqwHdJod8PrC5sseqGgHSpFHVs661ePmrwyoVo16AGYwxCaTNn4VfBTUw2z/mw7bLRykc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5dGmo0HJ/ikS0mc8iNYr0Ej5fF5drrX2bPdh5ib9nYdvyDVCL rGPQE7HmHKt9LGRXuWg2zAfziyIxaBc7wvbstwyDtr+rJDA9G/oQ4xOmnr0WRRnS1uA= X-Gm-Gg: AeBDievXSD++z7HWnylZZTN+GYw1QsWyN66uFHwwE6Tzyf01CwgLX0RO9zy+U60Ho2x VSdOtyuMAZLeqTjqzORxe+eQ8wmovBHV5AXB1UZFuIjdStL2KfFkyu4zZesHwyMQLs35yTzoNXX MiEMlUuiZb0sUs46+ZXdZo2CH1/sYmBnMWiUz2+7JSzedV4gQDoRrucj2mmpl7nuvsz0jobLqia jdeLMUiINSjrR/H181RhhKxJ6o6zsx64c0ozh0u2wd6BzWJsg8/IYsH786Uz/Fc7/wvuNoOh1rK RJNhs59TfJUTJ06s0sDGAja4iP91OeSLcnxhAgsyJXLbapiuQ910zUrJ6iyJQdgWbtDVFoNOBPD hMN09GZdI/AflsT+MR+zprJoB9Q4kpltVzFawlBYk9f+0gm9P/xxsr5D7JOGgiGIogKYKRHl5vG Ai+5DjcUoPS9RcaSjj1apq81tT4Hnn+tCULNO1jidRr4jg67S175zLN7EgNkCXi2jyDDd4QZmrR 1BD3qPkk16i0ZQR X-Received: by 2002:a05:620a:414a:b0:8cf:dd63:fae7 with SMTP id af79cd13be357-8f7d8f0e191mr1047242485a.34.1777471078348; Wed, 29 Apr 2026 06:57:58 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8f939a93224sm206336285a.0.2026.04.29.06.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 06:57:57 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wI5QL-000000007E8-1fxt; Wed, 29 Apr 2026 10:57:57 -0300 Date: Wed, 29 Apr 2026 10:57:57 -0300 From: Jason Gunthorpe To: "Boone, Max" Cc: Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Mark Bloch , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "netdev@vger.kernel.org" , "linux-rdma@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH RFC] net/mlx5: check whether VFs are assigned before disabling SR-IOV Message-ID: <20260429135757.GO849557@ziepe.ca> References: <20260428-mlx5-sriov-in-use-check-v1-1-c7b9e18c99a8@akamai.com> <20260429123833.GM849557@ziepe.ca> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 29, 2026 at 01:29:57PM +0000, Boone, Max wrote: > > On Tue, Apr 28, 2026 at 08:04:14PM +0200, Max Boone via B4 Relay wrote: > >> From: Max Boone > >> > >> When MLX5 cards are passed through to a VM, disabling SR-IOV by > >> setting the sriov_numvfs to 0 will render the machine unstable. > > > > What? How does that happen? > > Unstable is maybe a bit confusing phrasing on my part, “locks up” > might be a better description? > > In short: > - Enable by setting sriov_numvfs to positive > - vfio-pci passthrough to QEMU (or other process) > - Disable by setting sriov_numvfs to zero > - QEMU processes freeze, shell that was writing to sysfs freezes > - SIGKILL doesn’t seem to have much effect, shutdown never completes I'm not surprised, but this is definately a bug in VFIO that should be researched. And is it right that pci_vfs_assigned() doesn't fix this anyhow since only Xen activates it? > Python script to reproduce without QEMU: > - https://github.com/akamaxb/repro-vfio-sriov-removal/blob/main/vfio-sriov-bind.py > > Does: > 1. Require sriov_numvfs == 0 on the PF (report any existing users and exit if not) > 2. Add one SR-IOV VF > 3. Bind the VF to vfio-pci via driver_override + drivers_probe > 4. Open VFIO container + group, get device fd > 5. Create a KVM VM (registers an MMU notifier — required to trigger the race) > 6. Hold and wait for user input > > To trigger the bug while the script is waiting, in another terminal: > echo 0 > /sys/bus/pci/devices//sriov_numvfs > > On the vfio-pci end of it all, it prints these two lines to dmesg before it hangs: > - https://elixir.bootlin.com/linux/v7.0.1/source/drivers/vfio/pci/vfio_pci_core.c#L1826 The VFIO protocol requires userspace to implement this event channel and immediately close the VFIO FD when the driver is removed. The vfio driver unbind sleeps and waits for this. It should not hang the userspace vfio user, but you will get an unkillable process writing to the sriov_numvfs sysfs waiting on this. The above logging shows your test program doesn't implement the protocol so I don't expect it to work. vfio currently does not support a kernel lead isolation of its fds. > - https://elixir.bootlin.com/linux/v7.0.1/source/drivers/vfio/vfio_main.c#L421 And this is the above driver remove is waiting for the FD to close in response to the event. qemu is supposed to implement the event protocol, so I don't have a guess how you get a qemu to become unkillable - that seems to be the primary bug here. Would be good to know what system call qemu is stuck inside. I'd modify your test to implement the event protocol, setup an event fd to receive an interrupt on VFIO_PCI_REQ_IRQ_INDEX then trigger the teardown sequence when the eventfd triggers. That would clean out the basic flow. Jason