From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 459F3437101 for ; Mon, 10 Aug 2026 21:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786398428; cv=none; b=Q3WgcH2N2RyN6GebD27dtIWHWLFfNBBnBPW+V7QUqB1jQJhn+J19n5lqT+DDGpE4Q54JeIsWuHvN6DjVSWii+s5a8RGnwU2IBZLf30Wz9GkcaNTLdg98bW+Obttt/3c+f6Oih2lId61Lx3x73fZaZy09VMOYoGyghxyx8oPZO4w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786398428; c=relaxed/simple; bh=gLj89t1XtGHeoqqhdxlQE5veKwLUg9rzru7S0F8D1UE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XYVjVTdZ9kI8aDr/ZH5n5laY30Gb3LdkMrRTZsGr1sJZECrmDsIf0bUvF/uIb2rrl9WLFhAQX3KMY/LIyDQaQEE5Xzg6uJSEWlXNIPoInS5uH+z84oc/yDFikMFU63LP0fYSVt/fd0dBOTjtzSR6j+MqtTQvukiCY5C9ttfl3Sk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=j5g8fZCx; arc=none smtp.client-ip=209.85.214.182 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j5g8fZCx" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2cab97c86bdso17955ad.1 for ; Mon, 10 Aug 2026 14:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786398426; x=1787003226; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=qrPHJG3p8YfDYZ+uVx/4qIrGxMhgcPPKzeLgvNEMm4M=; b=j5g8fZCxB+A45oujTmVO502pCMcEluM+Yy+hlyBteMz1veLwbN3pqadrtBK6hT5oqX d2yUTrhNRkI2qZ1yPaRCYtoRAImuwYaRLyYXeR8ATb1g0hfU4ugaSrQF8yXQ0HAWb5NL ihjJUmQN2Kg2cRpyX3ICU6mJR1FejqZHySCnklE702OG9rLEJNufFyKz9tyKjte1oYPH LrgqLhxWCJGn7hEKQfEPv+RK7cDVgWV3N+NUUKccW4BiOW2sJe1U7L8aHT2+H4uT1kEK 8/zbzA2onKcT2HGBRjSF7HIbX4LzLnwKASfV+a0Y9OhcsF3B5L2cBj0ZQvHv8sjo+M0k 0iIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786398426; x=1787003226; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=qrPHJG3p8YfDYZ+uVx/4qIrGxMhgcPPKzeLgvNEMm4M=; b=ZL4BzugfNRdFpVN3+vFa3MS6dZIfhiOcJ0WS/WWCbiAmST+0Q8WvKaq8IhLLYk4rhD gdaLlWV7w6GYyXgB0TIWu03F17UiAjX9tu1nVtHow9V2EPQPh+Qjq6UKn4CmtT2NBTm2 Zg7SwkFEBLiGorQkLa9PXlelewgpgLIkJ7zIG4qXg1mDJD3BpOU7ovfLLSkEEVYrmQHi wn/vMIwPVlwP1FzI7w9XrFmVkmnpdja3XpH1uHlVp7VoFcDK3JTeToZNWFWVUhbJQnPj pjIlcmQs3FSKs4oiSGt4KZ8O0+Xo6rOHfqX6YuTxPHLeEgWslkAz+eCQYkMrqjjOqvHS OZHQ== X-Forwarded-Encrypted: i=1; AHgh+RrgyiNymziLsuWQqf8Ohe+G6RRyoKur3kNh11TgB4+USotcnMjMaV1GqKMgYKjutZ9dUSp5kw6UTXz1ihs=@vger.kernel.org X-Gm-Message-State: AOJu0YzlFhkwc3tbIMdI5XlE1wt4TdHfc7KKzcfovxkBh+0hQ8S/OnXS nomYGhFyVuvL3HGrOfg2EIBi6FinBigNFqaOzBK+G8OuNJTKmK9ReWTBEWToYmuh0g== X-Gm-Gg: AR+sD11soEg3B+rMlUFzTDfjf5TQfXfgZKmNPpHDXdvd8fneNIOEQ/nVI56O8VHh4qV oCdeu4JCxMp+MaQmMH4aDC3YUP5xtsYm1P/YS5YxYHDSqmF49RlTRxdA3FctrdI+x4JczgHQWCa H1FJO1w7CN4xx2BUGUpgpdJj6VphQZjjxq2C9QIyl92HirycX5nEaeLeZF/ccvrOt5FUiC9QYED 0pQ9DDqL3aH46FdcXUQK42Jp43CSyWBuicF5IbtmIlQDAsm/NT+Kf7uL453SW6wKn41h3R60Fzu zQR0SgeVg71YWwC86mZYudANna/0WFSIQikpfMAzp64U73TqqtPvlX60f2PjsXJKj8dHwERXPyt 9ihD9m3lzcUv1j8KrbDjjX3XbSefkBdMON507T2H0wCpgTk9exj8ayhfAnO1dR+za6kAaSn78ZR wBfhnT/Qa8Nrrdq9lXxbxPy9nw3mmZ3/aD+cF9LouhBgfHnZvl3JSeya67HFp06rVfozUi+t5T0 mxkvDZ+/xnUSvehpoawLUVug+sbTEh8806ye44xXlTxg6uUO0rSXJjPVG8= X-Received: by 2002:a17:903:b0f:b0:2c7:f0cc:dafa with SMTP id d9443c01a7336-2d312020793mr873965ad.5.1786398425735; Mon, 10 Aug 2026 14:47:05 -0700 (PDT) Received: from google.com (210.87.127.34.bc.googleusercontent.com. [34.127.87.210]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-392d51bf886sm1043442a91.7.2026.08.10.14.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 14:47:05 -0700 (PDT) Date: Mon, 10 Aug 2026 21:47:01 +0000 From: Samiullah Khawaja To: "Tian, Kevin" Cc: Alex Williamson , Jason Gunthorpe , "bhelgaas@google.com" , Leon Romanovsky , "dmatlack@google.com" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [RFC PATCH 1/1] vfio/pci: Disable sriov on PF device close Message-ID: References: <20260805003355.728299-1-skhawaja@google.com> <20260805003355.728299-2-skhawaja@google.com> 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=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: On Wed, Aug 05, 2026 at 09:34:32AM +0000, Tian, Kevin wrote: >> From: Samiullah Khawaja >> Sent: Wednesday, August 5, 2026 8:34 AM >> >> When userspace closes a VFIO device file descriptor, the vfio driver >> performs a hardware reset on the PCIe device to ensure it is returned to >> a clean state. However, if the closed device is an SR-IOV Physical >> Function (PF), it may have instantiated Virtual Functions (VFs) that are >> actively bound to host kernel drivers (or other vfio instances). >> >> When the PF is hardware-reset via VFIO, it implicitly disrupts SR-IOV >> operations at the device level. Because this reset happens without notifying >> the core PCI driver model, the kernel drivers bound to the VFs remain loaded >> and operate under the assumption that the VF hardware is still functional. >> >> This creates a state mismatch between the kernel's view of the hardware >> and the actual device state. Subsequent attempts by the host OS or bound >> drivers to interact with the VFs will fail, leading to unexpected >> errors. >> >> Disable SR-IOV on the device prior to issuing the PF reset so that the >> VFs can teardown and remove at the software level also. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/vfio/pci/vfio_pci_core.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c >> index a113c55845e1..b36c77eb3c40 100644 >> --- a/drivers/vfio/pci/vfio_pci_core.c >> +++ b/drivers/vfio/pci/vfio_pci_core.c >> @@ -826,6 +826,13 @@ void vfio_pci_core_close_device(struct vfio_device >> *core_vdev) >> #if IS_ENABLED(CONFIG_EEH) >> eeh_dev_release(vdev->pdev); >> #endif >> + >> + if (pci_num_vf(vdev->pdev)) { >> + device_lock(&vdev->pdev->dev); >> + vfio_pci_core_sriov_configure(vdev, 0); >> + device_unlock(&vdev->pdev->dev); >> + } >> + > >Sashiko reported several locking issues with this change: > >https://sashiko.dev/#/patchset/20260805003355.728299-2-skhawaja%40google.com > >Actually it is a discouraged usage allowing kernel drivers bound to VFs >which belongs to a PF owned by vfio userspace. Thanks for the feedback Kevin. I sent this as an RFC specifically to discuss the right approach for resolving this issue before fixing the locking issues that sashiko raised. I will get back to this once the discussion to fix this the right way concludes in the other thread. Thanks, Sami