diff mbox

[v6,15/19] swiotlb-xen: call dma_capable only if dev->dma_mask is allocated

Message ID 1380298207-29151-15-git-send-email-stefano.stabellini@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stefano Stabellini Sept. 27, 2013, 4:10 p.m. UTC
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 drivers/xen/swiotlb-xen.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Comments

Konrad Rzeszutek Wilk Sept. 30, 2013, 4:02 p.m. UTC | #1
On Fri, Sep 27, 2013 at 05:10:03PM +0100, Stefano Stabellini wrote:

Why? I am looking at X86 and IA64 and I see:

 79         if (!dev->dma_mask)                                                     
 80                 return 0;           


Why not port dma_capable over to ARM?

> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> ---
>  drivers/xen/swiotlb-xen.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 790c2eb..3011736 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -512,7 +512,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
>  	 * buffering it.
>  	 */
>  	if (!xen_feature(XENFEAT_auto_translated_physmap) &&
> -	    dma_capable(dev, dev_addr, size) &&
> +	    dev->dma_mask && dma_capable(dev, dev_addr, size) &&
>  	    !range_straddles_page_boundary(phys, size) && !swiotlb_force)
>  		return dev_addr;
>  
> @@ -532,7 +532,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
>  	/*
>  	 * Ensure that the address returned is DMA'ble
>  	 */
> -	if (!dma_capable(dev, dev_addr, size)) {
> +	if (dev->dma_mask && !dma_capable(dev, dev_addr, size)) {
>  		swiotlb_tbl_unmap_single(dev, map, size, dir);
>  		dev_addr = 0;
>  	}
> @@ -660,7 +660,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
>  
>  		if (swiotlb_force ||
>  		    xen_feature(XENFEAT_auto_translated_physmap) ||
> -		    !dma_capable(hwdev, dev_addr, sg->length) ||
> +		    (hwdev->dma_mask && !dma_capable(hwdev, dev_addr, sg->length)) ||
>  		    range_straddles_page_boundary(paddr, sg->length)) {
>  			/*
>  			 * Pass the dma_addr of the first slab in the iotlb buffer as
> -- 
> 1.7.2.5
>
Stefano Stabellini Oct. 2, 2013, 5:13 p.m. UTC | #2
The real issue is that some devices (xgmac, I am looking at you), don't
set the dma_mask, even though they are perfectly capable of doing dma.

Maybe I should modify the arm implementation of dma_capable (see
http://marc.info/?l=linux-kernel&m=138029832007821&w=2) to ignore the
dma_mask.

On Mon, 30 Sep 2013, Konrad Rzeszutek Wilk wrote:
> On Fri, Sep 27, 2013 at 05:10:03PM +0100, Stefano Stabellini wrote:
> 
> Why? I am looking at X86 and IA64 and I see:
> 
>  79         if (!dev->dma_mask)                                                     
>  80                 return 0;           
> 
> 
> Why not port dma_capable over to ARM?
> 
> > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > ---
> >  drivers/xen/swiotlb-xen.c |    6 +++---
> >  1 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> > index 790c2eb..3011736 100644
> > --- a/drivers/xen/swiotlb-xen.c
> > +++ b/drivers/xen/swiotlb-xen.c
> > @@ -512,7 +512,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
> >  	 * buffering it.
> >  	 */
> >  	if (!xen_feature(XENFEAT_auto_translated_physmap) &&
> > -	    dma_capable(dev, dev_addr, size) &&
> > +	    dev->dma_mask && dma_capable(dev, dev_addr, size) &&
> >  	    !range_straddles_page_boundary(phys, size) && !swiotlb_force)
> >  		return dev_addr;
> >  
> > @@ -532,7 +532,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
> >  	/*
> >  	 * Ensure that the address returned is DMA'ble
> >  	 */
> > -	if (!dma_capable(dev, dev_addr, size)) {
> > +	if (dev->dma_mask && !dma_capable(dev, dev_addr, size)) {
> >  		swiotlb_tbl_unmap_single(dev, map, size, dir);
> >  		dev_addr = 0;
> >  	}
> > @@ -660,7 +660,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
> >  
> >  		if (swiotlb_force ||
> >  		    xen_feature(XENFEAT_auto_translated_physmap) ||
> > -		    !dma_capable(hwdev, dev_addr, sg->length) ||
> > +		    (hwdev->dma_mask && !dma_capable(hwdev, dev_addr, sg->length)) ||
> >  		    range_straddles_page_boundary(paddr, sg->length)) {
> >  			/*
> >  			 * Pass the dma_addr of the first slab in the iotlb buffer as
> > -- 
> > 1.7.2.5
> > 
>
Konrad Rzeszutek Wilk Oct. 2, 2013, 5:22 p.m. UTC | #3
On Wed, Oct 02, 2013 at 06:13:35PM +0100, Stefano Stabellini wrote:
> The real issue is that some devices (xgmac, I am looking at you), don't
> set the dma_mask, even though they are perfectly capable of doing dma.

So this looks like a bug in the drivers. I thought I saw a huge patchset
by the ARM maintainer that tries to fix the dma_mask and dma_mask_coherent
bugs? And also fix the drivers to use the dma mask?

> 
> Maybe I should modify the arm implementation of dma_capable (see
> http://marc.info/?l=linux-kernel&m=138029832007821&w=2) to ignore the
> dma_mask.

Or fix the 'xgmac'?
> 
> On Mon, 30 Sep 2013, Konrad Rzeszutek Wilk wrote:
> > On Fri, Sep 27, 2013 at 05:10:03PM +0100, Stefano Stabellini wrote:
> > 
> > Why? I am looking at X86 and IA64 and I see:
> > 
> >  79         if (!dev->dma_mask)                                                     
> >  80                 return 0;           
> > 
> > 
> > Why not port dma_capable over to ARM?
> > 
> > > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > > ---
> > >  drivers/xen/swiotlb-xen.c |    6 +++---
> > >  1 files changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> > > index 790c2eb..3011736 100644
> > > --- a/drivers/xen/swiotlb-xen.c
> > > +++ b/drivers/xen/swiotlb-xen.c
> > > @@ -512,7 +512,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
> > >  	 * buffering it.
> > >  	 */
> > >  	if (!xen_feature(XENFEAT_auto_translated_physmap) &&
> > > -	    dma_capable(dev, dev_addr, size) &&
> > > +	    dev->dma_mask && dma_capable(dev, dev_addr, size) &&
> > >  	    !range_straddles_page_boundary(phys, size) && !swiotlb_force)
> > >  		return dev_addr;
> > >  
> > > @@ -532,7 +532,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
> > >  	/*
> > >  	 * Ensure that the address returned is DMA'ble
> > >  	 */
> > > -	if (!dma_capable(dev, dev_addr, size)) {
> > > +	if (dev->dma_mask && !dma_capable(dev, dev_addr, size)) {
> > >  		swiotlb_tbl_unmap_single(dev, map, size, dir);
> > >  		dev_addr = 0;
> > >  	}
> > > @@ -660,7 +660,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
> > >  
> > >  		if (swiotlb_force ||
> > >  		    xen_feature(XENFEAT_auto_translated_physmap) ||
> > > -		    !dma_capable(hwdev, dev_addr, sg->length) ||
> > > +		    (hwdev->dma_mask && !dma_capable(hwdev, dev_addr, sg->length)) ||
> > >  		    range_straddles_page_boundary(paddr, sg->length)) {
> > >  			/*
> > >  			 * Pass the dma_addr of the first slab in the iotlb buffer as
> > > -- 
> > > 1.7.2.5
> > > 
> >
Rob Herring Oct. 3, 2013, 6:35 p.m. UTC | #4
On Wed, Oct 2, 2013 at 12:22 PM, Konrad Rzeszutek Wilk
<konrad.wilk@oracle.com> wrote:
> On Wed, Oct 02, 2013 at 06:13:35PM +0100, Stefano Stabellini wrote:
>> The real issue is that some devices (xgmac, I am looking at you), don't
>> set the dma_mask, even though they are perfectly capable of doing dma.
>
> So this looks like a bug in the drivers. I thought I saw a huge patchset
> by the ARM maintainer that tries to fix the dma_mask and dma_mask_coherent
> bugs? And also fix the drivers to use the dma mask?

I think Russell only fixed incorrect handling of masks, not missing handling.

>>
>> Maybe I should modify the arm implementation of dma_capable (see
>> http://marc.info/?l=linux-kernel&m=138029832007821&w=2) to ignore the
>> dma_mask.
>
> Or fix the 'xgmac'?

There's really some core changes needed to fix this and I'd guess
there are lots of other cases of missing dma_mask. The problem is
platform devices don't create a mask to assign to dma_mask in the
first place. I think the right solution is assigning dma_mask to
&coherent_dma_mask by default as Russell did for AMBA devices. I don't
know if doing that would break anything or not.

Rob

>>
>> On Mon, 30 Sep 2013, Konrad Rzeszutek Wilk wrote:
>> > On Fri, Sep 27, 2013 at 05:10:03PM +0100, Stefano Stabellini wrote:
>> >
>> > Why? I am looking at X86 and IA64 and I see:
>> >
>> >  79         if (!dev->dma_mask)
>> >  80                 return 0;
>> >
>> >
>> > Why not port dma_capable over to ARM?
>> >
>> > > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>> > > ---
>> > >  drivers/xen/swiotlb-xen.c |    6 +++---
>> > >  1 files changed, 3 insertions(+), 3 deletions(-)
>> > >
>> > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
>> > > index 790c2eb..3011736 100644
>> > > --- a/drivers/xen/swiotlb-xen.c
>> > > +++ b/drivers/xen/swiotlb-xen.c
>> > > @@ -512,7 +512,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
>> > >    * buffering it.
>> > >    */
>> > >   if (!xen_feature(XENFEAT_auto_translated_physmap) &&
>> > > -     dma_capable(dev, dev_addr, size) &&
>> > > +     dev->dma_mask && dma_capable(dev, dev_addr, size) &&
>> > >       !range_straddles_page_boundary(phys, size) && !swiotlb_force)
>> > >           return dev_addr;
>> > >
>> > > @@ -532,7 +532,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
>> > >   /*
>> > >    * Ensure that the address returned is DMA'ble
>> > >    */
>> > > - if (!dma_capable(dev, dev_addr, size)) {
>> > > + if (dev->dma_mask && !dma_capable(dev, dev_addr, size)) {
>> > >           swiotlb_tbl_unmap_single(dev, map, size, dir);
>> > >           dev_addr = 0;
>> > >   }
>> > > @@ -660,7 +660,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
>> > >
>> > >           if (swiotlb_force ||
>> > >               xen_feature(XENFEAT_auto_translated_physmap) ||
>> > > -             !dma_capable(hwdev, dev_addr, sg->length) ||
>> > > +             (hwdev->dma_mask && !dma_capable(hwdev, dev_addr, sg->length)) ||
>> > >               range_straddles_page_boundary(paddr, sg->length)) {
>> > >                   /*
>> > >                    * Pass the dma_addr of the first slab in the iotlb buffer as
>> > > --
>> > > 1.7.2.5
>> > >
>> >
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox

Patch

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 790c2eb..3011736 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -512,7 +512,7 @@  dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	 * buffering it.
 	 */
 	if (!xen_feature(XENFEAT_auto_translated_physmap) &&
-	    dma_capable(dev, dev_addr, size) &&
+	    dev->dma_mask && dma_capable(dev, dev_addr, size) &&
 	    !range_straddles_page_boundary(phys, size) && !swiotlb_force)
 		return dev_addr;
 
@@ -532,7 +532,7 @@  dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Ensure that the address returned is DMA'ble
 	 */
-	if (!dma_capable(dev, dev_addr, size)) {
+	if (dev->dma_mask && !dma_capable(dev, dev_addr, size)) {
 		swiotlb_tbl_unmap_single(dev, map, size, dir);
 		dev_addr = 0;
 	}
@@ -660,7 +660,7 @@  xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
 
 		if (swiotlb_force ||
 		    xen_feature(XENFEAT_auto_translated_physmap) ||
-		    !dma_capable(hwdev, dev_addr, sg->length) ||
+		    (hwdev->dma_mask && !dma_capable(hwdev, dev_addr, sg->length)) ||
 		    range_straddles_page_boundary(paddr, sg->length)) {
 			/*
 			 * Pass the dma_addr of the first slab in the iotlb buffer as