Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1661062pxv; Sat, 10 Jul 2021 10:59:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlWTkA2Mi+gt81zXw8GiBKejvI2eXktmPNgqKYkVrDe8i7HG+WMs9d5zX9uJYuMDHsniOU X-Received: by 2002:a17:907:7709:: with SMTP id kw9mr45469258ejc.68.1625939961821; Sat, 10 Jul 2021 10:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625939961; cv=none; d=google.com; s=arc-20160816; b=RUvBzXaGR4jGLNefg0XsNmQK64I34MUerrfjdD22n6SgrIMktMgGWmkTrbEduKhKnX Vs9Dy1b6QVGuJQsdW1IQZF9fy5ZYDiSqOhY8uj+Rlb5qUPUCXDiAdpgc3JvohJboHCer mob7MXGxyNXJ2J8SF5duVu7Hk2DftdIWtqrKhHSTDqgq51iYBr1vtyI/ruGfwTkqbO0g MhN1QinC5H90RXcylaV6hnI0STvNE5GVjpZkcg+cxt0/0D10BWngx9Xr5AhGprBlu5eh 32Kj40m9HzE3b+RYMgXKMv1KxprCUjb0VfGuLvKtogzOfHVzIaiOrASKjC0jGLFJv4/M 40lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=/Am0uhBAEXHiTgENkWsIrhc4uV4GJPpvn66MI5SePOo=; b=kggqRCMSoZdZsKr2FP9zYPo93hViOTHIPsf1mdhnh2/eLNaPFnmjzzW4gsGosYnwOE Wl/ub3hnx6iVyccPFug5ZwJ/PB+OY2jGN/A7o7QAPClDQeUvXWoPjOIV6+7AY8I6OGLF bq9dKBZUJqHCbXZtBn4wab0FVKQIXZAkXo6jzx9Dz6ea5Gmjh5M3q3Z38e7tAYVmpIhi dUyxKfykCU9MSy8iMAJ8F/oJhg6oHaULp2p8JM7c1jWJ3nH3KJRETvL4HPE35qy70Ul3 Y7lyb6i4vix8UnouG3OcQmQ/vWZeXXcUKv1WFBhIiR9ONQXHUj+Oj7O3coS6CXbX88tV oy2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=CiU+TKI7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 5si11010695ejl.332.2021.07.10.10.58.58; Sat, 10 Jul 2021 10:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=CiU+TKI7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbhGJR4u (ORCPT + 99 others); Sat, 10 Jul 2021 13:56:50 -0400 Received: from vern.gendns.com ([98.142.107.122]:38772 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbhGJR4u (ORCPT ); Sat, 10 Jul 2021 13:56:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:References:Cc:To:From:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/Am0uhBAEXHiTgENkWsIrhc4uV4GJPpvn66MI5SePOo=; b=CiU+TKI7eo3mcppV0+grIy+B5u DqJZFdNCcSQt4IeCv7CmdSltFxiMB+/148PKt8QttcMNsitS9cOCm1k7VA3NmZgTi1DWVfGNS6quZ lEQ0md6oL08VAS4RZwcBUYzYhsxKhDEIRly64+d2RcO6z+aXalY/svt7hPSvDHq3RLe6To17uEDHt 0MhsFppUfxmXrw6FYbFJZ3YKHT7idoneijCb+hnZSjSHV55saXmVl4Hrgu63R96RZdEJmCFiGac/O vUiGjXxqY6ZnwxLME2hIFUA9b/v068Te5tSyA08S3OP9nzXWQjrjqYeWPvUy9oORn8zLRIzMHRKZU L6Q8glwQ==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:47624 helo=[192.168.0.134]) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1m2HAe-00GsEC-IC; Sat, 10 Jul 2021 13:53:59 -0400 Subject: Re: [PATCH v12 15/17] counter: Implement events_queue_size sysfs attribute From: David Lechner To: William Breathitt Gray , Jarkko Nikula Cc: jic23@kernel.org, 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, 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: <1a624011-0b43-ac42-be53-a42f81923e5a@linux.intel.com> <76cc7f77-a59c-86ef-8df9-65b877356b32@lechnology.com> Message-ID: Date: Sat, 10 Jul 2021 12:53:54 -0500 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: <76cc7f77-a59c-86ef-8df9-65b877356b32@lechnology.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/10/21 11:08 AM, David Lechner wrote: > On 7/10/21 10:43 AM, David Lechner wrote: >> On 7/10/21 5:25 AM, William Breathitt Gray wrote: >>>> 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 >>> I'm not sure how to resolve this warning. The purpose of this lock is to >>> limit chrdev to a single open at a time. To accomplish this I grab this >>> lock in counter_chrdev_open() and hold it until counter_chrdev_release() >>> is called. Is there a better way to accomplish this? >> >> How about using an atomic flag, e.g test_and_set_bit()? > > Another option could be to rethink it at a higher level and avoid the > need for a lock (and sysfs attribute) altogether. For example, would it > work to (re)allocate the kfifo buffer in the COUNTER_ENABLE_EVENTS_IOCTL > callback and add a parameter to that ioctl to specify the buffer size > (with units of events rather than bytes)? > Thinking about it a bit more, this probably isn't a good suggestion. It would create issues with being able to start reading from the chrdev before enabling events.