This is a note to let you know that I've just added the patch titled swiotlb: factor out a nr_slots helper to the 5.11-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: swiotlb-factor-out-a-nr_slots-helper.patch and it can be found in the queue-5.11 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Wed May 5 09:23:46 AM CEST 2021 From: Jianxiong Gao <jxgao@xxxxxxxxxx> Date: Thu, 29 Apr 2021 17:33:10 +0000 Subject: swiotlb: factor out a nr_slots helper To: stable@xxxxxxxxxxxxxxx, hch@xxxxxx, marcorr@xxxxxxxxxx, sashal@xxxxxxxxxx Cc: Jianxiong Gao <jxgao@xxxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Message-ID: <20210429173315.1252465-5-jxgao@xxxxxxxxxx> From: Jianxiong Gao <jxgao@xxxxxxxxxx> commit: c32a77fd18780a5192dfb6eec69f239faebf28fd Factor out a helper to find the number of slots for a given size. Signed-off-by: Christoph Hellwig <hch@xxxxxx> Acked-by: Jianxiong Gao <jxgao@xxxxxxxxxx> Tested-by: Jianxiong Gao <jxgao@xxxxxxxxxx> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Signed-off-by: Jianxiong Gao <jxgao@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/dma/swiotlb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -194,6 +194,11 @@ static inline unsigned long io_tlb_offse return val & (IO_TLB_SEGSIZE - 1); } +static inline unsigned long nr_slots(u64 val) +{ + return DIV_ROUND_UP(val, IO_TLB_SIZE); +} + /* * 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(struc tbl_dma_addr &= mask; - offset_slots = ALIGN(tbl_dma_addr, IO_TLB_SIZE) >> 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, IO_TLB_SIZE) >> 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, IO_TLB_SIZE) >> 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 dev enum dma_data_direction dir, unsigned long attrs) { unsigned long flags; - int i, count, nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> 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]; Patches currently in stable-queue which might be from jxgao@xxxxxxxxxx are queue-5.11/swiotlb-respect-min_align_mask.patch queue-5.11/swiotlb-factor-out-a-nr_slots-helper.patch queue-5.11/swiotlb-add-a-io_tlb_size-define.patch queue-5.11/swiotlb-clean-up-swiotlb_tbl_unmap_single.patch queue-5.11/swiotlb-factor-out-an-io_tlb_offset-helper.patch queue-5.11/swiotlb-don-t-modify-orig_addr-in-swiotlb_tbl_sync_single.patch queue-5.11/swiotlb-refactor-swiotlb_tbl_map_single.patch queue-5.11/driver-core-add-a-min_align_mask-field-to-struct-device_dma_parameters.patch queue-5.11/nvme-pci-set-min_align_mask.patch