diff mbox series

qlcnic: check pci_reset_function result

Message ID 20230331080605.42961-1-den-plotnikov@yandex-team.ru (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series qlcnic: check pci_reset_function result | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Denis Plotnikov March 31, 2023, 8:06 a.m. UTC
Static code analyzer complains to unchecked return value.
It seems that pci_reset_function return something meaningful
only if "reset_methods" is set.
Even if reset_methods isn't used check the return value to avoid
possible bugs leading to undefined behavior in the future.

Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Simon Horman March 31, 2023, 5:52 p.m. UTC | #1
On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
> Static code analyzer complains to unchecked return value.
> It seems that pci_reset_function return something meaningful
> only if "reset_methods" is set.
> Even if reset_methods isn't used check the return value to avoid
> possible bugs leading to undefined behavior in the future.
> 
> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>

nit: The tree this patch is targeted at should be designated, probably
     net-next, so the '[PATCH net-next]' in the subject.

> ---
>  drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> index 87f76bac2e463..39ecfc1a1dbd0 100644
> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
>  	int i, err, ring;
>  
>  	if (dev->flags & QLCNIC_NEED_FLR) {
> -		pci_reset_function(dev->pdev);
> +		err = pci_reset_function(dev->pdev);
> +		if (err && err != -ENOTTY)

Are you sure about the -ENOTTY part?

It seems odd to me that an FLR would be required but reset is not supported.

> +			return err;
>  		dev->flags &= ~QLCNIC_NEED_FLR;
>  	}
>  
> -- 
> 2.25.1
>
Denis Plotnikov April 3, 2023, 10:58 a.m. UTC | #2
On 31.03.2023 20:52, Simon Horman wrote:
> On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
>> Static code analyzer complains to unchecked return value.
>> It seems that pci_reset_function return something meaningful
>> only if "reset_methods" is set.
>> Even if reset_methods isn't used check the return value to avoid
>> possible bugs leading to undefined behavior in the future.
>>
>> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> nit: The tree this patch is targeted at should be designated, probably
>       net-next, so the '[PATCH net-next]' in the subject.
>
>> ---
>>   drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>> index 87f76bac2e463..39ecfc1a1dbd0 100644
>> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>> @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
>>   	int i, err, ring;
>>   
>>   	if (dev->flags & QLCNIC_NEED_FLR) {
>> -		pci_reset_function(dev->pdev);
>> +		err = pci_reset_function(dev->pdev);
>> +		if (err && err != -ENOTTY)
> Are you sure about the -ENOTTY part?
>
> It seems odd to me that an FLR would be required but reset is not supported.
No, I'm not sure. My logic is: if the reset method isn't set than 
pci_reset_function() returns -ENOTTY so treat that result as ok. 
pci_reset_function may return something different than -ENOTTY only if 
pci_reset_fn_methods[m].reset_fn is set.
>> +			return err;
>>   		dev->flags &= ~QLCNIC_NEED_FLR;
>>   	}
>>   
>> -- 
>> 2.25.1
>>
Simon Horman April 5, 2023, 1:04 p.m. UTC | #3
+ Bjorn Helgaas and linux-pci, as this is about FLR

On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
> 
> On 31.03.2023 20:52, Simon Horman wrote:
> > On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
> > > Static code analyzer complains to unchecked return value.
> > > It seems that pci_reset_function return something meaningful
> > > only if "reset_methods" is set.
> > > Even if reset_methods isn't used check the return value to avoid
> > > possible bugs leading to undefined behavior in the future.
> > > 
> > > Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> > nit: The tree this patch is targeted at should be designated, probably
> >       net-next, so the '[PATCH net-next]' in the subject.
> > 
> > > ---
> > >   drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
> > >   1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > index 87f76bac2e463..39ecfc1a1dbd0 100644
> > > --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
> > >   	int i, err, ring;
> > >   	if (dev->flags & QLCNIC_NEED_FLR) {
> > > -		pci_reset_function(dev->pdev);
> > > +		err = pci_reset_function(dev->pdev);
> > > +		if (err && err != -ENOTTY)
> > Are you sure about the -ENOTTY part?
> > 
> > It seems odd to me that an FLR would be required but reset is not supported.
> No, I'm not sure. My logic is: if the reset method isn't set than
> pci_reset_function() returns -ENOTTY so treat that result as ok.
> pci_reset_function may return something different than -ENOTTY only if
> pci_reset_fn_methods[m].reset_fn is set.

I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
I think my main question is if that can ever happen.
If that is unknown, then I think this conservative approach makes sense.

Bjorn, do you happen to have any guidance here?

> > > +			return err;
> > >   		dev->flags &= ~QLCNIC_NEED_FLR;
> > >   	}
> > > -- 
> > > 2.25.1
> > >
Bjorn Helgaas April 5, 2023, 7:37 p.m. UTC | #4
On Wed, Apr 05, 2023 at 03:04:39PM +0200, Simon Horman wrote:
> On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
> > On 31.03.2023 20:52, Simon Horman wrote:
> > > On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
> > > > Static code analyzer complains to unchecked return value.
> > > > It seems that pci_reset_function return something meaningful
> > > > only if "reset_methods" is set.
> > > > Even if reset_methods isn't used check the return value to avoid
> > > > possible bugs leading to undefined behavior in the future.
> > > > 
> > > > Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> > > nit: The tree this patch is targeted at should be designated, probably
> > >       net-next, so the '[PATCH net-next]' in the subject.
> > > 
> > > > ---
> > > >   drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
> > > >   1 file changed, 3 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > index 87f76bac2e463..39ecfc1a1dbd0 100644
> > > > --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
> > > >   	int i, err, ring;
> > > >   	if (dev->flags & QLCNIC_NEED_FLR) {
> > > > -		pci_reset_function(dev->pdev);
> > > > +		err = pci_reset_function(dev->pdev);
> > > > +		if (err && err != -ENOTTY)
> > > Are you sure about the -ENOTTY part?
> > > 
> > > It seems odd to me that an FLR would be required but reset is not supported.
> > No, I'm not sure. My logic is: if the reset method isn't set than
> > pci_reset_function() returns -ENOTTY so treat that result as ok.
> > pci_reset_function may return something different than -ENOTTY only if
> > pci_reset_fn_methods[m].reset_fn is set.
> 
> I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
> I think my main question is if that can ever happen.
> If that is unknown, then I think this conservative approach makes sense.

The commit log mentions "reset_methods", which I don't think is really
relevant here because reset_methods is an internal implementation
detail.  The point is that pci_reset_function() returns 0 if it was
successful and a negative value if it failed.

If the driver thinks the device needs to be reset, ignoring any
negative return value seems like a mistake because the device was not
reset.

If the reset is required for a firmware update to take effect, maybe a
diagnostic would be helpful if it fails, e.g., the other "Adapter
initialization failed.  Please reboot" messages.

"QLCNIC_NEED_FLR" suggests that the driver expects an FLR (as opposed
to other kinds of reset).  If the driver knows that all qlcnic devices
support FLR, it could use pcie_flr() directly.

pci_reset_function() does have the possibility that the reset works on
some devices but not all.  Secondary Bus Reset fails if there are
other functions on the same bus, e.g., a multi-function device.  And
there's some value in doing the reset the same way in all cases.

So I would suggest something like:

  if (dev->flags & QLCNIC_NEED_FLR) {
    err = pcie_flr(dev->pdev);
    if (err) {
      dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
      return err;
    }
    dev->flags &= ~QLCNIC_NEED_FLR;
  }

Or, if there are qlcnic devices that don't support FLR:

  if (dev->flags & QLCNIC_NEED_FLR) {
    err = pci_reset_function(dev->pdev);
    if (err) {
      dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
      return err;
    }
    dev->flags &= ~QLCNIC_NEED_FLR;
  }

> > > > +			return err;
> > > >   		dev->flags &= ~QLCNIC_NEED_FLR;
> > > >   	}
> > > > -- 
> > > > 2.25.1
> > > >
Simon Horman April 6, 2023, 7:03 a.m. UTC | #5
On Wed, Apr 05, 2023 at 02:37:08PM -0500, Bjorn Helgaas wrote:
> On Wed, Apr 05, 2023 at 03:04:39PM +0200, Simon Horman wrote:
> > On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
> > > On 31.03.2023 20:52, Simon Horman wrote:
> > > > On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
> > > > > Static code analyzer complains to unchecked return value.
> > > > > It seems that pci_reset_function return something meaningful
> > > > > only if "reset_methods" is set.
> > > > > Even if reset_methods isn't used check the return value to avoid
> > > > > possible bugs leading to undefined behavior in the future.
> > > > > 
> > > > > Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> > > > nit: The tree this patch is targeted at should be designated, probably
> > > >       net-next, so the '[PATCH net-next]' in the subject.
> > > > 
> > > > > ---
> > > > >   drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
> > > > >   1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > index 87f76bac2e463..39ecfc1a1dbd0 100644
> > > > > --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
> > > > >   	int i, err, ring;
> > > > >   	if (dev->flags & QLCNIC_NEED_FLR) {
> > > > > -		pci_reset_function(dev->pdev);
> > > > > +		err = pci_reset_function(dev->pdev);
> > > > > +		if (err && err != -ENOTTY)
> > > > Are you sure about the -ENOTTY part?
> > > > 
> > > > It seems odd to me that an FLR would be required but reset is not supported.
> > > No, I'm not sure. My logic is: if the reset method isn't set than
> > > pci_reset_function() returns -ENOTTY so treat that result as ok.
> > > pci_reset_function may return something different than -ENOTTY only if
> > > pci_reset_fn_methods[m].reset_fn is set.
> > 
> > I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
> > I think my main question is if that can ever happen.
> > If that is unknown, then I think this conservative approach makes sense.
> 
> The commit log mentions "reset_methods", which I don't think is really
> relevant here because reset_methods is an internal implementation
> detail.  The point is that pci_reset_function() returns 0 if it was
> successful and a negative value if it failed.
> 
> If the driver thinks the device needs to be reset, ignoring any
> negative return value seems like a mistake because the device was not
> reset.
> 
> If the reset is required for a firmware update to take effect, maybe a
> diagnostic would be helpful if it fails, e.g., the other "Adapter
> initialization failed.  Please reboot" messages.
> 
> "QLCNIC_NEED_FLR" suggests that the driver expects an FLR (as opposed
> to other kinds of reset).  If the driver knows that all qlcnic devices
> support FLR, it could use pcie_flr() directly.
> 
> pci_reset_function() does have the possibility that the reset works on
> some devices but not all.  Secondary Bus Reset fails if there are
> other functions on the same bus, e.g., a multi-function device.  And
> there's some value in doing the reset the same way in all cases.
> 
> So I would suggest something like:
> 
>   if (dev->flags & QLCNIC_NEED_FLR) {
>     err = pcie_flr(dev->pdev);
>     if (err) {
>       dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
>       return err;
>     }
>     dev->flags &= ~QLCNIC_NEED_FLR;
>   }
> 
> Or, if there are qlcnic devices that don't support FLR:
> 
>   if (dev->flags & QLCNIC_NEED_FLR) {
>     err = pci_reset_function(dev->pdev);
>     if (err) {
>       dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
>       return err;
>     }
>     dev->flags &= ~QLCNIC_NEED_FLR;
>   }

Thanks Bjorn,

that is very helpful.

I think that in order to move to option #1 some information would be needed
from those familiar with the device(s). As it is a more invasive change -
pci_reset_function -> pcie_flr.

So my feeling is that, in lieu of such feedback, option #2 is a good
improvement on the current code.

OTOH, this driver is 'Supported' as opposed to 'Maintained'.
So perhaps we can just use our best judgement and go for option #1.
Denis Plotnikov April 6, 2023, 9:23 a.m. UTC | #6
On 06.04.2023 10:03, Simon Horman wrote:
> On Wed, Apr 05, 2023 at 02:37:08PM -0500, Bjorn Helgaas wrote:
>> On Wed, Apr 05, 2023 at 03:04:39PM +0200, Simon Horman wrote:
>>> On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
>>>> On 31.03.2023 20:52, Simon Horman wrote:
>>>>> On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
>>>>>> Static code analyzer complains to unchecked return value.
>>>>>> It seems that pci_reset_function return something meaningful
>>>>>> only if "reset_methods" is set.
>>>>>> Even if reset_methods isn't used check the return value to avoid
>>>>>> possible bugs leading to undefined behavior in the future.
>>>>>>
>>>>>> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
>>>>> nit: The tree this patch is targeted at should be designated, probably
>>>>>        net-next, so the '[PATCH net-next]' in the subject.
>>>>>
>>>>>> ---
>>>>>>    drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
>>>>>>    1 file changed, 3 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>>>>>> index 87f76bac2e463..39ecfc1a1dbd0 100644
>>>>>> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>>>>>> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>>>>>> @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
>>>>>>    	int i, err, ring;
>>>>>>    	if (dev->flags & QLCNIC_NEED_FLR) {
>>>>>> -		pci_reset_function(dev->pdev);
>>>>>> +		err = pci_reset_function(dev->pdev);
>>>>>> +		if (err && err != -ENOTTY)
>>>>> Are you sure about the -ENOTTY part?
>>>>>
>>>>> It seems odd to me that an FLR would be required but reset is not supported.
>>>> No, I'm not sure. My logic is: if the reset method isn't set than
>>>> pci_reset_function() returns -ENOTTY so treat that result as ok.
>>>> pci_reset_function may return something different than -ENOTTY only if
>>>> pci_reset_fn_methods[m].reset_fn is set.
>>> I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
>>> I think my main question is if that can ever happen.
>>> If that is unknown, then I think this conservative approach makes sense.
>> The commit log mentions "reset_methods", which I don't think is really
>> relevant here because reset_methods is an internal implementation
>> detail.  The point is that pci_reset_function() returns 0 if it was
>> successful and a negative value if it failed.
>>
>> If the driver thinks the device needs to be reset, ignoring any
>> negative return value seems like a mistake because the device was not
>> reset.
>>
>> If the reset is required for a firmware update to take effect, maybe a
>> diagnostic would be helpful if it fails, e.g., the other "Adapter
>> initialization failed.  Please reboot" messages.
>>
>> "QLCNIC_NEED_FLR" suggests that the driver expects an FLR (as opposed
>> to other kinds of reset).  If the driver knows that all qlcnic devices
>> support FLR, it could use pcie_flr() directly.
>>
>> pci_reset_function() does have the possibility that the reset works on
>> some devices but not all.  Secondary Bus Reset fails if there are
>> other functions on the same bus, e.g., a multi-function device.  And
>> there's some value in doing the reset the same way in all cases.
>>
>> So I would suggest something like:
>>
>>    if (dev->flags & QLCNIC_NEED_FLR) {
>>      err = pcie_flr(dev->pdev);
>>      if (err) {
>>        dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
>>        return err;
>>      }
>>      dev->flags &= ~QLCNIC_NEED_FLR;
>>    }
>>
>> Or, if there are qlcnic devices that don't support FLR:
>>
>>    if (dev->flags & QLCNIC_NEED_FLR) {
>>      err = pci_reset_function(dev->pdev);
>>      if (err) {
>>        dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
>>        return err;
>>      }
>>      dev->flags &= ~QLCNIC_NEED_FLR;
>>    }
> Thanks Bjorn,
>
> that is very helpful.
>
> I think that in order to move to option #1 some information would be needed
> from those familiar with the device(s). As it is a more invasive change -
> pci_reset_function -> pcie_flr.
>
> So my feeling is that, in lieu of such feedback, option #2 is a good
> improvement on the current code.
>
> OTOH, this driver is 'Supported' as opposed to 'Maintained'.
> So perhaps we can just use our best judgement and go for option #1.

So, it looks like option #2 is the safest choice as we do reset only if 
FLR is needed (when pci_reset_function() makes sense)

If all agree with that I'll re-send the path
Simon Horman April 6, 2023, 11:43 a.m. UTC | #7
On Thu, Apr 06, 2023 at 12:23:49PM +0300, Denis Plotnikov wrote:
> 
> On 06.04.2023 10:03, Simon Horman wrote:
> > On Wed, Apr 05, 2023 at 02:37:08PM -0500, Bjorn Helgaas wrote:
> > > On Wed, Apr 05, 2023 at 03:04:39PM +0200, Simon Horman wrote:
> > > > On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
> > > > > On 31.03.2023 20:52, Simon Horman wrote:
> > > > > > On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
> > > > > > > Static code analyzer complains to unchecked return value.
> > > > > > > It seems that pci_reset_function return something meaningful
> > > > > > > only if "reset_methods" is set.
> > > > > > > Even if reset_methods isn't used check the return value to avoid
> > > > > > > possible bugs leading to undefined behavior in the future.
> > > > > > > 
> > > > > > > Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> > > > > > nit: The tree this patch is targeted at should be designated, probably
> > > > > >        net-next, so the '[PATCH net-next]' in the subject.
> > > > > > 
> > > > > > > ---
> > > > > > >    drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
> > > > > > >    1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > > > 
> > > > > > > diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > > > index 87f76bac2e463..39ecfc1a1dbd0 100644
> > > > > > > --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > > > +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > > > @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
> > > > > > >    	int i, err, ring;
> > > > > > >    	if (dev->flags & QLCNIC_NEED_FLR) {
> > > > > > > -		pci_reset_function(dev->pdev);
> > > > > > > +		err = pci_reset_function(dev->pdev);
> > > > > > > +		if (err && err != -ENOTTY)
> > > > > > Are you sure about the -ENOTTY part?
> > > > > > 
> > > > > > It seems odd to me that an FLR would be required but reset is not supported.
> > > > > No, I'm not sure. My logic is: if the reset method isn't set than
> > > > > pci_reset_function() returns -ENOTTY so treat that result as ok.
> > > > > pci_reset_function may return something different than -ENOTTY only if
> > > > > pci_reset_fn_methods[m].reset_fn is set.
> > > > I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
> > > > I think my main question is if that can ever happen.
> > > > If that is unknown, then I think this conservative approach makes sense.
> > > The commit log mentions "reset_methods", which I don't think is really
> > > relevant here because reset_methods is an internal implementation
> > > detail.  The point is that pci_reset_function() returns 0 if it was
> > > successful and a negative value if it failed.
> > > 
> > > If the driver thinks the device needs to be reset, ignoring any
> > > negative return value seems like a mistake because the device was not
> > > reset.
> > > 
> > > If the reset is required for a firmware update to take effect, maybe a
> > > diagnostic would be helpful if it fails, e.g., the other "Adapter
> > > initialization failed.  Please reboot" messages.
> > > 
> > > "QLCNIC_NEED_FLR" suggests that the driver expects an FLR (as opposed
> > > to other kinds of reset).  If the driver knows that all qlcnic devices
> > > support FLR, it could use pcie_flr() directly.
> > > 
> > > pci_reset_function() does have the possibility that the reset works on
> > > some devices but not all.  Secondary Bus Reset fails if there are
> > > other functions on the same bus, e.g., a multi-function device.  And
> > > there's some value in doing the reset the same way in all cases.
> > > 
> > > So I would suggest something like:
> > > 
> > >    if (dev->flags & QLCNIC_NEED_FLR) {
> > >      err = pcie_flr(dev->pdev);
> > >      if (err) {
> > >        dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
> > >        return err;
> > >      }
> > >      dev->flags &= ~QLCNIC_NEED_FLR;
> > >    }
> > > 
> > > Or, if there are qlcnic devices that don't support FLR:
> > > 
> > >    if (dev->flags & QLCNIC_NEED_FLR) {
> > >      err = pci_reset_function(dev->pdev);
> > >      if (err) {
> > >        dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
> > >        return err;
> > >      }
> > >      dev->flags &= ~QLCNIC_NEED_FLR;
> > >    }
> > Thanks Bjorn,
> > 
> > that is very helpful.
> > 
> > I think that in order to move to option #1 some information would be needed
> > from those familiar with the device(s). As it is a more invasive change -
> > pci_reset_function -> pcie_flr.
> > 
> > So my feeling is that, in lieu of such feedback, option #2 is a good
> > improvement on the current code.
> > 
> > OTOH, this driver is 'Supported' as opposed to 'Maintained'.
> > So perhaps we can just use our best judgement and go for option #1.
> 
> So, it looks like option #2 is the safest choice as we do reset only if FLR
> is needed (when pci_reset_function() makes sense)
> 
> If all agree with that I'll re-send the path

Yes. Maybe wait 24h, and if there is no further feedback go ahead with that
plan?
Simon Horman April 6, 2023, 12:42 p.m. UTC | #8
On Thu, Apr 06, 2023 at 01:43:44PM +0200, Simon Horman wrote:
> On Thu, Apr 06, 2023 at 12:23:49PM +0300, Denis Plotnikov wrote:
> > 
> > On 06.04.2023 10:03, Simon Horman wrote:
> > > On Wed, Apr 05, 2023 at 02:37:08PM -0500, Bjorn Helgaas wrote:
> > > > On Wed, Apr 05, 2023 at 03:04:39PM +0200, Simon Horman wrote:
> > > > > On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
> > > > > > On 31.03.2023 20:52, Simon Horman wrote:
> > > > > > > On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
> > > > > > > > Static code analyzer complains to unchecked return value.
> > > > > > > > It seems that pci_reset_function return something meaningful
> > > > > > > > only if "reset_methods" is set.
> > > > > > > > Even if reset_methods isn't used check the return value to avoid
> > > > > > > > possible bugs leading to undefined behavior in the future.
> > > > > > > > 
> > > > > > > > Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> > > > > > > nit: The tree this patch is targeted at should be designated, probably
> > > > > > >        net-next, so the '[PATCH net-next]' in the subject.
> > > > > > > 
> > > > > > > > ---
> > > > > > > >    drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
> > > > > > > >    1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > > > > 
> > > > > > > > diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > > > > index 87f76bac2e463..39ecfc1a1dbd0 100644
> > > > > > > > --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > > > > +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
> > > > > > > > @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
> > > > > > > >    	int i, err, ring;
> > > > > > > >    	if (dev->flags & QLCNIC_NEED_FLR) {
> > > > > > > > -		pci_reset_function(dev->pdev);
> > > > > > > > +		err = pci_reset_function(dev->pdev);
> > > > > > > > +		if (err && err != -ENOTTY)
> > > > > > > Are you sure about the -ENOTTY part?
> > > > > > > 
> > > > > > > It seems odd to me that an FLR would be required but reset is not supported.
> > > > > > No, I'm not sure. My logic is: if the reset method isn't set than
> > > > > > pci_reset_function() returns -ENOTTY so treat that result as ok.
> > > > > > pci_reset_function may return something different than -ENOTTY only if
> > > > > > pci_reset_fn_methods[m].reset_fn is set.
> > > > > I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
> > > > > I think my main question is if that can ever happen.
> > > > > If that is unknown, then I think this conservative approach makes sense.
> > > > The commit log mentions "reset_methods", which I don't think is really
> > > > relevant here because reset_methods is an internal implementation
> > > > detail.  The point is that pci_reset_function() returns 0 if it was
> > > > successful and a negative value if it failed.
> > > > 
> > > > If the driver thinks the device needs to be reset, ignoring any
> > > > negative return value seems like a mistake because the device was not
> > > > reset.
> > > > 
> > > > If the reset is required for a firmware update to take effect, maybe a
> > > > diagnostic would be helpful if it fails, e.g., the other "Adapter
> > > > initialization failed.  Please reboot" messages.
> > > > 
> > > > "QLCNIC_NEED_FLR" suggests that the driver expects an FLR (as opposed
> > > > to other kinds of reset).  If the driver knows that all qlcnic devices
> > > > support FLR, it could use pcie_flr() directly.
> > > > 
> > > > pci_reset_function() does have the possibility that the reset works on
> > > > some devices but not all.  Secondary Bus Reset fails if there are
> > > > other functions on the same bus, e.g., a multi-function device.  And
> > > > there's some value in doing the reset the same way in all cases.
> > > > 
> > > > So I would suggest something like:
> > > > 
> > > >    if (dev->flags & QLCNIC_NEED_FLR) {
> > > >      err = pcie_flr(dev->pdev);
> > > >      if (err) {
> > > >        dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
> > > >        return err;
> > > >      }
> > > >      dev->flags &= ~QLCNIC_NEED_FLR;
> > > >    }
> > > > 
> > > > Or, if there are qlcnic devices that don't support FLR:
> > > > 
> > > >    if (dev->flags & QLCNIC_NEED_FLR) {
> > > >      err = pci_reset_function(dev->pdev);
> > > >      if (err) {
> > > >        dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
> > > >        return err;
> > > >      }
> > > >      dev->flags &= ~QLCNIC_NEED_FLR;
> > > >    }
> > > Thanks Bjorn,
> > > 
> > > that is very helpful.
> > > 
> > > I think that in order to move to option #1 some information would be needed
> > > from those familiar with the device(s). As it is a more invasive change -
> > > pci_reset_function -> pcie_flr.
> > > 
> > > So my feeling is that, in lieu of such feedback, option #2 is a good
> > > improvement on the current code.
> > > 
> > > OTOH, this driver is 'Supported' as opposed to 'Maintained'.
> > > So perhaps we can just use our best judgement and go for option #1.
> > 
> > So, it looks like option #2 is the safest choice as we do reset only if FLR
> > is needed (when pci_reset_function() makes sense)
> > 
> > If all agree with that I'll re-send the path
> 
> Yes. Maybe wait 24h, and if there is no further feedback go ahead with that
> plan?

Perhaps a code comment, or the patch description could include
some information about the reasoning above.
Denis Plotnikov April 6, 2023, 3:06 p.m. UTC | #9
On 06.04.2023 14:43, Simon Horman wrote:
> On Thu, Apr 06, 2023 at 12:23:49PM +0300, Denis Plotnikov wrote:
>> On 06.04.2023 10:03, Simon Horman wrote:
>>> On Wed, Apr 05, 2023 at 02:37:08PM -0500, Bjorn Helgaas wrote:
>>>> On Wed, Apr 05, 2023 at 03:04:39PM +0200, Simon Horman wrote:
>>>>> On Mon, Apr 03, 2023 at 01:58:49PM +0300, Denis Plotnikov wrote:
>>>>>> On 31.03.2023 20:52, Simon Horman wrote:
>>>>>>> On Fri, Mar 31, 2023 at 11:06:05AM +0300, Denis Plotnikov wrote:
>>>>>>>> Static code analyzer complains to unchecked return value.
>>>>>>>> It seems that pci_reset_function return something meaningful
>>>>>>>> only if "reset_methods" is set.
>>>>>>>> Even if reset_methods isn't used check the return value to avoid
>>>>>>>> possible bugs leading to undefined behavior in the future.
>>>>>>>>
>>>>>>>> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
>>>>>>> nit: The tree this patch is targeted at should be designated, probably
>>>>>>>         net-next, so the '[PATCH net-next]' in the subject.
>>>>>>>
>>>>>>>> ---
>>>>>>>>     drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 4 +++-
>>>>>>>>     1 file changed, 3 insertions(+), 1 deletion(-)
>>>>>>>>
>>>>>>>> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>>>>>>>> index 87f76bac2e463..39ecfc1a1dbd0 100644
>>>>>>>> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>>>>>>>> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
>>>>>>>> @@ -628,7 +628,9 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
>>>>>>>>     	int i, err, ring;
>>>>>>>>     	if (dev->flags & QLCNIC_NEED_FLR) {
>>>>>>>> -		pci_reset_function(dev->pdev);
>>>>>>>> +		err = pci_reset_function(dev->pdev);
>>>>>>>> +		if (err && err != -ENOTTY)
>>>>>>> Are you sure about the -ENOTTY part?
>>>>>>>
>>>>>>> It seems odd to me that an FLR would be required but reset is not supported.
>>>>>> No, I'm not sure. My logic is: if the reset method isn't set than
>>>>>> pci_reset_function() returns -ENOTTY so treat that result as ok.
>>>>>> pci_reset_function may return something different than -ENOTTY only if
>>>>>> pci_reset_fn_methods[m].reset_fn is set.
>>>>> I see your reasoning: -ENOTTY means nothing happened, and probably that is ok.
>>>>> I think my main question is if that can ever happen.
>>>>> If that is unknown, then I think this conservative approach makes sense.
>>>> The commit log mentions "reset_methods", which I don't think is really
>>>> relevant here because reset_methods is an internal implementation
>>>> detail.  The point is that pci_reset_function() returns 0 if it was
>>>> successful and a negative value if it failed.
>>>>
>>>> If the driver thinks the device needs to be reset, ignoring any
>>>> negative return value seems like a mistake because the device was not
>>>> reset.
>>>>
>>>> If the reset is required for a firmware update to take effect, maybe a
>>>> diagnostic would be helpful if it fails, e.g., the other "Adapter
>>>> initialization failed.  Please reboot" messages.
>>>>
>>>> "QLCNIC_NEED_FLR" suggests that the driver expects an FLR (as opposed
>>>> to other kinds of reset).  If the driver knows that all qlcnic devices
>>>> support FLR, it could use pcie_flr() directly.
>>>>
>>>> pci_reset_function() does have the possibility that the reset works on
>>>> some devices but not all.  Secondary Bus Reset fails if there are
>>>> other functions on the same bus, e.g., a multi-function device.  And
>>>> there's some value in doing the reset the same way in all cases.
>>>>
>>>> So I would suggest something like:
>>>>
>>>>     if (dev->flags & QLCNIC_NEED_FLR) {
>>>>       err = pcie_flr(dev->pdev);
>>>>       if (err) {
>>>>         dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
>>>>         return err;
>>>>       }
>>>>       dev->flags &= ~QLCNIC_NEED_FLR;
>>>>     }
>>>>
>>>> Or, if there are qlcnic devices that don't support FLR:
>>>>
>>>>     if (dev->flags & QLCNIC_NEED_FLR) {
>>>>       err = pci_reset_function(dev->pdev);
>>>>       if (err) {
>>>>         dev_err(&pdev->dev, "Adapter reset failed (%d). Please reboot\n", err);
>>>>         return err;
>>>>       }
>>>>       dev->flags &= ~QLCNIC_NEED_FLR;
>>>>     }
>>> Thanks Bjorn,
>>>
>>> that is very helpful.
>>>
>>> I think that in order to move to option #1 some information would be needed
>>> from those familiar with the device(s). As it is a more invasive change -
>>> pci_reset_function -> pcie_flr.
>>>
>>> So my feeling is that, in lieu of such feedback, option #2 is a good
>>> improvement on the current code.
>>>
>>> OTOH, this driver is 'Supported' as opposed to 'Maintained'.
>>> So perhaps we can just use our best judgement and go for option #1.
>> So, it looks like option #2 is the safest choice as we do reset only if FLR
>> is needed (when pci_reset_function() makes sense)
>>
>> If all agree with that I'll re-send the path
> Yes. Maybe wait 24h, and if there is no further feedback go ahead with that
> plan?
Ok, will do so. Thanks!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
index 87f76bac2e463..39ecfc1a1dbd0 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
@@ -628,7 +628,9 @@  int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev)
 	int i, err, ring;
 
 	if (dev->flags & QLCNIC_NEED_FLR) {
-		pci_reset_function(dev->pdev);
+		err = pci_reset_function(dev->pdev);
+		if (err && err != -ENOTTY)
+			return err;
 		dev->flags &= ~QLCNIC_NEED_FLR;
 	}