All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Skakun <rm.skakun@gmail.com>
To: Christoph Hellwig <hch@lst.de>,
	Stefano Stabellini <sstabellini@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Juergen Gross <jgross@suse.com>,
	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>,
	Andrii Anisov <andrii_anisov@epam.com>,
	Roman Skakun <Roman_Skakun@epam.com>,
	Roman Skakun <rm.skakun@gmail.com>
Subject: Re: [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses
Date: Sat, 17 Jul 2021 11:39:21 +0300	[thread overview]
Message-ID: <CADu_u-Psn5QpOyZ18_NCPx14DYxmGmSqVod=_RBC3A_A93tGUw@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2107160828430.3916@sstabellini-ThinkPad-T480s>

> We can merge this patch and create a new one for
> xen_swiotlb_free_coherent() later.
> Yeah, no worries, I didn't know that exposing dma_common_vaddr_to_page
> was problematic.
>
> This patch is fine by me.

Good. I'm agreed too. Waiting for Christoph.

пт, 16 июл. 2021 г. в 18:29, Stefano Stabellini <sstabellini@kernel.org>:
>
> On Fri, 16 Jul 2021, Roman Skakun wrote:
> > > Technically this looks good.  But given that exposing a helper
> > > that does either vmalloc_to_page or virt_to_page is one of the
> > > never ending MM discussions I don't want to get into that discussion
> > > and just keep it local in the DMA code.
> > >
> > > Are you fine with me applying this version?
> >
> > Looks good to me, thanks!
> > But, Stefano asked me about using created helper in the
> > xen_swiotlb_free_coherent()
> > and I created a patch according to this mention.
> >
> > We can merge this patch and create a new one for
> > xen_swiotlb_free_coherent() later.
>
> Yeah, no worries, I didn't know that exposing dma_common_vaddr_to_page
> was problematic.
>
> This patch is fine by me.
>
>
> > пт, 16 июл. 2021 г. в 12:35, Christoph Hellwig <hch@lst.de>:
> > >
> > > Technically this looks good.  But given that exposing a helper
> > > that does either vmalloc_to_page or virt_to_page is one of the
> > > never ending MM discussions I don't want to get into that discussion
> > > and just keep it local in the DMA code.
> > >
> > > Are you fine with me applying this version?
> > >
> > > ---
> > > From 40ac971eab89330d6153e7721e88acd2d98833f9 Mon Sep 17 00:00:00 2001
> > > From: Roman Skakun <Roman_Skakun@epam.com>
> > > Date: Fri, 16 Jul 2021 11:39:34 +0300
> > > Subject: dma-mapping: handle vmalloc addresses in
> > >  dma_common_{mmap,get_sgtable}
> > >
> > > xen-swiotlb can use vmalloc backed addresses for dma coherent allocations
> > > and uses the common helpers.  Properly handle them to unbreak Xen on
> > > ARM platforms.
> > >
> > > Fixes: 1b65c4e5a9af ("swiotlb-xen: use xen_alloc/free_coherent_pages")
> > > Signed-off-by: Roman Skakun <roman_skakun@epam.com>
> > > Reviewed-by: Andrii Anisov <andrii_anisov@epam.com>
> > > [hch: split the patch, renamed the helpers]
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > > ---
> > >  kernel/dma/ops_helpers.c | 12 ++++++++++--
> > >  1 file changed, 10 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c
> > > index 910ae69cae77..af4a6ef48ce0 100644
> > > --- a/kernel/dma/ops_helpers.c
> > > +++ b/kernel/dma/ops_helpers.c
> > > @@ -5,6 +5,13 @@
> > >   */
> > >  #include <linux/dma-map-ops.h>
> > >
> > > +static struct page *dma_common_vaddr_to_page(void *cpu_addr)
> > > +{
> > > +       if (is_vmalloc_addr(cpu_addr))
> > > +               return vmalloc_to_page(cpu_addr);
> > > +       return virt_to_page(cpu_addr);
> > > +}
> > > +
> > >  /*
> > >   * Create scatter-list for the already allocated DMA buffer.
> > >   */
> > > @@ -12,7 +19,7 @@ int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
> > >                  void *cpu_addr, dma_addr_t dma_addr, size_t size,
> > >                  unsigned long attrs)
> > >  {
> > > -       struct page *page = virt_to_page(cpu_addr);
> > > +       struct page *page = dma_common_vaddr_to_page(cpu_addr);
> > >         int ret;
> > >
> > >         ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
> > > @@ -32,6 +39,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
> > >         unsigned long user_count = vma_pages(vma);
> > >         unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> > >         unsigned long off = vma->vm_pgoff;
> > > +       struct page *page = dma_common_vaddr_to_page(cpu_addr);
> > >         int ret = -ENXIO;
> > >
> > >         vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs);
> > > @@ -43,7 +51,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
> > >                 return -ENXIO;
> > >
> > >         return remap_pfn_range(vma, vma->vm_start,
> > > -                       page_to_pfn(virt_to_page(cpu_addr)) + vma->vm_pgoff,
> > > +                       page_to_pfn(page) + vma->vm_pgoff,
> > >                         user_count << PAGE_SHIFT, vma->vm_page_prot);
> > >  #else
> > >         return -ENXIO;
> > > --
> > > 2.30.2
> > >
> >
> >
> > --
> > Best Regards, Roman.
> >



-- 
Best Regards, Roman.

WARNING: multiple messages have this Message-ID (diff)
From: Roman Skakun <rm.skakun@gmail.com>
To: Christoph Hellwig <hch@lst.de>,
	Stefano Stabellini <sstabellini@kernel.org>
Cc: Juergen Gross <jgross@suse.com>,
	Andrii Anisov <andrii_anisov@epam.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>,
	linux-kernel@vger.kernel.org, Roman Skakun <rm.skakun@gmail.com>,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	iommu@lists.linux-foundation.org,
	Roman Skakun <Roman_Skakun@epam.com>,
	xen-devel@lists.xenproject.org,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Subject: Re: [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses
Date: Sat, 17 Jul 2021 11:39:21 +0300	[thread overview]
Message-ID: <CADu_u-Psn5QpOyZ18_NCPx14DYxmGmSqVod=_RBC3A_A93tGUw@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2107160828430.3916@sstabellini-ThinkPad-T480s>

> We can merge this patch and create a new one for
> xen_swiotlb_free_coherent() later.
> Yeah, no worries, I didn't know that exposing dma_common_vaddr_to_page
> was problematic.
>
> This patch is fine by me.

Good. I'm agreed too. Waiting for Christoph.

пт, 16 июл. 2021 г. в 18:29, Stefano Stabellini <sstabellini@kernel.org>:
>
> On Fri, 16 Jul 2021, Roman Skakun wrote:
> > > Technically this looks good.  But given that exposing a helper
> > > that does either vmalloc_to_page or virt_to_page is one of the
> > > never ending MM discussions I don't want to get into that discussion
> > > and just keep it local in the DMA code.
> > >
> > > Are you fine with me applying this version?
> >
> > Looks good to me, thanks!
> > But, Stefano asked me about using created helper in the
> > xen_swiotlb_free_coherent()
> > and I created a patch according to this mention.
> >
> > We can merge this patch and create a new one for
> > xen_swiotlb_free_coherent() later.
>
> Yeah, no worries, I didn't know that exposing dma_common_vaddr_to_page
> was problematic.
>
> This patch is fine by me.
>
>
> > пт, 16 июл. 2021 г. в 12:35, Christoph Hellwig <hch@lst.de>:
> > >
> > > Technically this looks good.  But given that exposing a helper
> > > that does either vmalloc_to_page or virt_to_page is one of the
> > > never ending MM discussions I don't want to get into that discussion
> > > and just keep it local in the DMA code.
> > >
> > > Are you fine with me applying this version?
> > >
> > > ---
> > > From 40ac971eab89330d6153e7721e88acd2d98833f9 Mon Sep 17 00:00:00 2001
> > > From: Roman Skakun <Roman_Skakun@epam.com>
> > > Date: Fri, 16 Jul 2021 11:39:34 +0300
> > > Subject: dma-mapping: handle vmalloc addresses in
> > >  dma_common_{mmap,get_sgtable}
> > >
> > > xen-swiotlb can use vmalloc backed addresses for dma coherent allocations
> > > and uses the common helpers.  Properly handle them to unbreak Xen on
> > > ARM platforms.
> > >
> > > Fixes: 1b65c4e5a9af ("swiotlb-xen: use xen_alloc/free_coherent_pages")
> > > Signed-off-by: Roman Skakun <roman_skakun@epam.com>
> > > Reviewed-by: Andrii Anisov <andrii_anisov@epam.com>
> > > [hch: split the patch, renamed the helpers]
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > > ---
> > >  kernel/dma/ops_helpers.c | 12 ++++++++++--
> > >  1 file changed, 10 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c
> > > index 910ae69cae77..af4a6ef48ce0 100644
> > > --- a/kernel/dma/ops_helpers.c
> > > +++ b/kernel/dma/ops_helpers.c
> > > @@ -5,6 +5,13 @@
> > >   */
> > >  #include <linux/dma-map-ops.h>
> > >
> > > +static struct page *dma_common_vaddr_to_page(void *cpu_addr)
> > > +{
> > > +       if (is_vmalloc_addr(cpu_addr))
> > > +               return vmalloc_to_page(cpu_addr);
> > > +       return virt_to_page(cpu_addr);
> > > +}
> > > +
> > >  /*
> > >   * Create scatter-list for the already allocated DMA buffer.
> > >   */
> > > @@ -12,7 +19,7 @@ int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
> > >                  void *cpu_addr, dma_addr_t dma_addr, size_t size,
> > >                  unsigned long attrs)
> > >  {
> > > -       struct page *page = virt_to_page(cpu_addr);
> > > +       struct page *page = dma_common_vaddr_to_page(cpu_addr);
> > >         int ret;
> > >
> > >         ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
> > > @@ -32,6 +39,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
> > >         unsigned long user_count = vma_pages(vma);
> > >         unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> > >         unsigned long off = vma->vm_pgoff;
> > > +       struct page *page = dma_common_vaddr_to_page(cpu_addr);
> > >         int ret = -ENXIO;
> > >
> > >         vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs);
> > > @@ -43,7 +51,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
> > >                 return -ENXIO;
> > >
> > >         return remap_pfn_range(vma, vma->vm_start,
> > > -                       page_to_pfn(virt_to_page(cpu_addr)) + vma->vm_pgoff,
> > > +                       page_to_pfn(page) + vma->vm_pgoff,
> > >                         user_count << PAGE_SHIFT, vma->vm_page_prot);
> > >  #else
> > >         return -ENXIO;
> > > --
> > > 2.30.2
> > >
> >
> >
> > --
> > Best Regards, Roman.
> >



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

  reply	other threads:[~2021-07-17  8:39 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  9:55 [PATCH] swiotlb-xen: override common mmap and get_sgtable dma ops 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
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 [this message]
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-Psn5QpOyZ18_NCPx14DYxmGmSqVod=_RBC3A_A93tGUw@mail.gmail.com' \
    --to=rm.skakun@gmail.com \
    --cc=Roman_Skakun@epam.com \
    --cc=andrii_anisov@epam.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=hch@lst.de \
    --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=sstabellini@kernel.org \
    --cc=volodymyr_babchuk@epam.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 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.