Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ice: live lock and timer re-init in ice_vf_fdir_init() during
  VF reset
- [Medium] ice: race with ctrl_vsi IRQ and timer in ice_vf_fdir_exit()
--

commit eec70f4e323b99b19bb5e3e82ec01ada929fa7eb
Author: Aleksandr Loktionov <[email protected]>

ice: cancel FDIR program timer on VF exit

This commit moves the setup of the VF FDIR timer to ice_vf_fdir_init()
and cancels it with timer_delete_sync() in ice_vf_fdir_exit() before
clearing ICE_VF_FDIR_CTX_VALID.

> diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c 
> b/drivers/net/ethernet/intel/ice/virt/fdir.c
> index 244da64722713..64824b10a47a4 100644
> --- a/drivers/net/ethernet/intel/ice/virt/fdir.c
> +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
[ ... ]
> @@ -2454,6 +2453,7 @@ void ice_vf_fdir_init(struct ice_vf *vf)
>       INIT_LIST_HEAD(&fdir->fdir_rule_list);
>  
>       spin_lock_init(&fdir->ctx_lock);
> +     timer_setup(&fdir->ctx_irq.rx_tmr, ice_vf_fdir_timer, 0);
>       fdir->ctx_irq.flags = 0;
>       fdir->ctx_done.flags = 0;
>       ice_vc_fdir_reset_cnt_all(fdir);

[Severity: Medium]
Can calling timer_setup() and spin_lock_init() in ice_vf_fdir_init()
re-initialize a live timer and spinlock during a VF reset?

In ice_reset_vf() and ice_reset_all_vfs(), ice_vf_fdir_exit() and
ice_vf_fdir_init() run before ice_vf_ctrl_vsi_release() stops the VF
control VSI and frees its interrupt:

drivers/net/ethernet/intel/ice/ice_vf_lib.c:ice_reset_vf() {
    ...
        ice_vf_fdir_exit(vf);
        ice_vf_fdir_init(vf);
        /* clean VF control VSI when resetting VF since it should be setup
         * only when VF creates its first FDIR rule.
         */
        if (vf->ctrl_vsi_idx != ICE_NO_VSI)
                ice_vf_ctrl_vsi_release(vf);
    ...
}

If a VF reset occurs while an FDIR programming completion interrupt is in
flight on ctrl_vsi, or while ice_flush_fdir_ctx() is running on another
CPU, those paths can access fdir->ctx_lock and fdir->ctx_irq.rx_tmr at
the same time as ice_vf_fdir_init() resets them:

CPU0                              CPU1 (<hardirq>)
ice_reset_vf()
  ice_vf_fdir_exit()
  ice_vf_fdir_init()
    spin_lock_init(&fdir->ctx_lock)
    timer_setup(&fdir->ctx_irq.rx_tmr, ...)
                                  ice_vc_fdir_irq_handler()
                                    spin_lock_irqsave(&fdir->ctx_lock, ...)
                                    ...
                                    timer_delete(&ctx_irq->rx_tmr)
                                      <-- concurrent timer_setup() / lock init
  ice_vf_ctrl_vsi_release()

This can corrupt spinlock, timer_list, or debugobjects state and trigger
lockdep splats.

> @@ -2465,6 +2465,14 @@ void ice_vf_fdir_init(struct ice_vf *vf)
>   */
>  void ice_vf_fdir_exit(struct ice_vf *vf)
>  {
> +     unsigned long flags;
> +
> +     timer_delete_sync(&vf->fdir.ctx_irq.rx_tmr);
> +
> +     spin_lock_irqsave(&vf->fdir.ctx_lock, flags);
> +     vf->fdir.ctx_irq.flags &= ~ICE_VF_FDIR_CTX_VALID;
> +     spin_unlock_irqrestore(&vf->fdir.ctx_lock, flags);
> +
>       ice_vc_fdir_flush_entry(vf);
>       idr_destroy(&vf->fdir.fdir_rule_idr);
>       ice_vc_fdir_rem_prof_all(vf);

[Severity: Medium]
Can an in-flight ctrl_vsi completion interrupt race with
ice_vf_fdir_exit() when a VF is reset or freed while an FDIR request is
pending?

All callers of ice_vf_fdir_exit() (ice_reset_vf(), ice_reset_all_vfs(),
and ice_free_vf_res()) release ctrl_vsi only after ice_vf_fdir_exit()
returns, so ice_vc_fdir_irq_handler() remains active throughout this
function:

CPU0                              CPU1 (<hardirq>)
ice_vf_fdir_exit()
  timer_delete_sync(&rx_tmr)
  spin_lock_irqsave(&ctx_lock)
  ctx_irq.flags &= ~ICE_VF_FDIR_CTX_VALID
  spin_unlock_irqrestore(&ctx_lock)
                                  ice_vc_fdir_irq_handler()
                                    spin_lock_irqsave(&ctx_lock)
                                    if (!(ctx_irq->flags &
                                          ICE_VF_FDIR_CTX_VALID))
                                      WARN_ON_ONCE(1);  <-- triggers warning
  ice_vc_fdir_flush_entry()
  ...
ice_vf_ctrl_vsi_release()

In addition, if ice_vc_fdir_irq_handler() fires after timer_delete_sync()
deactivates rx_tmr and before ctx_lock is taken to clear
ICE_VF_FDIR_CTX_VALID, timer_delete(&ctx_irq->rx_tmr) returns 0 and logs
"Unexpected inactive timer!".  And if either ice_vc_fdir_irq_handler() or
an already-running ice_vf_fdir_timer() callback waited on by
timer_delete_sync() promotes ctx_irq.conf into ctx_done.conf with
ICE_VF_FDIR_CTX_VALID set, ice_vf_fdir_exit() does not clear
ctx_done.flags before ice_vc_fdir_flush_entry() frees conf, leaving a
dangling ctx_done.conf pointer that a concurrent ice_flush_fdir_ctx() can
observe during ice_reset_vf().

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

Reply via email to