From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Christoph Hellwig <hch@lst.de>,
jxgao@google.com, gregkh@linuxfoundation.org
Cc: saravanak@google.com, konrad.wilk@oracle.com, marcorr@google.com,
linux-nvme@lists.infradead.org, iommu@lists.linux-foundation.org,
kbusch@kernel.org, robin.murphy@arm.com
Subject: Re: [PATCH 6/9] swiotlb: refactor swiotlb_tbl_map_single
Date: Mon, 22 Feb 2021 20:05:36 +0100 [thread overview]
Message-ID: <70edceb03e4bf283072397f9563dfc4162aec92a.camel@suse.de> (raw)
In-Reply-To: <20210207160327.2955490-7-hch@lst.de>
[-- Attachment #1.1: Type: text/plain, Size: 2899 bytes --]
Hi Christoph,
On Sun, 2021-02-07 at 17:03 +0100, Christoph Hellwig wrote:
> Split out a bunch of a self-contained helpers to make the function easier
> to follow.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/swiotlb.c | 179 +++++++++++++++++++++----------------------
> 1 file changed, 89 insertions(+), 90 deletions(-)
>
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index b38b1553c4663a..381c24ef1ac1d0 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -468,134 +468,133 @@ static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr,
> }
> }
>
>
> -phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
> - size_t mapping_size, size_t alloc_size,
> - enum dma_data_direction dir, unsigned long attrs)
> -{
> - dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start);
> - unsigned long flags;
> - phys_addr_t tlb_addr;
> - unsigned int nslots, stride, index, wrap;
> - int i;
> - unsigned long mask;
> - unsigned long offset_slots;
> - unsigned long max_slots;
> - unsigned long tmp_io_tlb_used;
> -
> - if (no_iotlb_memory)
> - panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
> -
> - if (mem_encrypt_active())
> - pr_warn_once("Memory encryption is active and system is using DMA bounce buffers\n");
> +#define slot_addr(start, idx) ((start) + ((idx) << IO_TLB_SHIFT))
>
>
> - if (mapping_size > alloc_size) {
> - dev_warn_once(hwdev, "Invalid sizes (mapping: %zd bytes, alloc: %zd bytes)",
> - mapping_size, alloc_size);
> - return (phys_addr_t)DMA_MAPPING_ERROR;
> - }
> -
> - mask = dma_get_seg_boundary(hwdev);
> +/*
> + * Carefully handle integer overflow which can occur when boundary_mask == ~0UL.
> + */
> +static inline unsigned long get_max_slots(unsigned long boundary_mask)
> +{
> + if (boundary_mask == ~0UL)
> + return 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
> + return nr_slots(boundary_mask + 1);
> +}
>
>
> - tbl_dma_addr &= mask;
> +static unsigned int wrap_index(unsigned int index)
> +{
> + if (index >= io_tlb_nslabs)
> + return 0;
> + return index;
> +}
>
>
> - offset_slots = nr_slots(tbl_dma_addr);
> +/*
> + * Find a suitable number of IO TLB entries size that will fit this request and
> + * allocate a buffer from that IO TLB pool.
> + */
> +static int find_slots(struct device *dev, size_t alloc_size)
> +{
> + unsigned long boundary_mask = dma_get_seg_boundary(dev);
> + dma_addr_t tbl_dma_addr =
> + phys_to_dma_unencrypted(dev, io_tlb_start) & boundary_mask;
> + unsigned int max_slots = get_max_slots(boundary_mask);
'max_slots' should be 'unsigned long' here. Breaks SWIOTLB on RPi4. Do you want
me to send a fix or you prefer editing the patch?
Regards,
Nicolas
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 158 bytes --]
_______________________________________________
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-22 19:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-07 16:03 preserve DMA offsets when using swiotlb v2 Christoph Hellwig
2021-02-07 16:03 ` [PATCH 1/9] driver core: add a min_align_mask field to struct device_dma_parameters Christoph Hellwig
2021-02-07 16:03 ` [PATCH 2/9] swiotlb: add a IO_TLB_SIZE define Christoph Hellwig
2021-02-07 16:03 ` [PATCH 3/9] swiotlb: factor out an io_tlb_offset helper Christoph Hellwig
2021-02-07 16:03 ` [PATCH 4/9] swiotlb: factor out a nr_slots helper Christoph Hellwig
2021-02-07 16:03 ` [PATCH 5/9] swiotlb: clean up swiotlb_tbl_unmap_single Christoph Hellwig
2021-02-07 16:03 ` [PATCH 6/9] swiotlb: refactor swiotlb_tbl_map_single Christoph Hellwig
2021-02-22 19:05 ` Nicolas Saenz Julienne [this message]
2021-02-22 19:29 ` Konrad Rzeszutek Wilk
2021-02-23 7:25 ` Christoph Hellwig
2021-02-07 16:03 ` [PATCH 7/9] swiotlb: don't modify orig_addr in swiotlb_tbl_sync_single Christoph Hellwig
2021-02-07 16:03 ` [PATCH 8/9] swiotlb: respect min_align_mask Christoph Hellwig
2021-02-07 16:03 ` [PATCH 9/9] nvme-pci: set min_align_mask Christoph Hellwig
2021-02-09 8:41 ` preserve DMA offsets when using swiotlb v2 Christoph Hellwig
2021-02-09 8:46 ` Greg KH
2021-02-09 19:49 ` Jianxiong Gao
2021-02-19 18:13 ` Konrad Rzeszutek Wilk
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=70edceb03e4bf283072397f9563dfc4162aec92a.camel@suse.de \
--to=nsaenzjulienne@suse.de \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--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=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