From: Christoph Hellwig <hch@lst.de>
To: Robin Murphy <robin.murphy@arm.com>
Cc: saravanak@google.com, konrad.wilk@oracle.com, marcorr@google.com,
gregkh@linuxfoundation.org, linux-nvme@lists.infradead.org,
kbusch@kernel.org, iommu@lists.linux-foundation.org,
erdemaktas@google.com, m.szyprowski@samsung.com,
Christoph Hellwig <hch@lst.de>,
jxgao@google.com
Subject: Re: [PATCH 7/8] swiotlb: respect min_align_mask
Date: Fri, 5 Feb 2021 11:34:17 +0100 [thread overview]
Message-ID: <20210205103417.GA6694@lst.de> (raw)
In-Reply-To: <2e51481c-1591-034c-3476-1a1f8891506a@arm.com>
On Thu, Feb 04, 2021 at 11:13:45PM +0000, Robin Murphy wrote:
>> + */
>> +static unsigned int swiotlb_align_offset(struct device *dev, u64 addr)
>> +{
>> + unsigned min_align_mask = dma_get_min_align_mask(dev);
>> +
>> + if (!min_align_mask)
>> + return 0;
>
> I doubt that's beneficial - even if the compiler can convert it into a
> csel, it'll then be doing unnecessary work to throw away a
> cheaply-calculated 0 in favour of hard-coded 0 in the one case it matters
True, I'll drop the checks.
> ;)
>
>> + return addr & min_align_mask & ((1 << IO_TLB_SHIFT) - 1);
>
> (BTW, for readability throughout, "#define IO_TLB_SIZE (1 << IO_TLB_SHIFT)"
> sure wouldn't go amiss...)
I actually had a patch doing just that, but as it is the only patch
touching swiotlb.h it caused endless rebuilds for me, so I dropped it
as it only had a few uses anyway. But I've added it back.
>> - if (alloc_size >= PAGE_SIZE)
>> + if (min_align_mask)
>> + stride = (min_align_mask + 1) >> IO_TLB_SHIFT;
>
> So this can't underflow because "min_align_mask" is actually just the
> high-order bits representing the number of iotlb slots needed to meet the
> requirement, right? (It took a good 5 minutes to realise this wasn't doing
> what I initially thought it did...)
Yes.
> In that case, a) could the local var be called something like
> iotlb_align_mask to clarify that it's *not* just a copy of the device's
> min_align_mask,
Ok.
> and b) maybe just have an unconditional initialisation that
> works either way:
>
> stride = (min_align_mask >> IO_TLB_SHIFT) + 1;
Sure.
> In fact with that, I think could just mask orig_addr with ~IO_TLB_SIZE in
> the call to check_alignment() below, or shift everything down by
> IO_TLB_SHIFT in check_alignment() itself, instead of mangling
> min_align_mask at all (I'm assuming we do need to ignore the low-order bits
> of orig_addr at this point).
Yes, we do need to ignore the low bits as they won't ever be set in
tlb_dma_addr. Not sure the shift helps as we need to mask first.
I ended up killing check_alignment entirely, in favor of a new
slot_addr helper that calculates the address based off the base and index
and which can be used in a few other places as this one.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-02-05 10:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-04 19:30 preserve DMA offsets when using swiotlb Christoph Hellwig
2021-02-04 19:30 ` [PATCH 1/8] driver core: add a min_align_mask field to struct device_dma_parameters Christoph Hellwig
2021-02-04 19:44 ` Greg KH
2021-02-04 19:30 ` [PATCH 2/8] swiotlb: add a io_tlb_offset helper Christoph Hellwig
2021-02-04 19:30 ` [PATCH 3/8] swiotlb: factor out a nr_slots helper Christoph Hellwig
2021-02-04 22:09 ` Robin Murphy
2021-02-05 9:45 ` Christoph Hellwig
2021-02-04 19:30 ` [PATCH 4/8] swiotlb: clean up swiotlb_tbl_unmap_single Christoph Hellwig
2021-02-04 19:30 ` [PATCH 5/8] swiotlb: refactor swiotlb_tbl_map_single Christoph Hellwig
2021-02-04 22:12 ` Robin Murphy
2021-02-05 9:45 ` Christoph Hellwig
2021-02-04 19:30 ` [PATCH 6/8] swiotlb: don't modify orig_addr in swiotlb_tbl_sync_single Christoph Hellwig
2021-02-04 19:30 ` [PATCH 7/8] swiotlb: respect min_align_mask Christoph Hellwig
2021-02-04 23:13 ` Robin Murphy
2021-02-05 10:34 ` Christoph Hellwig [this message]
2021-02-04 19:30 ` [PATCH 8/8] nvme-pci: set min_align_mask Christoph Hellwig
2021-02-04 19:32 ` Christoph Hellwig
2021-02-05 11:50 ` preserve DMA offsets when using swiotlb 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=20210205103417.GA6694@lst.de \
--to=hch@lst.de \
--cc=erdemaktas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jxgao@google.com \
--cc=kbusch@kernel.org \
--cc=konrad.wilk@oracle.com \
--cc=linux-nvme@lists.infradead.org \
--cc=m.szyprowski@samsung.com \
--cc=marcorr@google.com \
--cc=robin.murphy@arm.com \
--cc=saravanak@google.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