[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAL9mu0K4L-vGL1EyYc+p0q7tadQ39-VHcp1nd4gZs_HGKSmP2w@mail.gmail.com>
Date: Fri, 16 Apr 2021 16:56:57 +0800
From: dillon min <dillon.minfei@...il.com>
To: Johan Hovold <johan@...nel.org>
Cc: Greg KH <gregkh@...uxfoundation.org>, jirislaby@...nel.org,
Maxime Coquelin <mcoquelin.stm32@...il.com>,
Alexandre TORGUE <alexandre.torgue@...s.st.com>,
kernel test robot <lkp@...el.com>,
linux-serial@...r.kernel.org,
linux-stm32@...md-mailman.stormreply.com,
Linux ARM <linux-arm-kernel@...ts.infradead.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
kbuild-all@...ts.01.org, clang-built-linux@...glegroups.com,
Gerald Baeza <gerald.baeza@...s.st.com>,
Erwan Le Ray <erwan.leray@...s.st.com>
Subject: Re: [PATCH v2] serial: stm32: optimize spin lock usage
Hi Johan,
On Fri, Apr 16, 2021 at 4:35 PM Johan Hovold <johan@...nel.org> wrote:
>
> On Tue, Apr 13, 2021 at 07:44:39AM +0800, dillon min wrote:
> > Hi Johan, Erwan
> >
> > It seems still a bit of a problem in the current version, not deadlock
> > but access register at the same time.
> >
> > For driver , we should consider it running under smp, let's think
> > about it for this case:
> >
> > static void stm32_usart_console_write(struct console *co, const char *s,
> > unsigned int cnt)
> > {
> > .....
> > local_irq_save(flags);
> > if (port->sysrq)
> > locked = 0;
> > .....
> > access register cr1, tdr, isr
> > .....
> >
> > local_irq_restore(flags);
> > }
> >
> > if port->sysrq is 1, stm32_usart_console_write() just disable local
> > irq response by local_irq_save(), at the time of access register cr1,
> > tdr, isr. an TXE interrupt raised, for other cores(I know stm32
> > mpu/mcu do not have multi cores, just assume it has), it still has a
> > chance to handle interrupt. Then there is no lock to protect the uart
> > register.
>
> Right, the sysrq handling is a bit of a hack.
>
> > changes to below, should be more safe:
> >
> > .....
> > if (port->sysrq || oops_in_progress)
> > locked = spin_trylock_irqsave(&port->lock, flags);
>
> Except that the lock debugging code would detect the attempt at
> recursive locking here and complain loudly on UP.
>
> If you really want to fix this, we have uart_unlock_and_check_sysrq()
> which can be used to defer sysrq processing until the interrupt handler
> has released the lock.
Great, uart_unlock_and_check_sysrq() is fit to fix this. you mean make
the flow like below:
stm32_usart_threaded_interrupt()
spin_lock(&port->lock);
uart_unlock_and_check_sysrq(port, flags);
...
uart_prepare_sysrq_char();
printk();
stm32_usart_console_write();
locked = spin_trylock_irqsave(&port->lock); //only
handle oops, normal case
If so, I will submit v3 as you suggested. thanks.
Best regards.
Dillon,
>
> > else
> > spin_lock_irqsave(&port->lock, flags);
> >
> > ....
> >
> > if (locked)
> > spin_unlock_irqrestore(&port->lock, flags);
>
> Johan
Powered by blists - more mailing lists