From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.5 Received: by atuin.qyliss.net (Postfix, from userid 496) id DC0D015D16; Wed, 21 Apr 2021 10:16:34 +0000 (UTC) Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 18A7015C74; Wed, 21 Apr 2021 10:16:26 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 4424715BF8; Wed, 21 Apr 2021 10:16:23 +0000 (UTC) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by atuin.qyliss.net (Postfix) with ESMTPS id 4F08F15BF6 for ; Wed, 21 Apr 2021 10:16:19 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 59D735C00AE for ; Wed, 21 Apr 2021 06:16:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 21 Apr 2021 06:16:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h= from:to:subject:date:message-id:mime-version :content-transfer-encoding; s=fm2; bh=9K9Va9n70rKz5wy+ce3i3tnYHf VWJ/fyHUs6rOFaUH0=; b=Lk3LVPPq68J2rocciBF+Ih4zrDHd5GbntmzwN+Arnf 8ZmGdJwxM37oY1dE9/V4qHxU3/lAf6yCyCz+9jnsv24VGUZhBnP8WS7emVw2xmc5 4ahAj5aRsvLp6g2VY+dFZ2I2l+o0CIXrElmFZvOFq9AosocRQ37LhWvWhTsiTlCf voOJC/cJY+vZPokNmbcNDJzSfBSHIhjAS2COnCXh61SlNWJGvWqDxNZCZP9DWLs4 3i1puxxVIGvak8t7/Lgw7XUsh/n/q+f7Qg0/fuzs+KsOKn25bEuanqaon5eyTwEs C9irw5WrjNOxz0k51nTkPxm2p+U1G26Kcuzy1lyrk+Dw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=9K9Va9n70rKz5wy+c e3i3tnYHfVWJ/fyHUs6rOFaUH0=; b=k2cPNZqyMUPG7cWAL2aNwo0rL1ja5RuJs D7+3GzaFtM2LWfL/WUMjhwDev1DFTrhH7ev+SjSEyWf94ASNMQdubRVjwJbcjkdx muZYw6g/NaeNI/pPgVbK7/jKg+w88VvcUoWMojb4S9MQKEyVmNHEghFNRBZ3vGV5 jy6Sd6tD5CzdgeXrw5i2qD+NBmioboN1Mb+HpQBeoMQcUdQr9GJQj115EdMugQ+Q 0I5YtMZN2vRICzF9dayREOZ+Cf0Pf66Lv/SLMlTx/tR5Qf1GYpkmOYLe9sHw40+C aDdknPfOmkiI4qcaopLqBrjivEeaRI0NyD0mUVzQJBa4vBcoABHPA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddtkedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgggfestdekredtre dttdenucfhrhhomheptehlhihsshgrucftohhsshcuoehhihesrghlhihsshgrrdhisheq necuggftrfgrthhtvghrnhephedvfffghfetieejgfetfedtgffhvdehueehvdejudfgge fgleejgfelfeevgfefnecukfhppeekgedrudekgedrvddviedrkedunecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepqhihlhhishhsseigvddvtd drqhihlhhishhsrdhnvght X-ME-Proxy: Received: from x220.qyliss.net (p54b8e251.dip0.t-ipconnect.de [84.184.226.81]) by mail.messagingengine.com (Postfix) with ESMTPA id AC360108005C for ; Wed, 21 Apr 2021 06:16:16 -0400 (EDT) Received: by x220.qyliss.net (Postfix, from userid 1000) id 682BF1F; Wed, 21 Apr 2021 10:16:14 +0000 (UTC) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH nixpkgs] spectrumPackages.spectrum-testhost: fix driver bind Date: Wed, 21 Apr 2021 10:16:05 +0000 Message-Id: <20210421101605.20790-1-hi@alyssa.is> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: KJ5TLDQ6NXD7LIAMCM2TSYPFE7GXYZK4 X-Message-ID-Hash: KJ5TLDQ6NXD7LIAMCM2TSYPFE7GXYZK4 X-MailFrom: qyliss@x220.qyliss.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.4 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The following operations are available to us in /sys/bus/pci/drivers/vfio-pci: bind, unbind, new_id, remove_id bind and unbind control attachment of a device to a driver. new_id and remove_id control whether a device should be considered "supported" by a driver. But when an unassigned device is newly supported by a driver, the kernel will automatically bind it to that driver. We were relying on the new_id operation binding the device to the driver in this way. But if the driver is in the supported list, but not bound to anything, this won't happen. new_id won't do anything, because it's already in the supported list. So we can't rely on new_id binding for us, and need to try bind as well (at least if new_id fails). To reproduce: echo 8086 1502 > /sys/bus/pci/drivers/vfio-pci/new_id echo 0000:00:19.0 > /sys/bus/pci/drivers/vfio-pci/unbind (Use lspci -nn to find the right values for your hardware.) This will leave you with a device that is supported by vfio-pci but not bound to it, which would previously cause vm-net to fail to start, but should not after this change. --- .../linux/spectrum/testhost/default.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/spectrum/testhost/default.nix b/pkgs/os-specific/linux/spectrum/testhost/default.nix index 7e1a973e8c6..21c585f1490 100644 --- a/pkgs/os-specific/linux/spectrum/testhost/default.nix +++ b/pkgs/os-specific/linux/spectrum/testhost/default.nix @@ -142,7 +142,9 @@ let printf "%s" $PCI_LOCATION } - # (Re)bind the device to the VFIO PCI driver. + # Tell the VFIO driver it should support our device. This + # is allowed to fail because it might already know that, in + # which case it'll return EEXIST. if { modprobe vfio-pci } backtick -in device_id { if { dd bs=2 skip=1 count=2 status=none if=''${PCI_PATH}/vendor } @@ -155,6 +157,20 @@ let printf "%s" $device_id } + # Bind the device to the VFIO driver. This is allowed to + # fail because the new_id operation we just tried will have + # bound it automatically for us if it succeeded. In such a + # case, the kernel will return ENODEV (conistency!). + foreground { + redirfd -w 1 /sys/bus/pci/drivers/vfio-pci/bind + printf "%s" $PCI_LOCATION + } + + # Because we allow both new_id and bind to fail, we need to + # manually make sure now that at least one of them succeeded + # and the device is actually attached to the vfio-driver. + if { test -e /sys/bus/pci/drivers/vfio-pci/''${PCI_LOCATION} } + foreground { mkdir env } ${cloud-hypervisor}/bin/cloud-hypervisor -- 2.31.0