Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1518751

Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability

From Thomas Gleixner <tglx@linutronix.de>
Newsgroups linux.kernel
Subject Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability
Date 2016-11-10 10:00 +0100
Message-ID <sBTnb-3hK-9@gated-at.bofh.it> (permalink)
References <syzuG-4cJ-7@gated-at.bofh.it> <syzuG-4cJ-5@gated-at.bofh.it> <sBxwm-5sn-31@gated-at.bofh.it> <sBMlI-77l-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 10 Nov 2016, Lu Baolu wrote:
> On 11/09/2016 05:37 PM, Thomas Gleixner wrote:
> > On Tue, 1 Nov 2016, Lu Baolu wrote:
> >> +static void early_xdbc_write(struct console *con, const char *str, u32 n)
> >> +{
> >> +	int chunk, ret;
> >> +	static char buf[XDBC_MAX_PACKET];
> >> +	int use_cr = 0;
> >> +
> >> +	if (!xdbc.xdbc_reg)
> >> +		return;
> >> +	memset(buf, 0, XDBC_MAX_PACKET);
> > How is that dealing with reentrancy?
> >
> > early_printk() does not protect against it. Peter has a patch to prevent
> > concurrent access from different cpus, but it cannot and will never prevent
> > reentrancy on the same cpu (interrupt, nmi).
> 
> I can use a spinlock_irq to protect reentrancy of interrupt on the same
> cpu. But I have no idea about the nmi one.

spinlock wont work due to NMIs.

> This seems to be a common issue for all early printk drivers.

No. The other early printk drivers like serial do not have that problem as
they simply do:

   while (*buf) {
      while (inb(UART) & TX_BUSY)
   	 cpu_relax();
      outb(*buf++, UART);
   }

The wait for the UART to become ready is independent of the context as it
solely depends on the hardware.

As a result you can see the output from irq/nmi intermingled with the one
from thread context, but that's the only problem they have.

The only thing you can do to make this work is to prevent printing in NMI
context:

write()
{
	if (in_nmi())
		return;
	
	raw_spinlock_irqsave(&lock, flags);
	....

That fully serializes the writes and just ignores NMI context printks. Not
optimal, but I fear that's all you can do.

Thanks,

	tglx

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 0/4] usb: early: add support for early printk through USB3 debug port Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-01 06:10 +0100
  [PATCH v4 4/4] usb: doc: add document for USB3 debug port usage Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-01 06:10 +0100
  [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-01 06:10 +0100
    Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug  capability Thomas Gleixner <tglx@linutronix.de> - 2016-11-09 10:30 +0100
      Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-10 02:20 +0100
    Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug  capability Thomas Gleixner <tglx@linutronix.de> - 2016-11-09 10:40 +0100
      Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-10 02:30 +0100
        Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug  capability Thomas Gleixner <tglx@linutronix.de> - 2016-11-10 10:00 +0100
          Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Peter Zijlstra <peterz@infradead.org> - 2016-11-10 12:50 +0100
            Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-11 05:40 +0100
              Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Peter Zijlstra <peterz@infradead.org> - 2016-11-11 13:30 +0100
          Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-11 03:30 +0100
            Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-11 03:50 +0100
  [PATCH v4 2/4] x86: add support for earlyprintk via USB3 debug port Lu Baolu <baolu.lu@linux.intel.com> - 2016-11-01 06:10 +0100

csiph-web