Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: mana: swapped HWC request/response limits in
  mana_hwc_finish_channel()
- [Medium] net: mana: duplicate mana_hwc_teardown_queues() on HWC
  rebuild failure
--

commit 3fabf9cbfe8a174f5953b462e57e3b1f0fcf54f1
Author: Long Li <[email protected]>

net: mana: add dynamic HWC queue depth with reinit path

This commit adds support for dynamically rebuilding the MANA hardware
channel queues to the PF-reported queue depth (up to 128), validating
reported message size limits and doorbells, and falling back to bootstrap
queues if rebuilding fails.

Link: https://lore.kernel.org/r/[email protected]
Link: 
https://lore.kernel.org/r/[email protected]
Link: 
https://lore.kernel.org/r/[email protected]

> diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c 
> b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> index 8c2495ce5f526..cb73d0725206e 100644
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c

[ ... ]

> @@ -1175,32 +1256,169 @@ void mana_hwc_free_retained_channel(struct 
> gdma_context *gc)
>       gc->hwc.gdma_context = NULL;
>  }
>  
> -static int mana_hwc_create_bootstrap_channel(struct hw_channel_context *hwc)
> +static int
> +mana_hwc_validate_report(struct hw_channel_context *hwc,
> +                      const struct mana_hwc_init_report *report,
> +                      u32 expected_depth, bool check_depth,
> +                      bool require_exact_msg_sizes)
> +{
> +     if (!report->queue_depth || !report->max_req_msg_size ||
> +         !report->max_resp_msg_size) {
> +             dev_err(hwc->dev,
> +                     "HWC: invalid maxima depth=%u req=%u resp=%u\n",
> +                     report->queue_depth, report->max_req_msg_size,
> +                     report->max_resp_msg_size);
> +             return -EPROTO;
> +     }
> +
> +     if (require_exact_msg_sizes &&
> +         (report->max_req_msg_size != HW_CHANNEL_MAX_REQUEST_SIZE ||
> +          report->max_resp_msg_size != HW_CHANNEL_MAX_RESPONSE_SIZE)) {
> +             dev_err(hwc->dev,
> +                     "HWC: rebuilt message maxima req=%u resp=%u, expected 
> %u/%u\n",
> +                     report->max_req_msg_size, report->max_resp_msg_size,
> +                     HW_CHANNEL_MAX_REQUEST_SIZE,
> +                     HW_CHANNEL_MAX_RESPONSE_SIZE);
> +             return -EPROTO;
> +     }
> +
> +     if (check_depth && report->queue_depth != expected_depth) {
> +             dev_err(hwc->dev, "HWC: rebuilt depth %u, expected %u\n",
> +                     report->queue_depth, expected_depth);
> +             return -EPROTO;
> +     }
> +
> +     return 0;
> +}
> +
> +static int mana_hwc_finish_channel(struct hw_channel_context *hwc,
> +                                const struct mana_hwc_init_report *report)
> +{
> +     int err;
> +
> +     /* MAX_REQUEST sizes the RQ; MAX_RESPONSE sizes the SQ. */
> +     hwc->rx_msg_size_limit = report->max_req_msg_size;
> +     hwc->tx_msg_size_limit = report->max_resp_msg_size;

[Severity: Medium]
Are rx_msg_size_limit and tx_msg_size_limit swapped here?

On the HWC, the host sends requests over hwc->txq (GDMA_SQ) in
mana_hwc_send_request() and receives responses over hwc->rxq (GDMA_RQ) in
mana_hwc_rx_event_handler().  Because tx_msg_size_limit is populated from
report->max_resp_msg_size and rx_msg_size_limit from
report->max_req_msg_size, mana_hwc_get_max_req_size() and
mana_hwc_get_msg_index() check outgoing req_len against the PF-reported
response limit and incoming resp_len against the request limit.

When the PF reports asymmetric HWC_INIT_DATA_MAX_REQUEST and
HWC_INIT_DATA_MAX_RESPONSE values (where mana_hwc_prepare_channel() keeps
the bootstrap queues), a smaller MAX_RESPONSE will cause outgoing requests
such as mana_gd_create_dma_region() and mana_ib_gd_create_dma_region() to be
capped or rejected with -EMSGSIZE or -EINVAL against the response limit.

> +
> +     err = mana_hwc_test_channel(hwc);
> +     if (err)
> +             dev_err(hwc->dev, "Failed to test HWC: %d\n", err);
> +
> +     return err;
> +}

[ ... ]

> +static int mana_hwc_rebuild_channel(struct hw_channel_context *hwc,
> +                                 u16 q_depth,
> +                                 struct mana_hwc_init_report *report)
> +{
> +     u32 timeout_ms = mana_hwc_timeout_read(hwc);
> +     int cleanup_err;
> +     int err;
> +
> +     err = mana_hwc_teardown_queues(hwc);
> +     if (err)
> +             return err;
> +
> +     err = mana_hwc_build_channel(hwc, q_depth, report);
> +     if (!err)
> +             err = mana_hwc_validate_report(hwc, report, q_depth,
> +                                            true, true);
> +     if (!err)
> +             err = mana_hwc_finish_channel(hwc, report);
> +     if (!err)
> +             return 0;
> +
> +     dev_warn(hwc->dev,
> +              "HWC depth %u rebuild failed, restoring bootstrap: %d\n",
> +              q_depth, err);
> +
> +     cleanup_err = mana_hwc_teardown_queues(hwc);
> +     if (cleanup_err)
> +             return cleanup_err;

[ ... ]

> @@ -1233,7 +1451,7 @@ int mana_hwc_create_channel(struct gdma_context *gc)
>       gd->pdid = INVALID_PDID;
>       gd->doorbell = INVALID_DOORBELL;
>  
> -     err = mana_hwc_create_bootstrap_channel(hwc);
> +     err = mana_hwc_prepare_channel(hwc);
>       if (err) {
>               mana_hwc_release_channel(hwc);
>               return err;

[Severity: Medium]
Does failing inside mana_hwc_teardown_queues() during
mana_hwc_rebuild_channel() cause mana_hwc_release_channel() to run
mana_hwc_teardown_queues() a second time on the same active channel?

When mana_smc_teardown_hwc() fails in mana_hwc_teardown_queues(),
hwc->setup_active remains true and the channel is fenced, and that error is
returned through mana_hwc_prepare_channel() to mana_hwc_create_channel().
mana_hwc_release_channel() then calls mana_hwc_teardown_queues() again while
hwc->setup_active is still true, issuing a second SMC teardown transaction
that can stall in mana_smc_poll_register() for another 20 to 40 seconds or
send a duplicate SMC_MSG_TYPE_DESTROY_HWC if the PF completed the first
teardown right after it timed out.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=4

Reply via email to