media: pwc: Fix the URB buffer allocation
Subsystems (2)
PATCH 1/1 media: pwc: Fix the URB buffer allocation
The URB buffer allocation of pwc driver involves with the dma_map_single(), and it needs to pass the right device. Currently it passes usb_device.dev, but it's no real device that manages the DMA. Since the passed device has no DMA mask set up, now the pwc driver hits the WARN_ON_ONCE() check in dma_map_page_attrs() (that was introduced in 5.10), resulting in an error at URB allocations. Eventually this ended up with the black output.
This patch fixes the bug by passing the proper device, the bus controller, to make the URB allocation and map working again.
--- drivers/media/usb/pwc/pwc-if.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/pwc/pwc-if.c +2 -2
@@ -461,7 +461,7 @@ static int pwc_isoc_init(struct pwc_device *pdev) urb->pipe =usb_rcvisocpipe (udev, pdev->vendpoint); urb->transfer_flags =URB_ISO_ASAP |URB_NO_TRANSFER_DMA_MAP ; urb->transfer_buffer_length =ISO_BUFFER_SIZE ; - urb->transfer_buffer =pwc_alloc_urb_buffer (&udev->dev, + urb->transfer_buffer =pwc_alloc_urb_buffer (udev->bus->controller, urb->transfer_buffer_length, &urb->transfer_dma);if (urb->transfer_buffer ==NULL ) {
@@ -524,7 +524,7 @@ static void pwc_iso_free(struct pwc_device *pdev)if (urb) {PWC_DEBUG_MEMORY ("Freeing URB\n" );if (urb->transfer_buffer) -pwc_free_urb_buffer (&urb->dev->dev, +pwc_free_urb_buffer (urb->dev->bus->controller, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma);
Signature · 1 line
2.26.2
Thanks for the patch, it all looks good to me.
Feel free to add my r-b:
Quoted 44 lines · Takashi Iwai
The URB buffer allocation of pwc driver involves with the
dma_map_single(), and it needs to pass the right device. Currently it passes usb_device.dev, but it's no real device that manages the DMA. Since the passed device has no DMA mask set up, now the pwc driver hits theWARN_ON_ONCE()check indma_map_page_attrs()(that was introduced in 5.10), resulting in an error at URB allocations. Eventually this ended up with the black output.This patch fixes the bug by passing the proper device, the bus controller, to make the URB allocation and map working again.
Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/media/usb/pwc/pwc-if.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/usb/pwc/pwc-if.c +2
-3@@ -461,7 +461,7 @@ static int pwc_isoc_init(struct pwc_device *pdev) urb->pipe =usb_rcvisocpipe (udev, pdev->vendpoint); urb->transfer_flags =URB_ISO_ASAP |URB_NO_TRANSFER_DMA_MAP ; urb->transfer_buffer_length =ISO_BUFFER_SIZE ; - urb->transfer_buffer =pwc_alloc_urb_buffer (&udev->dev, + urb->transfer_buffer =pwc_alloc_urb_buffer (udev->bus->controller, urb->transfer_buffer_length, &urb->transfer_dma);if (urb->transfer_buffer ==NULL ) {@@ -524,7 +524,7 @@ static void pwc_iso_free(struct pwc_device *pdev)if (urb) {PWC_DEBUG_MEMORY ("Freeing URB\n" );if (urb->transfer_buffer) -pwc_free_urb_buffer (&urb->dev->dev, +pwc_free_urb_buffer (urb->dev->bus->controller, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma); --2.26.2
Hi Takashi,
Thank you for this patch, but it clashes with another patch trying to do the same thing that has already been merged in our tree:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
I do prefer your patch over the one already merged since it is a bit simpler, but shouldn't the calls to dma_sync_single_for_cpu() and dma_sync_single_for_device() in pwc-if.c also use urb->dev->bus->controller?
Also, Matwey's patch uses urb->dev->bus->sysdev instead of urb->dev->bus->controller. How does 'sysdev' relate to 'controller'? I think 'controller' is the right device to use, but either seems to work when I test it with my pwc webcam.
Andrew, your patch:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
is effectively identical to Takashi's, so I'll mark your patch as Obsoleted. Just so you know :-)
Regards,
Hans
Quoted 41 lines · Takashi Iwai
The URB buffer allocation of pwc driver involves with the
dma_map_single(), and it needs to pass the right device. Currently it passes usb_device.dev, but it's no real device that manages the DMA. Since the passed device has no DMA mask set up, now the pwc driver hits theWARN_ON_ONCE()check indma_map_page_attrs()(that was introduced in 5.10), resulting in an error at URB allocations. Eventually this ended up with the black output.This patch fixes the bug by passing the proper device, the bus controller, to make the URB allocation and map working again.
Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/media/usb/pwc/pwc-if.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/usb/pwc/pwc-if.c +2
-2@@ -461,7 +461,7 @@ static int pwc_isoc_init(struct pwc_device *pdev) urb->pipe =usb_rcvisocpipe (udev, pdev->vendpoint); urb->transfer_flags =URB_ISO_ASAP |URB_NO_TRANSFER_DMA_MAP ; urb->transfer_buffer_length =ISO_BUFFER_SIZE ; - urb->transfer_buffer =pwc_alloc_urb_buffer (&udev->dev, + urb->transfer_buffer =pwc_alloc_urb_buffer (udev->bus->controller, urb->transfer_buffer_length, &urb->transfer_dma);if (urb->transfer_buffer ==NULL ) {@@ -524,7 +524,7 @@ static void pwc_iso_free(struct pwc_device *pdev)if (urb) {PWC_DEBUG_MEMORY ("Freeing URB\n" );if (urb->transfer_buffer) -pwc_free_urb_buffer (&urb->dev->dev, +pwc_free_urb_buffer (urb->dev->bus->controller, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma);
Quoted 7 lines · Hans Verkuil
Hi Takashi,
Thank you for this patch, but it clashes with another patch trying to do the same thing that has already been merged in our tree:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
Quoted 7 lines
I do prefer your patch over the one already merged since it is a bit simpler, but shouldn't the calls to
dma_sync_single_for_cpu()anddma_sync_single_for_device()inpwc-if.calso useurb->dev->bus->controller?Also, Matwey's patch uses
urb->dev->bus->sysdevinstead ofurb->dev->bus->controller. How does 'sysdev' relate to 'controller'? I think 'controller' is the right device to use, but either seems to work when I test it with my pwc webcam.
Hi Hans
A quick grep in driver/usb show that all but one dma mapping operation use sysdev. The one other case uses controller. So the numbers suggest controller is wrong, sysdev is correct.
But maybe ask GregKH?
Andrew
Quoted 17 lines · Andrew Lunn
Quoted 7 lines · Hans Verkuil
Hi Takashi,
Thank you for this patch, but it clashes with another patch trying to do the same thing that has already been merged in our tree:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
Quoted 7 lines
I do prefer your patch over the one already merged since it is a bit simpler, but shouldn't the calls to
dma_sync_single_for_cpu()anddma_sync_single_for_device()inpwc-if.calso useurb->dev->bus->controller?Also, Matwey's patch uses
urb->dev->bus->sysdevinstead ofurb->dev->bus->controller. How does 'sysdev' relate to 'controller'? I think 'controller' is the right device to use, but either seems to work when I test it with my pwc webcam.
Quoted 5 lines
Hi Hans
A quick grep in driver/usb show that all but one dma mapping operation use sysdev. The one other case uses controller. So the numbers suggest controller is wrong, sysdev is correct.
Indeed, looks so. In most cases, this doesn't matter since both point to the same device object. In some cases like xhci-plat HCD, they differ. And sysdev might be a better choice from the consistency POV.
But this brought an interesting question, too. eg. USB chipidea HCD uses platform devices for both controller and sysdev, and I couldn't find any DMA mask setup. So, no matter what to use, the uwc driver would be broken on this... Maybe it's just not covered.
Quoted 1 line
But maybe ask GregKH?
To be certain, better to involve with USB people, yeah.
thanks,
Takashi
Hi Takashi
Quoted 9 lines
Indeed, looks so. In most cases, this doesn't matter since both point to the same device object. In some cases like xhci-plat HCD, they differ. And sysdev might be a better choice from the consistency POV.
But this brought an interesting question, too. eg. USB chipidea HCD uses platform devices for both controller and sysdev, and I couldn't find any DMA mask setup. So, no matter what to use, the uwc driver would be broken on this... Maybe it's just not covered.
Did you do a git bisect to see what actually broke it? "1161db6776bd:
media: usb: pwc: Don't use coherent DMA buffers for ISO transfer" introduced the code, not the regression. If we understand the regression, that might give us the answer about chipidea.
Andrew
Quoted 13 lines · Andrew Lunn
Hi Takashi
Quoted 9 lines
Indeed, looks so. In most cases, this doesn't matter since both point to the same device object. In some cases like xhci-plat HCD, they differ. And sysdev might be a better choice from the consistency POV.
But this brought an interesting question, too. eg. USB chipidea HCD uses platform devices for both controller and sysdev, and I couldn't find any DMA mask setup. So, no matter what to use, the uwc driver would be broken on this... Maybe it's just not covered.
Quoted 4 lines
Did you do a git bisect to see what actually broke it? "
1161db6776bd:
media: usb: pwc: Don't use coherent DMA buffers for ISO transfer" introduced the code, not the regression. If we understand the regression, that might give us the answer about chipidea.
It's the recent DMA core change, the commit f959dcd6ddfd ("dma-direct:
Fix potential NULL pointer dereference"). But basically it's a right fix, and the driver hitting this "regression" has been already broken but casually worked without setting a proper DMA mask.
Takashi
Quoted 20 lines · Takashi Iwai
Quoted 13 lines · Andrew Lunn
Hi Takashi
Quoted 9 lines
Indeed, looks so. In most cases, this doesn't matter since both point to the same device object. In some cases like xhci-plat HCD, they differ. And sysdev might be a better choice from the consistency POV.
But this brought an interesting question, too. eg. USB chipidea HCD uses platform devices for both controller and sysdev, and I couldn't find any DMA mask setup. So, no matter what to use, the uwc driver would be broken on this... Maybe it's just not covered.
Quoted 4 lines
Did you do a git bisect to see what actually broke it? "
1161db6776bd:
media: usb: pwc: Don't use coherent DMA buffers for ISO transfer" introduced the code, not the regression. If we understand the regression, that might give us the answer about chipidea.
Quoted 4 lines
It's the recent DMA core change, the commit
f959dcd6ddfd("dma-direct:
Fix potential NULL pointer dereference"). But basically it's a right fix, and the driver hitting this "regression" has been already broken but casually worked without setting a proper DMA mask.
So for the chipidea, it also just 'casually worked'. But now it probably does not. But that is a separate chipidea issue. None of my ARM systems use the chipidea IP core, so i cannot test anything.
Andrew
Quoted 21 lines · Andrew Lunn
Quoted 20 lines · Takashi Iwai
Quoted 17 lines · Andrew Lunn
Hi Takashi
Quoted 9 lines
Indeed, looks so. In most cases, this doesn't matter since both point to the same device object. In some cases like xhci-plat HCD, they differ. And sysdev might be a better choice from the consistency POV.
But this brought an interesting question, too. eg. USB chipidea HCD uses platform devices for both controller and sysdev, and I couldn't find any DMA mask setup. So, no matter what to use, the uwc driver would be broken on this... Maybe it's just not covered.
Did you do a git bisect to see what actually broke it? "
1161db6776bd:
media: usb: pwc: Don't use coherent DMA buffers for ISO transfer" introduced the code, not the regression. If we understand the regression, that might give us the answer about chipidea.
Quoted 8 lines
Quoted 4 lines
It's the recent DMA core change, the commit
f959dcd6ddfd("dma-direct:
Fix potential NULL pointer dereference"). But basically it's a right fix, and the driver hitting this "regression" has been already broken but casually worked without setting a proper DMA mask.So for the chipidea, it also just 'casually worked'. But now it probably does not. But that is a separate chipidea issue. None of my ARM systems use the chipidea IP core, so i cannot test anything.
Since few people use the pwc driver anymore, and certainly not on non-intel devices, I am happy with Matwey's patch as is merged in our media tree for 5.12.
I'll mark Takashi's patch as Obsolete in patchwork as well.
I might have an SBC with a chipidea, if so, I'll give it a quick spin.
Regards,
Hans
Quoted 32 lines · Hans Verkuil
Quoted 21 lines · Andrew Lunn
Quoted 20 lines · Takashi Iwai
Quoted 17 lines · Andrew Lunn
Hi Takashi
Quoted 9 lines
Indeed, looks so. In most cases, this doesn't matter since both point to the same device object. In some cases like xhci-plat HCD, they differ. And sysdev might be a better choice from the consistency POV.
But this brought an interesting question, too. eg. USB chipidea HCD uses platform devices for both controller and sysdev, and I couldn't find any DMA mask setup. So, no matter what to use, the uwc driver would be broken on this... Maybe it's just not covered.
Did you do a git bisect to see what actually broke it? "
1161db6776bd:
media: usb: pwc: Don't use coherent DMA buffers for ISO transfer" introduced the code, not the regression. If we understand the regression, that might give us the answer about chipidea.Quoted 8 lines
Quoted 4 lines
It's the recent DMA core change, the commit
f959dcd6ddfd("dma-direct:
Fix potential NULL pointer dereference"). But basically it's a right fix, and the driver hitting this "regression" has been already broken but casually worked without setting a proper DMA mask.So for the chipidea, it also just 'casually worked'. But now it probably does not. But that is a separate chipidea issue. None of my ARM systems use the chipidea IP core, so i cannot test anything.
Quoted 7 lines
Since few people use the pwc driver anymore, and certainly not on non-intel devices, I am happy with Matwey's patch as is merged in our media tree for 5.12.
I'll mark Takashi's patch as Obsolete in patchwork as well.
I might have an SBC with a chipidea, if so, I'll give it a quick spin.
Fair enough.
Thanks!
Takashi