mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: "Michael Kelley" <mhklinux@outlook.com>,
	"Will Deacon" <will@kernel.org>,
	"Petr Tesařík" <petr@tesarici.cz>
Cc: Christoph Hellwig <hch@lst.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Petr Tesarik <petr.tesarik1@huawei-partners.com>,
	"kernel-team@android.com" <kernel-team@android.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Dexuan Cui <decui@microsoft.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: [PATCH v5 6/6] swiotlb: Remove pointless stride adjustment for allocations >= PAGE_SIZE
Date: Mon, 4 Mar 2024 16:53:32 +0000	[thread overview]
Message-ID: <b63d4332-b659-4897-83c7-04e5ad397a69@arm.com> (raw)
In-Reply-To: <SN6PR02MB41571F68F8F9E003C4359948D4232@SN6PR02MB4157.namprd02.prod.outlook.com>

On 04/03/2024 4:10 pm, Michael Kelley wrote:
> From: Will Deacon <will@kernel.org> Sent: Monday, March 4, 2024 8:02 AM
>>
>> Hi folks,
>>
>> On Mon, Mar 04, 2024 at 04:55:06PM +0100, Petr Tesařík wrote:
>>> On Mon, 4 Mar 2024 13:37:56 +0000
>>> Robin Murphy <robin.murphy@arm.com> wrote:
>>>> On 04/03/2024 11:00 am, Petr Tesařík wrote:
>>>> [...]
>>>>>> Here's my take on tying all the threads together. There are
>>>>>> four alignment combinations:
>>>>>>
>>>>>> 1. alloc_align_mask: zero; min_align_mask: zero
>>
>> Based on this ^^^ ...
>>
>>>>>> xen_swiotlb_map_page() and dma_direct_map_page() are #1 or #2
>>>>>> via swiotlb_map() and swiotlb_tbl_map_single()
>>>>>>
>>>>>> iommu_dma_map_page() is #3 and #4 via swiotlb_tbl_map_single()
>>>>>>
>>>>>> swiotlb_alloc() is #3, directly to swiotlb_find_slots()
>>>>>>
>>>>>> For #1, the returned physical address has no constraints if
>>>>>> the requested size is less than a page. For page size or
>>>>>> greater, the discussed historical requirement for page
>>>>>> alignment applies.
>>
>> ... and this ^^^ ...
>>
>>
>>> I believe this patch series is now good as is, except the commit
>>> message should make it clear that alloc_align_mask and min_align_mask
>>> can both be zero, but that simply means no alignment constraints.
>>
>> ... my (possibly incorrect!) reading of the thread so far is that we
>> should preserve page-aligned allocation in this case if the allocation
>> size is >= PAGE_SIZE.
>>
>> Something like the diff below, to replace this final patch?
>>
>> Will
>>
>> --->8
>>
>> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
>> index c381a7ed718f..67eac05728c0 100644
>> --- a/kernel/dma/swiotlb.c
>> +++ b/kernel/dma/swiotlb.c
>> @@ -992,6 +992,14 @@ static int swiotlb_search_pool_area(struct device
>> *dev, struct io_tlb_pool *pool
>>          BUG_ON(!nslots);
>>          BUG_ON(area_index >= pool->nareas);
>>
>> +       /*
>> +        * Historically, allocations >= PAGE_SIZE were guaranteed to be
>> +        * page-aligned in the absence of any other alignment requirements.
>> +        * Since drivers may be relying on this, preserve the old behaviour.
>> +        */
>> +       if (!alloc_align_mask && !iotlb_align_mask && alloc_size >= PAGE_SIZE)
>> +               alloc_align_mask = PAGE_SIZE - 1;
>> +
> 
> Yes, I think that should do it.

In principle it might be more logical to fudge this into 
iotlb_align_mask rather than alloc_align_mask - since that's really the 
effective behaviour to preserve for streaming mappings - and then pass 
an explicit alloc_align_mask from swiotlb_alloc() to honour the 
dma-coherent requirements. However I also wouldn't really object to not 
going that far and instead just making the comment a bit clearer that 
this is still serving both purposes.

Cheers,
Robin.

> 
> Michael
> 
>>          /*
>>           * Ensure that the allocation is at least slot-aligned and update
>>           * 'iotlb_align_mask' to ignore bits that will be preserved when
>> @@ -1006,13 +1014,6 @@ static int swiotlb_search_pool_area(struct device *dev, struct io_tlb_pool *pool
>>           */
>>          stride = get_max_slots(max(alloc_align_mask, iotlb_align_mask));
>>
>> -       /*
>> -        * For allocations of PAGE_SIZE or larger only look for page aligned
>> -        * allocations.
>> -        */
>> -       if (alloc_size >= PAGE_SIZE)
>> -               stride = umax(stride, PAGE_SHIFT - IO_TLB_SHIFT + 1);
>> -
>>          spin_lock_irqsave(&area->lock, flags);
>>          if (unlikely(nslots > pool->area_nslabs - area->used))
>>                  goto not_found;
> 

  reply	other threads:[~2024-03-04 16:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 13:39 [PATCH v5 0/6] Fix double allocation in swiotlb_alloc() Will Deacon
2024-02-28 13:39 ` [PATCH v5 1/6] swiotlb: Fix double-allocation of slots due to broken alignment handling Will Deacon
2024-02-29  5:44   ` Michael Kelley
2024-02-28 13:39 ` [PATCH v5 2/6] swiotlb: Enforce page alignment in swiotlb_alloc() Will Deacon
2024-02-28 13:39 ` [PATCH v5 3/6] swiotlb: Honour dma_alloc_coherent() " Will Deacon
2024-02-28 13:39 ` [PATCH v5 4/6] swiotlb: Fix alignment checks when both allocation and DMA masks are present Will Deacon
2024-02-28 13:39 ` [PATCH v5 5/6] iommu/dma: Force swiotlb_max_mapping_size on an untrusted device Will Deacon
2024-02-29  5:57   ` Michael Kelley
2024-02-28 13:39 ` [PATCH v5 6/6] swiotlb: Remove pointless stride adjustment for allocations >= PAGE_SIZE Will Deacon
2024-02-29  6:07   ` Michael Kelley
2024-02-29  7:36     ` Michael Kelley
2024-02-29 13:33       ` Christoph Hellwig
2024-02-29 15:44         ` Michael Kelley
2024-02-29 15:47           ` Christoph Hellwig
2024-03-01 15:39             ` Petr Tesařík
2024-03-01 16:38               ` Robin Murphy
2024-03-01 17:33                 ` Petr Tesařík
2024-03-01 17:08               ` Petr Tesařík
2024-03-01 17:54                 ` Robin Murphy
2024-03-01 18:42                   ` Petr Tesařík
2024-03-04  3:31                     ` Michael Kelley
2024-03-04 11:00                       ` Petr Tesařík
2024-03-04 13:37                         ` Robin Murphy
2024-03-04 15:55                           ` Petr Tesařík
2024-03-04 16:02                             ` Will Deacon
2024-03-04 16:10                               ` Michael Kelley
2024-03-04 16:53                                 ` Robin Murphy [this message]
2024-03-04 18:22                                   ` Michael Kelley
2024-03-05 11:20                                     ` Robin Murphy
2024-03-05 15:15                                       ` Petr Tesařík
2024-03-04 19:04                                 ` Petr Tesařík
2024-03-05 14:08                                   ` Christoph Hellwig
2024-03-04 16:04                             ` Michael Kelley
2024-03-04 17:11                               ` Robin Murphy
2024-03-04 18:08                                 ` Michael Kelley
2024-03-05 14:05                           ` Christoph Hellwig
2024-03-04 15:32     ` Will Deacon

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=b63d4332-b659-4897-83c7-04e5ad397a69@arm.com \
    --to=robin.murphy@arm.com \
    --cc=decui@microsoft.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux.dev \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mhklinux@outlook.com \
    --cc=nicolinc@nvidia.com \
    --cc=petr.tesarik1@huawei-partners.com \
    --cc=petr@tesarici.cz \
    --cc=will@kernel.org \
    /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®