All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Skakun <rm.skakun@gmail.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>,
	Volodymyr Babchuk <volodymyr_babchuk@epam.com>,
	Roman Skakun <roman_skakun@epam.com>,
	Andrii Anisov <andrii_anisov@epam.com>
Subject: Re: [PATCH] swiotlb-xen: override common mmap and get_sgtable dma ops
Date: Mon, 14 Jun 2021 15:47:25 +0300	[thread overview]
Message-ID: <CADu_u-MqALJkG8RJHrr65vC_sHu-UyvCGwwUfaBong0eir5+hQ@mail.gmail.com> (raw)
In-Reply-To: <855a58e2-1e03-4763-cb56-81367b73762c@oracle.com>

Hey, Boris!
Thanks for the review.

I have an additional question about current implementation that disturbed me.
I think, that we can have cases when mapped memory can not be
physically contiguous.
In order to proceed this correctly need to apply some additional steps
to current implementation as well.

In mmap() :
1. Is the memory region physically contiguous?
2. Remap multiple ranges if it is not.

In get_sgtable() :
1. Is the memory region physically contiguous?
2. Create sgt that will be included multiple contiguous ranges if it is not.

What do you think about it?

Cheers!
Roman


пт, 11 июн. 2021 г. в 18:20, Boris Ostrovsky <boris.ostrovsky@oracle.com>:
>
>
> 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



-- 
Best Regards, Roman.

WARNING: multiple messages have this Message-ID
From: Roman Skakun <rm.skakun@gmail.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Andrii Anisov <andrii_anisov@epam.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>,
	linux-kernel@vger.kernel.org,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	iommu@lists.linux-foundation.org,
	Roman Skakun <roman_skakun@epam.com>,
	xen-devel@lists.xenproject.org,
	Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Subject: Re: [PATCH] swiotlb-xen: override common mmap and get_sgtable dma ops
Date: Mon, 14 Jun 2021 15:47:25 +0300	[thread overview]
Message-ID: <CADu_u-MqALJkG8RJHrr65vC_sHu-UyvCGwwUfaBong0eir5+hQ@mail.gmail.com> (raw)
In-Reply-To: <855a58e2-1e03-4763-cb56-81367b73762c@oracle.com>

Hey, Boris!
Thanks for the review.

I have an additional question about current implementation that disturbed me.
I think, that we can have cases when mapped memory can not be
physically contiguous.
In order to proceed this correctly need to apply some additional steps
to current implementation as well.

In mmap() :
1. Is the memory region physically contiguous?
2. Remap multiple ranges if it is not.

In get_sgtable() :
1. Is the memory region physically contiguous?
2. Create sgt that will be included multiple contiguous ranges if it is not.

What do you think about it?

Cheers!
Roman


пт, 11 июн. 2021 г. в 18:20, Boris Ostrovsky <boris.ostrovsky@oracle.com>:
>
>
> 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



-- 
Best Regards, Roman.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-06-14 12:47 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  9:55 Roman Skakun
2021-06-11  9:55 ` Roman Skakun
2021-06-11 15:19 ` Boris Ostrovsky
2021-06-11 15:19   ` Boris Ostrovsky
2021-06-14 12:47   ` Roman Skakun [this message]
2021-06-14 12:47     ` Roman Skakun
2021-06-14 12:47     ` Roman Skakun
2021-06-14 15:45     ` Boris Ostrovsky
2021-06-14 15:45       ` Boris Ostrovsky
2021-06-16 11:45       ` Roman Skakun
2021-06-16 11:45         ` Roman Skakun
2021-06-16 11:45         ` Roman Skakun
2021-06-16 11:42   ` [PATCH 1/2] Revert "swiotlb-xen: remove xen_swiotlb_dma_mmap and xen_swiotlb_dma_get_sgtable" Roman Skakun
2021-06-16 11:42     ` Roman Skakun
2021-06-16 11:42     ` [PATCH 2/2] swiotlb-xen: override common mmap and get_sgtable dma ops Roman Skakun
2021-06-16 11:42       ` Roman Skakun
2021-06-16 14:12       ` Boris Ostrovsky
2021-06-16 14:12         ` Boris Ostrovsky
2021-06-16 14:21         ` Christoph Hellwig
2021-06-16 14:21           ` Christoph Hellwig
2021-06-16 15:33           ` Boris Ostrovsky
2021-06-16 15:33             ` Boris Ostrovsky
2021-06-16 15:35             ` Christoph Hellwig
2021-06-16 15:35               ` Christoph Hellwig
2021-06-16 15:39               ` Boris Ostrovsky
2021-06-16 15:39                 ` Boris Ostrovsky
2021-06-16 15:44                 ` Christoph Hellwig
2021-06-16 15:44                   ` Christoph Hellwig
2021-06-22 13:34                   ` [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses Roman Skakun
2021-06-22 13:34                     ` Roman Skakun
2021-07-14  0:15                     ` Konrad Rzeszutek Wilk
2021-07-14  0:15                       ` Konrad Rzeszutek Wilk
2021-07-15  7:39                       ` Roman Skakun
2021-07-15  7:39                         ` Roman Skakun
2021-07-15  7:39                         ` Roman Skakun
2021-07-15 16:58                         ` Boris Ostrovsky
2021-07-15 16:58                           ` Boris Ostrovsky
2021-07-15 17:00                           ` Christoph Hellwig
2021-07-15 17:00                             ` Christoph Hellwig
2021-07-16  8:39                             ` Roman Skakun
2021-07-16  8:39                               ` Roman Skakun
2021-07-16  9:35                               ` Christoph Hellwig
2021-07-16  9:35                                 ` Christoph Hellwig
2021-07-16 12:53                                 ` Roman Skakun
2021-07-16 12:53                                   ` Roman Skakun
2021-07-16 12:53                                   ` Roman Skakun
2021-07-16 15:29                                   ` Stefano Stabellini
2021-07-16 15:29                                     ` Stefano Stabellini
2021-07-16 15:29                                     ` Stefano Stabellini
2021-07-17  8:39                                     ` Roman Skakun
2021-07-17  8:39                                       ` Roman Skakun
2021-07-17  8:39                                       ` Roman Skakun
2021-07-19  9:22                                       ` Christoph Hellwig
2021-07-19  9:22                                         ` Christoph Hellwig
2021-07-21 18:39                                         ` Roman Skakun
2021-07-21 18:39                                           ` Roman Skakun
2021-07-21 18:39                                           ` Roman Skakun
2021-07-14  1:23                     ` Stefano Stabellini
2021-07-14  1:23                       ` Stefano Stabellini
2021-07-14  1:23                       ` Stefano Stabellini
2021-07-15  7:31                       ` Roman Skakun
2021-07-15  7:31                         ` Roman Skakun
2021-07-15  7:31                         ` Roman Skakun

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=CADu_u-MqALJkG8RJHrr65vC_sHu-UyvCGwwUfaBong0eir5+hQ@mail.gmail.com \
    --to=rm.skakun@gmail.com \
    --cc=andrii_anisov@epam.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jgross@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleksandr_andrushchenko@epam.com \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=roman_skakun@epam.com \
    --cc=sstabellini@kernel.org \
    --cc=volodymyr_babchuk@epam.com \
    --cc=xen-devel@lists.xenproject.org \
    --subject='Re: [PATCH] swiotlb-xen: override common mmap and get_sgtable dma ops' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.