Patch "usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     usb-gadget-u_serial-avoid-spinlock-recursion-in-__gs.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ca5a1f67510fb72c0eec85d0dc62f9fea5896e98
Author: Prashanth K <quic_prashk@xxxxxxxxxxx>
Date:   Tue May 9 18:57:52 2023 +0530

    usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push
    
    [ Upstream commit e5990469943c711cb00bfde6338d2add6c6d0bfe ]
    
    When serial console over USB is enabled, gs_console_connect
    queues gs_console_work, where it acquires the spinlock and
    queues the usb request, and this request goes to gadget layer.
    Now consider a situation where gadget layer prints something
    to dmesg, this will eventually call gs_console_write() which
    requires cons->lock. And this causes spinlock recursion. Avoid
    this by excluding usb_ep_queue from the spinlock.
    
     spin_lock_irqsave //needs cons->lock
     gs_console_write
            .
            .
     _printk
     __warn_printk
     dev_warn/pr_err
            .
            .
     [USB Gadget Layer]
            .
            .
     usb_ep_queue
     gs_console_work
     __gs_console_push // acquires cons->lock
     process_one_work
    
    Signed-off-by: Prashanth K <quic_prashk@xxxxxxxxxxx>
    Link: https://lore.kernel.org/r/1683638872-6885-1-git-send-email-quic_prashk@xxxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 3b5a6430e2418..a717b53847a8e 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -917,8 +917,11 @@ static void __gs_console_push(struct gs_console *cons)
 	}
 
 	req->length = size;
+
+	spin_unlock_irq(&cons->lock);
 	if (usb_ep_queue(ep, req, GFP_ATOMIC))
 		req->length = 0;
+	spin_lock_irq(&cons->lock);
 }
 
 static void gs_console_work(struct work_struct *work)



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux