Message ID | 20220616025634.3693260-1-xiehongyu1@kylinos.cn (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v3,-next] usb: xhci: disable irq during initialization | expand |
Hi Hongyu,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on next-20220615]
url: https://github.com/intel-lab-lkp/linux/commits/Hongyu-Xie/usb-xhci-disable-irq-during-initialization/20220616-110418
base: 6012273897fefb12566580efedee10bb06e5e6ed
config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20220616/202206161315.DjaJzxlY-lkp@intel.com/config)
compiler: xtensa-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b8e08f7da837bf7aff0a032d4dbd6633c5a76f7d
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Hongyu-Xie/usb-xhci-disable-irq-during-initialization/20220616-110418
git checkout b8e08f7da837bf7aff0a032d4dbd6633c5a76f7d
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=xtensa SHELL=/bin/bash drivers/usb/host/
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from include/linux/bitops.h:7,
from include/linux/log2.h:12,
from include/asm-generic/div64.h:55,
from ./arch/xtensa/include/generated/asm/div64.h:1,
from include/linux/math.h:6,
from include/linux/math64.h:6,
from include/linux/time64.h:5,
from include/linux/restart_block.h:10,
from include/linux/thread_info.h:14,
from arch/xtensa/include/asm/current.h:18,
from include/linux/mutex.h:14,
from include/linux/kernfs.h:11,
from include/linux/sysfs.h:16,
from include/linux/kobject.h:20,
from include/linux/pci.h:35,
from drivers/usb/host/xhci.c:11:
drivers/usb/host/xhci.c: In function 'xhci_run_finished':
drivers/usb/host/xhci.c:619:40: error: 'flags' undeclared (first use in this function)
619 | spin_lock_irqsave(&xhci->lock, flags);
| ^~~~~
include/linux/typecheck.h:11:16: note: in definition of macro 'typecheck'
11 | typeof(x) __dummy2; \
| ^
include/linux/spinlock.h:390:9: note: in expansion of macro 'raw_spin_lock_irqsave'
390 | raw_spin_lock_irqsave(spinlock_check(lock), flags); \
| ^~~~~~~~~~~~~~~~~~~~~
drivers/usb/host/xhci.c:619:9: note: in expansion of macro 'spin_lock_irqsave'
619 | spin_lock_irqsave(&xhci->lock, flags);
| ^~~~~~~~~~~~~~~~~
drivers/usb/host/xhci.c:619:40: note: each undeclared identifier is reported only once for each function it appears in
619 | spin_lock_irqsave(&xhci->lock, flags);
| ^~~~~
include/linux/typecheck.h:11:16: note: in definition of macro 'typecheck'
11 | typeof(x) __dummy2; \
| ^
include/linux/spinlock.h:390:9: note: in expansion of macro 'raw_spin_lock_irqsave'
390 | raw_spin_lock_irqsave(spinlock_check(lock), flags); \
| ^~~~~~~~~~~~~~~~~~~~~
drivers/usb/host/xhci.c:619:9: note: in expansion of macro 'spin_lock_irqsave'
619 | spin_lock_irqsave(&xhci->lock, flags);
| ^~~~~~~~~~~~~~~~~
>> include/linux/typecheck.h:12:25: warning: comparison of distinct pointer types lacks a cast
12 | (void)(&__dummy == &__dummy2); \
| ^~
include/linux/spinlock.h:247:17: note: in expansion of macro 'typecheck'
247 | typecheck(unsigned long, flags); \
| ^~~~~~~~~
include/linux/spinlock.h:390:9: note: in expansion of macro 'raw_spin_lock_irqsave'
390 | raw_spin_lock_irqsave(spinlock_check(lock), flags); \
| ^~~~~~~~~~~~~~~~~~~~~
drivers/usb/host/xhci.c:619:9: note: in expansion of macro 'spin_lock_irqsave'
619 | spin_lock_irqsave(&xhci->lock, flags);
| ^~~~~~~~~~~~~~~~~
vim +12 include/linux/typecheck.h
e0deaff470900a Andrew Morton 2008-07-25 4
e0deaff470900a Andrew Morton 2008-07-25 5 /*
e0deaff470900a Andrew Morton 2008-07-25 6 * Check at compile time that something is of a particular type.
e0deaff470900a Andrew Morton 2008-07-25 7 * Always evaluates to 1 so you may use it easily in comparisons.
e0deaff470900a Andrew Morton 2008-07-25 8 */
e0deaff470900a Andrew Morton 2008-07-25 9 #define typecheck(type,x) \
e0deaff470900a Andrew Morton 2008-07-25 10 ({ type __dummy; \
e0deaff470900a Andrew Morton 2008-07-25 11 typeof(x) __dummy2; \
e0deaff470900a Andrew Morton 2008-07-25 @12 (void)(&__dummy == &__dummy2); \
e0deaff470900a Andrew Morton 2008-07-25 13 1; \
e0deaff470900a Andrew Morton 2008-07-25 14 })
e0deaff470900a Andrew Morton 2008-07-25 15
Hi Hongyu, Thank you for the patch! Yet something to improve: [auto build test ERROR on next-20220615] url: https://github.com/intel-lab-lkp/linux/commits/Hongyu-Xie/usb-xhci-disable-irq-during-initialization/20220616-110418 base: 6012273897fefb12566580efedee10bb06e5e6ed config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20220616/202206161602.1Lp2YCz7-lkp@intel.com/config) compiler: xtensa-linux-gcc (GCC) 11.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/b8e08f7da837bf7aff0a032d4dbd6633c5a76f7d git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Hongyu-Xie/usb-xhci-disable-irq-during-initialization/20220616-110418 git checkout b8e08f7da837bf7aff0a032d4dbd6633c5a76f7d # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=xtensa SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from include/linux/bitops.h:7, from include/linux/log2.h:12, from include/asm-generic/div64.h:55, from ./arch/xtensa/include/generated/asm/div64.h:1, from include/linux/math.h:6, from include/linux/math64.h:6, from include/linux/time64.h:5, from include/linux/restart_block.h:10, from include/linux/thread_info.h:14, from arch/xtensa/include/asm/current.h:18, from include/linux/mutex.h:14, from include/linux/kernfs.h:11, from include/linux/sysfs.h:16, from include/linux/kobject.h:20, from include/linux/pci.h:35, from drivers/usb/host/xhci.c:11: drivers/usb/host/xhci.c: In function 'xhci_run_finished': >> drivers/usb/host/xhci.c:619:40: error: 'flags' undeclared (first use in this function) 619 | spin_lock_irqsave(&xhci->lock, flags); | ^~~~~ include/linux/typecheck.h:11:16: note: in definition of macro 'typecheck' 11 | typeof(x) __dummy2; \ | ^ include/linux/spinlock.h:390:9: note: in expansion of macro 'raw_spin_lock_irqsave' 390 | raw_spin_lock_irqsave(spinlock_check(lock), flags); \ | ^~~~~~~~~~~~~~~~~~~~~ drivers/usb/host/xhci.c:619:9: note: in expansion of macro 'spin_lock_irqsave' 619 | spin_lock_irqsave(&xhci->lock, flags); | ^~~~~~~~~~~~~~~~~ drivers/usb/host/xhci.c:619:40: note: each undeclared identifier is reported only once for each function it appears in 619 | spin_lock_irqsave(&xhci->lock, flags); | ^~~~~ include/linux/typecheck.h:11:16: note: in definition of macro 'typecheck' 11 | typeof(x) __dummy2; \ | ^ include/linux/spinlock.h:390:9: note: in expansion of macro 'raw_spin_lock_irqsave' 390 | raw_spin_lock_irqsave(spinlock_check(lock), flags); \ | ^~~~~~~~~~~~~~~~~~~~~ drivers/usb/host/xhci.c:619:9: note: in expansion of macro 'spin_lock_irqsave' 619 | spin_lock_irqsave(&xhci->lock, flags); | ^~~~~~~~~~~~~~~~~ include/linux/typecheck.h:12:25: warning: comparison of distinct pointer types lacks a cast 12 | (void)(&__dummy == &__dummy2); \ | ^~ include/linux/spinlock.h:247:17: note: in expansion of macro 'typecheck' 247 | typecheck(unsigned long, flags); \ | ^~~~~~~~~ include/linux/spinlock.h:390:9: note: in expansion of macro 'raw_spin_lock_irqsave' 390 | raw_spin_lock_irqsave(spinlock_check(lock), flags); \ | ^~~~~~~~~~~~~~~~~~~~~ drivers/usb/host/xhci.c:619:9: note: in expansion of macro 'spin_lock_irqsave' 619 | spin_lock_irqsave(&xhci->lock, flags); | ^~~~~~~~~~~~~~~~~ vim +/flags +619 drivers/usb/host/xhci.c 610 611 612 static int xhci_run_finished(struct xhci_hcd *xhci) 613 { 614 u32 temp; 615 616 /* Prevent receiving irqs in the small window between enabling interrupt 617 * and setting Run/Stop bit 618 */ > 619 spin_lock_irqsave(&xhci->lock, flags); 620 621 /* Enable interrupt right before setting Run/Stop bit according to spec 622 * 4.2 623 */ 624 /* Set the HCD state before we enable the irqs */ 625 temp = readl(&xhci->op_regs->command); 626 temp |= (CMD_EIE); 627 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 628 "// Enable interrupts, cmd = 0x%x.", temp); 629 writel(temp, &xhci->op_regs->command); 630 631 temp = readl(&xhci->ir_set->irq_pending); 632 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 633 "// %s %p by writing 0x%x %s", 634 "Enabling event ring interrupter", 635 "to irq_pending", xhci->ir_set, 636 (unsigned int) ER_IRQ_ENABLE(temp)); 637 writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); 638 if (xhci_start(xhci)) { 639 xhci_halt(xhci); 640 spin_unlock_irqrestore(&xhci->lock, flags); 641 return -ENODEV; 642 } 643 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; 644 645 if (xhci->quirks & XHCI_NEC_HOST) 646 xhci_ring_cmd_db(xhci); 647 spin_unlock_irqrestore(&xhci->lock, flags); 648 return 0; 649 } 650
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 9ac56e9ffc64..5cf8baa4f6f3 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -611,15 +611,40 @@ static int xhci_init(struct usb_hcd *hcd) static int xhci_run_finished(struct xhci_hcd *xhci) { + u32 temp; + + /* Prevent receiving irqs in the small window between enabling interrupt + * and setting Run/Stop bit + */ + spin_lock_irqsave(&xhci->lock, flags); + + /* Enable interrupt right before setting Run/Stop bit according to spec + * 4.2 + */ + /* Set the HCD state before we enable the irqs */ + temp = readl(&xhci->op_regs->command); + temp |= (CMD_EIE); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "// Enable interrupts, cmd = 0x%x.", temp); + writel(temp, &xhci->op_regs->command); + + temp = readl(&xhci->ir_set->irq_pending); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "// %s %p by writing 0x%x %s", + "Enabling event ring interrupter", + "to irq_pending", xhci->ir_set, + (unsigned int) ER_IRQ_ENABLE(temp)); + writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); if (xhci_start(xhci)) { xhci_halt(xhci); + spin_unlock_irqrestore(&xhci->lock, flags); return -ENODEV; } xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; if (xhci->quirks & XHCI_NEC_HOST) xhci_ring_cmd_db(xhci); - + spin_unlock_irqrestore(&xhci->lock, flags); return 0; } @@ -668,19 +693,6 @@ int xhci_run(struct usb_hcd *hcd) temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; writel(temp, &xhci->ir_set->irq_control); - /* Set the HCD state before we enable the irqs */ - temp = readl(&xhci->op_regs->command); - temp |= (CMD_EIE); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Enable interrupts, cmd = 0x%x.", temp); - writel(temp, &xhci->op_regs->command); - - temp = readl(&xhci->ir_set->irq_pending); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Enabling event ring interrupter %p by writing 0x%x to irq_pending", - xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); - writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); - if (xhci->quirks & XHCI_NEC_HOST) { struct xhci_command *command;
irq is disabled in xhci_quiesce(called by xhci_halt, with bit:2 cleared in USBCMD register), but xhci_run(called by usb_add_hcd) re-enable it. It's possible that you will receive thousands of interrupt requests after initialization for 2.0 roothub. And you will get a lot of warning like, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?". This amount of interrupt requests will cause the entire system to freeze. This problem was first found on a device with ASM2142 host controller on it. Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn> --- v3: - enabling interrupt right before setting Run/Stop bit - spin_lock_irqsave to prevent receiving irqs in the small window according to Mathias's suggestion v2: fix compile error drivers/usb/host/xhci.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-)