From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795554304; b=fAhGN2TsIm9gdLv3Vmkj5LaqLKRjh6N66XmEe98ITzzyg8s179MO47/U3t/8L2E3sEJp KY7LwsX2MpifTwxo8DxWk6WJNND61//jCVB14qHxp7Om85mqI5JB6ybIPkF+F9YrXLEb7 gW6rTjErVBUOfC9NRSRUDIvL66UhN/0CdRFiDUlPAf6ViiwRdcXwd/lgjt0dO53VqBaFP bSD+uNAOA3gI+GZ2laTwCFpgQmB801401OgMvBgVH9ySloqgK1bscuo8/tQDQRaVb0UF7 UdcjJuAwiMq1wCnwxJYfZDatxWo4mIrsERtBVojRrTXsf/9XxSb+OgYp8wyN5Ovnc4A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795554304; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=8989DAIhEGp2+SqiqOgHbnDP3tqjvddGwcJYPtRttbc=; b=KVqMKwJF71qjfkav4WZvfyR5OU+lPyRKpBY9ejkhDsAMpjPG1QrghyGWnOZfq2ExQ5Ax 0A/+dOYp86LWErQ1BY/q7yhntBSuoHizgDKAEwQPlTBEtnyC384Kkd1vNMflQia2dR57e wCE9GNEFBndvpK/3zWpoajaD0hGzBjdAGe//BbFM7KsjbQz6mu1IwULksXOIUiNzVo0tB +dVlOe5SSyYNDTNOw6v+NPWjvmBW5aFsC7x9DiaFPvV0zhR8jnPwuufqMQD8vBqwWfJCj dl/B6eL3GaP4Yy1Wn0PFEcfI7xtoXRA62lmjBbAiPe4mid6eKAs2gi6Xjfjh0vf7QIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Zk43yelt; arc=none smtp.remote-ip=209.85.214.178 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 657A7606A323 for ; Tue, 24 Nov 2026 21:05:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 657A7606A323 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.a=rsa-sha256 header.s=20260707 header.b=Zk43yelt Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2f0afdb97abso150495ad.1 for ; Tue, 24 Nov 2026 13:05:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795554304; x=1796159104; 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=8989DAIhEGp2+SqiqOgHbnDP3tqjvddGwcJYPtRttbc=; b=Zk43yelt/tm8w8qrnUw/rYu8FoZfnG9Xcmo++SabJlb6abZbjfVjnfXI9XBZw/hv16 t9J8gTLH1sX5tjg/It/0QBr2WzKZaY4XroMeHNijrqAwKoXlcMeh8MCUjdw4+fKdt+md RJ362duEdbPSO3k5gsNh20PW+bipuMnBbFmth+eRATzNg7Dyn1iPORbToeVVtiu2b6AI hm4eeLQByAl4SS2/bYpWwJkDm00JSFY4WW83me9on7ZD4LR2C0L+7ip0ebIuUjbEEJKB R3YRFTxd2ka1it3eIloE22crT1tiIze58b8gMdGr/dFPC5uLraumWlzqrK3w/8ZePRfc zyHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795554304; x=1796159104; 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=8989DAIhEGp2+SqiqOgHbnDP3tqjvddGwcJYPtRttbc=; b=1ieH9aZTBxV3/jOLBSeVptfxypuJChMrXqsIZ8JoQR8pEGAH/pAhHFD8u6XH5XhEsf daf41Xan0CGRGUo/jmRkAMH+ZXyfUtWQJAiVb++wVgzabhxGtJ4lwyurmsq598QndgW+ 2aiMtaj5FtY1FXssV847pZbjMXhFPxUyGpm2fuvm5xnOASlEZ8WUZ8JJHRaUL+1WNZT3 dLKbB0LHJnZl3uG4Z4GBl/C2skhDIs59cJPkyITXxYFXhlXD2bYRPooWXwu7pN6jBtbd x0CUAPSeypap80nmVfgTz3LRSxV8o8WjLERCRg3N00w4GIbGuW8HjDjpTaF2YMaPlMzE FoQg== X-Forwarded-Encrypted: i=1; AL+hErFcUdMeM992ez9J+Q7vluy32xDmZMiVS5ytQFF+qDw/V1mrw+nYZQ4Zui3FZCY5YFJWIOE=@vger.kernel.org X-Gm-Message-State: APuU4Z/VbqVZx3XVlUDCO2oVg0i1+k6J1/3/zjzhZGTooHc0epSY2yfc 3fj9Bo7G+gnOPpg5ms0NEf/qXF//0uUPG8wq+mDic6ZJC9ltfF11ZFML7LrNkbyxlg== X-Gm-Gg: AZFdTZfEl+hkPlYCDwpDQTn30L4Z0tTmWyq8GaNonXPRkp8qCupW6oq7EJ2NO5VAFJG eWnqh/K9oXYgCBqA9ih4kcgpfOcwjtQsoUoO35hTOL5nSuPlQGZ+eNQa75IQA6/0mk7pyJvOMJU 3pvVSFet7RAwYDcAVk4ve+KZUUL5UYNIS2r4RCa9C+lXEoSYU1Dkech1QE8e4oFE9BNTybbKhAW dmGhvVgAuPCT2Q00Jw0xmssPYs53fg2gnylBV6OJyWXoC00cxjm5zxaJNKCyzVIqzPhpLNOlSrt lybozwE36cD+0g8D04bfToKVBTKENctV0VGak1kihYU5uei6kEUU6yxBGl1UcKhPDJGFIsqgyNX o//f+ckir6k/uL5EJCH/lzVIHqj3B0PoH3wzPPPYuoiSpLP11Z52A1YfXbv5UKvSU2A8AO0NniH ct55PuYLmJADWXPgEGMmJtwELNrxIH99rmkT5qoqgRfVXULA0UXsjbGtvukI+IJzIkrWoICaH/D AJWPtR1aZC/qBqPeDPwUbvqPfyPUyHuOiSb0uhNi39XT6qbenudhlIUcG2Prmm7V5Jvp62qFgeA afJkOAfxjv+39u8Wdv78OfksKeeCVjgUv6QsEnrTZXXFt9on9pP6xraypVmQRXvu/zfI/eHr2yN 7leh7ao0PG1pu5aAn0/PcJg== X-Received: by 2002:a17:903:3887:b0:2e2:d665:6ad8 with SMTP id d9443c01a7336-2f062b6ecb2mr14518045ad.4.1795554303196; Tue, 24 Nov 2026 13:05:03 -0800 (PST) Received: from google.com (25.75.145.34.bc.googleusercontent.com. [34.145.75.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41abb1b66sm25196583a91.1.2026.11.24.13.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 13:05:00 -0800 (PST) Date: Tue, 24 Nov 2026 21:04:57 +0000 From: Samiullah Khawaja To: Alex Williamson Cc: Bjorn Helgaas , Kevin Tian , Jason Gunthorpe , Anthony Pighin , Dave Jiang , Dan Williams , kvm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] vfio/pci: Only lock the upstream bridge if the reset may need it Message-ID: References: <20261112235700.2029562-1-skhawaja@google.com> <20261118163706.7138d246@shazbot.org> <20261119143237.4bf54796@shazbot.org> <20261124084852.661dd7c1@shazbot.org> 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 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20261124084852.661dd7c1@shazbot.org> On Tue, Nov 24, 2026 at 08:48:52AM -0700, Alex Williamson wrote: >On Fri, 20 Nov 2026 22:21:16 +0000 >Samiullah Khawaja wrote: > >> On Thu, Nov 19, 2026 at 02:32:37PM -0800, Alex Williamson wrote: >> >On Wed, 18 Nov 2026 16:37:06 -0800 >> >Alex Williamson wrote: >> > >> >> On Thu, 12 Nov 2026 23:57:00 +0000 >> >> Samiullah Khawaja wrote: >> >> >> >> > Commit 962ae6892d8b ("vfio/pci: Lock upstream bridge for >> >> > vfio_pci_core_disable()") makes vfio_pci_core_disable() trylock the >> >> > upstream bridge before resetting the device, and skips the reset if the >> >> > trylock fails. >> >> > >> >> > All VFs of a PF have the same upstream bridge. Take a device with two >> >> > VFs, both used by one process. When the process is killed, both VFs can >> >> > be released at the same time. The first one takes the bridge lock and >> >> > does its FLR, the second one fails the trylock and is never reset. >> >> > >> >> > The bridge lock is only needed for a bus reset, which is done through >> >> > the bridge. A VF is reset with FLR, and pci_parent_bus_reset() never >> >> > resets the bus for it because the PF and the other VFs are on the same >> >> > bus. >> >> > >> >> > Add pci_reset_needs_bridge_lock(), which returns true if any reset >> >> > method enabled for the device is a bus reset, and only lock the bridge >> >> > in vfio_pci_core_disable() when it does. >> >> > >> >> > Fixes: 962ae6892d8b ("vfio/pci: Lock upstream bridge for vfio_pci_core_disable()") >> >> > Cc: stable@vger.kernel.org >> >> > Signed-off-by: Samiullah Khawaja >> >> > --- >> >> > Tested in QEMU with an igb PF behind a PCIe root port, bound to vfio-pci >> >> > with two VFs. Both VFs are opened through VFIO and then closed from two >> >> > threads at the same time, counting FLRs with a kprobe on pcie_flr(). >> >> > Without this patch one VF missed its FLR in 50 of 50 rounds, with it >> >> > both VFs were reset in every round. I will send a VFIO selftest for this >> >> > separately. >> >> > --- >> >> > drivers/pci/pci.c | 28 ++++++++++++++++++++++++++++ >> >> > drivers/vfio/pci/vfio_pci_core.c | 3 ++- >> >> > include/linux/pci.h | 1 + >> >> > 3 files changed, 31 insertions(+), 1 deletion(-) >> >> > >> >> [snip] >> >> >> > + >> >> > + if (pci_reset_fn_methods[m].reset_fn == pci_reset_bus_function || >> >> > + pci_reset_fn_methods[m].reset_fn == cxl_reset_bus_function) >> >> >> >> This looks like a maintenance nightmare. What if instead we did >> >> something like: >> >> >> >> bool pci_parent_bus_reset_possible(struct pci_dev *dev) >> >> { >> >> struct pci_dev *pdev; >> >> >> >> if (pci_is_root_bus(dev->bus) || dev->subordinate || >> >> !dev->bus->self || dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) >> >> return false; >> >> >> >> list_for_each_entry(pdev, &dev->bus->devices, bus_list) >> >> if (pdev != dev) >> >> return false; >> >> >> >> return true; >> >> } >> >> EXPORT_SYMBOL_GPL(pci_parent_bus_reset_possible); >> >> >> >> static int pci_parent_bus_reset(struct pci_dev *dev, bool probe) >> >> { >> >> if (!pci_parent_bus_reset_possible(dev)) >> >> return -ENOTTY; >> >> >> >> if (probe) >> >> return 0; >> >> >> >> return pci_bridge_secondary_bus_reset(dev->bus->self); >> >> } >> >> >> >> Where we'd then condition acquiring the bridge lock on whether it's >> >> even possible for a function scoped reset to perform a bus reset. >> >> >> >> It's a bit broader of a test than whether we actually have the necessary >> >> methods in our reset_fn list, but since we're not locking the reset_fn >> >> list between test and function-reset, it's also safer. Thanks, >> > >> >After exploring Ionut's patch[1], what I propose above is probably >> >wrong. We don't have any guarantees that the sibling topology is >> >static and this bus-reset-possible function presents it as immutable. >> >The existing bus-reset function has the same race, but the gap is >> >smaller, let's not make it bigger. >> > >> >There are however immutable properties we can test that cover a fair >> >number of cases. For example: >> > >> >bool pci_reset_function_needs_bridge_lock(struct pci_dev *dev) >> >{ >> > return pci_upstream_bridge(dev) && >> > !(dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) && !dev->is_virtfn; >> >} >> >EXPORT_SYMBOL_GPL(pci_reset_function_needs_bridge_lock); >> > >> >We should be able to use this as a condition on whether we acquire the >> >bridge device lock, in pci_reset_function() and in vfio-pci code. >> >Thanks, >> >> This sounds good and it will also fix the bug that I am seeing. >> >> The only caveat is that pci_dev_wait() might fail during VF reset and >> then it might try to do a bus reset if the VF is behind a pciehp or CXL >> port. I would prefer to do it only for vfio-pci code as that is where >> the reset skip issue is. pci_reset_function() takes the lock and >> serializes the VF reset. Are you ok with doing it just for vfio-pci? > >I think the test I'm proposing precludes a bus reset, ie. there is no >upstream bridge, the device flags prevent it, or we're provided with a >VF. It's only those cases where we can't do a bus reset anyway, that >we can skip the bridge device lock. I think that means it's useful in >PCI-core as well as vfio-pci. Did I miss something? Yes, the slot reset probe doesn't account for the VFs and will allow reset of the slot when hotplug is enabled. I think that is probably a fix that needs to be done orthogonal to this. I will send a v2 of this by doing the needs_bridge_lock() as you mentioned above. > >I do see that cxl_reset_bus_function() only does a cursory test for >probe, but then calls pci_reset_bus_function() when it executes, which >is an inconsistency issue of its own. Thanks, > >Alex Thanks, Sami