From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB7A2C07E9B for ; Tue, 6 Jul 2021 12:05:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9149B61956 for ; Tue, 6 Jul 2021 12:05:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241480AbhGFMIY (ORCPT ); Tue, 6 Jul 2021 08:08:24 -0400 Received: from mga09.intel.com ([134.134.136.24]:54311 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240630AbhGFLrC (ORCPT ); Tue, 6 Jul 2021 07:47:02 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10036"; a="209053296" X-IronPort-AV: E=Sophos;i="5.83,328,1616482800"; d="scan'208";a="209053296" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2021 04:40:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,328,1616482800"; d="scan'208";a="427558993" Received: from mylly.fi.intel.com (HELO [10.237.72.174]) ([10.237.72.174]) by orsmga002.jf.intel.com with ESMTP; 06 Jul 2021 04:40:14 -0700 Subject: Re: [PATCH v12 15/17] counter: Implement events_queue_size sysfs attribute To: William Breathitt Gray , jic23@kernel.org Cc: linux-stm32@st-md-mailman.stormreply.com, kernel@pengutronix.de, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, david@lechnology.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, o.rempel@pengutronix.de References: From: Jarkko Nikula Message-ID: <1a624011-0b43-ac42-be53-a42f81923e5a@linux.intel.com> Date: Tue, 6 Jul 2021 14:40:13 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi On 7/5/21 11:19 AM, William Breathitt Gray wrote: > The events_queue_size sysfs attribute provides a way for users to > dynamically configure the Counter events queue size for the Counter > character device interface. The size is in number of struct > counter_event data structures. The number of elements will be rounded-up > to a power of 2 due to a requirement of the kfifo_alloc function called > during reallocation of the queue. > ... > diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c > index 92805b1f65b8..13644c87d02a 100644 > --- a/drivers/counter/counter-chrdev.c > +++ b/drivers/counter/counter-chrdev.c > @@ -323,6 +323,9 @@ static int counter_chrdev_open(struct inode *inode, struct file *filp) > typeof(*counter), > chrdev); > > + if (!mutex_trylock(&counter->chrdev_lock)) > + return -EBUSY; > + > get_device(&counter->dev); > filp->private_data = counter; > > @@ -339,6 +342,7 @@ static int counter_chrdev_release(struct inode *inode, struct file *filp) > return err; > > put_device(&counter->dev); > + mutex_unlock(&counter->chrdev_lock); > > return 0; > } I got two separate mutex warnings from counter_chrdev_open() by doing blind "cat /dev/counter0". First one due mutex being uninitialized: [ 441.057342] DEBUG_LOCKS_WARN_ON(lock->magic != lock) [ 441.057355] WARNING: CPU: 2 PID: 366 at kernel/locking/mutex.c:1416 mutex_trylock+0xf2/0x130 ... [ 441.217331] Call Trace: [ 441.220062] counter_chrdev_open+0x21/0x60 [counter] ... which I fixed trivially by (please be free to use it) --- a/drivers/counter/counter-chrdev.c +++ b/drivers/counter/counter-chrdev.c @@ -364,6 +364,7 @@ int counter_chrdev_add(struct counter_device *const counter) spin_lock_init(&counter->events_list_lock); init_waitqueue_head(&counter->events_wait); mutex_init(&counter->events_lock); + mutex_init(&counter->chrdev_lock); /* Initialize character device */ cdev_init(&counter->chrdev, &counter_fops); and after that [ 16.564403] ================================================ [ 16.570725] WARNING: lock held when returning to user space! [ 16.577044] 5.13.0-next-20210706+ #4 Not tainted [ 16.582198] ------------------------------------------------ [ 16.588507] cat/331 is leaving the kernel with locks still held! [ 16.595214] 1 lock held by cat/331: [ 16.599103] #0: ffff888102bb3630 (&counter->chrdev_lock){+.+.}-{3:3}, at: counter_chrdev_open+0x21/0x60 [counter] Jarkko From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB4A5C07E96 for ; Tue, 6 Jul 2021 11:57:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B03B1620D8 for ; Tue, 6 Jul 2021 11:57:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B03B1620D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HyDLDH6bZutE+ki69nxIBsL6JtUqBuojiFqIjjCBBgg=; b=CMWGMBPO2gADS2Kc1scoopU8uq ir7pZdFUmUey4vTEzuZgTl1AzqUuQ20/FJelIXIkwfLL7tabf/BpSve/6lP5VoAAdtwl9kJzxSWrP XE9BpCgOavjftF/cc3g+2Qc2eLYaI36ojENfAt1/frNLfT5mpbynHYVKRLdCQvWDVkh/sqmJ+PhVX zlqY/cnkFuyNcBuT2mcl5zYPL4hdrCIEQEPJ5OwHJhHSIH5HHvx4zKXLsBhzG8jsyPP7Z2jgcYZJO RdEVOfFk7BT5hXmFK5d75RlnJboX8R+Ofkclp/4DtnGkNtNz5fB4GTi/o/7xs50cydfZ/UEcHir08 oKtXyVqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0jd8-00BZyB-1e; Tue, 06 Jul 2021 11:52:46 +0000 Received: from mga06.intel.com ([134.134.136.31]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0jR7-00BT3K-7E for linux-arm-kernel@lists.infradead.org; Tue, 06 Jul 2021 11:40:22 +0000 X-IronPort-AV: E=McAfee;i="6200,9189,10036"; a="270219692" X-IronPort-AV: E=Sophos;i="5.83,328,1616482800"; d="scan'208";a="270219692" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2021 04:40:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,328,1616482800"; d="scan'208";a="427558993" Received: from mylly.fi.intel.com (HELO [10.237.72.174]) ([10.237.72.174]) by orsmga002.jf.intel.com with ESMTP; 06 Jul 2021 04:40:14 -0700 Subject: Re: [PATCH v12 15/17] counter: Implement events_queue_size sysfs attribute To: William Breathitt Gray , jic23@kernel.org Cc: linux-stm32@st-md-mailman.stormreply.com, kernel@pengutronix.de, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, david@lechnology.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, o.rempel@pengutronix.de References: From: Jarkko Nikula Message-ID: <1a624011-0b43-ac42-be53-a42f81923e5a@linux.intel.com> Date: Tue, 6 Jul 2021 14:40:13 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210706_044021_395645_95B49A64 X-CRM114-Status: GOOD ( 20.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi On 7/5/21 11:19 AM, William Breathitt Gray wrote: > The events_queue_size sysfs attribute provides a way for users to > dynamically configure the Counter events queue size for the Counter > character device interface. The size is in number of struct > counter_event data structures. The number of elements will be rounded-up > to a power of 2 due to a requirement of the kfifo_alloc function called > during reallocation of the queue. > ... > diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c > index 92805b1f65b8..13644c87d02a 100644 > --- a/drivers/counter/counter-chrdev.c > +++ b/drivers/counter/counter-chrdev.c > @@ -323,6 +323,9 @@ static int counter_chrdev_open(struct inode *inode, struct file *filp) > typeof(*counter), > chrdev); > > + if (!mutex_trylock(&counter->chrdev_lock)) > + return -EBUSY; > + > get_device(&counter->dev); > filp->private_data = counter; > > @@ -339,6 +342,7 @@ static int counter_chrdev_release(struct inode *inode, struct file *filp) > return err; > > put_device(&counter->dev); > + mutex_unlock(&counter->chrdev_lock); > > return 0; > } I got two separate mutex warnings from counter_chrdev_open() by doing blind "cat /dev/counter0". First one due mutex being uninitialized: [ 441.057342] DEBUG_LOCKS_WARN_ON(lock->magic != lock) [ 441.057355] WARNING: CPU: 2 PID: 366 at kernel/locking/mutex.c:1416 mutex_trylock+0xf2/0x130 ... [ 441.217331] Call Trace: [ 441.220062] counter_chrdev_open+0x21/0x60 [counter] ... which I fixed trivially by (please be free to use it) --- a/drivers/counter/counter-chrdev.c +++ b/drivers/counter/counter-chrdev.c @@ -364,6 +364,7 @@ int counter_chrdev_add(struct counter_device *const counter) spin_lock_init(&counter->events_list_lock); init_waitqueue_head(&counter->events_wait); mutex_init(&counter->events_lock); + mutex_init(&counter->chrdev_lock); /* Initialize character device */ cdev_init(&counter->chrdev, &counter_fops); and after that [ 16.564403] ================================================ [ 16.570725] WARNING: lock held when returning to user space! [ 16.577044] 5.13.0-next-20210706+ #4 Not tainted [ 16.582198] ------------------------------------------------ [ 16.588507] cat/331 is leaving the kernel with locks still held! [ 16.595214] 1 lock held by cat/331: [ 16.599103] #0: ffff888102bb3630 (&counter->chrdev_lock){+.+.}-{3:3}, at: counter_chrdev_open+0x21/0x60 [counter] Jarkko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel