From nobody Mon Nov 06 10:17:48 2023 X-Original-To: dev-commits-src-main@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 4SP6jn17RMz508jq; Mon, 6 Nov 2023 10:17:49 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SP6jn0Z01z4SqM; Mon, 6 Nov 2023 10:17:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699265869; 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=YIDARx0cXawpUvAaP99PkDhMLeJw0036NqQ7xId8XQc=; b=U6x5O2A34RgvEvHc0JXcw+MO2p2K/ghaMtWk8stpfaZub8LdKcNfwCdKkHo6txEEYSdQTh 4h2hb7h2j9iJUftKREOnVUZLrYJ+R2g8yHOy39u+jX007wbVTM7sxyCHqMjU8UF/fc/IH3 JqWKP2bn2W6DpBh+9tVI9l6FNGiOAjOHLNcn76tQpxf3V7UtimbNbJH3AhFw2pL+PEpyoQ HegHOh6iw+5mNJdvlBT4iOJrTFUtRFRI3X/u1O2+CuWGC40Kbp6vu8/kqmU/wSXmV0T1pT tExuAHY4ilrq1Lihwmw89hffhluY1ZT9KiW6xPo+lT2q0kLD5jPpWgy/3GTJxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699265869; 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=YIDARx0cXawpUvAaP99PkDhMLeJw0036NqQ7xId8XQc=; b=Jhn/cg9JsrijjEDWTW7LzPJMI6ty/adNdeK91VHLWELk/02x2bmMWlmHdrmKlYRDwexsIc viAUTvazwxg/uUVFy20vyb3GLRwAz30YKQ/Xbv31Jha7AGGbiQHrvf9dEMfwSk90vE/Q5b yIvJKRhhd/a1iHd8inIHRNWCjdIFEkK38kTAREYtIXtV9HQ7OsDXFMIepGo9Ieb0mSGcTA pq989njjWVTpGNzR9/WaDUWkviQD51xajUXIdIoeYfptmZscOEVp9paDzY5VACZhF1R+vB +IkeOuM9POpGQc9QWzSixrI2/oZGfuyZ8Iic1tjvJrJC8ppxOXrGVwEpovMZDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699265869; a=rsa-sha256; cv=none; b=ZgWP04jZSBxP7J4Z0x+7odiftGiV7OAVgGtPDZXjikxnUdKdw7+alI5FsFyF3/zpnh1tYY sOEbaZ5GT7SjzvggCTnNsxRW1AQMZVJyGERaoqc6wHq/9GVK26fe0a+JisI1/1o81tSkK+ EOPupAFfCHUVXIGqS2mfajZpfQdEC/J2iylAnyLhcASbEmbHpecC0dn9OzMmFi0KDQc3AQ AJ1JQt/SlkOTkXnMMRjYiZsxnmYnJD8BxBeYMzGRkjdVb+XLBuRvK7TLzLrYJMs05DMXxe 1eCMBTO8Ydj3ouQtRyr9DJmbneMZBzjEAzd6n/qCFSuEZ81ESmIYmcnUBsU8+A== 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 4SP6jm6ZlSz13fj; Mon, 6 Nov 2023 10:17:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3A6AHmq7007450; Mon, 6 Nov 2023 10:17:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A6AHmpL007447; Mon, 6 Nov 2023 10:17:48 GMT (envelope-from git) Date: Mon, 6 Nov 2023 10:17:48 GMT Message-Id: <202311061017.3A6AHmpL007447@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: 318bbb6d5a1e - main - xen-netfront: attempt to make cleanup idempotent List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 318bbb6d5a1eae77eb5dc687bcc63c0f99558e21 Auto-Submitted: auto-generated The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=318bbb6d5a1eae77eb5dc687bcc63c0f99558e21 commit 318bbb6d5a1eae77eb5dc687bcc63c0f99558e21 Author: Roger Pau Monné AuthorDate: 2023-11-03 09:28:16 +0000 Commit: Roger Pau Monné CommitDate: 2023-11-06 10:17:40 +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 --- 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 dafb838cf328..6ac6ecc3bdb7 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -589,8 +589,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); @@ -717,7 +719,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, @@ -732,6 +737,7 @@ destroy_rxq(struct netfront_rxq *rxq) callout_drain(&rxq->rx_refill); free(rxq->ring.sring, M_DEVBUF); + rxq->ring.sring = NULL; } static void @@ -763,6 +769,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); @@ -819,7 +827,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); } @@ -829,9 +840,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, @@ -870,6 +886,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;