Skip to contentSkip to conversation

net/netvsc: support runtime queue count reconfiguration

PATCH In review Long Li 2 participants 3 messages Feb 25 – Feb 26 Network drivers

lore
Share & tools
lore

Long Li

author
#0 lore raw

PATCH 1/1 net/netvsc: support runtime queue count reconfiguration

Add support for changing the number of RX/TX queues at runtime via port stop/configure/start. When the queue count changes, perform a full NVS/RNDIS teardown and reinit to allocate fresh VMBus subchannels matching the new queue count, then reconfigure RSS indirection table accordingly.

Key changes:
- hn_dev_configure: detect queue count changes and perform full NVS session reinit with subchannel teardown/recreation
- hn_dev_stop: drain pending TX completions (up to 1s) to prevent stale completions from corrupting queue state after reconfig
- eth_hn_dev_uninit: close subchannels before primary channel to prevent resource leaks on device removal
- hn_vf_tx/rx_queue_release: null VF queue pointers after release to prevent use-after-free when the ethdev framework releases excess queues during VF reconfiguration

---
 drivers/net/netvsc/hn_ethdev.c | 151 ++++++++++++++++++++++++++++++++-
 drivers/net/netvsc/hn_vf.c     |   8 +-
 2 files changed, 154 insertions(+), 5 deletions(-)
drivers/net/netvsc/hn_ethdev.c +148 -3
index 6584819f4f..a0bb37a66c 100644
@@ -745,6 +745,9 @@ netvsc_hotadd_callback(const char *device_name, enum rte_dev_event_type type,
 	}
 }
 
+static void hn_detach(struct hn_data *hv);
+static int hn_attach(struct hn_data *hv, unsigned int mtu);
+
 static int hn_dev_configure(struct rte_eth_dev *dev)
 {
 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
@@ -754,6 +757,7 @@ static int hn_dev_configure(struct rte_eth_dev *dev)
 	struct hn_data *hv = dev->data->dev_private;
 	uint64_t unsupported;
 	int i, err, subchan;
+	uint32_t old_subchans = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -778,6 +782,7 @@ static int hn_dev_configure(struct rte_eth_dev *dev)
 
 	hv->vlan_strip = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
 
+	/* Configure RNDIS offload regardless of queue count change */
 	err = hn_rndis_conf_offload(hv, txmode->offloads,
 				    rxmode->offloads);
 	if (err) {
@@ -786,28 +791,93 @@ static int hn_dev_configure(struct rte_eth_dev *dev)
 		return err;
 	}
 
+	/* If queue count unchanged, skip subchannel teardown/reinit */
+	if (RTE_MAX(dev->data->nb_rx_queues,
+		    dev->data->nb_tx_queues) == hv->num_queues)
+		goto skip_reinit;
+
 	hv->num_queues = RTE_MAX(dev->data->nb_rx_queues,
 				 dev->data->nb_tx_queues);
 
+	/* Close all existing subchannels */
+	for (i = 1; i < HN_MAX_CHANNELS; i++) {
+		if (hv->channels[i] != NULL) {
+			rte_vmbus_chan_close(hv->channels[i]);
+			hv->channels[i] = NULL;
+			old_subchans++;
+		}
+	}
+
+	/*
+	 * If subchannels existed, do a full NVS/RNDIS teardown
+	 * and vmbus re-init to ensure a clean NVS session.
+	 * Cannot re-send NVS subchannel request on the same
+	 * session without invalidating the data path.
+	 */
+	if (old_subchans > 0) {
+		PMD_DRV_LOG(NOTICE,
+			    "reinit NVS (had %u subchannels)",
+			    old_subchans);
+
+		hn_detach(hv);
+
+		rte_vmbus_chan_close(hv->channels[0]);
+		rte_free(hv->channels[0]);
+		hv->channels[0] = NULL;
+
+		rte_vmbus_unmap_device(hv->vmbus);
+		err = rte_vmbus_map_device(hv->vmbus);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				    "Could not re-map vmbus device!");
+			goto reinit_failed;
+		}
+
+		hv->rxbuf_res = hv->vmbus->resource[HV_RECV_BUF_MAP];
+		hv->chim_res  = hv->vmbus->resource[HV_SEND_BUF_MAP];
+
+		err = rte_vmbus_chan_open(hv->vmbus, &hv->channels[0]);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				    "Could not re-open vmbus channel!");
+			goto reinit_failed;
+		}
+
+		rte_vmbus_set_latency(hv->vmbus, hv->channels[0],
+				      hv->latency);
+
+		err = hn_attach(hv, dev->data->mtu);
+		if (err) {
+			rte_vmbus_chan_close(hv->channels[0]);
+			rte_free(hv->channels[0]);
+			hv->channels[0] = NULL;
+			PMD_DRV_LOG(ERR,
+				    "NVS reinit failed: %d", err);
+			goto reinit_failed;
+		}
+	}
+
 	for (i = 0; i < NDIS_HASH_INDCNT; i++)
 		hv->rss_ind[i] = i % dev->data->nb_rx_queues;
 
 	hn_rss_hash_init(hv, rss_conf);
 
 	subchan = hv->num_queues - 1;
+
+	/* Allocate fresh subchannels and configure RSS */
 	if (subchan > 0) {
 		err = hn_subchan_configure(hv, subchan);
 		if (err) {
 			PMD_DRV_LOG(NOTICE,
 				    "subchannel configuration failed");
-			return err;
+			goto subchan_cleanup;
 		}
 
 		err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
 		if (err) {
 			PMD_DRV_LOG(NOTICE,
 				"rss disable failed");
-			return err;
+			goto subchan_cleanup;
 		}
 
 		if (rss_conf->rss_hf != 0) {
@@ -815,12 +885,53 @@ static int hn_dev_configure(struct rte_eth_dev *dev)
 			if (err) {
 				PMD_DRV_LOG(NOTICE,
 					    "initial RSS config failed");
-				return err;
+				goto subchan_cleanup;
 			}
 		}
 	}
 
+skip_reinit:
 	return hn_vf_configure_locked(dev, dev_conf);
+
+subchan_cleanup:
+	for (i = 1; i < HN_MAX_CHANNELS; i++) {
+		if (hv->channels[i] != NULL) {
+			rte_vmbus_chan_close(hv->channels[i]);
+			hv->channels[i] = NULL;
+		}
+	}
+	hv->num_queues = 1;
+	return err;
+
+reinit_failed:
+	/* Device is in a broken state after failed reinit.
+	 * Try to re-establish minimal connectivity.
+	 */
+	PMD_DRV_LOG(ERR,
+		    "reinit failed (err %d), attempting recovery", err);
+	if (hv->channels[0] == NULL) {
+		if (rte_vmbus_chan_open(hv->vmbus, &hv->channels[0]) == 0) {
+			if (hn_attach(hv, dev->data->mtu) == 0) {
+				hv->num_queues = 1;
+				PMD_DRV_LOG(NOTICE,
+					    "recovery successful on primary channel");
+			} else {
+				rte_vmbus_chan_close(hv->channels[0]);
+				rte_free(hv->channels[0]);
+				hv->channels[0] = NULL;
+				hv->num_queues = 0;
+				PMD_DRV_LOG(ERR,
+					    "recovery failed, device unusable");
+			}
+		} else {
+			hv->num_queues = 0;
+			PMD_DRV_LOG(ERR,
+				    "recovery failed, device unusable");
+		}
+	} else {
+		hv->num_queues = 1;
+	}
+	return err;
 }
 
 static int hn_dev_stats_get(struct rte_eth_dev *dev,
@@ -1067,6 +1178,7 @@ hn_dev_stop(struct rte_eth_dev *dev)
 {
 	struct hn_data *hv = dev->data->dev_private;
 	int i, ret;
+	unsigned int retry;
 
 	PMD_INIT_FUNC_TRACE();
 	dev->data->dev_started = 0;
@@ -1075,6 +1187,29 @@ hn_dev_stop(struct rte_eth_dev *dev)
 	hn_rndis_set_rxfilter(hv, 0);
 	ret = hn_vf_stop(dev);
 
+	/*
+	 * Drain pending TX completions to prevent stale completions
+	 * from corrupting queue state after port reconfiguration.
+	 */
+	for (retry = 0; retry < 100; retry++) {
+		uint32_t pending = 0;
+
+		for (i = 0; i < hv->num_queues; i++) {
+			struct hn_tx_queue *txq = dev->data->tx_queues[i];
+
+			if (txq == NULL)
+				continue;
+			hn_process_events(hv, i, 0);
+			pending += rte_mempool_in_use_count(txq->txdesc_pool);
+		}
+		if (pending == 0)
+			break;
+		rte_delay_ms(10);
+	}
+	if (retry >= 100)
+		PMD_DRV_LOG(WARNING,
+			    "Failed to drain all TX completions");
+
 	for (i = 0; i < hv->num_queues; i++) {
 		dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
 		dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
@@ -1433,6 +1568,7 @@ eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct hn_data *hv = eth_dev->data->dev_private;
 	int ret, ret_stop;
+	int i;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1444,6 +1580,15 @@ eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
 
 	hn_detach(hv);
 	hn_chim_uninit(eth_dev);
+
+	/* Close any subchannels before closing the primary channel */
+	for (i = 1; i < HN_MAX_CHANNELS; i++) {
+		if (hv->channels[i] != NULL) {
+			rte_vmbus_chan_close(hv->channels[i]);
+			hv->channels[i] = NULL;
+		}
+	}
+
 	rte_vmbus_chan_close(hv->channels[0]);
 	rte_free(hv->primary);
 	ret = rte_eth_dev_owner_delete(hv->owner.id);
drivers/net/netvsc/hn_vf.c +6 -2
index 0ecfaf54ea..756241e58d 100644
@@ -639,8 +639,10 @@ void hn_vf_tx_queue_release(struct hn_data *hv, uint16_t queue_id)
 
 	rte_rwlock_read_lock(&hv->vf_lock);
 	vf_dev = hn_get_vf_dev(hv);
-	if (vf_dev && vf_dev->dev_ops->tx_queue_release)
+	if (vf_dev && vf_dev->dev_ops->tx_queue_release) {
 		(*vf_dev->dev_ops->tx_queue_release)(vf_dev, queue_id);
+		vf_dev->data->tx_queues[queue_id] = NULL;
+	}
 
 	rte_rwlock_read_unlock(&hv->vf_lock);
 }
@@ -671,8 +673,10 @@ void hn_vf_rx_queue_release(struct hn_data *hv, uint16_t queue_id)
 
 	rte_rwlock_read_lock(&hv->vf_lock);
 	vf_dev = hn_get_vf_dev(hv);
-	if (vf_dev && vf_dev->dev_ops->rx_queue_release)
+	if (vf_dev && vf_dev->dev_ops->rx_queue_release) {
 		(*vf_dev->dev_ops->rx_queue_release)(vf_dev, queue_id);
+		vf_dev->data->rx_queues[queue_id] = NULL;
+	}
 	rte_rwlock_read_unlock(&hv->vf_lock);
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 17 lines · On Wed, 25 Feb 2026 11:50:40 -0800 Long Li <[email protected]> wrote:

Add support for changing the number of RX/TX queues at runtime via port stop/configure/start. When the queue count changes, perform a full NVS/RNDIS teardown and reinit to allocate fresh VMBus subchannels matching the new queue count, then reconfigure RSS indirection table accordingly.

Key changes:
- hn_dev_configure: detect queue count changes and perform full NVS session reinit with subchannel teardown/recreation
- hn_dev_stop: drain pending TX completions (up to 1s) to prevent stale completions from corrupting queue state after reconfig
- eth_hn_dev_uninit: close subchannels before primary channel to prevent resource leaks on device removal
- hn_vf_tx/rx_queue_release: null VF queue pointers after release to prevent use-after-free when the ethdev framework releases excess queues during VF reconfiguration

Quoted 2 lines

---

Sorry for AI review overload here...

## Patch Review: [PATCH] net/netvsc: support runtime queue count reconfiguration

### Errors

**(E1) hn_dev_configure: rte_vmbus_unmap_device after closing subchannels and primary channel — subsequent rte_vmbus_map_device failure leaves device in unrecoverable state with no channel and no mapping**

The reinit sequence is:

```c
hn_detach(hv);
rte_vmbus_chan_close(hv->channels[0]);
rte_free(hv->channels[0]);
hv->channels[0] = NULL;

rte_vmbus_unmap_device(hv->vmbus);
err = rte_vmbus_map_device(hv->vmbus);
if (err) {
    PMD_DRV_LOG(ERR, "Could not re-map vmbus device!");
    goto reinit_failed;
}
```

If rte_vmbus_map_device fails, execution goes to reinit_failed, which attempts recovery by calling rte_vmbus_chan_open. But the device is unmapped at this point — the MMIO regions are gone. rte_vmbus_chan_open on an unmapped device is undefined behavior (it will try to access unmapped ring buffers). The recovery path cannot work without a successful map. The recovery block should check whether the device is mapped before attempting channel open, or re-attempt the map first.

**(E2) hn_dev_configure: rte_free(hv->channels[0]) frees memory not allocated with rte_malloc**

After closing the primary channel:

```c
rte_vmbus_chan_close(hv->channels[0]);
rte_free(hv->channels[0]);
hv->channels[0] = NULL;
```

And similarly in the hn_attach failure recovery:

```c
rte_vmbus_chan_close(hv->channels[0]);
rte_free(hv->channels[0]);
hv->channels[0] = NULL;
```

channels[0] is allocated by rte_vmbus_chan_open(). Whether this is rte_malloc'd or regular malloc'd depends on the vmbus implementation. If rte_vmbus_chan_open uses malloc internally (which is common for control structures), then rte_free is a mismatch that may silently corrupt the heap. Need to verify the allocation source matches — or use the same free that rte_vmbus_chan_close would use. In eth_hn_dev_uninit (existing code), the primary channel is freed via rte_free(hv->primary), not rte_free(hv->channels[0]), suggesting these may be different pointers or the allocation path uses rte_malloc. Worth verifying.

**(E3) hn_dev_configure: RNDIS offload configuration applied before queue count change check, not re-applied after NVS teardown/reinit**

The sequence is:

```c
err = hn_rndis_conf_offload(hv, ...);  /* Configure RNDIS offload */
...
if (queue count unchanged)
    goto skip_reinit;

/* Close subchannels, hn_detach(), chan_close, chan_open, hn_attach() */
```

hn_detach() tears down the RNDIS session. hn_attach() establishes a new NVS/RNDIS session. But hn_rndis_conf_offload() was called *before* the teardown and is not called again after hn_attach(). The offload configuration from the first call is lost when the RNDIS session is destroyed. The offload configuration should be re-applied after hn_attach(), or moved to after the reinit block.

**(E4) hn_vf_tx_queue_release / hn_vf_rx_queue_release: setting queue pointer to NULL under read lock while Tx/Rx paths read the same pointer under read lock**

```c
rte_rwlock_read_lock(&hv->vf_lock);
vf_dev = hn_get_vf_dev(hv);
if (vf_dev && vf_dev->dev_ops->tx_queue_release) {
    (*vf_dev->dev_ops->tx_queue_release)(vf_dev, queue_id);
    vf_dev->data->tx_queues[queue_id] = NULL;
}
rte_rwlock_read_unlock(&hv->vf_lock);
```

The fast path (hn_xmit_pkts) reads vf_dev->data->tx_queues[queue_id] under the same read lock:

```c
void *sub_q = vf_dev->data->tx_queues[queue_id];
nb_tx = (*vf_dev->tx_pkt_burst)(sub_q, tx_pkts, nb_pkts);
```

Multiple readers can hold a rwlock simultaneously. This means a Tx thread could read the queue pointer, then the release thread NULLs it and frees the underlying memory, and the Tx thread calls into freed memory. The NULL assignment after release prevents *subsequent* accesses, but doesn't protect a concurrent reader that already loaded the pointer. This needs a write lock, not a read lock.

### Warnings

**(W1) hn_dev_configure: subchan_cleanup error path sets hv->num_queues = 1 but doesn't restore RSS indirection table**

The subchan_cleanup label closes subchannels and resets num_queues to 1, but the RSS indirection table (hv->rss_ind[]) was already updated to distribute across the new (failed) queue count:

```c
for (i = 0; i < NDIS_HASH_INDCNT; i++)
    hv->rss_ind[i] = i % dev->data->nb_rx_queues;
```

If nb_rx_queues was e.g. 4 and subchannel allocation failed, the indirection table points to queues 0-3 but only queue 0 exists. The indirection table should be reset to all-zeros in the cleanup path.

**(W2) hn_dev_stop: TX drain loop accesses dev->data->tx_queues[i] up to hv->num_queues without bounds check against configured queue count**

```c
for (i = 0; i < hv->num_queues; i++) {
    struct hn_tx_queue *txq = dev->data->tx_queues[i];
    if (txq == NULL)
        continue;
    ...
```

hv->num_queues could be larger than the actual number of configured Tx queues (dev->data->nb_tx_queues) if configuration reduced the count but num_queues wasn't yet updated. The NULL check provides some protection, but iterating with RTE_MIN(hv->num_queues, dev->data->nb_tx_queues) would be safer.

**(W3) Missing Cc: [email protected] and Fixes: tag for the eth_hn_dev_uninit subchannel leak fix**

The commit message states this change prevents resource leaks on device removal ("close subchannels before primary channel"). This is a bug fix for existing code, not just infrastructure for the new feature. It should have a Fixes: tag referencing the commit that added subchannel support, and Cc: [email protected] for backport consideration. Alternatively, this could be split into a separate bug-fix patch.

**(W4) hn_dev_configure: recovery path uses deeply nested if/else with duplicated error logging**

The reinit_failed block has three levels of nesting with repeated "recovery failed, device unusable" messages. Consider restructuring with early-return or goto to reduce nesting and deduplicate the error messages.

**(W5) Comment style: multi-line comment at reinit_failed doesn't follow DPDK style**

```c
	/* Device is in a broken state after failed reinit.
	 * Try to re-establish minimal connectivity.
	 */
```

DPDK style requires the first line of a multi-line comment to contain only /*:

```c
	/*
	 * Device is in a broken state after failed reinit.
	 * Try to re-establish minimal connectivity.
	 */
```

---

### Summary

The most critical findings are E3 (lost RNDIS offload config after teardown/reinit — the device will come back with default offload settings rather than what was requested), E4 (read lock insufficient for queue pointer NULLing — concurrent Tx/Rx can use-after-free), and E1 (recovery path after failed remap operates on unmapped device). E2 needs verification of the allocation source for channels[0].

The overall approach of full NVS teardown/reinit for queue count changes is sound, and the TX drain in hn_dev_stop and subchannel cleanup in eth_hn_dev_uninit are good improvements. The error handling is thorough for the most part — the recovery attempt in reinit_failed is a nice touch even if the unmapped-device issue needs fixing.

author
#2 lore raw
Quoted 23 lines

Subject: [EXTERNAL] Re: [PATCH] net/netvsc: support runtime queue count reconfiguration

Quoted 17 lines · On Wed, 25 Feb 2026 11:50:40 -0800 Long Li <[email protected]> wrote:

Add support for changing the number of RX/TX queues at runtime via port stop/configure/start. When the queue count changes, perform a full NVS/RNDIS teardown and reinit to allocate fresh VMBus subchannels matching the new queue count, then reconfigure RSS indirection table accordingly.

Key changes:
- hn_dev_configure: detect queue count changes and perform full NVS session reinit with subchannel teardown/recreation
- hn_dev_stop: drain pending TX completions (up to 1s) to prevent stale completions from corrupting queue state after reconfig
- eth_hn_dev_uninit: close subchannels before primary channel to prevent resource leaks on device removal
- hn_vf_tx/rx_queue_release: null VF queue pointers after release to prevent use-after-free when the ethdev framework releases excess queues during VF reconfiguration

Quoted 4 lines
Quoted 2 lines

---

Sorry for AI review overload here...

E2 is not correct, all others make sense.

I'm sending v2, with two patches. One original patch, the other patch suggested by W3 with a "fixes" tag.

Thanks,
Long

Quoted 195 lines

## Patch Review: [PATCH] net/netvsc: support runtime queue count reconfiguration

### Errors

**(E1) hn_dev_configure: rte_vmbus_unmap_device after closing subchannels and primary channel — subsequent rte_vmbus_map_device failure leaves device in unrecoverable state with no channel and no mapping**

The reinit sequence is:

```c
hn_detach(hv);
rte_vmbus_chan_close(hv->channels[0]);
rte_free(hv->channels[0]);
hv->channels[0] = NULL;

rte_vmbus_unmap_device(hv->vmbus);
err = rte_vmbus_map_device(hv->vmbus);
if (err) {
    PMD_DRV_LOG(ERR, "Could not re-map vmbus device!");
    goto reinit_failed;
}
```

If rte_vmbus_map_device fails, execution goes to reinit_failed, which attempts recovery by calling rte_vmbus_chan_open. But the device is unmapped at this point — the MMIO regions are gone. rte_vmbus_chan_open on an unmapped device is undefined behavior (it will try to access unmapped ring buffers). The recovery path cannot work without a successful map. The recovery block should check whether the device is mapped before attempting channel open, or re- attempt the map first.

**(E2) hn_dev_configure: rte_free(hv->channels[0]) frees memory not allocated with rte_malloc**

After closing the primary channel:

```c
rte_vmbus_chan_close(hv->channels[0]);
rte_free(hv->channels[0]);
hv->channels[0] = NULL;
```

And similarly in the hn_attach failure recovery:

```c
rte_vmbus_chan_close(hv->channels[0]);
rte_free(hv->channels[0]);
hv->channels[0] = NULL;
```

channels[0] is allocated by rte_vmbus_chan_open(). Whether this is rte_malloc'd or regular malloc'd depends on the vmbus implementation. If rte_vmbus_chan_open uses malloc internally (which is common for control structures), then rte_free is a mismatch that may silently corrupt the heap. Need to verify the allocation source matches — or use the same free that rte_vmbus_chan_close would use. In eth_hn_dev_uninit (existing code), the primary channel is freed via rte_free(hv->primary), not `rte_free(hv-

Quoted 1 line

channels[0])`, suggesting these may be different pointers or the allocation path

uses rte_malloc. Worth verifying.

**(E3) hn_dev_configure: RNDIS offload configuration applied before queue count change check, not re-applied after NVS teardown/reinit**

The sequence is:

```c
err = hn_rndis_conf_offload(hv, ...);  /* Configure RNDIS offload */ ...
if (queue count unchanged)
    goto skip_reinit;

/* Close subchannels, hn_detach(), chan_close, chan_open, hn_attach() */ ```

`hn_detach()` tears down the RNDIS session. `hn_attach()` establishes a new
NVS/RNDIS session. But `hn_rndis_conf_offload()` was called *before* the
teardown and is not called again after `hn_attach()`. The offload configuration
from the first call is lost when the RNDIS session is destroyed. The offload
configuration should be re-applied after `hn_attach()`, or moved to after the reinit
block.

**(E4) `hn_vf_tx_queue_release` / `hn_vf_rx_queue_release`: setting queue
pointer to NULL under read lock while Tx/Rx paths read the same pointer under
read lock**

```c
rte_rwlock_read_lock(&hv->vf_lock);
vf_dev = hn_get_vf_dev(hv);
if (vf_dev && vf_dev->dev_ops->tx_queue_release) {
    (*vf_dev->dev_ops->tx_queue_release)(vf_dev, queue_id);
    vf_dev->data->tx_queues[queue_id] = NULL; } rte_rwlock_read_unlock(&hv-
Quoted 1 line

vf_lock);

```

The fast path (`hn_xmit_pkts`) reads `vf_dev->data->tx_queues[queue_id]` under
the same read lock:

```c

void *sub_q = vf_dev->data->tx_queues[queue_id]; nb_tx = (*vf_dev->tx_pkt_burst)(sub_q, tx_pkts, nb_pkts); ```

Multiple readers can hold a rwlock simultaneously. This means a Tx thread could read the queue pointer, then the release thread NULLs it and frees the underlying memory, and the Tx thread calls into freed memory. The NULL assignment after release prevents *subsequent* accesses, but doesn't protect a concurrent reader that already loaded the pointer. This needs a write lock, not a read lock.

### Warnings

**(W1) hn_dev_configure: subchan_cleanup error path sets hv->num_queues = 1 but doesn't restore RSS indirection table**

The subchan_cleanup label closes subchannels and resets num_queues to 1, but the RSS indirection table (hv->rss_ind[]) was already updated to distribute across the new (failed) queue count:

```c
for (i = 0; i < NDIS_HASH_INDCNT; i++)
    hv->rss_ind[i] = i % dev->data->nb_rx_queues; ```

If `nb_rx_queues` was e.g. 4 and subchannel allocation failed, the indirection
table points to queues 0-3 but only queue 0 exists. The indirection table should be
reset to all-zeros in the cleanup path.

**(W2) `hn_dev_stop`: TX drain loop accesses `dev->data->tx_queues[i]` up to
`hv->num_queues` without bounds check against configured queue count**

```c
for (i = 0; i < hv->num_queues; i++) {
    struct hn_tx_queue *txq = dev->data->tx_queues[i];
    if (txq == NULL)
        continue;
    ...
```

`hv->num_queues` could be larger than the actual number of configured Tx
queues (`dev->data->nb_tx_queues`) if configuration reduced the count but
`num_queues` wasn't yet updated. The NULL check provides some protection,
but iterating with `RTE_MIN(hv->num_queues, dev->data->nb_tx_queues)` would
be safer.

**(W3) Missing `Cc: [email protected]` and `Fixes:` tag for the
`eth_hn_dev_uninit` subchannel leak fix**

The commit message states this change prevents resource leaks on device
removal ("close subchannels before primary channel"). This is a bug fix for
existing code, not just infrastructure for the new feature. It should have a `Fixes:`
tag referencing the commit that added subchannel support, and `Cc:
[email protected]` for backport consideration. Alternatively, this could be split into
a separate bug-fix patch.

**(W4) `hn_dev_configure`: recovery path uses deeply nested if/else with
duplicated error logging**

The `reinit_failed` block has three levels of nesting with repeated "recovery failed,
device unusable" messages. Consider restructuring with early-return or goto to
reduce nesting and deduplicate the error messages.

**(W5) Comment style: multi-line comment at `reinit_failed` doesn't follow DPDK
style**

```c
	/* Device is in a broken state after failed reinit.
	 * Try to re-establish minimal connectivity.
	 */
```

DPDK style requires the first line of a multi-line comment to contain only `/*`:

```c
	/*
	 * Device is in a broken state after failed reinit.
	 * Try to re-establish minimal connectivity.
	 */

```

---

### Summary

The most critical findings are E3 (lost RNDIS offload config after teardown/reinit — the device will come back with default offload settings rather than what was requested), E4 (read lock insufficient for queue pointer NULLing — concurrent Tx/Rx can use-after-free), and E1 (recovery path after failed remap operates on unmapped device). E2 needs verification of the allocation source for channels[0].

The overall approach of full NVS teardown/reinit for queue count changes is sound, and the TX drain in hn_dev_stop and subchannel cleanup in eth_hn_dev_uninit are good improvements. The error handling is thorough for the most part — the recovery attempt in reinit_failed is a nice touch even if the unmapped-device issue needs fixing.