Linux IOMMU Development
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Ben Dooks <ben.dooks@sifive.com>,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	iommu@lists.linux-foundation.org, Christoph Hellwig <hch@lst.de>
Cc: Sudip Mukherjee <sudip.mukherjee@sifive.com>,
	Jude Onyenegecha <jude.onyenegecha@sifive.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: Re: [PATCH] swiotlb: ensure io_tlb_default_mem spinlock always initialised
Date: Mon, 11 Jul 2022 11:07:17 +0100	[thread overview]
Message-ID: <e6c43ef0-870b-5fe6-141e-0a3d566b030e@arm.com> (raw)
In-Reply-To: <683344bd-dc9b-0bb5-9377-b3e9ab410a74@sifive.com>

On 2022-07-11 08:26, Ben Dooks wrote:
> 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?

If none of your peripherals should need SWIOTLB, then the fact that
you're ending up in swiotlb_map() at all is a clear sign that
something's wrong. Most likely someone's forgotten to set their DMA
masks correctly.

However, by inspection it seems we do have a bug here as well, for which
the correct fix should be as below. The fireworks you're *supposed* to
get in that situation are considerably louder and more obvious than a
DEBUG_SPINLOCK complaint ;)

Thanks,
Robin.

----->8-----
Subject: [PATCH] swiotlb: Fail map correctly with failed io_tlb_default_mem

In the failure case of trying to use a buffer which we'd previously
failed to allocate, the "!mem" condition is no longer sufficient since
io_tlb_default_mem became static and assigned by default. Update the
condition to work as intended per the rest of that conversion.

Fixes: 463e862ac63e ("swiotlb: Convert io_default_tlb_mem to static allocation")
Signed-off-by: Robin Murphy <robin.murphy@arm.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..5830dce6081b 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -580,7 +580,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
  	int index;
  	phys_addr_t tlb_addr;
  
-	if (!mem)
+	if (!mem || !mem->nslabs)
  		panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
  
  	if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
-- 
2.36.1.dirty


  reply	other threads:[~2022-07-11 10:07 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
2022-07-11 10:07     ` Robin Murphy [this message]
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=e6c43ef0-870b-5fe6-141e-0a3d566b030e@arm.com \
    --to=robin.murphy@arm.com \
    --cc=ben.dooks@sifive.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=iommu@lists.linux.dev \
    --cc=jude.onyenegecha@sifive.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.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