[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] swiotlb-xen: override common mmap and get_sgtable dma ops


  • To: Roman Skakun <rm.skakun@xxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, iommu@xxxxxxxxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
  • From: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Date: Fri, 11 Jun 2021 11:19:58 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RHPeAxPjO/Hey6EKM0y2x1JoEIz/0e2OqSrgeCEPOdM=; b=GH1lrR550GGZ0LT5oQAltVOKO5ZOE0VW5+9wk2xeZeRcA1/HS7SMjszlfhPBmn+lPOxgvsEMPztcDDwLrUBZeyFU/J/7v4jy1G+wOwBuagf+aIZat9xoSHrwLnyKrrS4bKsUm5n/wu82rHpPipbqoJiZbJUw+qF2Jhf9s5sjXhDHGLzY95HoM6ornQu2tkxrjVupONO7rnasmuuzKp4sPEKQoFghqbGJistIBHbPUYfVh6ULlCxOqJar7pxr063mqBgIYlcVPd9EBmIdmT/5olKwEW06ddPPMnUaF1+ykUDbPIqMRIG+OWlhbFccwmghS/1d7V5pHGK+sksruMnKoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DJ+z2AQfj4TfEHH+L5Es6fW/jZq7jCKglCNxcW4NGoM75ez6/9jYJthlJlKjS7I+cLCF07Uh38+zJpEleXzrOZHfuqd+DqKD/T9C9PxfjAvcgm0xc4mqHT2fgNQQskoPiM5wHiOfueRG7XlS7gEByK1x79nWjSuLwUjpkMDsEFnh2UtlFaYyPs26/0a8EV9gmt9v6QDjMR2cJlIkOrPkdt3VfklO5qawi8y0fpbDEl25KT1DJHGD++w+Z9s6BjWNGLfrl/ZQn+hfDaXapsgtJBR7KkMSJRLMaXx+ivcgciMqVhEZAh1v4WQJtBZgObvxRkA0OQEyZk5fCnJD+OyX4Q==
  • Authentication-results: epam.com; dkim=none (message not signed) header.d=none;epam.com; dmarc=none action=none header.from=oracle.com;
  • Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Roman Skakun <roman_skakun@xxxxxxxx>, Andrii Anisov <andrii_anisov@xxxxxxxx>
  • Delivery-date: Fri, 11 Jun 2021 15:20:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 6/11/21 5:55 AM, Roman Skakun wrote:
>  
> +static int
> +xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
> +             void *cpu_addr, dma_addr_t dma_addr, size_t size,
> +             unsigned long attrs)
> +{
> +     unsigned long user_count = vma_pages(vma);
> +     unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> +     unsigned long off = vma->vm_pgoff;
> +     struct page *page;
> +
> +     if (is_vmalloc_addr(cpu_addr))
> +             page = vmalloc_to_page(cpu_addr);
> +     else
> +             page = virt_to_page(cpu_addr);
> +
> +     vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs);
> +
> +     if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret))
> +             return -ENXIO;
> +
> +     if (off >= count || user_count > count - off)
> +             return -ENXIO;
> +
> +     return remap_pfn_range(vma, vma->vm_start,
> +                     page_to_pfn(page) + vma->vm_pgoff,
> +                     user_count << PAGE_SHIFT, vma->vm_page_prot);
> +}


I suggest you create a helper for computing page value and then revert 
922659ea771b3fd728149262c5ea15608fab9719 and pass result of the helper instead 
of cpu_addr. Here and in xen_swiotlb_dma_get_sgtable().


And use this new helper in xen_swiotlb_free_coherent() too. I am curious though 
why this was not a problem when Stefano was looking at the problem that 
introduced this vmalloc check (i.e. 8b1e868f66076490189a36d984fcce286cdd6295). 
Stefano?


-boris



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.