[patch] drivers/iommu: Fix iova DEBUG_PREEMPT splat

Mike Galbraith
2016-06-13T12:56:42Z

[ 646.138847] BUG: using smp_processor_id() in preemptible [00000000] code: usb-storage/309
[ 646.138852] caller is debug_smp_processor_id+0x17/0x20
[ 646.138854] CPU: 0 PID: 309 Comm: usb-storage Not tainted 4.7.0-master #855
[ 646.138855] Hardware name: MEDION MS-7848/MS-7848, BIOS M7848W08.20C 09/23/2013
[ 646.138856] 0000000000000000 ffff8803f784ba48 ffffffff812da34c 0000000000000000
[ 646.138859] ffffffff81a18ad8 ffff8803f784ba78 ffffffff812f4c1c ffffffff81a0dd4e
[ 646.138860] 000000000001db40 ffff8803f9100318 0000000000000001 ffff8803f784ba88
[ 646.138862] Call Trace:
[ 646.138866] [<ffffffff812da34c>] dump_stack+0x65/0x89
[ 646.138868] [<ffffffff812f4c1c>] check_preemption_disabled+0xdc/0xf0
[ 646.138869] [<ffffffff812f4c47>] debug_smp_processor_id+0x17/0x20
[ 646.138873] [<ffffffff813e9c5b>] alloc_iova_fast+0xbb/0x1e0
[ 646.138874] [<ffffffff813ed1cf>] intel_alloc_iova+0x9f/0xd0
[ 646.138876] [<ffffffff813f118f>] intel_map_sg+0xbf/0x220
[ 646.138878] [<ffffffff8147cc84>] usb_hcd_map_urb_for_dma+0x2d4/0x4e0
[ 646.138879] [<ffffffff8147cf37>] usb_hcd_submit_urb+0xa7/0xa90
[ 646.138881] [<ffffffff8162717a>] ? __schedule+0x27a/0x750
[ 646.138882] [<ffffffff81627699>] ? schedule+0x49/0xa0
[ 646.138884] [<ffffffff8162a510>] ? schedule_timeout+0x210/0x290
[ 646.138885] [<ffffffff8147e869>] usb_submit_urb.part.6+0x299/0x530
[ 646.138887] [<ffffffff8147eb34>] usb_submit_urb+0x34/0x70
[ 646.138888] [<ffffffff8147fc48>] usb_sg_wait+0x88/0x180
[ 646.138891] [<ffffffffa008d58e>] usb_stor_bulk_transfer_sglist.part.4+0x7e/0xe0 [usb_storage]
[ 646.138893] [<ffffffffa008d63f>] usb_stor_bulk_srb+0x4f/0x60 [usb_storage]
[ 646.138895] [<ffffffffa008d773>] usb_stor_Bulk_transport+0x123/0x3a0 [usb_storage]
[ 646.138896] [<ffffffff81627699>] ? schedule+0x49/0xa0
[ 646.138898] [<ffffffffa008dfac>] usb_stor_invoke_transport+0x2c/0x4c0 [usb_storage]
[ 646.138900] [<ffffffff81085b35>] ? wake_up_process+0x15/0x20
[ 646.138903] [<ffffffff81062ff5>] ? wakeup_softirqd+0x35/0x40
[ 646.138904] [<ffffffff81082363>] ? preempt_count_add+0xa3/0xc0
[ 646.138906] [<ffffffff8162af8d>] ? _raw_spin_unlock_irq+0x1d/0x40
[ 646.138907] [<ffffffff816288d8>] ? wait_for_completion_interruptible+0x128/0x150
[ 646.138909] [<ffffffffa008cf20>] usb_stor_pad12_command+0x40/0x50 [usb_storage]
[ 646.138910] [<ffffffffa008f456>] usb_stor_control_thread+0x146/0x240 [usb_storage]
[ 646.138912] [<ffffffffa008f310>] ? fill_inquiry_response+0x20/0x20 [usb_storage]
[ 646.138914] [<ffffffffa008f310>] ? fill_inquiry_response+0x20/0x20 [usb_storage]
[ 646.138916] [<ffffffff8107bb79>] kthread+0xc9/0xe0
[ 646.138918] [<ffffffff8162b79f>] ret_from_fork+0x1f/0x40
[ 646.138919] [<ffffffff8107bab0>] ? kthread_park+0x60/0x60

Signed-off-by: Mike Galbraith <umgwanakikbuti@gmail.com>
Cc: Joerg Roedel <joro@8bytes.org>
---
drivers/iommu/iova.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -749,8 +749,9 @@ static bool __iova_rcache_insert(struct
bool can_insert = false;
unsigned long flags;

+ local_irq_save(flags);
cpu_rcache = this_cpu_ptr(rcache->cpu_rcaches);
- spin_lock_irqsave(&cpu_rcache->lock, flags);
+ spin_lock(&cpu_rcache->lock);

if (!iova_magazine_full(cpu_rcache->loaded)) {
can_insert = true;
@@ -812,8 +813,9 @@ static unsigned long __iova_rcache_get(s
bool has_pfn = false;
unsigned long flags;

+ local_irq_save(flags);
cpu_rcache = this_cpu_ptr(rcache->cpu_rcaches);
- spin_lock_irqsave(&cpu_rcache->lock, flags);
+ spin_lock(&cpu_rcache->lock);

if (!iova_magazine_empty(cpu_rcache->loaded)) {
has_pfn = true;