Re: [PATCH] xhci: Free the command allocated for setting LPM if we return early

2023-04-03 Thread Mathias Nyman

On 28.3.2023 1.25, Mirsad Goran Todorovac wrote:

On 27. 03. 2023. 11:50, Mathias Nyman wrote:

The command allocated to set exit latency LPM values need to be freed in
case the command is never queued. This would be the case if there is no
change in exit latency values, or device is missing.

Fixes: 5c2a380a5aa8 ("xhci: Allocate separate command structures for each LPM 
command")
Cc: 
Signed-off-by: Mathias Nyman 
---
  drivers/usb/host/xhci.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index bdb6dd819a3b..6307bae9cddf 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4442,6 +4442,7 @@ static int __maybe_unused 
xhci_change_max_exit_latency(struct xhci_hcd *xhci,
  
  	if (!virt_dev || max_exit_latency == virt_dev->current_mel) {

spin_unlock_irqrestore(>lock, flags);
+   xhci_free_command(xhci, command);
return 0;
}
  


After more testing, I can confirm that your patch fixes the leak in the original
environment.


Thanks for testing.
Can I add the tags below to the patch?
 
Reported-by: Mirsad Goran Todorovac 

Tested-by: Mirsad Goran Todorovac 

Thanks
Mathias



--
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss


Re: BUG: drivers/usb/host/xhci: memleak in alloc from xhci_disable_usb3_lpm_timeout()

2023-04-03 Thread Mathias Nyman

On 25.3.2023 13.33, Mirsad Goran Todorovac wrote:

On 25. 03. 2023. 12:27, Mirsad Goran Todorovac wrote:

Hi all!

Here are again the good news and the bad news:

BAD:  another kernel memory leak detected (one more to hunt down and fix)
GOOD: another kernel memory leak detected (one less unaccounted for)

I tried to make some fun, but maintainers are busy folks, so let's get down
to business:

---
Nine (9) new systemd-udevd kernel memory leaks occurred (unable to reproduce).

The platform is Ubuntu 22.10 with (relatively recent) systemd 251.4-1ubuntu7.1
on LENOVO_MT_82H8_BU_idea_FM_IdeaPad 3 15ITL6 with BIOS GGCN51WW from 
11/16/2022.

The symptom (/sys/kernel/debug/kmemleak output):

unreferenced object 0x909698ff9280 (size 64):
   comm "systemd-udevd", pid 436, jiffies 4294893239 (age 6287.088s)
   hex dump (first 32 bytes):
 e0 51 bb 99 96 90 ff ff 00 00 00 00 00 00 00 00  .Q..
 40 5b bb 99 96 90 ff ff 00 00 00 00 00 00 00 00  @[..
   backtrace:
 [] slab_post_alloc_hook+0x8c/0x320
 [] __kmem_cache_alloc_node+0x1c7/0x2b0
 [] kmalloc_node_trace+0x2b/0xa0
 [] xhci_alloc_command+0x7c/0x1b0
 [] xhci_alloc_command_with_ctx+0x21/0x70
 [] xhci_change_max_exit_latency+0x2e/0x1c0>>  
[] xhci_disable_usb3_lpm_timeout+0x7b/0xb0
 [] usb_disable_link_state+0x57/0xe0


Thanks for the report.

I think I found the leak, and wrote a patch for it.
Any chance you could test it with the same setup?

https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git/commit/?h=for-usb-linus=8bacee588602ed74cc22aaf4c56b796300e5a943

Thanks
-Mathias


--
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss


Re: [PATCH] xhci: Free the command allocated for setting LPM if we return early

2023-04-03 Thread Mathias Nyman

On 27.3.2023 14.51, Greg KH wrote:

On Mon, Mar 27, 2023 at 12:50:19PM +0300, Mathias Nyman wrote:

The command allocated to set exit latency LPM values need to be freed in
case the command is never queued. This would be the case if there is no
change in exit latency values, or device is missing.

Fixes: 5c2a380a5aa8 ("xhci: Allocate separate command structures for each LPM 
command")
Cc: 
Signed-off-by: Mathias Nyman 
---
  drivers/usb/host/xhci.c | 1 +
  1 file changed, 1 insertion(+)


Do you want me to take this now, or will you be sending this to me in a
separate series of xhci fixes?  Either is fine with me.


I can send a separate series this week, there are some other fixes as well.

Thanks
Mathias


--
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss


[PATCH] xhci: Free the command allocated for setting LPM if we return early

2023-04-03 Thread Mathias Nyman
The command allocated to set exit latency LPM values need to be freed in
case the command is never queued. This would be the case if there is no
change in exit latency values, or device is missing.

Fixes: 5c2a380a5aa8 ("xhci: Allocate separate command structures for each LPM 
command")
Cc: 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index bdb6dd819a3b..6307bae9cddf 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4442,6 +4442,7 @@ static int __maybe_unused 
xhci_change_max_exit_latency(struct xhci_hcd *xhci,
 
if (!virt_dev || max_exit_latency == virt_dev->current_mel) {
spin_unlock_irqrestore(>lock, flags);
+   xhci_free_command(xhci, command);
return 0;
}
 
-- 
2.25.1


-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss