From nobody Tue Mar 3 03:24:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1771408359; cv=none; d=zohomail.com; s=zohoarc; b=VnEXrH/d2t+hmp3sOxfWP5KrNWRGnC+YkiINAbTdZRyv+zQY2V5z10C6r6HRin0kdrIr8cfes+x+RkSL8LtTiRSv9KSwuGuyikuTtnq8+VzLpId6ErkAsqdFvJRQW+DACNetfUA38XWdiXyOKvqWua8DABHbWqmUof+ybGFuzkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771408359; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6an1q48KjRbAhbQVvdoHYoaIrt1Vz4lUP6AS4HcAAwE=; b=jBzLa+3TkWi31A0Uzb9YTKcrMitraT1vcT5M8cLJxK8cp3S84/4uqy8c8JACPra1ZfyJ2uTGSNBMBEqAbcO9GC7pUGlNypASHB7bKoIJYHXO/X8Qqt3SFyh+aSaLwCyU4Wh5QgF2Ev/SRTdiYrlIFmWIJWETCP9edXKxi6J0Yoo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1771408359715256.3224737676685; Wed, 18 Feb 2026 01:52:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1235389.1538375 (Exim 4.92) (envelope-from ) id 1vseED-0006o2-HX; Wed, 18 Feb 2026 09:52:17 +0000 Received: by outflank-mailman (output) from mailman id 1235389.1538375; Wed, 18 Feb 2026 09:52:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vseED-0006nv-Dp; Wed, 18 Feb 2026 09:52:17 +0000 Received: by outflank-mailman (input) for mailman id 1235389; Wed, 18 Feb 2026 09:52:16 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vseEC-0006na-6V for xen-devel@lists.xenproject.org; Wed, 18 Feb 2026 09:52:16 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 80498518-0caf-11f1-9ccf-f158ae23cfc8; Wed, 18 Feb 2026 10:52:13 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 496CB3E6CC; Wed, 18 Feb 2026 09:52:13 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D48623EA65; Wed, 18 Feb 2026 09:52:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 25S1MsyLlWnqfQAAD6G6ig (envelope-from ); Wed, 18 Feb 2026 09:52:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 80498518-0caf-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1771408333; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6an1q48KjRbAhbQVvdoHYoaIrt1Vz4lUP6AS4HcAAwE=; b=HwDxVjLb5rzDl98jUuVjANDuW0gyL4FJdreRStmSyureZa5ALvayYjScEEWK1ueAgSPLG2 jNYC5qBwn0mUXSImvJfemPNtD2iXHRxpT8NsXkaDIiLAFbWL3Rn2lg2KJqS46DqXsoWwhM uJJkkR0Y5EEtyMsOifaOGmOjBTifh40= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1771408333; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6an1q48KjRbAhbQVvdoHYoaIrt1Vz4lUP6AS4HcAAwE=; b=HwDxVjLb5rzDl98jUuVjANDuW0gyL4FJdreRStmSyureZa5ALvayYjScEEWK1ueAgSPLG2 jNYC5qBwn0mUXSImvJfemPNtD2iXHRxpT8NsXkaDIiLAFbWL3Rn2lg2KJqS46DqXsoWwhM uJJkkR0Y5EEtyMsOifaOGmOjBTifh40= From: Juergen Gross To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bjorn Helgaas , "James E.J. Bottomley" , "Martin K. Petersen" , xen-devel@lists.xenproject.org, =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v2 1/2] xenbus: add xenbus_device parameter to xenbus_read_driver_state() Date: Wed, 18 Feb 2026 10:52:04 +0100 Message-ID: <20260218095205.453657-2-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260218095205.453657-1-jgross@suse.com> References: <20260218095205.453657-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: -5.80 X-Spam-Level: X-Spamd-Result: default: False [-5.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCPT_COUNT_TWELVE(0.00)[17]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TAGGED_RCPT(0.00)[netdev]; R_RATELIMIT(0.00)[to_ip_from(RLsote1drt81dzioaq3931x19g)]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1771408360845158500 In order to prepare checking the xenbus device status in xenbus_read_driver_state(), add the pointer to struct xenbus_device as a parameter. Signed-off-by: Juergen Gross Tested-by: Marek Marczykowski-G=C3=B3recki Signed-off-by: Juergen Gross Acked-by: Bjorn Helgaas # drivers/pci/xen-pcifront.c Acked-by: Jakub Kicinski Acked-by: Martin K. Petersen # SCSI --- V2: - add dev parameter description (kernel test robot) --- drivers/net/xen-netfront.c | 34 +++++++++++----------- drivers/pci/xen-pcifront.c | 8 ++--- drivers/scsi/xen-scsifront.c | 2 +- drivers/xen/xen-pciback/xenbus.c | 10 +++---- drivers/xen/xenbus/xenbus_client.c | 4 ++- drivers/xen/xenbus/xenbus_probe.c | 6 ++-- drivers/xen/xenbus/xenbus_probe_frontend.c | 2 +- include/xen/xenbus.h | 3 +- 8 files changed, 36 insertions(+), 33 deletions(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 0969d5c9f6b7..2c414b77dd0f 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -1646,7 +1646,7 @@ static int xennet_xdp_set(struct net_device *dev, str= uct bpf_prog *prog, =20 /* avoid the race with XDP headroom adjustment */ wait_event(module_wq, - xenbus_read_driver_state(np->xbdev->otherend) =3D=3D + xenbus_read_driver_state(np->xbdev, np->xbdev->otherend) =3D=3D XenbusStateReconfigured); np->netfront_xdp_enabled =3D true; =20 @@ -1764,9 +1764,9 @@ static struct net_device *xennet_create_dev(struct xe= nbus_device *dev) do { xenbus_switch_state(dev, XenbusStateInitialising); err =3D wait_event_timeout(module_wq, - xenbus_read_driver_state(dev->otherend) !=3D + xenbus_read_driver_state(dev, dev->otherend) !=3D XenbusStateClosed && - xenbus_read_driver_state(dev->otherend) !=3D + xenbus_read_driver_state(dev, dev->otherend) !=3D XenbusStateUnknown, XENNET_TIMEOUT); } while (!err); =20 @@ -2627,31 +2627,31 @@ static void xennet_bus_close(struct xenbus_device *= dev) { int ret; =20 - if (xenbus_read_driver_state(dev->otherend) =3D=3D XenbusStateClosed) + if (xenbus_read_driver_state(dev, dev->otherend) =3D=3D XenbusStateClosed) return; do { xenbus_switch_state(dev, XenbusStateClosing); ret =3D wait_event_timeout(module_wq, - xenbus_read_driver_state(dev->otherend) =3D=3D - XenbusStateClosing || - xenbus_read_driver_state(dev->otherend) =3D=3D - XenbusStateClosed || - xenbus_read_driver_state(dev->otherend) =3D=3D - XenbusStateUnknown, - XENNET_TIMEOUT); + xenbus_read_driver_state(dev, dev->otherend) =3D=3D + XenbusStateClosing || + xenbus_read_driver_state(dev, dev->otherend) =3D=3D + XenbusStateClosed || + xenbus_read_driver_state(dev, dev->otherend) =3D=3D + XenbusStateUnknown, + XENNET_TIMEOUT); } while (!ret); =20 - if (xenbus_read_driver_state(dev->otherend) =3D=3D XenbusStateClosed) + if (xenbus_read_driver_state(dev, dev->otherend) =3D=3D XenbusStateClosed) return; =20 do { xenbus_switch_state(dev, XenbusStateClosed); ret =3D wait_event_timeout(module_wq, - xenbus_read_driver_state(dev->otherend) =3D=3D - XenbusStateClosed || - xenbus_read_driver_state(dev->otherend) =3D=3D - XenbusStateUnknown, - XENNET_TIMEOUT); + xenbus_read_driver_state(dev, dev->otherend) =3D=3D + XenbusStateClosed || + xenbus_read_driver_state(dev, dev->otherend) =3D=3D + XenbusStateUnknown, + XENNET_TIMEOUT); } while (!ret); } =20 diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index 11636634ae51..cd22bf984024 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -856,7 +856,7 @@ static void pcifront_try_connect(struct pcifront_device= *pdev) int err; =20 /* Only connect once */ - if (xenbus_read_driver_state(pdev->xdev->nodename) !=3D + if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename) !=3D XenbusStateInitialised) return; =20 @@ -876,7 +876,7 @@ static int pcifront_try_disconnect(struct pcifront_devi= ce *pdev) enum xenbus_state prev_state; =20 =20 - prev_state =3D xenbus_read_driver_state(pdev->xdev->nodename); + prev_state =3D xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename); =20 if (prev_state >=3D XenbusStateClosing) goto out; @@ -895,7 +895,7 @@ static int pcifront_try_disconnect(struct pcifront_devi= ce *pdev) =20 static void pcifront_attach_devices(struct pcifront_device *pdev) { - if (xenbus_read_driver_state(pdev->xdev->nodename) =3D=3D + if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename) =3D=3D XenbusStateReconfiguring) pcifront_connect(pdev); } @@ -909,7 +909,7 @@ static int pcifront_detach_devices(struct pcifront_devi= ce *pdev) struct pci_dev *pci_dev; char str[64]; =20 - state =3D xenbus_read_driver_state(pdev->xdev->nodename); + state =3D xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename); if (state =3D=3D XenbusStateInitialised) { dev_dbg(&pdev->xdev->dev, "Handle skipped connect.\n"); /* We missed Connected and need to initialize. */ diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c index 924025305753..ef74d4da5ab0 100644 --- a/drivers/scsi/xen-scsifront.c +++ b/drivers/scsi/xen-scsifront.c @@ -1175,7 +1175,7 @@ static void scsifront_backend_changed(struct xenbus_d= evice *dev, return; } =20 - if (xenbus_read_driver_state(dev->nodename) =3D=3D + if (xenbus_read_driver_state(dev, dev->nodename) =3D=3D XenbusStateInitialised) scsifront_do_lun_hotplug(info, VSCSIFRONT_OP_ADD_LUN); =20 diff --git a/drivers/xen/xen-pciback/xenbus.c b/drivers/xen/xen-pciback/xen= bus.c index b11e401f1b1e..4bd1c7a8957e 100644 --- a/drivers/xen/xen-pciback/xenbus.c +++ b/drivers/xen/xen-pciback/xenbus.c @@ -149,12 +149,12 @@ static int xen_pcibk_attach(struct xen_pcibk_device *= pdev) =20 mutex_lock(&pdev->dev_lock); /* Make sure we only do this setup once */ - if (xenbus_read_driver_state(pdev->xdev->nodename) !=3D + if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename) !=3D XenbusStateInitialised) goto out; =20 /* Wait for frontend to state that it has published the configuration */ - if (xenbus_read_driver_state(pdev->xdev->otherend) !=3D + if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->otherend) !=3D XenbusStateInitialised) goto out; =20 @@ -374,7 +374,7 @@ static int xen_pcibk_reconfigure(struct xen_pcibk_devic= e *pdev, dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n"); =20 mutex_lock(&pdev->dev_lock); - if (xenbus_read_driver_state(pdev->xdev->nodename) !=3D state) + if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename) !=3D state) goto out; =20 err =3D xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", @@ -572,7 +572,7 @@ static int xen_pcibk_setup_backend(struct xen_pcibk_dev= ice *pdev) /* It's possible we could get the call to setup twice, so make sure * we're not already connected. */ - if (xenbus_read_driver_state(pdev->xdev->nodename) !=3D + if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename) !=3D XenbusStateInitWait) goto out; =20 @@ -662,7 +662,7 @@ static void xen_pcibk_be_watch(struct xenbus_watch *wat= ch, struct xen_pcibk_device *pdev =3D container_of(watch, struct xen_pcibk_device, be_watch); =20 - switch (xenbus_read_driver_state(pdev->xdev->nodename)) { + switch (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename)) { case XenbusStateInitWait: xen_pcibk_setup_backend(pdev); break; diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus= _client.c index 2dc874fb5506..e502435145ae 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -931,12 +931,14 @@ static int xenbus_unmap_ring_hvm(struct xenbus_device= *dev, void *vaddr) =20 /** * xenbus_read_driver_state - read state from a store path + * @dev: xenbus device pointer * @path: path for driver * * Returns: the state of the driver rooted at the given store path, or * XenbusStateUnknown if no state can be read. */ -enum xenbus_state xenbus_read_driver_state(const char *path) +enum xenbus_state xenbus_read_driver_state(const struct xenbus_device *dev, + const char *path) { enum xenbus_state result; int err =3D xenbus_gather(XBT_NIL, path, "state", "%d", &result, NULL); diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 9f9011cd7447..2eed06ba5d38 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -191,7 +191,7 @@ void xenbus_otherend_changed(struct xenbus_watch *watch, return; } =20 - state =3D xenbus_read_driver_state(dev->otherend); + state =3D xenbus_read_driver_state(dev, dev->otherend); =20 dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n", state, xenbus_strstate(state), dev->otherend_watch.node, path); @@ -364,7 +364,7 @@ void xenbus_dev_remove(struct device *_dev) * closed. */ if (!drv->allow_rebind || - xenbus_read_driver_state(dev->nodename) =3D=3D XenbusStateClosing) + xenbus_read_driver_state(dev, dev->nodename) =3D=3D XenbusStateClosin= g) xenbus_switch_state(dev, XenbusStateClosed); } EXPORT_SYMBOL_GPL(xenbus_dev_remove); @@ -514,7 +514,7 @@ int xenbus_probe_node(struct xen_bus_type *bus, size_t stringlen; char *tmpstring; =20 - enum xenbus_state state =3D xenbus_read_driver_state(nodename); + enum xenbus_state state =3D xenbus_read_driver_state(NULL, nodename); =20 if (state !=3D XenbusStateInitialising) { /* Device is not new, so ignore it. This can happen if a diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbu= s/xenbus_probe_frontend.c index f04707d1f667..ca04609730df 100644 --- a/drivers/xen/xenbus/xenbus_probe_frontend.c +++ b/drivers/xen/xenbus/xenbus_probe_frontend.c @@ -253,7 +253,7 @@ static int print_device_status(struct device *dev, void= *data) } else if (xendev->state < XenbusStateConnected) { enum xenbus_state rstate =3D XenbusStateUnknown; if (xendev->otherend) - rstate =3D xenbus_read_driver_state(xendev->otherend); + rstate =3D xenbus_read_driver_state(xendev, xendev->otherend); pr_warn("Timeout connecting to device: %s (local state %d, remote state = %d)\n", xendev->nodename, xendev->state, rstate); } diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index c94caf852aea..15319da65b7f 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -228,7 +228,8 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, = void *vaddr); int xenbus_alloc_evtchn(struct xenbus_device *dev, evtchn_port_t *port); int xenbus_free_evtchn(struct xenbus_device *dev, evtchn_port_t port); =20 -enum xenbus_state xenbus_read_driver_state(const char *path); +enum xenbus_state xenbus_read_driver_state(const struct xenbus_device *dev, + const char *path); =20 __printf(3, 4) void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,= ...); --=20 2.53.0 From nobody Tue Mar 3 03:24:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1771408361; cv=none; d=zohomail.com; s=zohoarc; b=Aar+3Vj62wZlBdkCYwSvF2KKZL76tOOVG0kMY4Qwzk6r4zcY15IISE71txAd7AbGw9YGed4SPlv8Pb/wsc9Do9gB7BIiDUOU9WEcu038hJuovq0OkYs3TBT3CPorG9j0kpuABg415QKWwM8cPimqlln1NQRQbnXgOAkM287Cp8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771408361; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Us/u84SsxFMO0tl1d+eBym7mS0CVvhetUanmuDsPoqE=; b=Wm52dJOdPRw3nB539FXQeeCvcH+SOrH3bbkUJ6lzBKEfW2v5xxa9m9KGGP+ARGb7gKjScLpNfb2Cej8KBRsbpUvn0ouX6j0gfBY8UcqdJwlZGf+XHJgYqxFobb9y0VwgefpDiq+YobbflaOA2DHCkkaZnghr8v8HyoK+TAL3Gak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1771408361605380.37707388348895; Wed, 18 Feb 2026 01:52:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1235390.1538384 (Exim 4.92) (envelope-from ) id 1vseEG-00073A-NN; Wed, 18 Feb 2026 09:52:20 +0000 Received: by outflank-mailman (output) from mailman id 1235390.1538384; Wed, 18 Feb 2026 09:52:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vseEG-000731-Ko; Wed, 18 Feb 2026 09:52:20 +0000 Received: by outflank-mailman (input) for mailman id 1235390; Wed, 18 Feb 2026 09:52:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vseEF-0006Zz-PB for xen-devel@lists.xenproject.org; Wed, 18 Feb 2026 09:52:19 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8393c050-0caf-11f1-b164-2bf370ae4941; Wed, 18 Feb 2026 10:52:19 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BDB405BCC8; Wed, 18 Feb 2026 09:52:18 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 886533EA65; Wed, 18 Feb 2026 09:52:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id eMwnINKLlWn0fQAAD6G6ig (envelope-from ); Wed, 18 Feb 2026 09:52:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8393c050-0caf-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1771408338; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Us/u84SsxFMO0tl1d+eBym7mS0CVvhetUanmuDsPoqE=; b=C65Oht9X6FM1TbuBFE3CaVYZlsnmaR9Nss+awa/RYN8fsCAsnGCLQVIy/KV9SrI5PFePYa jRWpttC0vb0wu4IoTttLhb8Wxcy5Zjz7vc/rlEzvuXlqjeX3cRICn1+EL3XjiOS7X0Btnl NYaJKyFJOO1XXlz08F2XDfJfAgaVPUE= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1771408338; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Us/u84SsxFMO0tl1d+eBym7mS0CVvhetUanmuDsPoqE=; b=C65Oht9X6FM1TbuBFE3CaVYZlsnmaR9Nss+awa/RYN8fsCAsnGCLQVIy/KV9SrI5PFePYa jRWpttC0vb0wu4IoTttLhb8Wxcy5Zjz7vc/rlEzvuXlqjeX3cRICn1+EL3XjiOS7X0Btnl NYaJKyFJOO1XXlz08F2XDfJfAgaVPUE= From: Juergen Gross To: linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v2 2/2] xen/xenbus: better handle backend crash Date: Wed, 18 Feb 2026 10:52:05 +0100 Message-ID: <20260218095205.453657-3-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260218095205.453657-1-jgross@suse.com> References: <20260218095205.453657-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: -7.30 X-Spam-Level: X-Spamd-Result: default: False [-7.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1771408362666158500 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=C3=B3recki Signed-off-by: Juergen Gross Tested-by: Marek Marczykowski-G=C3=B3recki --- drivers/xen/xenbus/xenbus_client.c | 13 +++++++++-- drivers/xen/xenbus/xenbus_probe.c | 36 ++++++++++++++++++++++++++++++ include/xen/xenbus.h | 1 + 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus= _client.c index e502435145ae..19672b08a680 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -226,8 +226,9 @@ __xenbus_switch_state(struct xenbus_device *dev, struct xenbus_transaction xbt; int current_state; int err, abort; + bool vanished =3D false; =20 - if (state =3D=3D dev->state) + if (state =3D=3D dev->state || dev->vanished) return 0; =20 again: @@ -242,6 +243,10 @@ __xenbus_switch_state(struct xenbus_device *dev, err =3D xenbus_scanf(xbt, dev->nodename, "state", "%d", ¤t_state); if (err !=3D 1) goto abort; + if (current_state !=3D dev->state && current_state =3D=3D XenbusStateInit= ialising) { + vanished =3D true; + goto abort; + } =20 err =3D xenbus_printf(xbt, dev->nodename, "state", "%d", state); if (err) { @@ -256,7 +261,7 @@ __xenbus_switch_state(struct xenbus_device *dev, if (err =3D=3D -EAGAIN && !abort) goto again; xenbus_switch_fatal(dev, depth, err, "ending transaction"); - } else + } else if (!vanished) dev->state =3D state; =20 return 0; @@ -941,6 +946,10 @@ enum xenbus_state xenbus_read_driver_state(const struc= t xenbus_device *dev, const char *path) { enum xenbus_state result; + + if (dev && dev->vanished) + return XenbusStateUnknown; + int err =3D xenbus_gather(XBT_NIL, path, "state", "%d", &result, NULL); if (err) result =3D XenbusStateUnknown; diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 2eed06ba5d38..eb260eceb4d2 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -444,6 +444,9 @@ static void xenbus_cleanup_devices(const char *path, st= ruct bus_type *bus) info.dev =3D NULL; bus_for_each_dev(bus, NULL, &info, cleanup_dev); if (info.dev) { + dev_warn(&info.dev->dev, + "device forcefully removed from xenstore\n"); + info.dev->vanished =3D true; device_unregister(&info.dev->dev); put_device(&info.dev->dev); } @@ -659,6 +662,39 @@ void xenbus_dev_changed(const char *node, struct xen_b= us_type *bus) return; =20 dev =3D xenbus_device_find(root, &bus->bus); + /* + * Backend domain crash results in not coordinated frontend removal, + * without going through XenbusStateClosing. If this is a new instance + * of the same device Xen tools will have reset the state to + * XenbusStateInitializing. + * It might be that the backend crashed early during the init phase of + * device setup, in which case the known state would have been + * XenbusStateInitializing. So test the backend domid to match the + * saved one. In case the new backend happens to have the same domid as + * the old one, we can just carry on, as there is no inconsistency + * resulting in this case. + */ + if (dev && !strcmp(bus->root, "device")) { + enum xenbus_state state =3D xenbus_read_driver_state(dev, dev->nodename); + unsigned int backend =3D xenbus_read_unsigned(root, "backend-id", + dev->otherend_id); + + if (state =3D=3D XenbusStateInitialising && + (state !=3D dev->state || backend !=3D dev->otherend_id)) { + /* + * State has been reset, assume the old one vanished + * and new one needs to be probed. + */ + dev_warn(&dev->dev, + "state reset occurred, reconnecting\n"); + dev->vanished =3D true; + } + if (dev->vanished) { + device_unregister(&dev->dev); + put_device(&dev->dev); + dev =3D NULL; + } + } if (!dev) xenbus_probe_node(bus, type, root); else diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 15319da65b7f..8ca15743af7f 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -80,6 +80,7 @@ struct xenbus_device { const char *devicetype; const char *nodename; const char *otherend; + bool vanished; int otherend_id; struct xenbus_watch otherend_watch; struct device dev; --=20 2.53.0