From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410307; b=csh7+NpAOB1J7RH92eFdZDxKoe3Zbiuyyw2+tQRqt5AIV/1DB+HyYpcLOApjHfQWbdqX YsoLEHHx6fj+/L/zquxtIJpmslPhPdlCoVcWuIpIvMaE+ZkfBhJU+pIpCkedIOkH6IHFu aVRSwdQL2r8FVyRYjA/89jS72ERRMsIyQZz8HxN5zKBlOOwIIikfdAoIk4CaIIdyTy+JU ooVdCSK+JUXwqad/afNFwxLoI7cyrg0GBSvKNA9gVGff1xAM0zHZ2EPWJmcp8H8Anitct g5Knk76txKmj/wlHQsBd+5F3pDFui5PV/0NcRx/WgOIn0gq4j9q5j224kveNBQH+8dg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410307; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=wqGn20kEpY32cVm3p+z1vA6qYZCfH8pQYTrNh/8+AKo=; b=nz++0McCGcb9bdBAtnTaA6OWifZg6j9XaWnOhRvVmnWmisx67SNd8XYTtYMG38ar2L1/ r+NiV26o9vJom+shhyJyuVFrzH3S3iGBzCwVGb2u3HvxDo5zbpm2aWPZmXW0ChWaJO3UH HfjRufxrISL9jLcqHV1ndeqnYmF22Uk4xhp3GrLG8Sj0KcRQYHStSiJKPjlo0ebfhhJ24 gJ4aR6Wezwqv+z16f2YxBqurogQJ9FhmbXcLM/Q4Wt/JCQFVKQxbTm+74KcwyLg3q9bOv 9ONBvJcJ23CqN/+mLhgdYXdgFuPfBpKDfiCwhE6lsaj8pBatDTax0fElQwkslCO8S8g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L5V2uPeM; arc=none smtp.remote-ip=74.125.82.52 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (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 F2697606A322 for ; Fri, 4 Dec 2026 18:51:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2697606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L5V2uPeM Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1b5d5f0ba39so1491815c88.0 for ; Fri, 04 Dec 2026 10:51:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410306; x=1797015106; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=wqGn20kEpY32cVm3p+z1vA6qYZCfH8pQYTrNh/8+AKo=; b=L5V2uPeMBzdC+akTBAXB2Tn+ye3cI6eypYbr+aSaiLdnhmhJZrdsq9ctXqfw1VYfFy Cc9kqGYJdk3n2hUpXOzWzVmcJSctVE7/BXbJ49gB64hZ4nexez8RWfyAXF+39mBU24Bh lXT0ux5wC0PkIzDcMSILmej5jOBh8iDnn36e89nlB4vLqNfF5CcupW3+13l6sDpjJTdl eZIMAILtrV7mFlX7+NgvqrGX9slgXX6SIQzC5XXw9KIi09rYzNIljmwnwrKk31bnOjpJ +FSr3eTapXwRdyZhCVtpI2yX6qOu7EMPDkZWD71khjn0OfZCZP1JtdrcJtgY0W+Ceing GAzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410306; x=1797015106; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wqGn20kEpY32cVm3p+z1vA6qYZCfH8pQYTrNh/8+AKo=; b=ZUoUKUaPrKmId9go6bHem0YpAyD0YOpK43xusYDrbsAjcdwaxh2x8Dahdu4MsoLxkt 6BYl3oEuFrn0ZVcXsXe0n2L3xRQNb7jvDd7SFPrjOtlViisijZ6wnNf7ZaTHWVZN3YsB H/7zVjFGql7T0ihnag6VXnucRCu6b5nARFRJqNpW5gH1UrwQrnWfCVZg8MIJB65uTqVy avWHVsu3/61GHQ+/FWBB3Cf98gSE+Yeld5qJSWeQf3l6rcFpUESxuk6CjajFMp1oOs1V GkVGxLGQlB5uFkDQz5Qw6s7DC9ztS93IHCtDRIKLNqMg0V8dih+ReHlC7dqdqR7NsyF3 ncjg== X-Forwarded-Encrypted: i=1; AL+hErH9QGJVvuZDX9KM2hvXO2JiGCICmfPbw9X489iRYPNQM+SjDVdrN/GWaBHihQiOtqSzpdHnRZLbkGvq5Zs=@vger.kernel.org X-Gm-Message-State: APuU4Z+ctJtiNInMNyD6pQ/uEibA3TTBLfi9a5TIUsFa3k9lv1+V0NXd ZSGyOrQtGtdOFXPFSAy5JVCkECYkU+PviYUKOoxZPq6fkqCKJCZ/YiF1 X-Gm-Gg: AZFdTZf9A6OodvQDx1US63a8EuNI68fHavtzjhx1Yek3U0fPE4LqpFBRSrsQApVmSfT SwP0eHSLTcYp3vgZfbUyYgyiDkiey/hy5+SCEZLwGbEOzb7jBUaBvIH+4EHFAy/HPYZUqntsxKu 7j0MkXRETp4JUxKu1iZeXnUFYK5SGBaWDddGCqX9jNF2oXVPPGq0kQtRcBklm9DvR9k89FL7nH5 9+8Q66noltRAEHLOrlot9vugSVLaV2wOG4DYJdpzzI7PjJpNtn/7SF3KUGA+wCayqrrSfhZQLcm 4LpGYA7IqX4zgvKN2iTTiSdhB9n7hqDHxQWNX6XcSbU9iosXKURdvV6uwWlw5nvGzgfUKWYOhS9 ID3hZV3CBjnoQFq7n8nuJTMHZbRDGZWFSBd5AjZ7SeFY1MaIQWPOB4yBqdqnyGHSbtETno9vzW4 WzwyPMpvajgxhor9iAdjjtdBiPoH4VE1u0N7/BQLE24E+Mah+47fNsuLA5ryAxDZTB3dsXOE6B4 VBXBiiRUnxzR2fvkZKCo/oR4D3xHuDjufbVOaWMWtDOEYnNcGA3kPQItdeWIgd6I3UP6ayBTxsS beU+DF6PISdQf/tcK4JF4ImSmQHNPc9z3W45+CHhKNB7D0zEAnft+8dmfgeyWYoOimI= X-Received: by 2002:a05:7022:4583:b0:187:c940:21b9 with SMTP id a92af1059eb24-1b5d711570dmr3717302c88.30.1796410306088; Fri, 04 Dec 2026 10:51:46 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875220c35asm10316734eec.22.2026.12.04.10.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:51:45 -0800 (PST) From: Praneeth Balasubramanian To: Juergen Gross , Stefano Stabellini Cc: Oleksandr Tyshchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [PATCH] xen-pciback: Hold the device lock when initializing seized devices late Date: Fri, 4 Dec 2026 10:51:43 -0800 Message-Id: <20261204185143.1688493-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pcistub_init_device() resets the device through pcistub_reset_device_state(), which calls __pci_reset_function_locked(). That function requires the device lock, and since commit f06e0ad226fd ("PCI: Use device_lock_assert() to verify device lock is held") it asserts it. When the driver is probed for a device after initialization, as for a device bound through sysfs, pcistub_seize() runs pcistub_init_device() from ->probe(), so the driver core holds the lock. Devices that are seized while the driver registers, such as those listed in xen-pciback.hide=, are initialized later by pcistub_init_devices_late(), which does not take the lock. A dom0 kernel with lockdep warns once for each such device at boot, and the reset is not serialized against other users of the device lock. Take the device lock around pcistub_init_device() in pcistub_init_devices_late(), so it runs in the same context as on the probe path. The missing lock was found by a static check that turns the locking rule in a function's comment into a Clang context-analysis requirement on its callers. Compile tested only. Fixes: cd9db80e5257 ("xen/pciback: Support pci_reset_function, aka FLR or D3 support.") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by a compiler-based check, part of research at UCSB SecLab. The locking rule stated in the kernel-doc comment of the called function was turned into a Clang context-analysis requirement (__must_hold) on that function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every caller. An LLM was used only to turn the comment into a machine-readable rule; the report itself comes from the compiler. The patch and changelog were drafted with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64, clang 23, allmodconfig). Not runtime-tested, and I have not observed the race myself. drivers/xen/xen-pciback/pci_stub.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index d1a335233aab..9eba7a982300 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -508,7 +508,9 @@ static int __init pcistub_init_devices_late(void) spin_unlock_irqrestore(&pcistub_devices_lock, flags); + device_lock(&psdev->dev->dev); err = pcistub_init_device(psdev); + device_unlock(&psdev->dev->dev); if (err) { dev_err(&psdev->dev->dev, "error %d initializing device\n", err); -- 2.25.1