> > +static int netc_switch_reset(struct netc_switch *priv)
> > +{
> > +   struct pci_dev *pdev = priv->pdev;
> > +   int err;
> > +
> > +   if (!priv->configured) {
> > +           /* The hardware will be configured after netc_switch_reset()
> > +            * is called, so set priv->configured to true.
> > +            */
> > +           priv->configured = true;
> > +           return 0;
> > +   }
> 
> [Severity: Medium]
> Can the first netc_setup() start on stale hardware tables if the FLR in
> probe failed?
> 
> The commit message says:
> 
>     The probe path already performs a FLR in netc_switch_pci_init(), so
>     the first setup will skip the reset because the priv->configured flag
>     is not set.
> 
> But netc_switch_pci_init() ignores the pcie_flr() return value:
> 
> drivers/net/dsa/netc/netc_main.c:netc_switch_pci_init() {
>     ...
>       pcie_flr(pdev);
>       err = pcim_enable_device(pdev);
>     ...
> }
> 
> pcie_flr() can fail. It returns -ENOTTY if config space is not
> accessible or if pci_dev_wait() times out. It can also fail through
> pci_dev_reset_iommu_prepare() for an ATS-capable device behind an
> IOMMU.
> 
> Suppose that happens after an unbind/rebind:
> 
> netc_switch_probe()
>   netc_switch_pci_init()
>     pcie_flr()            <- fails, error ignored
>   dsa_register_switch()
>     netc_setup()
>       netc_switch_reset() <- returns 0 early, !priv->configured
> 
> The FDB, VLAN filter, IPFT, BPT and ETT entries from the previous binding
> would then stay in hardware. netc_setup() builds empty software state on
> top of them, and the driver has no record of those entries to remove.
> 
> Later setups treat an FLR failure as fatal, so a failed first FLR is
> handled differently. Should the probe path check the pcie_flr() result
> and fail probe? Alternatively, priv->configured could be set only after
> a successful FLR, so that the first setup retries the reset.

I think this is a false positive, or it is a theoretical issue. For NETC switch,
it supports FLR, and the FLR time is hardwired 32.768us. If a time out
occurs in FLR, that should be a hardware issue.



Reply via email to