Subject: Re: [PATCH v3 net] qed/qede: Fix scheduling while atomic

From: Jakub Kicinski <[email-masked]>
Date: Tue, 2 May 2023 20:03:07 -0700

On Fri, 28 Apr 2023 10:26:51 -0700 Stephen Hemminger wrote:
> On Fri, 28 Apr 2023 09:13:37 -0700
> Manish Chopra <[email-masked]> wrote:
> 
> > -		usleep_range(1000, 2000);
> > +
> > +		if (is_atomic)
> > +			udelay(QED_BAR_ACQUIRE_TIMEOUT_UDELAY);
> > +		else
> > +			usleep_range(QED_BAR_ACQUIRE_TIMEOUT_USLEEP,
> > +				     QED_BAR_ACQUIRE_TIMEOUT_USLEEP * 2);
> >  	}  
> 
> This is a variant of the conditional locking which is an ugly design pattern.
> It makes static checking tools break and
> a source of more bugs.
> 
> Better to fix the infrastructure or caller to not spin, or have two different
> functions.

FWIW the most common way to solve this issue is using a delayed work
which reads out the stats periodically from a non-atomic context, and
return a stashed copy from get_stat64.