Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp466739imu; Fri, 9 Nov 2018 00:15:56 -0800 (PST) X-Google-Smtp-Source: AJdET5fcdpbl5i4NugVQmUaMnlcwa3Hp7a0zdv23uMuaSGlkjEM2qN2QdltFTgRBL0yc9nM8a34f X-Received: by 2002:a17:902:3064:: with SMTP id u91-v6mr7902484plb.164.1541751356374; Fri, 09 Nov 2018 00:15:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541751356; cv=none; d=google.com; s=arc-20160816; b=Um/pwmzUwjDpPShM5DSuwAHSF89PJuxoVPEhnawPyeZBDXUu4/RVs/iBEgsfWeivqE HEcxcvuahHAP4nBFR/8gZni0CU0WJrHJAufSkcCfJKInh3JsPKB+TOFAfi3AIUs72Gwb 5qJOra8jBd3oSnGD/OQsnxuU4nr11AEkFcGBCuljQRAl8czWcWNp+7P/YYcHoAVqkjfb 2lygFb5bo+jpvjziIkb6XPA9rKnigPs29JNLiBFTC484JPHhASbnV06wU/u/t0d4LmUk ewTqrl9VKkirS850w9INmy2AJjK6GjMevxzuKxMINew8qg6hnMbLZWUfSo/QtUyHOZ0e qCzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=SAZgrEFO5GeiEEGzNMOU5pZ71Z9Imit5Ej3U9itkfmk=; b=jlSEfvK+8nLAdHHqOgMT86ULInmixU5PCGFisLKMLy+ACEfqhQI1qGx1nyNr6oVFFM 6zZHqtMZxZOPEfT1KVhRE9fI7zFuxGf5NWsdKwwCrWrKycTaS/Rranzji+JaZTDarMkH nu/EElbhcm5q3QCOmRqiLcdUR03HGmCfOvH8qGwpUQ5gNHS4vcHK4u9dNlZiYTB+pqP1 RQQIP8DAqz3CqpfopAM2oZLCoY987djkCDaE9kz/u34s7V3Es6RalEwGHeUAc56JAvsx E2IL2B5p+D7tmKSe99ERKKpvGJQmNrpQ8BxkJRiFzVlW3TnNETsb2bskq2c2CnqTL2Z1 Te9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2-v6si7416263plm.306.2018.11.09.00.15.39; Fri, 09 Nov 2018 00:15:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728411AbeKIRx2 (ORCPT + 99 others); Fri, 9 Nov 2018 12:53:28 -0500 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:43751 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727662AbeKIRx2 (ORCPT ); Fri, 9 Nov 2018 12:53:28 -0500 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 1215E80548; Fri, 9 Nov 2018 09:13:56 +0100 (CET) Date: Fri, 9 Nov 2018 09:13:58 +0100 From: Pavel Machek To: Baolin Wang Cc: Geert Uytterhoeven , Jacek Anaszewski , rteysseyre@gmail.com, =?iso-8859-1?Q?Bj=F6rn?= Andersson , Mark Brown , Linux LED Subsystem , Linux Kernel Mailing List Subject: Re: [PATCH v14 1/2] leds: core: Introduce LED pattern trigger Message-ID: <20181109081358.GD12450@amd> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="k4f25fnPtRuIRUb3" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --k4f25fnPtRuIRUb3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed 2018-11-07 11:23:52, Baolin Wang wrote: > Hi Geert, >=20 > On 6 November 2018 at 23:57, Geert Uytterhoeven wr= ote: > > Hi Baolin, > > > > On Tue, Oct 2, 2018 at 6:39 PM Baolin Wang wro= te: > >> This patch adds one new led trigger that LED device can configure > >> the software or hardware pattern and trigger it. > >> > >> Consumers can write 'pattern' file to enable the software pattern > >> which alters the brightness for the specified duration with one > >> software timer. > >> > >> Moreover consumers can write 'hw_pattern' file to enable the hardware > >> pattern for some LED controllers which can autonomously control > >> brightness over time, according to some preprogrammed hardware > >> patterns. > >> > >> Signed-off-by: Raphael Teysseyre > >> Signed-off-by: Baolin Wang > > > >> --- /dev/null > >> +++ b/drivers/leds/trigger/ledtrig-pattern.c > >> @@ -0,0 +1,431 @@ > > > >> +static void pattern_trig_timer_function(struct timer_list *t) > >> +{ > >> + struct pattern_trig_data *data =3D from_timer(data, t, timer); > >> + > >> + mutex_lock(&data->lock); > > > > Timer functions run in interrupt context, hence if CONFIG_DEBUG_ATOMIC_= SLEEP=3Dy: > > > > BUG: sleeping function called from invalid context at kernel/locking/mu= tex.c:254 > > in_atomic(): 1, irqs_disabled(): 0, pid: 0, name: swapper/1 > > CPU: 1 PID: 0 Comm: swapper/1 Not tainted > > 4.20.0-rc1-koelsch-00841-ga338c8181013c1a9 #171 > > Hardware name: Generic R-Car Gen2 (Flattened Device Tree) > > [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > > [] (show_stack) from [] (dump_stack+0x7c/0x9c) > > [] (dump_stack) from [] (___might_sleep+0xf4/0x158) > > [] (___might_sleep) from [] (mutex_lock+0x18/0x60) > > [] (mutex_lock) from [] > > (pattern_trig_timer_function+0x1c/0x11c) > > [] (pattern_trig_timer_function) from [] > > (call_timer_fn+0x1c/0x90) > > [] (call_timer_fn) from [] (expire_timers+0x94/0xa4) > > [] (expire_timers) from [] (run_timer_softirq+0x108= /0x15c) > > [] (run_timer_softirq) from [] (__do_softirq+0x1d4/= 0x258) > > [] (__do_softirq) from [] (irq_exit+0x64/0xc4) > > [] (irq_exit) from [] (__handle_domain_irq+0x80/0xb= 4) > > [] (__handle_domain_irq) from [] (gic_handle_irq+0x= 58/0x90) > > [] (gic_handle_irq) from [] (__irq_svc+0x58/0x74) > > Exception stack(0xeb483f60 to 0xeb483fa8) > > 3f60: 00000000 00000000 eb9afaa0 c0217e80 00000000 ffffe000 00000000 c0= e06408 > > 3f80: 00000002 c0e0647c c0c6a5f0 00000000 c0e04900 eb483fb0 c0207ea8 c0= 207e98 > > 3fa0: 60020013 ffffffff > > [] (__irq_svc) from [] (arch_cpu_idle+0x1c/0x38) > > [] (arch_cpu_idle) from [] (do_idle+0x138/0x268) > > [] (do_idle) from [] (cpu_startup_entry+0x18/0x1c) > > [] (cpu_startup_entry) from [<402022ec>] (0x402022ec) > > > > Either this should use a spinlock instead of a mutex, or the timer > > function should kick a workqueue to do the real work. > > >=20 > Ah, sorry I missed this. Good catch. >=20 > After more thinking, the easy fix is that I think we can remove the > mutex lock in pattern_trig_timer_function(). Since the mutex lock is > used to protect the pattern trigger data, but before changing new > pattern trigger data (pattern values or repeat value) by users, we > always cancel the timer firstly to clear previous patterns' > performance. That means there is no race in > pattern_trig_timer_function(), so we can drop the mutex lock in > pattern_trig_timer_function() to avoid this issue. >=20 > I will send one patch to fix this issue. Thanks. That's kind of interesting, but yes, it should work. Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --k4f25fnPtRuIRUb3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlvlQcYACgkQMOfwapXb+vIgTQCfdl40iS1czNt8D9OJf/A32jfF 8noAniM9zrGGCOlj8d3NvB4D0UnBXzqb =mQQf -----END PGP SIGNATURE----- --k4f25fnPtRuIRUb3--