All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Wolfgang Grandegger" <wg@grandegger.com>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Raju Rangoju" <rajur@chelsio.com>,
	"Jeroen de Borst" <jeroendb@google.com>,
	"Praveen Kaligineedi" <pkaligineedi@google.com>,
	"Shailend Chand" <shailend@google.com>,
	"Douglas Miller" <dougmill@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Nick Child" <nnac123@linux.ibm.com>,
	"Haren Myneni" <haren@linux.ibm.com>,
	"Rick Lindsley" <ricklind@linux.ibm.com>,
	"Dany Madden" <danymadden@us.ibm.com>,
	"Thomas Falcon" <tlfalcon@linux.ibm.com>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Krzysztof Halasa" <khalasa@piap.pl>,
	"Kalle Valo" <kvalo@kernel.org>,
	"Jeff Johnson" <quic_jjohnson@quicinc.com>,
	"Gregory Greenman" <gregory.greenman@intel.com>,
	"Chandrashekar Devegowda" <chandrashekar.devegowda@intel.com>,
	"Intel Corporation" <linuxwwan@intel.com>,
	"Chiranjeevi Rapolu" <chiranjeevi.rapolu@linux.intel.com>,
	"Liu Haijun" <haijun.liu@mediatek.com>,
	"M Chetan Kumar" <m.chetan.kumar@linux.intel.com>,
	"Ricardo Martinez" <ricardo.martinez@linux.intel.com>,
	"Loic Poulain" <loic.poulain@linaro.org>,
	"Sergey Ryazanov" <ryazanov.s.a@gmail.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Yuanjun Gong" <ruc_gongyuanjun@163.com>,
	"Simon Horman" <horms@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Ziwei Xiao" <ziweixiao@google.com>,
	"Rushil Gupta" <rushilg@google.com>,
	"Coco Li" <lixiaoyan@google.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Junfeng Guo" <junfeng.guo@intel.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Wei Fang" <wei.fang@nxp.com>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
	"Yuri Karpov" <YKarpov@ispras.ru>,
	"Zhengchao Shao" <shaozhengchao@huawei.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Zheng Zengkai" <zhengzengkai@huawei.com>,
	"Lee Jones" <lee@kernel.org>,
	"Maximilian Luz" <luzmaximilian@gmail.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Dawei Li" <set_pte_at@outlook.com>,
	Anjaneyulu <pagadala.yesu.anjaneyulu@intel.com>,
	"Benjamin Berg" <benjamin.berg@intel.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, ath10k@lists.infradead.org,
	linux-wireless@vger.kernel.org
Subject: Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule
Date: Fri, 6 Oct 2023 20:49:41 +0200	[thread overview]
Message-ID: <652056c5.5d0a0220.2b60d.c5dc@mx.google.com> (raw)
In-Reply-To: <CANn89iLtYZJPOQE7OkAbEdmhT8qjzAJ+27poa__3c8Nf0M6u_w@mail.gmail.com>

On Thu, Oct 05, 2023 at 06:16:26PM +0200, Eric Dumazet wrote:
> On Tue, Oct 3, 2023 at 8:36 PM Christian Marangi <ansuelsmth@gmail.com> wrote:
> >
> > Replace if condition of napi_schedule_prep/__napi_schedule and use bool
> > from napi_schedule directly where possible.
> >
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> >  drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
> >  drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
> >  drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
> >  3 files changed, 3 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c
> > index 02aa6fd8ebc2..a9014d7932db 100644
> > --- a/drivers/net/ethernet/atheros/atlx/atl1.c
> > +++ b/drivers/net/ethernet/atheros/atlx/atl1.c
> > @@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
> >
> >  static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
> >  {
> > -       if (!napi_schedule_prep(&adapter->napi))
> > +       if (!napi_schedule(&adapter->napi))
> >                 /* It is possible in case even the RX/TX ints are disabled via IMR
> >                  * register the ISR bits are set anyway (but do not produce IRQ).
> >                  * To handle such situation the napi functions used to check is
> > @@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
> >                  */
> >                 return 0;
> >
> > -       __napi_schedule(&adapter->napi);
> > -
> >         /*
> >          * Disable RX/TX ints via IMR register if it is
> >          * allowed. NAPI handler must reenable them in same
> > diff --git a/drivers/net/ethernet/toshiba/tc35815.c b/drivers/net/ethernet/toshiba/tc35815.c
> > index 14cf6ecf6d0d..a8b8a0e13f9a 100644
> > --- a/drivers/net/ethernet/toshiba/tc35815.c
> > +++ b/drivers/net/ethernet/toshiba/tc35815.c
> > @@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
> >         if (!(dmactl & DMA_IntMask)) {
> >                 /* disable interrupts */
> >                 tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
> > -               if (napi_schedule_prep(&lp->napi))
> > -                       __napi_schedule(&lp->napi);
> > -               else {
> > +               if (!napi_schedule(&lp->napi)) {
> >                         printk(KERN_ERR "%s: interrupt taken in poll\n",
> >                                dev->name);
> >                         BUG();
> 
> Hmmm... could you also remove this BUG() ? I think this code path can be taken
> if some applications are using busy polling.
> 
> Or simply rewrite this with the traditional
> 
> if (napi_schedule_prep(&lp->napi)) {
>    /* disable interrupts */
>    tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
>     __napi_schedule(&lp->napi);
> }
> 
>

Mhhh is it safe to do so? I mean it seems very wrong to print a warning
and BUG() instead of disabling the interrupt only if napi can be
scheduled... Maybe is very old code? The more I see this the more I see
problem... (randomly disabling the interrupt and then make the kernel
die)

> 
> > diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > index 23b5a0adcbd6..146bc7bd14fb 100644
> > --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > @@ -1660,9 +1660,7 @@ irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
> >         IWL_DEBUG_ISR(trans, "[%d] Got interrupt\n", entry->entry);
> >
> >         local_bh_disable();
> > -       if (napi_schedule_prep(&rxq->napi))
> > -               __napi_schedule(&rxq->napi);
> > -       else
> > +       if (!napi_schedule(&rxq->napi))
> >                 iwl_pcie_clear_irq(trans, entry->entry);
> 
> Same remark here about twisted logic.
> 

Ehhh here we need to be careful... We can do the usual prep/__schedule
with the DMA disable in between...

From the comments of iwl_pcie_clear_irq.

	/*
	 * Before sending the interrupt the HW disables it to prevent
	 * a nested interrupt. This is done by writing 1 to the corresponding
	 * bit in the mask register. After handling the interrupt, it should be
	 * re-enabled by clearing this bit. This register is defined as
	 * write 1 clear (W1C) register, meaning that it's being clear
	 * by writing 1 to the bit.
	 */

So the device disable the interrupt after being fired and the bit needs
to set again for the interrupt to be reenabled. So the function
correctly reenable the irq if a napi can't be scheduled... Think there
isn't another way to handle this.

> >         local_bh_enable();
> >
> > --
> > 2.40.1
> >

-- 
	Ansuel

_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

WARNING: multiple messages have this Message-ID (diff)
From: Christian Marangi <ansuelsmth@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Wolfgang Grandegger" <wg@grandegger.com>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Raju Rangoju" <rajur@chelsio.com>,
	"Jeroen de Borst" <jeroendb@google.com>,
	"Praveen Kaligineedi" <pkaligineedi@google.com>,
	"Shailend Chand" <shailend@google.com>,
	"Douglas Miller" <dougmill@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Nick Child" <nnac123@linux.ibm.com>,
	"Haren Myneni" <haren@linux.ibm.com>,
	"Rick Lindsley" <ricklind@linux.ibm.com>,
	"Dany Madden" <danymadden@us.ibm.com>,
	"Thomas Falcon" <tlfalcon@linux.ibm.com>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Krzysztof Halasa" <khalasa@piap.pl>,
	"Kalle Valo" <kvalo@kernel.org>,
	"Jeff Johnson" <quic_jjohnson@quicinc.com>,
	"Gregory Greenman" <gregory.greenman@intel.com>,
	"Chandrashekar Devegowda" <chandrashekar.devegowda@intel.com>,
	"Intel Corporation" <linuxwwan@intel.com>,
	"Chiranjeevi Rapolu" <chiranjeevi.rapolu@linux.intel.com>,
	"Liu Haijun" <haijun.liu@mediatek.com>,
	"M Chetan Kumar" <m.chetan.kumar@linux.intel.com>,
	"Ricardo Martinez" <ricardo.martinez@linux.intel.com>,
	"Loic Poulain" <loic.poulain@linaro.org>,
	"Sergey Ryazanov" <ryazanov.s.a@gmail.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Yuanjun Gong" <ruc_gongyuanjun@163.com>,
	"Simon Horman" <horms@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Ziwei Xiao" <ziweixiao@google.com>,
	"Rushil Gupta" <rushilg@google.com>,
	"Coco Li" <lixiaoyan@google.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Junfeng Guo" <junfeng.guo@intel.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Wei Fang" <wei.fang@nxp.com>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
	"Yuri Karpov" <YKarpov@ispras.ru>,
	"Zhengchao Shao" <shaozhengchao@huawei.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Zheng Zengkai" <zhengzengkai@huawei.com>,
	"Lee Jones" <lee@kernel.org>,
	"Maximilian Luz" <luzmaximilian@gmail.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Dawei Li" <set_pte_at@outlook.com>,
	Anjaneyulu <pagadala.yesu.anjaneyulu@intel.com>,
	"Benjamin Berg" <benjamin.berg@intel.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, ath10k@lists.infradead.org,
	linux-wireless@vger.kernel.org
Subject: Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule
Date: Fri, 6 Oct 2023 20:49:41 +0200	[thread overview]
Message-ID: <652056c5.5d0a0220.2b60d.c5dc@mx.google.com> (raw)
In-Reply-To: <CANn89iLtYZJPOQE7OkAbEdmhT8qjzAJ+27poa__3c8Nf0M6u_w@mail.gmail.com>

On Thu, Oct 05, 2023 at 06:16:26PM +0200, Eric Dumazet wrote:
> On Tue, Oct 3, 2023 at 8:36 PM Christian Marangi <ansuelsmth@gmail.com> wrote:
> >
> > Replace if condition of napi_schedule_prep/__napi_schedule and use bool
> > from napi_schedule directly where possible.
> >
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> >  drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
> >  drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
> >  drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
> >  3 files changed, 3 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c
> > index 02aa6fd8ebc2..a9014d7932db 100644
> > --- a/drivers/net/ethernet/atheros/atlx/atl1.c
> > +++ b/drivers/net/ethernet/atheros/atlx/atl1.c
> > @@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
> >
> >  static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
> >  {
> > -       if (!napi_schedule_prep(&adapter->napi))
> > +       if (!napi_schedule(&adapter->napi))
> >                 /* It is possible in case even the RX/TX ints are disabled via IMR
> >                  * register the ISR bits are set anyway (but do not produce IRQ).
> >                  * To handle such situation the napi functions used to check is
> > @@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
> >                  */
> >                 return 0;
> >
> > -       __napi_schedule(&adapter->napi);
> > -
> >         /*
> >          * Disable RX/TX ints via IMR register if it is
> >          * allowed. NAPI handler must reenable them in same
> > diff --git a/drivers/net/ethernet/toshiba/tc35815.c b/drivers/net/ethernet/toshiba/tc35815.c
> > index 14cf6ecf6d0d..a8b8a0e13f9a 100644
> > --- a/drivers/net/ethernet/toshiba/tc35815.c
> > +++ b/drivers/net/ethernet/toshiba/tc35815.c
> > @@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
> >         if (!(dmactl & DMA_IntMask)) {
> >                 /* disable interrupts */
> >                 tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
> > -               if (napi_schedule_prep(&lp->napi))
> > -                       __napi_schedule(&lp->napi);
> > -               else {
> > +               if (!napi_schedule(&lp->napi)) {
> >                         printk(KERN_ERR "%s: interrupt taken in poll\n",
> >                                dev->name);
> >                         BUG();
> 
> Hmmm... could you also remove this BUG() ? I think this code path can be taken
> if some applications are using busy polling.
> 
> Or simply rewrite this with the traditional
> 
> if (napi_schedule_prep(&lp->napi)) {
>    /* disable interrupts */
>    tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
>     __napi_schedule(&lp->napi);
> }
> 
>

Mhhh is it safe to do so? I mean it seems very wrong to print a warning
and BUG() instead of disabling the interrupt only if napi can be
scheduled... Maybe is very old code? The more I see this the more I see
problem... (randomly disabling the interrupt and then make the kernel
die)

> 
> > diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > index 23b5a0adcbd6..146bc7bd14fb 100644
> > --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > @@ -1660,9 +1660,7 @@ irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
> >         IWL_DEBUG_ISR(trans, "[%d] Got interrupt\n", entry->entry);
> >
> >         local_bh_disable();
> > -       if (napi_schedule_prep(&rxq->napi))
> > -               __napi_schedule(&rxq->napi);
> > -       else
> > +       if (!napi_schedule(&rxq->napi))
> >                 iwl_pcie_clear_irq(trans, entry->entry);
> 
> Same remark here about twisted logic.
> 

Ehhh here we need to be careful... We can do the usual prep/__schedule
with the DMA disable in between...

From the comments of iwl_pcie_clear_irq.

	/*
	 * Before sending the interrupt the HW disables it to prevent
	 * a nested interrupt. This is done by writing 1 to the corresponding
	 * bit in the mask register. After handling the interrupt, it should be
	 * re-enabled by clearing this bit. This register is defined as
	 * write 1 clear (W1C) register, meaning that it's being clear
	 * by writing 1 to the bit.
	 */

So the device disable the interrupt after being fired and the bit needs
to set again for the interrupt to be reenabled. So the function
correctly reenable the irq if a napi can't be scheduled... Think there
isn't another way to handle this.

> >         local_bh_enable();
> >
> > --
> > 2.40.1
> >

-- 
	Ansuel

WARNING: multiple messages have this Message-ID (diff)
From: Christian Marangi <ansuelsmth@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "Andrew Lunn" <andrew@lunn.ch>,
	"Sergey Ryazanov" <ryazanov.s.a@gmail.com>,
	"Ziwei Xiao" <ziweixiao@google.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Rick Lindsley" <ricklind@linux.ibm.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	"Krzysztof Halasa" <khalasa@piap.pl>,
	"Yuri Karpov" <YKarpov@ispras.ru>,
	netdev@vger.kernel.org, ath10k@lists.infradead.org,
	"Dany Madden" <danymadden@us.ibm.com>,
	"Gregory Greenman" <gregory.greenman@intel.com>,
	"Zhengchao Shao" <shaozhengchao@huawei.com>,
	"Chiranjeevi Rapolu" <chiranjeevi.rapolu@linux.intel.com>,
	"Dawei Li" <set_pte_at@outlook.com>,
	"Intel Corporation" <linuxwwan@intel.com>,
	"Rob Herring" <robh@kernel.org>,
	"Jeroen de Borst" <jeroendb@google.com>,
	"Leon Romanovsky" <leon@kernel.org>,
	linux-rdma@vger.kernel.org, "Lee Jones" <lee@kernel.org>,
	"Haren Myneni" <haren@linux.ibm.com>,
	linux-stm32@st-md-mailman.stormreply.com,
	"Rushil Gupta" <rushilg@google.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Thomas Falcon" <tlfalcon@linux.ibm.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-wireless@vger.kernel.org,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>, "Wei Fang" <wei.fang@nxp.com>,
	"Wolfgang Grandegger" <wg@grandegger.com>,
	"Nick Child" <nnac123@linux.ibm.com>,
	"Simon Horman" <horms@kernel.org>,
	"Liu Haijun" <haijun.liu@mediatek.com>,
	"Kalle Valo" <kvalo@kernel.org>,
	linuxppc-dev@lists.ozlabs.org,
	"Nicholas Piggin" <npiggin@gmail.com>,
	linux-can@vger.kernel.org,
	"Yuanjun Gong" <ruc_gongyuanjun@163.com>,
	"Shailend Chand" <shailend@google.com>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Benjamin Berg" <benjamin.berg@intel.com>,
	"M Chetan Kumar" <m.chetan.kumar@linux.intel.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Coco Li" <lixiaoyan@google.com>,
	linux-arm-kernel@lists.infradead.org,
	"Chandrashekar Devegowda" <chandrashekar.devegowda@intel.com>,
	"Ricardo Martinez" <ricardo.martinez@linux.intel.com>,
	"Loic Poulain" <loic.poulain@linaro.org>,
	"Zheng Zengkai" <zhengzengkai@huawei.com>,
	"Maximilian Lu z" <luzmaximilian@gmail.com>,
	Anjaneyulu <pagadala.yesu.anjaneyulu@intel.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Douglas Miller" <dougmill@linux.ibm.com>,
	linux-kernel@vger.kernel.org, "Tariq Toukan" <tariqt@nvidia.com>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
	"Junfeng Guo" <junfeng.guo@intel.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Raju Rangoju" <rajur@chelsio.com>,
	"Praveen Kaligineedi" <pkaligineedi@google.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Jeff Johnson" <quic_jjohnson@quicinc.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule
Date: Fri, 6 Oct 2023 20:49:41 +0200	[thread overview]
Message-ID: <652056c5.5d0a0220.2b60d.c5dc@mx.google.com> (raw)
In-Reply-To: <CANn89iLtYZJPOQE7OkAbEdmhT8qjzAJ+27poa__3c8Nf0M6u_w@mail.gmail.com>

On Thu, Oct 05, 2023 at 06:16:26PM +0200, Eric Dumazet wrote:
> On Tue, Oct 3, 2023 at 8:36 PM Christian Marangi <ansuelsmth@gmail.com> wrote:
> >
> > Replace if condition of napi_schedule_prep/__napi_schedule and use bool
> > from napi_schedule directly where possible.
> >
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> >  drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
> >  drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
> >  drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
> >  3 files changed, 3 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c
> > index 02aa6fd8ebc2..a9014d7932db 100644
> > --- a/drivers/net/ethernet/atheros/atlx/atl1.c
> > +++ b/drivers/net/ethernet/atheros/atlx/atl1.c
> > @@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
> >
> >  static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
> >  {
> > -       if (!napi_schedule_prep(&adapter->napi))
> > +       if (!napi_schedule(&adapter->napi))
> >                 /* It is possible in case even the RX/TX ints are disabled via IMR
> >                  * register the ISR bits are set anyway (but do not produce IRQ).
> >                  * To handle such situation the napi functions used to check is
> > @@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
> >                  */
> >                 return 0;
> >
> > -       __napi_schedule(&adapter->napi);
> > -
> >         /*
> >          * Disable RX/TX ints via IMR register if it is
> >          * allowed. NAPI handler must reenable them in same
> > diff --git a/drivers/net/ethernet/toshiba/tc35815.c b/drivers/net/ethernet/toshiba/tc35815.c
> > index 14cf6ecf6d0d..a8b8a0e13f9a 100644
> > --- a/drivers/net/ethernet/toshiba/tc35815.c
> > +++ b/drivers/net/ethernet/toshiba/tc35815.c
> > @@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
> >         if (!(dmactl & DMA_IntMask)) {
> >                 /* disable interrupts */
> >                 tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
> > -               if (napi_schedule_prep(&lp->napi))
> > -                       __napi_schedule(&lp->napi);
> > -               else {
> > +               if (!napi_schedule(&lp->napi)) {
> >                         printk(KERN_ERR "%s: interrupt taken in poll\n",
> >                                dev->name);
> >                         BUG();
> 
> Hmmm... could you also remove this BUG() ? I think this code path can be taken
> if some applications are using busy polling.
> 
> Or simply rewrite this with the traditional
> 
> if (napi_schedule_prep(&lp->napi)) {
>    /* disable interrupts */
>    tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
>     __napi_schedule(&lp->napi);
> }
> 
>

Mhhh is it safe to do so? I mean it seems very wrong to print a warning
and BUG() instead of disabling the interrupt only if napi can be
scheduled... Maybe is very old code? The more I see this the more I see
problem... (randomly disabling the interrupt and then make the kernel
die)

> 
> > diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > index 23b5a0adcbd6..146bc7bd14fb 100644
> > --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
> > @@ -1660,9 +1660,7 @@ irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
> >         IWL_DEBUG_ISR(trans, "[%d] Got interrupt\n", entry->entry);
> >
> >         local_bh_disable();
> > -       if (napi_schedule_prep(&rxq->napi))
> > -               __napi_schedule(&rxq->napi);
> > -       else
> > +       if (!napi_schedule(&rxq->napi))
> >                 iwl_pcie_clear_irq(trans, entry->entry);
> 
> Same remark here about twisted logic.
> 

Ehhh here we need to be careful... We can do the usual prep/__schedule
with the DMA disable in between...

From the comments of iwl_pcie_clear_irq.

	/*
	 * Before sending the interrupt the HW disables it to prevent
	 * a nested interrupt. This is done by writing 1 to the corresponding
	 * bit in the mask register. After handling the interrupt, it should be
	 * re-enabled by clearing this bit. This register is defined as
	 * write 1 clear (W1C) register, meaning that it's being clear
	 * by writing 1 to the bit.
	 */

So the device disable the interrupt after being fired and the bit needs
to set again for the interrupt to be reenabled. So the function
correctly reenable the irq if a napi can't be scheduled... Think there
isn't another way to handle this.

> >         local_bh_enable();
> >
> > --
> > 2.40.1
> >

-- 
	Ansuel

  reply	other threads:[~2023-10-06 18:49 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 14:51 [net-next PATCH v2 1/4] netdev: replace simple napi_schedule_prep/__napi_schedule to napi_schedule Christian Marangi
2023-10-03 14:51 ` Christian Marangi
2023-10-03 14:51 ` [net-next PATCH v2 2/4] netdev: make napi_schedule return bool on NAPI successful schedule Christian Marangi
2023-10-03 14:51   ` Christian Marangi
2023-10-03 14:51 ` [net-next PATCH v2 3/4] netdev: replace napi_reschedule with napi_schedule Christian Marangi
2023-10-03 14:51   ` Christian Marangi
2023-10-05 16:11   ` Eric Dumazet
2023-10-05 16:11     ` Eric Dumazet
2023-10-05 16:11     ` Eric Dumazet
2023-10-05 16:32     ` Jakub Kicinski
2023-10-05 16:32       ` Jakub Kicinski
2023-10-05 16:32       ` Jakub Kicinski
2023-10-05 16:41       ` Eric Dumazet
2023-10-05 16:41         ` Eric Dumazet
2023-10-05 16:41         ` Eric Dumazet
2023-10-06 18:52         ` Christian Marangi
2023-10-06 18:52           ` Christian Marangi
2023-10-06 18:52           ` Christian Marangi
2023-10-08  7:00           ` Eric Dumazet
2023-10-08  7:00             ` Eric Dumazet
2023-10-08  7:00             ` Eric Dumazet
2023-10-03 14:51 ` [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule Christian Marangi
2023-10-03 14:51   ` Christian Marangi
2023-10-05 16:16   ` Eric Dumazet
2023-10-05 16:16     ` Eric Dumazet
2023-10-05 16:16     ` Eric Dumazet
2023-10-06 18:49     ` Christian Marangi [this message]
2023-10-06 18:49       ` Christian Marangi
2023-10-06 18:49       ` Christian Marangi
2023-10-08  7:08       ` Eric Dumazet
2023-10-08  7:08         ` Eric Dumazet
2023-10-08  7:08         ` Eric Dumazet
2023-10-08 18:27         ` Christian Marangi
2023-10-08 18:27           ` Christian Marangi
2023-10-08 18:27           ` Christian Marangi
2023-10-09  8:27           ` Eric Dumazet
2023-10-09  8:27             ` Eric Dumazet
2023-10-09  8:27             ` Eric Dumazet
2023-10-05 16:09 ` [net-next PATCH v2 1/4] netdev: replace simple napi_schedule_prep/__napi_schedule to napi_schedule Eric Dumazet
2023-10-05 16:09   ` Eric Dumazet
2023-10-05 16:09   ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=652056c5.5d0a0220.2b60d.c5dc@mx.google.com \
    --to=ansuelsmth@gmail.com \
    --cc=YKarpov@ispras.ru \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew@lunn.ch \
    --cc=ath10k@lists.infradead.org \
    --cc=benjamin.berg@intel.com \
    --cc=chandrashekar.devegowda@intel.com \
    --cc=chiranjeevi.rapolu@linux.intel.com \
    --cc=chris.snook@gmail.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=danymadden@us.ibm.com \
    --cc=davem@davemloft.net \
    --cc=dougmill@linux.ibm.com \
    --cc=edumazet@google.com \
    --cc=gregory.greenman@intel.com \
    --cc=haijun.liu@mediatek.com \
    --cc=haren@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=jeroendb@google.com \
    --cc=jgg@ziepe.ca \
    --cc=joabreu@synopsys.com \
    --cc=johannes@sipsolutions.net \
    --cc=junfeng.guo@intel.com \
    --cc=khalasa@piap.pl \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=lee@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=linuxwwan@intel.com \
    --cc=lixiaoyan@google.com \
    --cc=loic.poulain@linaro.org \
    --cc=luzmaximilian@gmail.com \
    --cc=m.chetan.kumar@linux.intel.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mkl@pengutronix.de \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=nnac123@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pagadala.yesu.anjaneyulu@intel.com \
    --cc=pkaligineedi@google.com \
    --cc=quic_jjohnson@quicinc.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rajur@chelsio.com \
    --cc=ricardo.martinez@linux.intel.com \
    --cc=ricklind@linux.ibm.com \
    --cc=robh@kernel.org \
    --cc=ruc_gongyuanjun@163.com \
    --cc=rushilg@google.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=set_pte_at@outlook.com \
    --cc=shailend@google.com \
    --cc=shaozhengchao@huawei.com \
    --cc=tariqt@nvidia.com \
    --cc=tglx@linutronix.de \
    --cc=tlfalcon@linux.ibm.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wei.fang@nxp.com \
    --cc=wg@grandegger.com \
    --cc=zhengzengkai@huawei.com \
    --cc=ziweixiao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.