Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2674409rdb; Mon, 12 Feb 2024 12:27:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJ6uJSHnzkwQcVMcW3VScRnKvt24DdivWEic3XG9NTmjgjYEghCg4OFKtUUfi8yH1Yvdgq X-Received: by 2002:a05:6512:1091:b0:510:206b:e94a with SMTP id j17-20020a056512109100b00510206be94amr6815145lfg.53.1707769647119; Mon, 12 Feb 2024 12:27:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707769647; cv=pass; d=google.com; s=arc-20160816; b=voZ8KSQTxnkUlFfh4MtERCJmPRAf5ZKtxsDXJDeVg00osKV6/9fzMPQXz6tLLTXLUP s7DwRzxknG3Q2GFo+1YBcgoY14qIST3kbE7xtsaHtqK3G7KZV0VMz2UPD3ggVyP/MGFJ WnrRtQYvhTYgP4hcicl/urTYAIeOvTCodFmoqYe61/dWQejc8kbmoFEzrAQLqrqXYKmu y5I/bLcuwnIXFZRnXX8bNn5UoVRDuCUhy1Pw1sh15PTaxIEnWvxL8eJiwrhvy2IVUOqM 3cVEjMseJ9Pq5ekCmJNln5TX1YAYlVCRl+blfDIPiltx+2o+VGbG+ZdVshlyPT1RPLxU mrVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=IzSfHfB9vB6mkei1eSRaYufw4qd5wp5Iokfv9clki4E=; fh=NgqAxcFpnXXXGwxrIAj5PHpein9DE2A56kVx/4qs+/M=; b=jdFSk7Iwgeh0Kf5oEB7WitpALIOcht3QFSFAq8refKk10jX3U+c8MDTqdNhVM5n5My gkRHViRmwJf4wbEm4O9mtUpqISBC1q+ghQkUtCqugIjleLt66KzjWmWDKNiw84Rp7Q0f ZiwtupXnB1WciH3hcl+Ixx7sXDICVZZot3a2DwlnYWGx4p0CIXo8A2Tzu8xi53aA3xcc 2aYSmibOWynMwvK5Fc6ze3hMC1I4mEIqSW9YYF4G8VrA5s52Gjs4Lss3LAbCeCkdYEaF 0RPphsJaqk+MsPnAg3LN1SOB4JxV6KO5QtwJ3O3AHnlVFxuq4GKn4FoIbw8kCcqLSSaG yP6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XhINWtyy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62334-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVRzJW0YQlNbJ6EQTQATLKcYMy/KzVOVEkI21rNilgmzaOki1diDGX/U3/ZX/g1v2vX0POkQ19a/cWR/CzYjtIeWDl7sM7Z8VW9RnMQzw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g11-20020a17090613cb00b00a3bad8bd8c2si479679ejc.308.2024.02.12.12.27.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 12:27:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62334-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XhINWtyy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62334-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D54FB1F2130E for ; Mon, 12 Feb 2024 20:27:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2F19482ED; Mon, 12 Feb 2024 20:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XhINWtyy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C70AB482C0; Mon, 12 Feb 2024 20:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707769636; cv=none; b=oTeMoDMXO6FcDhtbvk81vUnDxCYzsrbITe9tuhv+tOo5+bcH8/fodtz1f1ogxEJQTz+T671Ob2ToKAtGf4SxRCmLyeI3U7EpILnATbEKomGSebbP9PAMxmHSHBsPOHW8ClkjB9I6BcAE0NmPsYiPaULzbCYY6qW+A3+f+fp9c4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707769636; c=relaxed/simple; bh=pWDQCMLUflAad9f8MUqSo1m1Bx83z4sgVK5qLQvTnNs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=tlSuF4KmbDxR/5kv47hLbGW5CmDvMmP+nIV3/nCThwP8Hj5ZOHE8bdHiqeCxGmH7g5Ad69MzMsRWNviQuwW4oNrzCRv1PI4l+rvGGYVrV6ENDAjUHfzQIy/1wtY8gypwBU1m4dXCYh49crIwJTVjK9HQkgJNBrQ6qV4mCnS8U3w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XhINWtyy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2247FC433C7; Mon, 12 Feb 2024 20:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707769636; bh=pWDQCMLUflAad9f8MUqSo1m1Bx83z4sgVK5qLQvTnNs=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=XhINWtyyG5izYAPM6w22Bfzpl14vWfSd/4cQmzY7gVGFGapkVp8U7T3lQkxHvy+q8 NIqy9EovCPqzr2RUW1H2uogAHdUz6IpNNJz0ZddA6i5WgpDITLF2DMxFMNVrl6MiEu 2Kq4b6z9CPtNBjuBAsa5hQ0X66n+eVqeCxBrRGJnpkXwg3KPhH2EFlsluY6zS9SWiD iPxr9BUhvNiVV6kGs2h2RiIYn05Sj54aalF4Xohq6cnNwSfkGl4B80O+ZJz9UV0A8l 7ZyaKuMjWctK+5+WzAypZm1TSrn8pgX15xDNhsFnq8nSQu3oz3dBQ4brokGOTs3ya7 /PPdLeK8MufYg== Date: Mon, 12 Feb 2024 14:27:14 -0600 From: Bjorn Helgaas To: Leon Romanovsky Cc: Kuppuswamy Sathyanarayanan , Jim Harris , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Gunthorpe , Alex Williamson , Pierre =?utf-8?Q?Cr=C3=A9gut?= Subject: Re: [PATCH v2 1/2] PCI/IOV: Revert "PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes" Message-ID: <20240212202714.GA1142983@bhelgaas> 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 Content-Disposition: inline In-Reply-To: <20240211084844.GA805332@unreal> On Sun, Feb 11, 2024 at 10:48:44AM +0200, Leon Romanovsky wrote: > On Fri, Feb 09, 2024 at 07:20:28PM -0800, Kuppuswamy Sathyanarayanan wrote: > > On 2/9/24 3:52 PM, Jim Harris wrote: > > > If an SR-IOV enabled device is held by vfio, and the device is removed, > > > vfio will hold device lock and notify userspace of the removal. If > > > userspace reads the sriov_numvfs sysfs entry, that thread will be blocked > > > since sriov_numvfs_show() also tries to acquire the device lock. If that > > > same thread is responsible for releasing the device to vfio, it results in > > > a deadlock. > > > > > > The proper way to detect a change to the num_VFs value is to listen for a > > > sysfs event, not to add a device_lock() on the attribute _show() in the > > > kernel. The lock was not about detecting a change; Pierre did this: ip monitor dev ${DEVICE} | grep --line-buffered "^${id}:" | while read line; do \ cat ${path}/device/sriov_numvfs; \ which I assume works by listening for sysfs events. The problem was that after the event occurred, the sriov_numvfs read got a stale value (see https://bugzilla.kernel.org/show_bug.cgi?id=202991). So I would drop this sentence because I don't think it accurately reflects the reason for 35ff867b7657. > > Since you are reverting a commit that synchronizes SysFS read > > /write, please add some comments about why it is not an > > issue anymore. > > It was never an issue, the idea that sysfs read and write should be > serialized by kernel is not correct by definition. I think it *was* an issue. The behavior Pierre observed at was clearly wrong, and we added 35ff867b7657 ("PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes") to resolve it. We should try to avoid reintroducing the problem, so I think we should probably squash these two patches and describe it as a deadlock fix instead of dismissing 35ff867b7657 as being based on false premises. It would be awesome if you had time to verify that these patches also resolve the problem you saw, Pierre. I think we should also add: Fixes: 35ff867b7657 ("PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes") as a trigger for backporting this to kernels that include 35ff867b7657. Bjorn > > > This reverts commit 35ff867b76576e32f34c698ccd11343f7d616204. > > > Revert had a small conflict, the sprintf() is now changed to sysfs_emit(). > > > > > > Link: https://lore.kernel.org/linux-pci/ZXJI5+f8bUelVXqu@ubuntu/ > > > Suggested-by: Leon Romanovsky > > > Reviewed-by: Leon Romanovsky > > > Signed-off-by: Jim Harris > > > --- > > > drivers/pci/iov.c | 8 +------- > > > 1 file changed, 1 insertion(+), 7 deletions(-) > > > > > > diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c > > > index aaa33e8dc4c9..0ca20cd518d5 100644 > > > --- a/drivers/pci/iov.c > > > +++ b/drivers/pci/iov.c > > > @@ -395,14 +395,8 @@ static ssize_t sriov_numvfs_show(struct device *dev, > > > char *buf) > > > { > > > struct pci_dev *pdev = to_pci_dev(dev); > > > - u16 num_vfs; > > > - > > > - /* Serialize vs sriov_numvfs_store() so readers see valid num_VFs */ > > > - device_lock(&pdev->dev); > > > - num_vfs = pdev->sriov->num_VFs; > > > - device_unlock(&pdev->dev); > > > > > > - return sysfs_emit(buf, "%u\n", num_vfs); > > > + return sysfs_emit(buf, "%u\n", pdev->sriov->num_VFs); > > > } > > > > > > /* > > > > > -- > > Sathyanarayanan Kuppuswamy > > Linux Kernel Developer > >