Linux IOMMU Development
 help / color / mirror / Atom feed
From: Ben Dooks <ben.dooks@sifive.com>
To: Robin Murphy <robin.murphy@arm.com>,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	iommu@lists.linux-foundation.org
Cc: Sudip Mukherjee <sudip.mukherjee@sifive.com>,
	Jude Onyenegecha <jude.onyenegecha@sifive.com>
Subject: Re: [PATCH] swiotlb: ensure io_tlb_default_mem spinlock always initialised
Date: Mon, 11 Jul 2022 08:26:12 +0100	[thread overview]
Message-ID: <683344bd-dc9b-0bb5-9377-b3e9ab410a74@sifive.com> (raw)
In-Reply-To: <fdf5d34e-7668-c05c-9098-30e34939c88a@arm.com>

On 08/07/2022 21:32, Robin Murphy wrote:
> On 2022-07-08 18:08, Ben Dooks wrote:
>> If the io_tlb_default_mem is used by a device that then gets used
>> by the swiotlb code, the spinlock warning is triggered causing a
>> lot of stack-trace.
> 
> Hang on, how have we got as far as trying to allocate out of an 
> uninitialised SWIOTLB at all? That seems like either something's gone 
> more fundamentally wrong or we're missing a proper check somewhere. I 
> don't think papering over it like this is right.
> 
> Thanks,
> Robin
We have a system where we have no DMA capable memory in the 32bit
window, which means even if we initialise swiotlb we don't have
any dma capable memory. The code says go use an IOMMU but we don't
have one of those either (and all peripherals are capable of DMA
from any of the memory, so there shouldn't be the need for one)

Is there any other way of fixing this DMA allocation issue?

I added this fix as swiotlb prints an error but also causes
an annoying stack backtrace.

> 
>> Fix this by making the structure's lock initialised at build time.
>>
>> Avoids the following BUG trigger:
>>
>> [    3.046401] BUG: spinlock bad magic on CPU#3, kworker/u8:0/7
>> [    3.046689]  lock: io_tlb_default_mem+0x30/0x60, .magic: 00000000, 
>> .owner: <none>/-1, .owner_cpu: 0
>> [    3.047217] CPU: 3 PID: 7 Comm: kworker/u8:0 Not tainted 
>> 5.17.0-00056-g1e9bac738084-dirty #310
>> [    3.048363] Workqueue: events_unbound deferred_probe_work_func
>> [    3.048892] Call Trace:
>> [    3.049224] [<ffffffff800048aa>] dump_backtrace+0x1c/0x24
>> [    3.049576] [<ffffffff805c5f74>] show_stack+0x2c/0x38
>> [    3.049898] [<ffffffff805cade2>] dump_stack_lvl+0x40/0x58
>> [    3.050216] [<ffffffff805cae0e>] dump_stack+0x14/0x1c
>> [    3.050460] [<ffffffff805c69f6>] spin_dump+0x62/0x6e
>> [    3.050681] [<ffffffff8004e000>] do_raw_spin_lock+0xb0/0xd0
>> [    3.050934] [<ffffffff805d5b58>] _raw_spin_lock_irqsave+0x20/0x2c
>> [    3.051157] [<ffffffff80067e38>] swiotlb_tbl_map_single+0xce/0x3da
>> [    3.051372] [<ffffffff80068320>] swiotlb_map+0x3a/0x15c
>> [    3.051668] [<ffffffff80065a56>] dma_map_page_attrs+0x76/0x162
>> [    3.051975] [<ffffffff8031d542>] dw_pcie_host_init+0x326/0x3f2
>>
>> Signed-off-by: Ben Dooks <ben.dooks@sifive.com>
>> ---
>>   kernel/dma/swiotlb.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
>> index cb50f8d38360..a707a944c39a 100644
>> --- a/kernel/dma/swiotlb.c
>> +++ b/kernel/dma/swiotlb.c
>> @@ -65,7 +65,7 @@
>>   static bool swiotlb_force_bounce;
>>   static bool swiotlb_force_disable;
>> -struct io_tlb_mem io_tlb_default_mem;
>> +struct io_tlb_mem io_tlb_default_mem = { .lock = 
>> __SPIN_LOCK_UNLOCKED(io_tlb_default_mem.lock) } ;
>>   phys_addr_t swiotlb_unencrypted_base;


  reply	other threads:[~2022-07-11  7:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 17:08 [PATCH] swiotlb: ensure io_tlb_default_mem spinlock always initialised Ben Dooks
2022-07-08 20:32 ` Robin Murphy
2022-07-11  7:26   ` Ben Dooks [this message]
2022-07-11 10:07     ` Robin Murphy
2022-07-11 10:21       ` Christoph Hellwig
2022-07-11 10:24         ` Ben Dooks
2022-07-11 10:39           ` Christoph Hellwig
2022-07-11 10:42             ` Ben Dooks
2022-07-11 11:01               ` Robin Murphy
2022-07-11 11:52                 ` Conor.Dooley
2022-07-11 12:45                   ` Ben Dooks
2022-07-11 12:56                     ` Conor.Dooley
2022-07-11 12:54                 ` Ben Dooks
2022-07-11 13:40                   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=683344bd-dc9b-0bb5-9377-b3e9ab410a74@sifive.com \
    --to=ben.dooks@sifive.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=iommu@lists.linux.dev \
    --cc=jude.onyenegecha@sifive.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=sudip.mukherjee@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox