linux/include/xen
Juergen Gross e2dcf90655 xen/xenbus: better handle backend crash
When the backend domain crashes, coordinated device cleanup is not
possible (as it involves waiting for the backend state change). In that
case, toolstack forcefully removes frontend xenstore entries.
xenbus_dev_changed() handles this case, and triggers device cleanup.
It's possible that toolstack manages to connect new device in that
place, before xenbus_dev_changed() notices the old one is missing. If
that happens, new one won't be probed and will forever remain in
XenbusStateInitialising.

Fix this by checking the frontend's state in Xenstore. In case it has
been reset to XenbusStateInitialising by Xen tools, consider this
being the result of an unplug+plug operation.

It's important that cleanup on such unplug doesn't modify Xenstore
entries (especially the "state" key) as it belong to the new device
to be probed - changing it would derail establishing connection to the
new backend (most likely, closing the device before it was even
connected). Handle this case by setting new xenbus_device->vanished
flag to true, and check it before changing state entry.

And even if xenbus_dev_changed() correctly detects the device was
forcefully removed, the cleanup handling is still racy. Since this whole
handling doesn't happened in a single Xenstore transaction, it's possible
that toolstack might put a new device there already. Avoid re-creating
the state key (which in the case of loosing the race would actually
close newly attached device).

The problem does not apply to frontend domain crash, as this case
involves coordinated cleanup.

Problem originally reported at
https://lore.kernel.org/xen-devel/aOZvivyZ9YhVWDLN@mail-itl/T/#t,
including reproduction steps.

Based-on-patch-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Tested-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Message-ID: <20260218095205.453657-3-jgross@suse.com>
2026-03-04 15:31:40 +01:00
..
arm arm/xen: remove lazy mode related definitions 2023-09-19 07:04:49 +02:00
interface xen/mcelog: Add __nonstring annotations for unterminated strings 2025-03-14 11:15:16 +01:00
acpi.h xen: Remove dependency between pciback and privcmd 2024-10-18 11:59:04 +02:00
balloon.h xen/balloon: Bring alloc(free)_xenballooned_pages helpers back 2022-01-06 09:53:35 +01:00
events.h x86/xen: eliminate some private header files 2024-07-11 16:33:48 +02:00
features.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
grant_table.h xen: replace XENFEAT_auto_translated_physmap with xen_pv_domain() 2025-09-08 17:01:36 +02:00
hvc-console.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hvm.h x86/xen: Add support for HVMOP_set_evtchn_upcall_vector 2022-08-12 11:28:21 +02:00
mem-reservation.h xen: replace XENFEAT_auto_translated_physmap with xen_pv_domain() 2025-09-08 17:01:36 +02:00
page.h swiotlb-xen: remove XEN_PFN_PHYS 2020-08-04 07:50:43 +02:00
pci.h xen/pci: Add a function to reset device for xen 2024-09-25 09:54:40 +02:00
platform_pci.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
swiotlb-xen.h swiotlb-xen: fix DMA_ATTR_NO_KERNEL_MAPPING on arm 2022-05-11 19:48:32 +02:00
xen-front-pgdir-shbuf.h xen: Introduce shared buffer helpers for page directory... 2018-12-18 12:15:55 -05:00
xen-ops.h xen: replace XENFEAT_auto_translated_physmap with xen_pv_domain() 2025-09-08 17:01:36 +02:00
xen.h Partial revert "x86/xen: fix balloon target initialization for PVH dom0" 2026-02-02 07:31:22 +01:00
xenbus.h xen/xenbus: better handle backend crash 2026-03-04 15:31:40 +01:00
xenbus_dev.h xen: xenbus_dev.h: delete incorrect file name 2022-02-03 08:16:32 +01:00