Skip to content

Commit 59df44b

Browse files
zhang-ruijoergroedel
authored andcommitted
iommu/vt-d: Avoid memory allocation in iommu_suspend()
The iommu_suspend() syscore suspend callback is invoked with IRQ disabled. Allocating memory with the GFP_KERNEL flag may re-enable IRQs during the suspend callback, which can cause intermittent suspend/hibernation problems with the following kernel traces: Calling iommu_suspend+0x0/0x1d0 ------------[ cut here ]------------ WARNING: CPU: 0 PID: 15 at kernel/time/timekeeping.c:868 ktime_get+0x9b/0xb0 ... CPU: 0 PID: 15 Comm: rcu_preempt Tainted: G U E 6.3-intel #r1 RIP: 0010:ktime_get+0x9b/0xb0 ... Call Trace: <IRQ> tick_sched_timer+0x22/0x90 ? __pfx_tick_sched_timer+0x10/0x10 __hrtimer_run_queues+0x111/0x2b0 hrtimer_interrupt+0xfa/0x230 __sysvec_apic_timer_interrupt+0x63/0x140 sysvec_apic_timer_interrupt+0x7b/0xa0 </IRQ> <TASK> asm_sysvec_apic_timer_interrupt+0x1f/0x30 ... ------------[ cut here ]------------ Interrupts enabled after iommu_suspend+0x0/0x1d0 WARNING: CPU: 0 PID: 27420 at drivers/base/syscore.c:68 syscore_suspend+0x147/0x270 CPU: 0 PID: 27420 Comm: rtcwake Tainted: G U W E 6.3-intel #r1 RIP: 0010:syscore_suspend+0x147/0x270 ... Call Trace: <TASK> hibernation_snapshot+0x25b/0x670 hibernate+0xcd/0x390 state_store+0xcf/0xe0 kobj_attr_store+0x13/0x30 sysfs_kf_write+0x3f/0x50 kernfs_fop_write_iter+0x128/0x200 vfs_write+0x1fd/0x3c0 ksys_write+0x6f/0xf0 __x64_sys_write+0x1d/0x30 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc Given that only 4 words memory is needed, avoid the memory allocation in iommu_suspend(). CC: [email protected] Fixes: 33e0715 ("iommu/vt-d: Avoid GFP_ATOMIC where it is not needed") Signed-off-by: Zhang Rui <[email protected]> Tested-by: Ooi, Chin Hao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent c7bd8a1 commit 59df44b

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,13 +2998,6 @@ static int iommu_suspend(void)
29982998
struct intel_iommu *iommu = NULL;
29992999
unsigned long flag;
30003000

3001-
for_each_active_iommu(iommu, drhd) {
3002-
iommu->iommu_state = kcalloc(MAX_SR_DMAR_REGS, sizeof(u32),
3003-
GFP_KERNEL);
3004-
if (!iommu->iommu_state)
3005-
goto nomem;
3006-
}
3007-
30083001
iommu_flush_all();
30093002

30103003
for_each_active_iommu(iommu, drhd) {
@@ -3024,12 +3017,6 @@ static int iommu_suspend(void)
30243017
raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
30253018
}
30263019
return 0;
3027-
3028-
nomem:
3029-
for_each_active_iommu(iommu, drhd)
3030-
kfree(iommu->iommu_state);
3031-
3032-
return -ENOMEM;
30333020
}
30343021

30353022
static void iommu_resume(void)
@@ -3061,9 +3048,6 @@ static void iommu_resume(void)
30613048

30623049
raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
30633050
}
3064-
3065-
for_each_active_iommu(iommu, drhd)
3066-
kfree(iommu->iommu_state);
30673051
}
30683052

30693053
static struct syscore_ops iommu_syscore_ops = {

drivers/iommu/intel/iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ struct intel_iommu {
681681
struct iopf_queue *iopf_queue;
682682
unsigned char iopfq_name[16];
683683
struct q_inval *qi; /* Queued invalidation info */
684-
u32 *iommu_state; /* Store iommu states between suspend and resume.*/
684+
u32 iommu_state[MAX_SR_DMAR_REGS]; /* Store iommu states between suspend and resume.*/
685685

686686
#ifdef CONFIG_IRQ_REMAP
687687
struct ir_table *ir_table; /* Interrupt remapping info */

0 commit comments

Comments
 (0)