From patchwork Thu Dec 19 12:52:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akash M X-Patchwork-Id: 852324 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC98E224AE2 for ; Thu, 19 Dec 2024 12:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734612781; cv=none; b=nSt5dQn3VOI/YwbZGt269Y9sVubfGKcd4GmUUaP6dfJftrypi9l/NXgDxgATiHccWDpg8omS75gAqzfF/bK6IF4O2hqGzd0Cph+Eu8YbSXdLfsgTSLAyyRPFVpo8X1tewYCV+JYougxWxrvwRluF1HYO2cfPnuB8+NpR5NTAo+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734612781; c=relaxed/simple; bh=B97Llbf0YREjqIyQt5vPG9mxDBeer5PpFc5dHxjfnIU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: References; b=lrdo2Giq/DwuPXw4dLWRfNmGFGmyMaR7S0v2f+kHXdeo1z1CgEm13miY7FLnFTJXk+HBK+cUtZkelqShYFOzz4dSkZk/EIBUHqXTllS7dJe48u1S7YhEosfc3lYZMUlVvVkwCJiXZCKUpVw5chAwhfuwxtow5SsSayzVnqFg6AM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=guORhkVa; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="guORhkVa" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20241219125251epoutp011f03d1231f70caf36c7472b2cb823986~SlSAHOhrt0213402134epoutp01- for ; Thu, 19 Dec 2024 12:52:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20241219125251epoutp011f03d1231f70caf36c7472b2cb823986~SlSAHOhrt0213402134epoutp01- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1734612771; bh=sKFhPF8oggiXR9rwfVQ+SiG0Bh6p6hc1OP+VypPhxH0=; h=From:To:Cc:Subject:Date:References:From; b=guORhkVa/iUGpuyz3HhKqlVtYXbJeCp5GTiva2UnlEZ1U8MyucjS6L7TZGAgueJaQ 8IBOGgVRCsUsqVvoPR8F/WhbjHtfu2UjD3UI/zK22C9GTzdiRGfpl3T9L3mJXk7v9N GJcJFswBvfBOdJpqupC4Cg+F8Bu0Ai3lBV+94W7w= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20241219125250epcas5p1a75755930a7962bc29049e9e0bb5c190~SlR-N-SV01606816068epcas5p17; Thu, 19 Dec 2024 12:52:50 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.178]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4YDVns0Ql1z4x9Pv; Thu, 19 Dec 2024 12:52:49 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id FD.B9.19710.02714676; Thu, 19 Dec 2024 21:52:48 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20241219125248epcas5p3887188e4df29b7b580cce9cfe6fed79f~SlR9YqXDB1112611126epcas5p38; Thu, 19 Dec 2024 12:52:48 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20241219125248epsmtrp13e551a8fb58ff228bdded55e244e8fcf~SlR9XikME1714617146epsmtrp1U; Thu, 19 Dec 2024 12:52:48 +0000 (GMT) X-AuditID: b6c32a44-363dc70000004cfe-fd-6764172032b0 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id B3.87.33707.02714676; Thu, 19 Dec 2024 21:52:48 +0900 (KST) Received: from INBRO002811.samsungds.net (unknown [107.122.5.126]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20241219125245epsmtip1d6bc9c94517ed39a0b607421663d72eb~SlR6nhplK0310303103epsmtip14; Thu, 19 Dec 2024 12:52:45 +0000 (GMT) From: Akash M To: gregkh@linuxfoundation.org, paul@crapouillou.net, Chris.Wulff@biamp.com, tudor.ambarus@linaro.org, m.grzeschik@pengutronix.de, viro@zeniv.linux.org.uk, quic_jjohnson@quicinc.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jh0801.jung@samsung.com, dh10.jung@samsung.com, naushad@samsung.com, akash.m5@samsung.com, rc93.raju@samsung.com, taehyun.cho@samsung.com, hongpooh.kim@samsung.com, eomji.oh@samsung.com, shijie.cai@samsung.com, alim.akhtar@samsung.com, selvarasu.g@samsung.com, stable@vger.kernel.org Subject: [PATCH] usb: gadget: f_fs: Remove WARN_ON in functionfs_bind Date: Thu, 19 Dec 2024 18:22:19 +0530 Message-ID: <20241219125221.1679-1-akash.m5@samsung.com> X-Mailer: git-send-email 2.46.0.windows.1 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-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572F2/yMYzUvG7ZL 7mZ/+dn6fKvH0q5PnQ8ePZONEzhfGnJfKe78/pALVw4lJt/9vzVUqnaf6gEx356mbvmYkz7K ZWcOVTfcXHZy0oHdhtvmJV9oYu0X//nMKnGeyFGZLbHrvaUadnjZT1t1RFRxQei6RkMhLrnT r1TVA31fVzppMJ617W5R27jDSeFwX1nhuhX1wdoeO/dJBflx21w9tNPrmU3Uz7urjthcveiu xFKckWioxVxUnAgAn7qIoBUDAAA= X-CMS-MailID: 20241219125248epcas5p3887188e4df29b7b580cce9cfe6fed79f X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20241219125248epcas5p3887188e4df29b7b580cce9cfe6fed79f References: This commit addresses an issue related to below kernel panic where panic_on_warn is enabled. It is caused by the unnecessary use of WARN_ON in functionsfs_bind, which easily leads to the following scenarios. 1.adb_write in adbd 2. UDC write via configfs ================= ===================== ->usb_ffs_open_thread() ->UDC write ->open_functionfs() ->configfs_write_iter() ->adb_open() ->gadget_dev_desc_UDC_store() ->adb_write() ->usb_gadget_register_driver_owner ->driver_register() ->StartMonitor() ->bus_add_driver() ->adb_read() ->gadget_bind_driver() ->configfs_composite_bind() ->usb_add_function() ->open_functionfs() ->ffs_func_bind() ->adb_open() ->functionfs_bind() state !=FFS_ACTIVE> The adb_open, adb_read, and adb_write operations are invoked from the daemon, but trying to bind the function is a process that is invoked by UDC write through configfs, which opens up the possibility of a race condition between the two paths. In this race scenario, the kernel panic occurs due to the WARN_ON from functionfs_bind when panic_on_warn is enabled. This commit fixes the kernel panic by removing the unnecessary WARN_ON. Kernel panic - not syncing: kernel: panic_on_warn set ... [ 14.542395] Call trace: [ 14.542464] ffs_func_bind+0x1c8/0x14a8 [ 14.542468] usb_add_function+0xcc/0x1f0 [ 14.542473] configfs_composite_bind+0x468/0x588 [ 14.542478] gadget_bind_driver+0x108/0x27c [ 14.542483] really_probe+0x190/0x374 [ 14.542488] __driver_probe_device+0xa0/0x12c [ 14.542492] driver_probe_device+0x3c/0x220 [ 14.542498] __driver_attach+0x11c/0x1fc [ 14.542502] bus_for_each_dev+0x104/0x160 [ 14.542506] driver_attach+0x24/0x34 [ 14.542510] bus_add_driver+0x154/0x270 [ 14.542514] driver_register+0x68/0x104 [ 14.542518] usb_gadget_register_driver_owner+0x48/0xf4 [ 14.542523] gadget_dev_desc_UDC_store+0xf8/0x144 [ 14.542526] configfs_write_iter+0xf0/0x138 Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver") Cc: stable@vger.kernel.org Signed-off-by: Akash M diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 2920f8000bbd..92c883440e02 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -2285,7 +2285,7 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) struct usb_gadget_strings **lang; int first_id; - if (WARN_ON(ffs->state != FFS_ACTIVE + if ((ffs->state != FFS_ACTIVE || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) return -EBADFD;