From: "zhangpeng (AS)" <zhangpeng362@huawei.com>
To: Petr Tesarik <petr.tesarik1@huawei-partners.com>, <hch@lst.de>,
<m.szyprowski@samsung.com>, <robin.murphy@arm.com>,
<iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Cc: <wangkefeng.wang@huawei.com>, <sunnanyong@huawei.com>
Subject: Re: [PATCH] swiotlb: check alloc_size before the allocation of a new memory pool
Date: Tue, 9 Jan 2024 10:34:15 +0800 [thread overview]
Message-ID: <237db58a-18ad-b3ea-7559-3c22169cba26@huawei.com> (raw)
In-Reply-To: <c68cfc31-317c-4709-a2e5-3729a137b1bb@huawei-partners.com>
On 2024/1/8 23:46, Petr Tesarik wrote:
> On 1/8/2024 3:00 PM, Peng Zhang wrote:
>> From: ZhangPeng <zhangpeng362@huawei.com>
>>
>> The allocation request for swiotlb contiguous memory greater than
>> 128*2KB cannot be fulfilled because it exceeds the maximum contiguous
>> memory limit. If the swiotlb memory we allocate is larger than 128*2KB,
>> swiotlb_find_slots() will still schedule the allocation of a new memory
>> pool, which will increase memory overhead.
>>
>> Fix it by adding a check with alloc_size no more than 128*2KB before
>> scheduling the allocation of a new memory pool in swiotlb_find_slots().
>>
>> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
>> ---
>> kernel/dma/swiotlb.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
>> index 33d942615be5..cc92cff02c60 100644
>> --- a/kernel/dma/swiotlb.c
>> +++ b/kernel/dma/swiotlb.c
>> @@ -1126,6 +1126,9 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
>> u64 phys_limit;
>> int index;
>>
>> + if (alloc_size > IO_TLB_SEGSIZE * IO_TLB_SIZE)
>> + return -1;
>> +
>> rcu_read_lock();
>> list_for_each_entry_rcu(pool, &mem->pools, node) {
>> index = swiotlb_pool_find_slots(dev, pool, orig_addr,
> IIUC this such big allocations are not normally required by drivers, but
> I have already run into a similar issue with a Raspberry Pi 4 dma-buf
> object, so they can be triggered at will by user space. I also believe
> this sanity check is a good idea in general, not only when dynamic
> SWIOTLB is enabled.
>
> Reviewed-by: Petr Tesarik <petr.tesarik1@huawei-partners.com>
>
> Petr T
Thanks for your review!
--
Best Regards,
Peng
next prev parent reply other threads:[~2024-01-09 2:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-08 14:00 Peng Zhang
2024-01-08 15:46 ` Petr Tesarik
2024-01-09 2:34 ` zhangpeng (AS) [this message]
2024-01-08 17:06 ` Christoph Hellwig
2024-01-09 2:34 ` zhangpeng (AS)
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=237db58a-18ad-b3ea-7559-3c22169cba26@huawei.com \
--to=zhangpeng362@huawei.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=petr.tesarik1@huawei-partners.com \
--cc=robin.murphy@arm.com \
--cc=sunnanyong@huawei.com \
--cc=wangkefeng.wang@huawei.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
all inboxes | Powered by JetHome®