public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
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, kbusch@kernel.org,
	iommu@lists.linux-foundation.org, erdemaktas@google.com,
	m.szyprowski@samsung.com
Subject: Re: [PATCH 3/8] swiotlb: factor out a nr_slots helper
Date: Thu, 4 Feb 2021 22:09:02 +0000	[thread overview]
Message-ID: <ae995e9d-4476-cea2-a4d7-9e9cbab5aafd@arm.com> (raw)
In-Reply-To: <20210204193035.2606838-4-hch@lst.de>

On 2021-02-04 19:30, Christoph Hellwig wrote:
> Factor out a helper to find the number of slots for a given size.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   kernel/dma/swiotlb.c | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 838dbad10ab916..0c0b81799edbdb 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -194,6 +194,11 @@ static inline unsigned long io_tlb_offset(unsigned long val)
>   	return val & (IO_TLB_SEGSIZE - 1);
>   }
>   
> +static unsigned long nr_slots(u64 val)
> +{
> +	return ALIGN(val, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;

Would DIV_ROUND_UP(val, 1 << IOTLB_SHIFT) be even clearer?

Robin.

> +}
> +
>   /*
>    * Early SWIOTLB allocation may be too early to allow an architecture to
>    * perform the desired operations.  This function allows the architecture to
> @@ -493,20 +498,20 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
>   
>   	tbl_dma_addr &= mask;
>   
> -	offset_slots = ALIGN(tbl_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
> +	offset_slots = nr_slots(tbl_dma_addr);
>   
>   	/*
>   	 * Carefully handle integer overflow which can occur when mask == ~0UL.
>   	 */
>   	max_slots = mask + 1
> -		    ? ALIGN(mask + 1, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT
> +		    ? nr_slots(mask + 1)
>   		    : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
>   
>   	/*
>   	 * For mappings greater than or equal to a page, we limit the stride
>   	 * (and hence alignment) to a page size.
>   	 */
> -	nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
> +	nslots = nr_slots(alloc_size);
>   	if (alloc_size >= PAGE_SIZE)
>   		stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
>   	else
> @@ -602,7 +607,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
>   			      enum dma_data_direction dir, unsigned long attrs)
>   {
>   	unsigned long flags;
> -	int i, count, nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
> +	int i, count, nslots = nr_slots(alloc_size);
>   	int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
>   	phys_addr_t orig_addr = io_tlb_orig_addr[index];
>   
> 

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2021-02-04 22:09 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 [this message]
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
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=ae995e9d-4476-cea2-a4d7-9e9cbab5aafd@arm.com \
    --to=robin.murphy@arm.com \
    --cc=erdemaktas@google.com \
    --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=m.szyprowski@samsung.com \
    --cc=marcorr@google.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