From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410308; b=yZKjTYSQyuo+9zjUpFt+8zfSBu443Dcmh4OkPiyI+xuc6iQFyG5GtMPFpYorLnjMD2cU EJIWAybOqMhUu7T0oBT6YDq8wZGYjiIERSRYJd38KJxMju4B9raRTgzIMTXq11iABc7Eb MPe3uMo1KdisdXMuaLYmKVZ0E7kSwXO7+y0eifbk2eFHl6QwE6n0P4RjcaGIwC8GulGlt 8R37K391wAEOUBJ8s7I9fCI9byhh0zjITosaeCSM+/QLe1LA76BMgnhmFr8DSdkIAwwG2 Zj8EQs0uKi3QirEZLa4LUoapn/JsJK0TZZo0ej6z+6Nnt24rGsqlynGJMPrRo+SU+SQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410308; 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=s0UgXLcy2W9ZINEOw8oy1aC1Iya16x9aoZNhBFNSlGD3DlozOFwyGMOH+6+yeoJfqgDs UQJaEx7UIPmPbLayksUmjQIonCX0gNXc0aWwzunA1XiSe8HtfxhtlSh4pUDaW0hllzo9l K7obV3YaEisJ0z19Ll8q2DDxeeQZ7G8m6vJRwppU0v5wMULmbHYOXEz6Ow4YaL5N2tDDA 4LqYG2++5tcGwo+afV8PyCwvoHE2HJD9xKHyAwmmonhyYzEQ9TBMFKy3xfEJh+IkhlJq1 ZGfx37SzXJihHwv/q9vfnpkrko4GLFNxqaeQcwRUXn37Bb8ASR04NN+XtB7Cg3HT73Q== 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.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 0B5E4606A32D for ; Fri, 4 Dec 2026 18:51:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B5E4606A32D 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-f53.google.com with SMTP id a92af1059eb24-1b5d5fdefe2so1484761c88.1 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=Z82CQU/MEAz7LdqzHxG3M8+yL2I9txv7+zJaY3yCTGPR/ET25SPXS/nxF/uxBpMvoY IimnpjivcDpvCFdBtmThO0xrDp3ogwPwPSeSLtXPDxk4tgJx0d1V4RR/0iraSmschSks SdiTu6sZYUQ1VmnDBEsnInFYNv9LN1KPMR1pQrbELATbffiX7U462ljz7wztSeeLIIIb O2HjdMquULs+kM5qr91NAi7eJxg9B2MVz53VpoTO+DOGo3ptSYkkx6NycWEhWDt6vvLK 03cJgDdcyRsIR0aLS49PDiihMkWaQtXmv/choHEZS2rGKli6pxAjO7/xnBDU/w0RpQBs Ou8w== X-Forwarded-Encrypted: i=1; AL+hErEYvkZlA6c7G2OCoxzGRZ6b0DuBzOR/syRQ/VbkE3bWs0olDpKdchBRVeQba0zIRV2DA1LszrM=@vger.kernel.org X-Gm-Message-State: APuU4Z+0RHjUFAxa9AA7FlOdeEVlurha9zGm+GRmQQ3xBA2j5ts+iJiC XAh8s5PlpRGZRKwTeDiVwgjbkd0vbJR2lcKUy6cHLmJ+eZTqxNSClfKO X-Gm-Gg: AZFdTZe8Iz9Ip3lz96zLAXfOSHGg5FuBSABAn82bNjE2dNJTUp8QCjJ0FYqbHULyJsN COFsEhVqGhNOyWHrBzkvuTc5Llz7WDE6Zd3GOeIVIu7DRpgYtBecvTXVDSk866ToyP4Eb/1a27G aUIXXXfcetTcmIv3n3+aIpVVy3R56L+AabYhqDwsPFLmiplWImPLXKedcG6gopUudmg/DHi4I5r SJzZzO9qBu1M2i+gmJjdl8AcUfxX489qdKh6A3GGno6yNup6VvU0bXWqT6CV8j59QTuqHQPaRVM 76Bh0lo9iAU5lqV+ApaZ9KA2vnHT4w6XpfcVznxnzVFVgy9b9LMuj3syzGmQVcaDaN2dUXgxOZ4 RQNDLjXnqiqLAuAJXLG6SUbOm9B6/xjuCdOLta79uLRH1WCph1l66gBFu9kSoRrrWc+vBFAAVJs fkWSyknx4KQzGbadyq5JC1MyxaLd2glaYUGiJppIRjm/sdrdnVdOf5PAbaqXmt5iJcfSqM88o10 +FGuUH1gC/lAPJsEgrdv2at/lAQUgmhAKcRtcqZdX7/itU4Ilst16gmiboHsIqfFmDRQpzRrQrf e0kXWucfuZ53X1Jxir95sIuFYXLiggf1XbMFu/JLjiWDCJk7dBQYClahB22q0yYGNe8= 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: stable@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