From nobody Mon May 11 01:32:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1453BC433EF for ; Tue, 19 Apr 2022 10:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350719AbiDSKbV (ORCPT ); Tue, 19 Apr 2022 06:31:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350670AbiDSKa7 (ORCPT ); Tue, 19 Apr 2022 06:30:59 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD927275F6 for ; Tue, 19 Apr 2022 03:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1650364096; x=1681900096; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=oZHnRkPCm8T5oXIKxLsR0BkDUMS+EsF7CIAupgKOdV0=; b=MikVig0b5Bh4EB6MDcY9L4pBB71HgkqSQu8lTzqndFzrsp9gBCYAjbPe Jggg0/Fgs9BZ/AjHphJv9vdPXOkwz2ZR+qBzistvbVAqUHj4z2eevSUql NwiAobKDwbz9c65b6+vQXduQBJwUZpNCtU+WGtAOY5Z+Bm73jLQBopgpw Y=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 19 Apr 2022 03:28:16 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 03:28:16 -0700 Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 19 Apr 2022 03:28:13 -0700 From: Mukesh Ojha To: CC: , , , , Mukesh Ojha Subject: [PATCH] devcoredump : Serialize devcd_del work Date: Tue, 19 Apr 2022 15:57:57 +0530 Message-ID: <1650364077-22694-1-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01c.na.qualcomm.com (10.47.97.222) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In following scenario(diagram), when one thread X running dev_coredumpm() a= dds devcd device to the framework which sends uevent notification to userspace and another thread Y reads this uevent and call to devcd_data_write() which eventually try to delete the queued timer that is not initialized/que= ued yet. So, debug object reports some warning and in the meantime, timer is initial= ized and queued from X path. and from Y path, it gets reinitialized again and timer->entry.pprev=3DNULL and try_to_grab_pending() stucks. To fix this, introduce mutex to serialize the behaviour. cpu0(X) cpu1(Y) dev_coredump() uevent sent to userspace device_add() =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D> userspace process Y reads the uevents writes to devcd fd which results into writes to devcd_data_write() mod_delayed_work() try_to_grab_pending() del_timer() debug_assert_init() INIT_DELAYED_WORK schedule_delayed_work debug_object_fixup() timer_fixup_assert_in= it() timer_setup() do_init_timer()=C2= =A0=C2=A0 =3D=3D> reinitialized the = timer to = timer->entry.pprev=3DNULL timer_pending() !hlist_unhashed_lockless= (&timer->entry) !h->pprev =3D=3D> del= _timer checks and finds= it to be NULL try_to_grab_pending() stucks. Link: https://lore.kernel.org/lkml/2e1f81e2-428c-f11f-ce92-eb11048cb271@qui= cinc.com/ Signed-off-by: Mukesh Ojha --- drivers/base/devcoredump.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c index f4d794d..316f566 100644 --- a/drivers/base/devcoredump.c +++ b/drivers/base/devcoredump.c @@ -25,6 +25,7 @@ struct devcd_entry { struct device devcd_dev; void *data; size_t datalen; + struct mutex mutex; struct module *owner; ssize_t (*read)(char *buffer, loff_t offset, size_t count, void *data, size_t datalen); @@ -84,7 +85,9 @@ static ssize_t devcd_data_write(struct file *filp, struct= kobject *kobj, struct device *dev =3D kobj_to_dev(kobj); struct devcd_entry *devcd =3D dev_to_devcd(dev); =20 + mutex_lock(&devcd->mutex); mod_delayed_work(system_wq, &devcd->del_wk, 0); + mutex_unlock(&devcd->mutex); =20 return count; } @@ -112,7 +115,9 @@ static int devcd_free(struct device *dev, void *data) { struct devcd_entry *devcd =3D dev_to_devcd(dev); =20 + mutex_lock(&devcd->mutex); flush_delayed_work(&devcd->del_wk); + mutex_unlock(&devcd->mutex); return 0; } =20 @@ -278,13 +283,14 @@ void dev_coredumpm(struct device *dev, struct module = *owner, devcd->read =3D read; devcd->free =3D free; devcd->failing_dev =3D get_device(dev); - + mutex_init(&devcd->mutex); device_initialize(&devcd->devcd_dev); =20 dev_set_name(&devcd->devcd_dev, "devcd%d", atomic_inc_return(&devcd_count)); devcd->devcd_dev.class =3D &devcd_class; =20 + mutex_lock(&devcd->mutex); if (device_add(&devcd->devcd_dev)) goto put_device; =20 @@ -301,10 +307,11 @@ void dev_coredumpm(struct device *dev, struct module = *owner, =20 INIT_DELAYED_WORK(&devcd->del_wk, devcd_del); schedule_delayed_work(&devcd->del_wk, DEVCD_TIMEOUT); - + mutex_unlock(&devcd->mutex); return; put_device: put_device(&devcd->devcd_dev); + mutex_unlock(&devcd->mutex); put_module: module_put(owner); free: --=20 2.7.4