From nobody Fri Oct 11 07:36:32 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XPz2n2Ytyz5YR9b; Fri, 11 Oct 2024 07:36:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XPz2n0TbLz4m9J; Fri, 11 Oct 2024 07:36:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728632193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5/ziNUyzQ6Ud1SzJhbX6GAwi1StZFS2uFYFFzcDd+tM=; b=tzd3lY8nwszhBhwxsqxGAq8ox2qM6ym68LJ/gpVEnlZ/GYubutw9ID6X79BpLPsTGn+nJS ba4S47Ne7Dx4DNXkgc9KVkM2W0TBd822CLMhPdR7stGRkJpUKvJEdbjdhGh7dkKFVBWTF/ DExTjHEEX8FPui1eHXj198OSMxwMeKurVGIDvG817TrtuNVJYqHAPG2A92EQTOxyp3GeHV UgBlk1+uDef3O25MYd01h7XLv7TjlPgV6UwnkkQiXafl+/V0pFDliRVbhm7ewzSD4E00gd C0l5xeEMRdms6pE0lpty3972iMRNILkPQocvJFsnrxBa5f10kN5jtsaNZ1rNWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728632193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5/ziNUyzQ6Ud1SzJhbX6GAwi1StZFS2uFYFFzcDd+tM=; b=FdC9PbOdoINapZGdNYSRHS52IEMANQgaeLe9g5F5K238xA/8/xbWOZspjrw2wFqzxxarRW KMLguzHhyKFnKv5WiS9UmlNxKOlJNk8/8yvXYf4TXs9YAIuzez+bVLzY8t5W0TprMyLeC0 +aek3R1QIcN8zTHQ5cxk6R2K5mldCYLGGNzDKuzzjVF/NMmLXL7OciblX7Z44MIa8rHMl5 mrkAsVG9QNC4I4kYMeJShJ9Y18wwhZgOGTcIu3U2bYLuJHEvK7UxrTFfFdGFOP9l6wFleP RiZnzFig6HpbOYBU2sIO2tAIb7+yqpVN1Au+0qIit+rQLpFebNEN53SFDbEcnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728632193; a=rsa-sha256; cv=none; b=aw0UrI5m5p9kqtCesrw2wKX6j5KZmpTNx3B0jhZZF7LqPzav1A+AM3z23If6GbaGM52H2l JsfS/HlA5ewgxQ2zexBgEmBZ9u1YXgIoAhPvGVfiW0AGYFEjiFpJxzUupI9ylo9bYAHxzN TplzOwvZHUdT1LNgifwFOx6SUjDumlzQZuO6Gi3ASBF3cTfhAoY38fWzf/kwJL0wwaxm+s Bp7yGkx1CxswTAx5n6MxXLHyN5dCCWUynL+XVJveixhhNw4Gqhf5gOSaBGdRgMSx/PGv8o 9M6icTGrsIiMKYWb2mrFy5IuGbNBAp5FUTMhP8XAoBSh69h401dBnvI5v2xcEw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XPz2n05d6zYLq; Fri, 11 Oct 2024 07:36:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49B7aWai040757; Fri, 11 Oct 2024 07:36:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49B7aWUP040754; Fri, 11 Oct 2024 07:36:32 GMT (envelope-from git) Date: Fri, 11 Oct 2024 07:36:32 GMT Message-Id: <202410110736.49B7aWUP040754@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: c1782c2d28a5 - stable/14 - xen-netfront: attempt to make cleanup idempotent List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c1782c2d28a59fab389aa6457f109afe3e9b43fc Auto-Submitted: auto-generated The branch stable/14 has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=c1782c2d28a59fab389aa6457f109afe3e9b43fc commit c1782c2d28a59fab389aa6457f109afe3e9b43fc Author: Roger Pau Monné AuthorDate: 2023-11-03 09:28:16 +0000 Commit: Roger Pau Monné CommitDate: 2024-10-11 07:06:25 +0000 xen-netfront: attempt to make cleanup idempotent Current cleanup code assumes that all the fields are allocated and/or setup by the time cleanup is called, but this is not always true: a failure in mid-setup of the device will cause the functions to be called with possibly uninitialized fields. Fix the functions to cope with such sate, while also attempting to make the cleanup idempotent. Finally fix an error path during setup that would not mark the device as closed, and hence prevents the kernel from finishing booting. Fixes: 96375eac945c ("xen-netfront: add multiqueue support") Sponsored by: Citrix Systems R&D (cherry picked from commit 318bbb6d5a1eae77eb5dc687bcc63c0f99558e21) --- sys/dev/xen/netfront/netfront.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c index da0f1680a87e..e13fb8765bae 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -597,8 +597,10 @@ talk_to_backend(device_t dev, struct netfront_info *info) num_queues = max_queues; err = setup_device(dev, info, num_queues); - if (err != 0) + if (err != 0) { + xenbus_dev_fatal(dev, err, "setup device"); goto out; + } again: err = xs_transaction_start(&xst); @@ -725,7 +727,10 @@ disconnect_rxq(struct netfront_rxq *rxq) xn_release_rx_bufs(rxq); gnttab_free_grant_references(rxq->gref_head); - gnttab_end_foreign_access(rxq->ring_ref, NULL); + if (rxq->ring_ref != GRANT_REF_INVALID) { + gnttab_end_foreign_access(rxq->ring_ref, NULL); + rxq->ring_ref = GRANT_REF_INVALID; + } /* * No split event channel support at the moment, handle will * be unbound in tx. So no need to call xen_intr_unbind here, @@ -740,6 +745,7 @@ destroy_rxq(struct netfront_rxq *rxq) callout_drain(&rxq->rx_refill); free(rxq->ring.sring, M_DEVBUF); + rxq->ring.sring = NULL; } static void @@ -771,6 +777,8 @@ setup_rxqs(device_t dev, struct netfront_info *info, rxq->id = q; rxq->info = info; + + rxq->gref_head = GNTTAB_LIST_END; rxq->ring_ref = GRANT_REF_INVALID; rxq->ring.sring = NULL; snprintf(rxq->name, XN_QUEUE_NAME_LEN, "xnrx_%u", q); @@ -827,7 +835,10 @@ disconnect_txq(struct netfront_txq *txq) xn_release_tx_bufs(txq); gnttab_free_grant_references(txq->gref_head); - gnttab_end_foreign_access(txq->ring_ref, NULL); + if (txq->ring_ref != GRANT_REF_INVALID) { + gnttab_end_foreign_access(txq->ring_ref, NULL); + txq->ring_ref = GRANT_REF_INVALID; + } xen_intr_unbind(&txq->xen_intr_handle); } @@ -837,9 +848,14 @@ destroy_txq(struct netfront_txq *txq) unsigned int i; free(txq->ring.sring, M_DEVBUF); + txq->ring.sring = NULL; buf_ring_free(txq->br, M_DEVBUF); - taskqueue_drain_all(txq->tq); - taskqueue_free(txq->tq); + txq->br = NULL; + if (txq->tq) { + taskqueue_drain_all(txq->tq); + taskqueue_free(txq->tq); + txq->tq = NULL; + } for (i = 0; i <= NET_TX_RING_SIZE; i++) { bus_dmamap_destroy(txq->info->dma_tag, @@ -878,6 +894,7 @@ setup_txqs(device_t dev, struct netfront_info *info, txq->id = q; txq->info = info; + txq->gref_head = GNTTAB_LIST_END; txq->ring_ref = GRANT_REF_INVALID; txq->ring.sring = NULL;