DMA debug trace pointing to rtl8187
------------[ cut here ]------------ WARNING: at /usr/src/linux-2.6.22.9/lib/dma-debug.c:609 check_for_stack+0x6b/0x8b() Hardware name: P5W DH Deluxe
ehci_hcd 0000:00:1d.7: DMA-API: device driver maps memory fromstack [addr=ffff88007fa79968]
Modules linked in:
Pid: 297, comm: khubd Not tainted 2.6.30-rc4-git1 #32
Call Trace: [<ffffffff802331c2>] warn_slowpath+0xd3/0x107
[<ffffffff803e4740>] ? soft_cursor+0x1a0/0x1b4
[<ffffffff804f3c68>] ? ehci_qtd_alloc+0x18/0x5b
[<ffffffff80229e89>] ? update_curr+0x4f/0xe2
[<ffffffff8022a66b>] ? dequeue_task_fair+0x4a/0x1b3
[<ffffffff8022f304>] ? finish_task_switch+0x51/0xac
[<ffffffff8064e242>] ? thread_return+0x3e/0xaf
[<ffffffff803c598f>] check_for_stack+0x6b/0x8b [<ffffffff803c6c4d>] debug_dma_map_page+0xfa/0x11f [<ffffffff804e4396>] usb_hcd_submit_urb+0x296/0x938
[<ffffffff803b553c>] ? kobject_set_name_vargs+0x4f/0x58
[<ffffffff8044ffa2>] ? dev_set_name+0x64/0x66
[<ffffffff8064e242>] ? thread_return+0x3e/0xaf
[<ffffffff804e4f32>] usb_submit_urb+0x20b/0x222 [<ffffffff804e5f6f>] usb_start_wait_urb+0x4a/0xb7 [<ffffffff804e61d3>] usb_control_msg+0xcf/0xf1 [<ffffffff806419b0>] rtl8187_probe+0x1b5/0x7e8
[<ffffffff804bc668>] ? rtl8187_eeprom_register_read+0x0/0x82
[<ffffffff804bc478>] ? rtl8187_eeprom_register_write+0x0/0x95
[<ffffffff804e7815>] ? usb_autopm_do_device+0xd1/0xdd
[<ffffffff804e81a2>] usb_probe_interface+0x114/0x16d [<ffffffff80452e79>] driver_probe_device+0x9b/0x140
[<ffffffff80452f99>] ? __device_attach+0x0/0x3c
[<ffffffff80452fcc>] __device_attach+0x33/0x3c [<ffffffff804524ac>] bus_for_each_drv+0x51/0x87 [<ffffffff80453057>] device_attach+0x5e/0x73 [<ffffffff804522e1>] bus_attach_device+0x25/0x5b [<ffffffff8045104c>] device_add+0x47f/0x5d5 [<ffffffff804e6e5a>] usb_set_configuration+0x4f4/0x55b [<ffffffff804ee876>] generic_probe+0x56/0xa0 [<ffffffff804e70a7>] usb_probe_device+0x33/0x35 [<ffffffff80452e79>] driver_probe_device+0x9b/0x140
[<ffffffff80452f99>] ? __device_attach+0x0/0x3c
[<ffffffff80452fcc>] __device_attach+0x33/0x3c [<ffffffff804524ac>] bus_for_each_drv+0x51/0x87 [<ffffffff80453057>] device_attach+0x5e/0x73 [<ffffffff804522e1>] bus_attach_device+0x25/0x5b [<ffffffff8045104c>] device_add+0x47f/0x5d5 [<ffffffff804e1088>] usb_new_device+0x66/0xc6 [<ffffffff804e25e6>] hub_thread+0xb56/0x10e0
[<ffffffff80245e2e>] ? autoremove_wake_function+0x0/0x38
[<ffffffff804e1a90>] ? hub_thread+0x0/0x10e0
[<ffffffff804e1a90>] ? hub_thread+0x0/0x10e0
[<ffffffff80245a9a>] kthread+0x56/0x83 [<ffffffff8020beea>] child_rip+0xa/0x20
[<ffffffff80245a44>] ? kthread+0x0/0x83
[<ffffffff8020bee0>] ? child_rip+0x0/0x20
-- eric
CC'ed linux-usb,
The ehci_hcd driver uses buffers on the stack for DMA?
Quoted 3 lines · On Sun, 03 May 2009 17:36:24 +0200 Eric Valette <[email protected]> wrote:
------------[ cut here ]------------ WARNING: at /usr/src/linux-2.6.22.9/lib/dma-debug.c:609
Hmm, the kernel version is wired. lib/dma-debug.c was added in 2.6.30-rc.
Quoted 115 lines
check_for_stack+0x6b/0x8b() Hardware name: P5W DH Deluxe
ehci_hcd0000:00:1d.7: DMA-API: device driver maps memory fromstack [addr=ffff88007fa79968]Modules linked in:Pid: 297, comm: khubd Not tainted 2.6.30-rc4-git1 #32
Call Trace: [<ffffffff802331c2>] warn_slowpath+0xd3/0x107[<
ffffffff803e4740>] ?soft_cursor+0x1a0/0x1b4[<
ffffffff804f3c68>] ?ehci_qtd_alloc+0x18/0x5b[<
ffffffff80229e89>] ?update_curr+0x4f/0xe2[<
ffffffff8022a66b>] ?dequeue_task_fair+0x4a/0x1b3[<
ffffffff8022f304>] ?finish_task_switch+0x51/0xac[<
ffffffff8064e242>] ?thread_return+0x3e/0xaf[<ffffffff803c598f>] check_for_stack+0x6b/0x8b [<ffffffff803c6c4d>] debug_dma_map_page+0xfa/0x11f [<ffffffff804e4396>] usb_hcd_submit_urb+0x296/0x938[<
ffffffff803b553c>] ?kobject_set_name_vargs+0x4f/0x58[<
ffffffff8044ffa2>] ?dev_set_name+0x64/0x66[<
ffffffff8064e242>] ?thread_return+0x3e/0xaf[<ffffffff804e4f32>] usb_submit_urb+0x20b/0x222 [<ffffffff804e5f6f>] usb_start_wait_urb+0x4a/0xb7 [<ffffffff804e61d3>] usb_control_msg+0xcf/0xf1 [<ffffffff806419b0>] rtl8187_probe+0x1b5/0x7e8[<
ffffffff804bc668>] ?rtl8187_eeprom_register_read+0x0/0x82[<
ffffffff804bc478>] ?rtl8187_eeprom_register_write+0x0/0x95[<
ffffffff804e7815>] ?usb_autopm_do_device+0xd1/0xdd[<ffffffff804e81a2>] usb_probe_interface+0x114/0x16d [<ffffffff80452e79>] driver_probe_device+0x9b/0x140[<
ffffffff80452f99>] ?__device_attach+0x0/0x3c[<ffffffff80452fcc>] __device_attach+0x33/0x3c [<ffffffff804524ac>] bus_for_each_drv+0x51/0x87 [<ffffffff80453057>] device_attach+0x5e/0x73 [<ffffffff804522e1>] bus_attach_device+0x25/0x5b [<ffffffff8045104c>] device_add+0x47f/0x5d5 [<ffffffff804e6e5a>] usb_set_configuration+0x4f4/0x55b [<ffffffff804ee876>] generic_probe+0x56/0xa0 [<ffffffff804e70a7>] usb_probe_device+0x33/0x35 [<ffffffff80452e79>] driver_probe_device+0x9b/0x140[<
ffffffff80452f99>] ?__device_attach+0x0/0x3c[<ffffffff80452fcc>] __device_attach+0x33/0x3c [<ffffffff804524ac>] bus_for_each_drv+0x51/0x87 [<ffffffff80453057>] device_attach+0x5e/0x73 [<ffffffff804522e1>] bus_attach_device+0x25/0x5b [<ffffffff8045104c>] device_add+0x47f/0x5d5 [<ffffffff804e1088>] usb_new_device+0x66/0xc6 [<ffffffff804e25e6>] hub_thread+0xb56/0x10e0[<
ffffffff80245e2e>] ?autoremove_wake_function+0x0/0x38[<
ffffffff804e1a90>] ?hub_thread+0x0/0x10e0[<
ffffffff804e1a90>] ?hub_thread+0x0/0x10e0[<ffffffff80245a9a>] kthread+0x56/0x83 [<ffffffff8020beea>] child_rip+0xa/0x20[<
ffffffff80245a44>] ?kthread+0x0/0x83[<
ffffffff8020bee0>] ?child_rip+0x0/0x20-- eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 7 lines · FUJITA Tomonori
CC'ed linux-usb,
The
ehci_hcddriver uses buffers on the stack for DMA?On Sun, 03 May 2009 17:36:24 +0200
Eric Valette <[email protected]> wrote:
Quoted 6 lines
Quoted 3 lines
------------[ cut here ]------------ WARNING: at /usr/src/linux-2.6.22.9/lib/dma-debug.c:609Hmm, the kernel version is wired.
lib/dma-debug.cwas added in 2.6.30-rc.
No that's the file path. I use ketchup to apply patches...
Quoted 9 lines
Quoted 9 lines
check_for_stack+0x6b/0x8b() Hardware name: P5W DH Deluxe
ehci_hcd0000:00:1d.7: DMA-API: device driver maps memory fromstack [addr=ffff88007fa79968]Modules linked in:Pid: 297, comm: khubd Not tainted 2.6.30-rc4-git1 #32
Here is the real version.
-- eric
Quoted 21 lines · Eric Valette
Quoted 7 lines · FUJITA Tomonori
CC'ed linux-usb,
The
ehci_hcddriver uses buffers on the stack for DMA?On Sun, 03 May 2009 17:36:24 +0200
Eric Valette <[email protected]> wrote:Quoted 6 lines
Quoted 3 lines
------------[ cut here ]------------ WARNING: at /usr/src/linux-2.6.22.9/lib/dma-debug.c:609Hmm, the kernel version is wired.
lib/dma-debug.cwas added in 2.6.30-rc.No that's the file path. I use ketchup to apply patches...
Quoted 4 lines
Quoted 4 lines
check_for_stack+0x6b/0x8b() Hardware name: P5W DH Deluxe
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
ehci_hcd0000:00:1d.7: DMA-API: device driver maps memory fromstack [addr=ffff88007fa79968]Modules linked in:Pid: 297, comm: khubd Not tainted 2.6.30-rc4-git1 #32
Here is the real version.
The problem is in the rtl8187 driver.
They are calling usb_control_msg and passing a pointer to a buffer on the stack. See drivers/net/wireless/rtl818x/rtl8187.h for where the problem happens in numerous places.
Also it looks like rtl8225_write_8051() is incorrect. You are passing a pointer to a variable that was passed as an argument. I don't know where that is supposed to be on, somewhere on the stack I guess.
Larry, care to fix this up?
thanks,
greg k-h
[RFT] rtl8187: use DMA-aware buffers with usb_control_msg
This definitely needs to fail more gracefully in the event of a kmalloc failure...
--- drivers/net/wireless/rtl818x/rtl8187.h | 72 ++++++++++++++++++++---- drivers/net/wireless/rtl818x/rtl8187_rtl8225.c | 11 +++- 2 files changed, 71 insertions(+), 12 deletions(-)
drivers/net/wireless/rtl818x/rtl8187.h +61 -11
@@ -134,13 +134,21 @@ void rtl8187_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data);static inline u8 rtl818x_ioread8_idx (struct rtl8187_priv *priv,u8 *addr,u8 idx) { -u8 val; +u8 val, *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, + (unsigned long )addr, idx &0x03 , buf,sizeof (val),HZ /2 ); + val = *buf; +kfree (buf); +return val; }
@@ -152,13 +160,21 @@ static inline u8 rtl818x_ioread8(struct rtl8187_priv *priv, u8 *addr)static inline u16 rtl818x_ioread16_idx (struct rtl8187_priv *priv,__le16 *addr,u8 idx) { -__le16 val; +__le16 val, *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, + (unsigned long )addr, idx &0x03 , buf,sizeof (val),HZ /2 ); + val = *buf; +kfree (buf); +return le16_to_cpu (val); }
@@ -170,13 +186,21 @@ static inline u16 rtl818x_ioread16(struct rtl8187_priv *priv, __le16 *addr)static inline u32 rtl818x_ioread32_idx (struct rtl8187_priv *priv,__le32 *addr,u8 idx) { -__le32 val; +__le32 val, *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, + (unsigned long )addr, idx &0x03 , buf,sizeof (val),HZ /2 ); + val = *buf; +kfree (buf); +return le32_to_cpu (val); }
@@ -188,10 +212,20 @@ static inline u32 rtl818x_ioread32(struct rtl8187_priv *priv, __le32 *addr)static inline void rtl818x_iowrite8_idx (struct rtl8187_priv *priv,u8 *addr,u8 val,u8 idx) { +u8 *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ + *buf = val; +usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &val, + (unsigned long )addr, idx &0x03 , buf,sizeof (val),HZ /2 ); + +kfree (buf); }static inline void rtl818x_iowrite8 (struct rtl8187_priv *priv,u8 *addr,u8 val)
@@ -202,12 +236,20 @@ static inline void rtl818x_iowrite8(struct rtl8187_priv *priv, u8 *addr, u8 val)static inline void rtl818x_iowrite16_idx (struct rtl8187_priv *priv,__le16 *addr,u16 val,u8 idx) { -__le16 buf =cpu_to_le16 (val); +__le16 *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ + *buf =cpu_to_le16 (val);usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &buf,sizeof (buf), + (unsigned long )addr, idx &0x03 , buf,sizeof (*buf),HZ /2 ); + +kfree (buf); } static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,
@@ -219,12 +261,20 @@ static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,static inline void rtl818x_iowrite32_idx (struct rtl8187_priv *priv,__le32 *addr,u32 val,u8 idx) { -__le32 buf =cpu_to_le32 (val); +__le32 *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ + *buf =cpu_to_le32 (val);usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &buf,sizeof (buf), + (unsigned long )addr, idx &0x03 , buf,sizeof (*buf),HZ /2 ); + +kfree (buf); } static inline void rtl818x_iowrite32(struct rtl8187_priv *priv, __le32 *addr,
drivers/net/wireless/rtl818x/rtl8187_rtl8225.c +10 -1
@@ -70,6 +70,13 @@ static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data) {struct rtl8187_priv *priv = dev->priv;u16 reg80, reg82, reg84; +__le16 *buf; + +/* Use "DMA-aware" buffer. */ + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +BUG ();/* TODO -- handle this more gracefully */ + *buf = data; reg80 =rtl818x_ioread16 (priv, &priv->map->RFPinsOutput); reg82 =rtl818x_ioread16 (priv, &priv->map->RFPinsEnable);
@@ -90,13 +97,15 @@ static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data)usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - addr,0x8225 , &data,sizeof (data),HZ /2 ); + addr,0x8225 , buf,sizeof (*buf),HZ /2 );rtl818x_iowrite16 (priv, &priv->map->RFPinsOutput, reg80 | (1 <<2 ));udelay (10 );rtl818x_iowrite16 (priv, &priv->map->RFPinsOutput, reg80 | (1 <<2 ));rtl818x_iowrite16 (priv, &priv->map->RFPinsSelect, reg84); + +kfree (buf); }static void rtl8225_write (struct ieee80211_hw *dev,u8 addr,u16 data)
Signature · 1 line
1.6.0.6
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 4 lines · John W. Linville
This definitely needs to fail more gracefully in the event of a kmalloc failure...
Signed-off-by John W. Linville <[email protected]>
I am using this patch with compat-wireless with 2.6.29.2-134.fc11.x86_64 - presumably one needs to be using 2.6.30-rcX to see any problems?
We mostly inherited that code concerned (and its style) from the vendor driver.
Quoted 5 lines · Greg KH
Also it looks like
rtl8225_write_8051()is incorrect. You are passing a pointer to a variable that was passed as an argument. I don't know where that is supposed to be on, somewhere on the stack I guess.Larry, care to fix this up?
I think John's patch resolves this issue to the extent it can - rtl8225_write_8051() is called by rtl8225_write() which in turns gets its input mostly in the form of magic contants (except a few instances). So allocating a buffer and copying the magic contants in, just before calling usb_control_msg() seems an acceptable way forward?
Hin-Tak
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 5 lines · Hin-Tak Leung
Quoted 4 lines · John W. Linville
This definitely needs to fail more gracefully in the event of a kmalloc failure...
Signed-off-by John W. Linville <[email protected]>
OK guys. Thanks for your support and sorry for the delay: I add to struggle with drm git to compile with 2.6.30-rc4-git3 (due to various non yet integraed things my automated rebuild procedure does git fetch for drm, xf86-video-nouveau, ...) , leading to no X server which for me is more annoying than a trace in a USB wireless driver that I seldom use only to test some new wireless feature (two GE port onboard).
The patch fix the DMA warning and the driver seems to work (just associated it) but I must say that the allocation failure handling path and the fact that we use now kmalloc for allocating a few bytes in such a routine makes me worry about possible negative performance impact unless theses routines are used only in a slow configuration path (did no took time to red the code due to many other problems).
BTW if someone know who I should send this attached patch for DRM git, I would gladly forward it.
-- eric
linux-core/drm_os_linux.h +0 -5
@@ -32,11 +32,6 @@/** IRQ handler arguments and return type and values */ #define DRM_IRQ_ARGS int irq, void *arg/** backwards compatibility with old irq return values */ -#ifndef IRQ_HANDLED -typedef void irqreturn_t ; -#define IRQ_HANDLED /* nothing */ -#define IRQ_NONE /* nothing */ -#endif /** AGP types */ #if __OS_HAS_AGP
linux-core/drm_sysfs.c +4 -4
@@ -162,14 +162,14 @@ int drm_sysfs_device_add(struct drm_minor *minor)int err;int i, j;char *minor_str; - + minor->kdev.parent = &minor->dev->pdev->dev; minor->kdev.class = drm_class; minor->kdev.release = drm_sysfs_device_release; minor->kdev.devt = minor->device; - minor_str ="card%d" ; - -snprintf (minor->kdev.bus_id,BUS_ID_SIZE , minor_str, minor->index); + minor_str ="card%d" ; + +dev_set_name (&minor->kdev, minor_str, minor->index); err =device_register (&minor->kdev);if (err) {
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 6 lines · Eric Valette
The patch fix the DMA warning and the driver seems to work (just associated it) but I must say that the allocation failure handling path and the fact that we use now kmalloc for allocating a few bytes in such a routine makes me worry about possible negative performance impact unless theses routines are used only in a slow configuration path (did no took time to red the code due to many other problems).
usb_control messages are slow and should not be on the "fast path" of any data being sent through the device. Any overhead of the kmalloc/kfree is totally eaten up by the actual transmission turn around time of the message itself, so you don't have to worry about the performance impact.
thanks for testing.
Quoted 2 lines
BTW if someone know who I should send this attached patch for DRM git, I would gladly forward it.
To the drm maintainer?
thanks,
greg k-h
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 8 lines · Greg KH
Quoted 6 lines · Eric Valette
The patch fix the DMA warning and the driver seems to work (just associated it) but I must say that the allocation failure handling path and the fact that we use now kmalloc for allocating a few bytes in such a routine makes me worry about possible negative performance impact unless theses routines are used only in a slow configuration path (did no took time to red the code due to many other problems).
Quoted 5 lines
usb_controlmessages are slow and should not be on the "fast path" of any data being sent through the device. Any overhead of the kmalloc/kfree is totally eaten up by the actual transmission turn around time of the message itself, so you don't have to worry about the performance impact.
Yeah, I don't like the original version either. Even if the kmalloc's aren't a big performance hit, the failure path sucks. I've included a new version below, but unfortunately I haven't had a chance to test it. Please give it a try if you get a chance?
Quoted 1 line
thanks for testing.
Ditto!
---
Quoted 1 line
From
73f58f111f3ec5009c603bb4abf86e5ef4c5503fMon Sep 17 00:00:00 2001
From: John W. Linville <[email protected]>
Date: Wed, 6 May 2009 13:57:27 -0400
Subject: [PATCH] rtl8187: use DMA-aware buffers with usb_control_msg
--- drivers/net/wireless/rtl818x/rtl8187.h | 57 ++++++++++++++++++------ drivers/net/wireless/rtl818x/rtl8187_dev.c | 8 +++ drivers/net/wireless/rtl818x/rtl8187_rtl8225.c | 8 +++- 3 files changed, 58 insertions(+), 15 deletions(-)
drivers/net/wireless/rtl818x/rtl8187.h +43 -14
@@ -127,6 +127,12 @@ struct rtl8187_priv {__le64 buf;struct sk_buff_head queue; } b_tx_status;/* This queue is used by both -b and non-b devices */ +struct mutex io_mutex; +union { +u8 bits8; +__le16 bits16; +__le32 bits32; + } *io_dmabuf; };void rtl8187_write_phy (struct ieee80211_hw *dev,u8 addr,u32 data);
@@ -136,10 +142,14 @@ static inline u8 rtl818x_ioread8_idx(struct rtl8187_priv *priv, {u8 val; +mutex_lock (&priv->io_mutex);usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits8,sizeof (val),HZ /2 ); + + val = priv->io_dmabuf->bits8; +mutex_unlock (&priv->io_mutex);return val; }
@@ -154,10 +164,14 @@ static inline u16 rtl818x_ioread16_idx(struct rtl8187_priv *priv, {__le16 val; +mutex_lock (&priv->io_mutex);usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits16,sizeof (val),HZ /2 ); + + val = priv->io_dmabuf->bits16; +mutex_unlock (&priv->io_mutex);return le16_to_cpu (val); }
@@ -172,10 +186,14 @@ static inline u32 rtl818x_ioread32_idx(struct rtl8187_priv *priv, {__le32 val; +mutex_lock (&priv->io_mutex);usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits32,sizeof (val),HZ /2 ); + + val = priv->io_dmabuf->bits32; +mutex_unlock (&priv->io_mutex);return le32_to_cpu (val); }
@@ -188,10 +206,15 @@ static inline u32 rtl818x_ioread32(struct rtl8187_priv *priv, __le32 *addr)static inline void rtl818x_iowrite8_idx (struct rtl8187_priv *priv,u8 *addr,u8 val,u8 idx) { +mutex_lock (&priv->io_mutex); + + priv->io_dmabuf->bits8 = val;usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits8,sizeof (val),HZ /2 ); + +mutex_unlock (&priv->io_mutex); }static inline void rtl818x_iowrite8 (struct rtl8187_priv *priv,u8 *addr,u8 val)
@@ -202,12 +225,15 @@ static inline void rtl818x_iowrite8(struct rtl8187_priv *priv, u8 *addr, u8 val)static inline void rtl818x_iowrite16_idx (struct rtl8187_priv *priv,__le16 *addr,u16 val,u8 idx) { -__le16 buf =cpu_to_le16 (val); +mutex_lock (&priv->io_mutex); + priv->io_dmabuf->bits16 =cpu_to_le16 (val);usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &buf,sizeof (buf), -HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits16,sizeof (val),HZ /2 ); + +mutex_unlock (&priv->io_mutex); } static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,
@@ -219,12 +245,15 @@ static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,static inline void rtl818x_iowrite32_idx (struct rtl8187_priv *priv,__le32 *addr,u32 val,u8 idx) { -__le32 buf =cpu_to_le32 (val); +mutex_lock (&priv->io_mutex); + priv->io_dmabuf->bits32 =cpu_to_le32 (val);usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &buf,sizeof (buf), -HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits32,sizeof (val),HZ /2 ); + +mutex_unlock (&priv->io_mutex); } static inline void rtl818x_iowrite32(struct rtl8187_priv *priv, __le32 *addr,
drivers/net/wireless/rtl818x/rtl8187_dev.c +8 -0
@@ -1326,6 +1326,14 @@ static int __devinit rtl8187_probe(struct usb_interface *intf, priv = dev->priv; priv->is_rtl8187b = (id->driver_info ==DEVICE_RTL8187B ); +/* allocate "DMA aware" buffer for register accesses */ + priv->io_dmabuf =kmalloc (sizeof (*priv->io_dmabuf),GFP_KERNEL ); +if (!priv->io_dmabuf) { + err = -ENOMEM ; + goto err_free_dev; + } +mutex_init (&priv->io_mutex); +SET_IEEE80211_DEV (dev, &intf->dev);usb_set_intfdata (intf, dev); priv->udev = udev;
drivers/net/wireless/rtl818x/rtl8187_rtl8225.c +7 -1
@@ -88,9 +88,15 @@ static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data)rtl818x_iowrite16 (priv, &priv->map->RFPinsOutput, reg80);udelay (10 ); +mutex_lock (&priv->io_mutex); + + priv->io_dmabuf->bits16 = data;usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - addr,0x8225 , &data,sizeof (data),HZ /2 ); + addr,0x8225 , &priv->io_dmabuf->bits16,sizeof (data), +HZ /2 ); + +mutex_unlock (&priv->io_mutex);rtl818x_iowrite16 (priv, &priv->map->RFPinsOutput, reg80 | (1 <<2 ));udelay (10 );
Signature · 5 lines
1.6.0.6 -- John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 10 lines · John W. Linville
Quoted 5 lines
usb_controlmessages are slow and should not be on the "fast path" of any data being sent through the device. Any overhead of the kmalloc/kfree is totally eaten up by the actual transmission turn around time of the message itself, so you don't have to worry about the performance impact.Yeah, I don't like the original version either. Even if the kmalloc's aren't a big performance hit, the failure path sucks. I've included a new version below, but unfortunately I haven't had a chance to test it. Please give it a try if you get a chance?
Looks good to me, a bit cleaner even.
thanks,
greg k-h
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
In reply to John W. LinvilleQuoted 5 lines · John W. Linville
Yeah, I don't like the original version either. Even if the kmalloc's aren't a big performance hit, the failure path sucks. I've included a new version below, but unfortunately I haven't had a chance to test it. Please give it a try if you get a chance?
This one tests just fine here running on the latest pull of wireless testing (v2.6.30-rc4-22732-gd879ac6). I think there is a leak of priv->io_dmabuf when the driver is unloaded, and kfree(priv->io_dmabuf) should be added to rtl8187_disconnect(). Otherwise ACK.
Larry
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 11 lines · Larry Finger
Quoted 5 lines · John W. Linville
Yeah, I don't like the original version either. Even if the kmalloc's aren't a big performance hit, the failure path sucks. I've included a new version below, but unfortunately I haven't had a chance to test it. Please give it a try if you get a chance?
This one tests just fine here running on the latest pull of wireless testing (v2.6.30-rc4-22732-gd879ac6). I think there is a leak of
priv->io_dmabufwhen the driver is unloaded, andkfree(priv->io_dmabuf)should be added tortl8187_disconnect(). Otherwise ACK.
Doh!
---
Quoted 1 line
From
dbc8e19329b52c53832cbb03eea76646e44aab07Mon Sep 17 00:00:00 2001
From: John W. Linville <[email protected]>
Date: Wed, 6 May 2009 13:57:27 -0400
Subject: [PATCH] rtl8187: use DMA-aware buffers with usb_control_msg
--- drivers/net/wireless/rtl818x/rtl8187.h | 57 ++++++++++++++++++------ drivers/net/wireless/rtl818x/rtl8187_dev.c | 13 +++++- drivers/net/wireless/rtl818x/rtl8187_rtl8225.c | 8 +++- 3 files changed, 62 insertions(+), 16 deletions(-)
drivers/net/wireless/rtl818x/rtl8187.h +43 -14
@@ -127,6 +127,12 @@ struct rtl8187_priv {__le64 buf;struct sk_buff_head queue; } b_tx_status;/* This queue is used by both -b and non-b devices */ +struct mutex io_mutex; +union { +u8 bits8; +__le16 bits16; +__le32 bits32; + } *io_dmabuf; };void rtl8187_write_phy (struct ieee80211_hw *dev,u8 addr,u32 data);
@@ -136,10 +142,14 @@ static inline u8 rtl818x_ioread8_idx(struct rtl8187_priv *priv, {u8 val; +mutex_lock (&priv->io_mutex);usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits8,sizeof (val),HZ /2 ); + + val = priv->io_dmabuf->bits8; +mutex_unlock (&priv->io_mutex);return val; }
@@ -154,10 +164,14 @@ static inline u16 rtl818x_ioread16_idx(struct rtl8187_priv *priv, {__le16 val; +mutex_lock (&priv->io_mutex);usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits16,sizeof (val),HZ /2 ); + + val = priv->io_dmabuf->bits16; +mutex_unlock (&priv->io_mutex);return le16_to_cpu (val); }
@@ -172,10 +186,14 @@ static inline u32 rtl818x_ioread32_idx(struct rtl8187_priv *priv, {__le32 val; +mutex_lock (&priv->io_mutex);usb_control_msg (priv->udev,usb_rcvctrlpipe (priv->udev,0 ),RTL8187_REQ_GET_REG ,RTL8187_REQT_READ , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits32,sizeof (val),HZ /2 ); + + val = priv->io_dmabuf->bits32; +mutex_unlock (&priv->io_mutex);return le32_to_cpu (val); }
@@ -188,10 +206,15 @@ static inline u32 rtl818x_ioread32(struct rtl8187_priv *priv, __le32 *addr)static inline void rtl818x_iowrite8_idx (struct rtl8187_priv *priv,u8 *addr,u8 val,u8 idx) { +mutex_lock (&priv->io_mutex); + + priv->io_dmabuf->bits8 = val;usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &val, -sizeof (val),HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits8,sizeof (val),HZ /2 ); + +mutex_unlock (&priv->io_mutex); }static inline void rtl818x_iowrite8 (struct rtl8187_priv *priv,u8 *addr,u8 val)
@@ -202,12 +225,15 @@ static inline void rtl818x_iowrite8(struct rtl8187_priv *priv, u8 *addr, u8 val)static inline void rtl818x_iowrite16_idx (struct rtl8187_priv *priv,__le16 *addr,u16 val,u8 idx) { -__le16 buf =cpu_to_le16 (val); +mutex_lock (&priv->io_mutex); + priv->io_dmabuf->bits16 =cpu_to_le16 (val);usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &buf,sizeof (buf), -HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits16,sizeof (val),HZ /2 ); + +mutex_unlock (&priv->io_mutex); } static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,
@@ -219,12 +245,15 @@ static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,static inline void rtl818x_iowrite32_idx (struct rtl8187_priv *priv,__le32 *addr,u32 val,u8 idx) { -__le32 buf =cpu_to_le32 (val); +mutex_lock (&priv->io_mutex); + priv->io_dmabuf->bits32 =cpu_to_le32 (val);usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - (unsigned long )addr, idx &0x03 , &buf,sizeof (buf), -HZ /2 ); + (unsigned long )addr, idx &0x03 , + &priv->io_dmabuf->bits32,sizeof (val),HZ /2 ); + +mutex_unlock (&priv->io_mutex); } static inline void rtl818x_iowrite32(struct rtl8187_priv *priv, __le32 *addr,
drivers/net/wireless/rtl818x/rtl8187_dev.c +12 -1
@@ -1326,6 +1326,14 @@ static int __devinit rtl8187_probe(struct usb_interface *intf, priv = dev->priv; priv->is_rtl8187b = (id->driver_info ==DEVICE_RTL8187B ); +/* allocate "DMA aware" buffer for register accesses */ + priv->io_dmabuf =kmalloc (sizeof (*priv->io_dmabuf),GFP_KERNEL ); +if (!priv->io_dmabuf) { + err = -ENOMEM ; + goto err_free_dev; + } +mutex_init (&priv->io_mutex); +SET_IEEE80211_DEV (dev, &intf->dev);usb_set_intfdata (intf, dev); priv->udev = udev;
@@ -1489,7 +1497,7 @@ static int __devinit rtl8187_probe(struct usb_interface *intf, err =ieee80211_register_hw (dev);if (err) {printk (KERN_ERR "rtl8187: Cannot register device\n" ); - goto err_free_dev; + goto err_free_dmabuf; }mutex_init (&priv->conf_mutex);skb_queue_head_init (&priv->b_tx_status.queue);
@@ -1506,6 +1514,8 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,return 0 ; + err_free_dmabuf: +kfree (priv->io_dmabuf); err_free_dev:ieee80211_free_hw (dev);usb_set_intfdata (intf,NULL );
@@ -1529,6 +1539,7 @@ static void __devexit rtl8187_disconnect(struct usb_interface *intf) priv = dev->priv;usb_reset_device (priv->udev);usb_put_dev (interface_to_usbdev (intf)); +kfree (priv->io_dmabuf);ieee80211_free_hw (dev); }
drivers/net/wireless/rtl818x/rtl8187_rtl8225.c +7 -1
@@ -88,9 +88,15 @@ static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data)rtl818x_iowrite16 (priv, &priv->map->RFPinsOutput, reg80);udelay (10 ); +mutex_lock (&priv->io_mutex); + + priv->io_dmabuf->bits16 = data;usb_control_msg (priv->udev,usb_sndctrlpipe (priv->udev,0 ),RTL8187_REQ_SET_REG ,RTL8187_REQT_WRITE , - addr,0x8225 , &data,sizeof (data),HZ /2 ); + addr,0x8225 , &priv->io_dmabuf->bits16,sizeof (data), +HZ /2 ); + +mutex_unlock (&priv->io_mutex);rtl818x_iowrite16 (priv, &priv->map->RFPinsOutput, reg80 | (1 <<2 ));udelay (10 );
Signature · 5 lines
1.6.0.6 -- John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
Re: [RFT] rtl8187: use DMA-aware buffers with usb_control_msg
Quoted 4 lines · John W. Linville
Quoted 3 lines · Larry Finger
Quoted 2 lines · John W. Linville
Yeah, I don't like the original version either. =A0Even if the kma=
lloc's
Quoted 1 line
Quoted 1 line
Quoted 1 line
aren't a big performance hit, the failure path sucks. =A0I've incl=
uded a
Quoted 1 line
Quoted 1 line
Quoted 1 line
new version below, but unfortunately I haven't had a chance to tes=
t it.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Please give it a try if you get a chance?
This one tests just fine here running on the latest pull of wireless=
testing
Quoted 1 line
Quoted 1 line
(v2.6.30-rc4-22732-gd879ac6). I think there is a leak of priv->io_dm=
abuf when
Quoted 1 line
Quoted 1 line
the driver is unloaded, and
kfree(priv->io_dmabuf)should be added t=
o
Quoted 7 lines
Quoted 1 line
rtl8187_disconnect(). Otherwise ACK.Doh!
---
From
dbc8e19329b52c53832cbb03eea76646e44aab07Mon Sep 17 00:00:00 200=
1
Quoted 5 lines
From: John W. Linville <[email protected]>
Date: Wed, 6 May 2009 13:57:27 -0400
Subject: [PATCH] rtl8187: use DMA-aware buffers withusb_control_msgSigned-off-by John W. Linville <[email protected]>
This looks so much cleaner. ACK - I see you already checked this in to wireless-testing. Tried to give it a go just now, but got bitten by the wext key management change, I think.
Hin-Tak
--
To unsubscribe from this list: send the line "unsubscribe linux-wireles= s" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 36 lines · Greg KH
Quoted 21 lines · Eric Valette
Quoted 7 lines · FUJITA Tomonori
CC'ed linux-usb,
The
ehci_hcddriver uses buffers on the stack for DMA?On Sun, 03 May 2009 17:36:24 +0200
Eric Valette <[email protected]> wrote:Quoted 6 lines
Quoted 3 lines
------------[ cut here ]------------ WARNING: at /usr/src/linux-2.6.22.9/lib/dma-debug.c:609Hmm, the kernel version is wired.
lib/dma-debug.cwas added in 2.6.30-rc.No that's the file path. I use ketchup to apply patches...
Quoted 4 lines
Quoted 4 lines
check_for_stack+0x6b/0x8b() Hardware name: P5W DH DeluxeQuoted 7 lines
Quoted 5 lines
Quoted 5 lines
ehci_hcd0000:00:1d.7: DMA-API: device driver maps memory fromstack [addr=ffff88007fa79968]Modules linked in:Pid: 297, comm: khubd Not tainted 2.6.30-rc4-git1 #32
Here is the real version.
The problem is in the rtl8187 driver.
They are calling
usb_control_msgand passing a pointer to a buffer on the stack. Seedrivers/net/wireless/rtl818x/rtl8187.hfor where the problem happens in numerous places.
Quoted 5 lines
Also it looks like
rtl8225_write_8051()is incorrect. You are passing a pointer to a variable that was passed as an argument. I don't know where that is supposed to be on, somewhere on the stack I guess.Larry, care to fix this up?
I just sent '[RFT] rtl8187: use DMA-aware buffers with usb_control_msg' as a parallel reply to this message. It is pretty ugly w.r.t. kmalloc failures, but it might be worth testing just to see if it helps the problem at hand...?
John
Signature · 2 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
Quoted 7 lines · Greg KH
The problem is in the rtl8187 driver.
They are calling
usb_control_msgand passing a pointer to a buffer on the stack. Seedrivers/net/wireless/rtl818x/rtl8187.hfor where the problem happens in numerous places.
Quoted 5 lines
Also it looks like
rtl8225_write_8051()is incorrect. You are passing a pointer to a variable that was passed as an argument. I don't know where that is supposed to be on, somewhere on the stack I guess.Larry, care to fix this up?
Yes, I'll try to fix it. I'm currently traveling and have intermittent Internet access.
I think there is a second problem that John's fix does not treat. Although the buffer is removed from the stack, there is no assurance that the buffer obtained with kmalloc() is reachable by DMA. This case will be triggered if the USB adapter does 32-bit DMA and the system has more than 4 GB RAM.
Please let me know if my analysis is wrong. If so, then John's patch will be fine, although the error handling should be improved. The severity should be that of a warning rather than a bug. If I'm correct, my fix would be to allocate a DMA-reachable buffer in the initialization and keep a pointer to it in the private area.
I just saw John's version 2 that looks more like what I was thinking about. I will be testing soon.
Thanks,
Larry
Quoted 2 lines · Larry Finger
I just saw John's version 2 that looks more like what I was thinking about. I will be testing soon.
Should find time to compile, test and browse the WEB a little using WiFi at 9PM (France = UTC +2 right now).
I'll report ASAP.
--eric
Quoted 7 lines · Eric Valette
Quoted 2 lines · Larry Finger
I just saw John's version 2 that looks more like what I was thinking about. I will be testing soon.
Should find time to compile, test and browse the WEB a little using WiFi at 9PM (France = UTC +2 right now).
Well is 9:20 PM and the new patch has been tested on 2.6.30-rc5. This mail will be sent using my wlan0 interface.
Would like to say thanks to all of you who helped analysing and fixing it.
Whish you all a nice sunday.
-- eric
Quoted 4 lines · Larry Finger
I think there is a second problem that John's fix does not treat. Although the buffer is removed from the stack, there is no assurance that the buffer obtained with
kmalloc()is reachable by DMA. This case will be triggered if the USB adapter does 32-bit DMA and the system has more than 4 GB RAM.
Memory returned by kmalloc will always be able to be DMAable. If not, we have lots of problems :)
thanks,
greg k-h
Quoted 5 lines · On Saturday 09 May 2009 21:29:59 Greg KH wrote:
Quoted 4 lines · Larry Finger
I think there is a second problem that John's fix does not treat. Although the buffer is removed from the stack, there is no assurance that the buffer obtained with
kmalloc()is reachable by DMA. This case will be triggered if the USB adapter does 32-bit DMA and the system has more than 4 GB RAM.
In practice this does not hit, because such systems' kmalloc does not return memory above 4G (i386) _or_ the DMA mapping functions take care of bounce buffering or I/O-remapping (should be true for all other arches).
So if the device is able to do DMA with addresses >=32bit it should be fine, provided it correctly sets the DMA mask.
Quoted 2 lines
Memory returned by kmalloc will always be able to be DMAable. If not, we have lots of problems :)
True for sane devices.
False for devices like Broadcom HND-DMA, which should only be used to slap thy hw engineers.
Signature · 1 line
Greetings, Michael.
Quoted 3 lines · FUJITA Tomonori
CC'ed linux-usb,
The
ehci_hcddriver uses buffers on the stack for DMA?
No, it should not.
But USB drivers are known to do this incorrectly. Those USB drivers should be fixed.
Quoted 9 lines
Quoted 3 lines · On Sun, 03 May 2009 17:36:24 +0200 Eric Valette <[email protected]> wrote:
------------[ cut here ]------------ WARNING: at /usr/src/linux-2.6.22.9/lib/dma-debug.c:609Hmm, the kernel version is wired.
lib/dma-debug.cwas added in 2.6.30-rc.
Very odd. What specific kernel version caused this warning?
thanks,
greg k-h