RE: [PATCH] swiotlb: manipulate orig_addr when tlb_addr has offset

From: Chanho Park
Date: Mon May 10 2021 - 05:04:26 EST


(RESEND due to wrong encrypted message setting)

Hi,

> On Mon, May 10, 2021 at 05:30:57PM +0900, Chanho Park wrote:
> > +static unsigned int swiotlb_align_offset(struct device *dev, u64
> > +addr);
>
> Please just move swiotlb_align_offset up to avoid the forward declaration.

Okay. I'll move the position of the function next patch.

>
> > /*
> > * Bounce: copy the swiotlb buffer from or back to the original dma
> location
> > */
> > @@ -346,10 +347,17 @@ static void swiotlb_bounce(struct device *dev,
> phys_addr_t tlb_addr, size_t size
> > size_t alloc_size = mem->slots[index].alloc_size;
> > unsigned long pfn = PFN_DOWN(orig_addr);
> > unsigned char *vaddr = phys_to_virt(tlb_addr);
> > + unsigned int tlb_offset;
> >
> > if (orig_addr == INVALID_PHYS_ADDR)
> > return;
> >
> > + tlb_offset = (unsigned int)tlb_addr & (IO_TLB_SIZE - 1);
> > + tlb_offset -= swiotlb_align_offset(dev, orig_addr);
>
> Nit: I'd write this as:
>
> tlb_offset = (tlb_addr & (IO_TLB_SIZE - 1)) -
> swiotlb_align_offset(dev, orig_addr);
>
> as there is no need for the cast, and just having a single assignment is
> easier to follow.

Great. It can be a single assignment as you suggested.

Best Regards,
Chanho Park