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=-8.3 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 22745C388F2 for ; Tue, 20 Oct 2020 15:55:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 A63F822251 for ; Tue, 20 Oct 2020 15:55:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gwPMD4jq"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=lechnology.com header.i=@lechnology.com header.b="P3RuPwL/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A63F822251 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lechnology.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=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=C4RTkeIZ3SocrLrKh71C7vwkfCP5itxN80xVGi3yDsE=; b=gwPMD4jqYWu1D/S0W3ur/G+Xz BFyNBH1Q3Cqsou5dqpezxxytzvx6x/usO2KYfFNspZeiVjuYc4hfw28x8TITsVyzjiHEqc7IW+MPn iNbE/dEEkw1wOsHpSPxqspWOmIl217pI3IUJcavOYEyWykUgUPbIh7wXpfNjuSpSBI3LzyPLz19IM iZ8mzMQYm/8RWBQ1D3zOIRAepWyDmV8fzy2V6KRwidUY2Q95ClRQud64JZt97eVUcNdkjifTyrBx5 0M/n70TnsFVBDP3YMNBSAtecONBZako0Xy4V6vKPVdCiqSFbQ3/dYF0m9Zv5HMuBYU9PgtC0C2ViG 1Sk1kALLA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUtxF-0001xh-UF; Tue, 20 Oct 2020 15:53:42 +0000 Received: from vern.gendns.com ([98.142.107.122]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUtxB-0001vT-SN for linux-arm-kernel@lists.infradead.org; Tue, 20 Oct 2020 15:53:39 +0000 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:From:References:Cc:To: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=e9XW3jL6KSRGVR5MuWFAFYvj2Zv/gs4PcbWW0YWvtFQ=; b=P3RuPwL/u6XjviQQnM2x00N/BZ wF3Ap47wJroh41dfEJhjkUpcAl/89vXj4DR3P44tiaLiDFGJdFX87JSYs8A3kkCzQ9+5VRK3Svfud 7gAUr+4AsweDb2CRkQYB2j+g/dzEYm2F724nN3VQseqhE6HKgumlpnlwF8KzSZbuZmEteXFLOc3P0 P3/CJOgSP7Gd70Kh68nTfxjPdvjnMM81cCw8w2GSEi8CLyqbUXgTVctEubrBZ3teUUkTt/avjfj5V sGuzUrKNqJbJjiy8nzPp/opqPGXgvcWm0hYd6++M2shpTPN9oc5GA+ea72VWrMHH8MiswCBAHiTBW f43dnrPw==; Received: from [2600:1700:4830:165f::19e] (port=57840) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1kUtx8-00026P-2E; Tue, 20 Oct 2020 11:53:34 -0400 Subject: Re: [PATCH v5 3/5] counter: Add character device interface To: William Breathitt Gray References: <00be1fccc672c5207f3b04fe4cc09c29e22641f4.1601170670.git.vilhelm.gray@gmail.com> <181eb08a-be0a-f7cc-259d-b2a0f279950b@lechnology.com> <20201018164905.GD231549@shinobu> From: David Lechner Message-ID: Date: Tue, 20 Oct 2020 10:53:32 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201018164905.GD231549@shinobu> Content-Language: en-US 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 - lists.infradead.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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201020_115337_981308_F2154779 X-CRM114-Status: GOOD ( 28.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.torgue@st.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mcoquelin.stm32@gmail.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, jic23@kernel.org 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 >>> +static long counter_chrdev_ioctl(struct file *filp, unsigned int cmd, >>> + unsigned long arg) >>> +{ >>> + struct counter_device *const counter = filp->private_data; >>> + raw_spinlock_t *const events_lock = &counter->events_lock; >>> + unsigned long flags; >>> + struct list_head *const events_list = &counter->events_list; >>> + struct list_head *const next_events_list = &counter->next_events_list; >>> + >>> + switch (cmd) { >>> + case COUNTER_CLEAR_WATCHES_IOCTL: >>> + raw_spin_lock_irqsave(events_lock, flags); >>> + counter_events_list_free(events_list); >>> + raw_spin_unlock_irqrestore(events_lock, flags); >>> + counter_events_list_free(next_events_list); >> >> I think this ioctl is doing too much. If we have to use it for both >> stopping events and clearing the list accumulated by >> COUNTER_SET_WATCH_IOCTL, then we have a race condition of no events >> after clearing watches during the time we are adding new ones and >> until we load the new ones. >> >> It would probably make more sense to call this ioctl >> COUNTER_STOP_WATCHES_IOCTL and move counter_events_list_free( >> next_events_list) to the end of COUNTER_LOAD_WATCHES_IOCTL. > > I don't think we will necessarily have a race condition here. > COUNTER_CLEAR_WATCHES_IOCTL is intended to just clear the watches; e.g. > bring us back to a clear state when some sort of job has completely > finished and the user is no longer going to watch events for a while > (maybe they're adjusting the conveyor for the next job or some similar > operation). > > I think the scenario you're concerned about is when you need to swap > watches in the middle of a job without losing events. In this case, you > wouldn't need to use COUNTER_CLEAR_WATCHES_IOCTL at all. Instead, you > would just set up the watches via COUNTER_SET_WATCH_IOCTL, and then use > COUNTER_LOAD_WATCHES_IOCTL to perform the swap; after > COUNTER_LOAD_WATCHES_IOCTL completes, next_events_list is empty (thanks > to list_replace_init()) and you're ready for the next set of watches. > Got it. I think I missed the fact that list_replace_init() clears next_events_list. >>> + >>> +static int counter_chrdev_release(struct inode *inode, struct file *filp) >>> +{ >>> + struct counter_device *const counter = filp->private_data; >>> + unsigned long flags; >>> + >>> + put_device(&counter->dev); >> >> put_device() should be at the end of the function in case it is the last >> reference. > > put_device() shouldn't affect the counter_device events members, so I > don't think there's a difference in this case if it's called at the > beginning or end of the counter_chrdev_release function. > It isn't possible the some memory allocated with devm_kalloc() could be be referenced after calling put_device() now or in the future? >>> +} >>> +EXPORT_SYMBOL_GPL(counter_push_event); >> >> >>> diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c >>> index e66ed99dd5ea..cefef61f170d 100644 >>> --- a/drivers/counter/counter-sysfs.c >>> +++ b/drivers/counter/counter-sysfs.c >> >> >> Not sure why sysfs changes are in the chrdev patch. Are these >> changes related somehow? > > Sorry, I forgot to explain this in the cover letter. The changes here > are only useful for the character device interface. These changes > introduce the extensionZ_name and extensionZ_width sysfs attributes. > > In the character device interface, extensions are selected by their id > number, and the value returned depends on the type of data. The new > sysfs attributes introduced here allow users to match the id of an > extension with its name, as well as the bit width of the value returned > so that the user knows whether to use the value_u8 or value_u64 union > member in struct counter_event. > Are we sure that all value types will always be CPU-endian unsigned integers? Or should we make an enum to describe the data type instead of just the width? _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel