From patchwork Wed Feb 14 22:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Harris X-Patchwork-Id: 201173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp33984dyb; Wed, 14 Feb 2024 15:01:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUhAmk/KRm4PTiq0s3IAIJTRnD4Pt4ULJ38TJE7vXNNyCDtOJFid9V9B8y1zN9RWy7afzarEQ93PmBaBFY0oQXJmWJaAA== X-Google-Smtp-Source: AGHT+IGh85qKq3sl5Nt/q62sIvvQ+Hl9ix+zgLyPcqWvhI//bU+Lp2/4rzJFo8Qa8Pr9Em+67IM7 X-Received: by 2002:a05:6808:16a0:b0:3bd:bef9:84b9 with SMTP id bb32-20020a05680816a000b003bdbef984b9mr251784oib.33.1707951667009; Wed, 14 Feb 2024 15:01:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707951666; cv=pass; d=google.com; s=arc-20160816; b=t3ydDTzjTAo683p044dDeHFDaY0knslrw48LewKvRhlPYIpE8Ifsx2kKCZBmokv0io Lc8Oc/vTseQZbI+ucpuHKfmv18H9J3oom5PvFD57M7HDor4nAkBZEw+kvRYidjaDCYn2 76zfhoGtaO5huykAzbIn1CKBbFbhJ7/nt6fq3Acmq4QpBIbt7qne9q7RSCo7m2Bvk2ng MdYVgn03qi6TjaPGb1mXmY76UyilRn+aRAEw5XXABER3v4JjFJTSqYP1RRyI4XI6SCly 3ayQaRiC/hzQ5aefxKg+qs/hDjQLkwjC6rNkn1iNTAdgUzSoop4b/wVAOIwrrps3b2hP POiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:content-transfer-encoding:content-id :content-language:accept-language:in-reply-to:message-id:date :thread-index:thread-topic:subject:to:from:dkim-signature :dkim-filter; bh=NWHjQPlaGIQ9OtliJHmGY1JMnvToGgMO8MA8ryL6e5g=; fh=JCCJgeotx/m0tnisC8Wo8fH5XA3UmgP9gd185wPI8pc=; b=QLF+Dt+fqFBZNw6lgYd27xTdIncNKOs9J3FNlTrnSx6j86e4BLCRCfwCLoV3o180AD Rp2AQUAVZFFzgzFLDT5ln65xlggqSI/wmhzPZSP+AMXECuX/zp2r9d505TvXMfk1WkNw hdsd+Zpw2mx32fVrOmr6I+lEMEJMh86N1RIaqFTezWqJcDXpbZQlCkBdxQ75cyd56GOd inVM+W1bufrG2iIdNNlqJpHXvpne+M1LFCkYt7KetztbrWymfD7/3E1Vw3i6wwQM64Vo KBtZXKoXvzJ+P7+W+h/E3Pijk5lS1P2u9QX1G7TH0oGpy0wdZ/E1XXQxPIrsi2z7ECxs C3/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iISglxAa; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-66091-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66091-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f16-20020ac84710000000b0042bee82eeb1si2947qtp.633.2024.02.14.15.01.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 15:01:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66091-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iISglxAa; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-66091-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66091-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 766411C26548 for ; Wed, 14 Feb 2024 23:00:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 639091420D3; Wed, 14 Feb 2024 22:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="iISglxAa" Received: from mailout2.w2.samsung.com (mailout2.w2.samsung.com [211.189.100.12]) (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 1C5E21419B1; Wed, 14 Feb 2024 22:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.189.100.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707951593; cv=none; b=bjj6MSPI8tQMYHXecL3F54QmII+uSXRpqlT+Fx7X+goPIuEiGtviOOPgLe588tYJuS2sqiv+JROW8z+XchgMTbbJ4cfii23vkzH34k+xYh+D9/3Hx/Er36sdrQPG5L946TOrW0w0JGUf2Rdl/DnCSEb3WkPt3aCThcl1bWS4TRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707951593; c=relaxed/simple; bh=NWHjQPlaGIQ9OtliJHmGY1JMnvToGgMO8MA8ryL6e5g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=pNeGITCqI5rJPkL/Zfv9SSGJ4rUtqEtjKU4Nv29BSmWP65fsGy3zSYfEIOk0BdEKcR4FQ2Ao3z8wTCIackDWa5J/UW4h9ws4Fn4dzxQpF45+U/TMXoOHoBSPi5qKN5sVsNu5PGDesz+DnFkzw/1eWiDbr2iQtT3cCHN2D0gEnlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=iISglxAa; arc=none smtp.client-ip=211.189.100.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from uscas1p1.samsung.com (unknown [182.198.245.206]) by mailout2.w2.samsung.com (KnoxPortal) with ESMTP id 20240214225944usoutp029bb5161cc91390c85bc25f43697aa417~z3OrJ-v6e1082210822usoutp02V; Wed, 14 Feb 2024 22:59:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w2.samsung.com 20240214225944usoutp029bb5161cc91390c85bc25f43697aa417~z3OrJ-v6e1082210822usoutp02V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1707951584; bh=NWHjQPlaGIQ9OtliJHmGY1JMnvToGgMO8MA8ryL6e5g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iISglxAa5pWGqgz0yG661PwTZzPlrNEUvdZ31H5On9wxXgrN1X2iShK05O9Ks6NAx 4A4+a0CB9WUE8a0AFvmq4yiNI4BR0w08DXVbCm+5khhNoTb7+kt0mqtfnVKn83Ka8y qQDfOeaA9qQhxMTnp0HZLmDaHq7KPgQHsd7UznT0= Received: from ussmges3new.samsung.com (u112.gpu85.samsung.co.kr [203.254.195.112]) by uscas1p2.samsung.com (KnoxPortal) with ESMTP id 20240214225944uscas1p26fa9f885a7fd56b6dfe1c7f1b7945330~z3Oqvi9Qb1133111331uscas1p2K; Wed, 14 Feb 2024 22:59:44 +0000 (GMT) Received: from uscas1p2.samsung.com ( [182.198.245.207]) by ussmges3new.samsung.com (USCPEMTA) with SMTP id 78.B6.09550.0E54DC56; Wed, 14 Feb 2024 17:59:44 -0500 (EST) Received: from ussmgxs2new.samsung.com (u91.gpu85.samsung.co.kr [203.254.195.91]) by uscas1p2.samsung.com (KnoxPortal) with ESMTP id 20240214225943uscas1p21ffa8b362bac11379168b83e42159160~z3OqcL0Yr3221832218uscas1p2B; Wed, 14 Feb 2024 22:59:43 +0000 (GMT) X-AuditID: cbfec370-bbbfe7000000254e-32-65cd45e06f44 Received: from SSI-EX2.ssi.samsung.com ( [105.128.3.66]) by ussmgxs2new.samsung.com (USCPEXMTA) with SMTP id 11.D5.45319.FD54DC56; Wed, 14 Feb 2024 17:59:43 -0500 (EST) Received: from SSI-EX2.ssi.samsung.com (105.128.2.227) by SSI-EX2.ssi.samsung.com (105.128.2.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.2375.24; Wed, 14 Feb 2024 14:59:42 -0800 Received: from SSI-EX2.ssi.samsung.com ([105.128.2.227]) by SSI-EX2.ssi.samsung.com ([105.128.2.227]) with mapi id 15.01.2375.024; Wed, 14 Feb 2024 14:59:42 -0800 From: Jim Harris To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , "Alison Schofield" , Vishal Verma , Ira Weiny , Dan Williams , Kees Cook , "Gustavo A. R. Silva" , "linux-kernel@vger.kernel.org" , "linux-cxl@vger.kernel.org" , "linux-hardening@vger.kernel.org" , Leon Romanovsky , "Jason Gunthorpe" , Alex Williamson , "pierre.cregut@orange.com" Subject: [PATCH v3 1/2] PCI/IOV: Revert "PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes" Thread-Topic: [PATCH v3 1/2] PCI/IOV: Revert "PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes" Thread-Index: AQHaX5l/Y5bHR2DvZ0+eeI1J9u0GaA== Date: Wed, 14 Feb 2024 22:59:42 +0000 Message-ID: <170795158249.2393.6069168125066679172.stgit@bgt-140510-bm01.eng.stellus.in> In-Reply-To: <170795147587.2393.15577527626926144858.stgit@bgt-140510-bm01.eng.stellus.in> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-ID: <84A3C9C8FC63C94C827BCF517FA70757@ssi.samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJKsWRmVeSWpSXmKPExsWy7djX87oPXM+mGjz+yWnx7X8Pm8XdxxfY LKZPvcBoceJmI5vF6ptrGC1+XZzGarH/6XMWiyv/9jBarFp4jc3iTHeuxaYNT1gszs86xWIx b/1PRovLu+awWaz/+p7N4taEY0wOAh6zGy6yeLQcecvqsXjPSyaPTas62Tx6m9+xebQ8O8nm 8X7fVTaPqbPrPT5vkgvgjOKySUnNySxLLdK3S+DKaJqxh6Vgm0DF7cUN7A2MDQJdjJwcEgIm Ev2nd7F0MXJxCAmsZJS4fPAxlNPKJDF/8mQ2mKrNKydAJdYwSix9e58NwvnEKNF67AZUZhmj xN+fbxhBWtgENCV+XVnDBJIQEfjIKtG3Ywo7SEJYIFHi0LdbrCC2iECaxPreHhYIW0/i1/2l YM0sAqoS35r6wGp4BSIkdp76BRbnFIiS+P35BZjNKCAm8f0UyAJODmYBcYlbT+YzQdwqKLFo 9h5mCFtM4t+uh1A/KErc//4S6AYOoHpNifW79CFa7SQm3bnABmErSkzpfsgOsVZQ4uTMJywQ rZISB1fcgLJXc0p0H1aBsF0kLs1ay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7wACrVnid5DkCurmvAzSScj4bTLgjdLIaRqLLRNTGnJy7sQrq2JPfY E0ah0SHn5DqAs9DPxpLJSAL6onaHScDXhqjY2kzwPBP19YwJeZ6Hun72ebgjiYmepVWBvDUY ZXe0UDzPQznnPnjwDWaghnwHyVtnI9uNt6QO+BqnXDP+TzJOSTJOSTJOSboMhGbgq+Y4peII tzyeTQng5EpOHa8I2H9YaQET/+PZWM3u+8De/i2gGghoUA0QTch8xNna56xEHC0/eoxVHd6r UsexXDWYQ5MyX3Fn9yJWAhXyJPYQyyawqn+qgPaUagSrDaZcvwjTgAomZ9qcm6TNpuCycOvn K9kiadHn9qaYus2XfqH09LvRI6GSjsf5tbO5zDQdQSt2yZ7FnihuXiPcFvJBvGFRXOV0KUgp rG+ojbQ1zNp+Kef019bGrMvKCLF9Ey0ThTrrF/qZThlGVuC8GrV/mD61TWlpWrAjTIiZ+akV q7Tvd/annJ5W931r75or906aiwtW3tl4ZnC3s3AwMfFVLqpQv+6vr5AQYu+UtgVeMtLVUZ7A 7omwN4mCJHnbHxRFMsezjFu8uqwvbJu33aZ7l3uVrw46mpisfNP5RD8t1DXXKcl6WLk02Xmx hwzvPvhW4dhnX4tD+tZXyUguRr5sMaHi5H8Ami8tP44DAAA= X-CMS-MailID: 20240214225943uscas1p21ffa8b362bac11379168b83e42159160 CMS-TYPE: 301P X-CMS-RootMailID: 20240214225943uscas1p21ffa8b362bac11379168b83e42159160 References: <170795147587.2393.15577527626926144858.stgit@bgt-140510-bm01.eng.stellus.in> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790917127015027935 X-GMAIL-MSGID: 1790917127015027935 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. 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); } /*