Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1810606pxb; Mon, 8 Mar 2021 07:00:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoj0pVTG0SM7LD7RK1qoFhOMhOqDKw6TIoNYSKfRST/+jQ4J8hDVMjMUSokoE+L8W23Rva X-Received: by 2002:a50:e1c9:: with SMTP id m9mr23586373edl.307.1615215652434; Mon, 08 Mar 2021 07:00:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615215652; cv=none; d=google.com; s=arc-20160816; b=CMZrP59Gw7CDEjmIEJD9OStuB83AsRiuogQ4XIBLGu7Xkdj2fxOCfUHMLzd0w9FkLB xwBEa5lNG4mC0HYxK/xqksuCt4QgjL8R/9sr6W95VlgBwqJnO+sbEcGIFV6SjkZ/mytj pw53pvtbAndgp+5nzIkdMdfe6X+sZs//VsSOj7TzbQ7Uzo2DuSjDFTe4K2IJQGb8Os8N wNIHH8qwLk736be0CErNrBHtG0LUw/atorS6sO2YKiY2M5i35r0sTtVfgETCtjAJuDuZ pxf/TtzE89mSs+1bYRs+PqGwqXOtnkJ4WZRPiV7e/oj/Qbb4Gq2wseWuMDsezIc8E7CO 85og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=OEM8wMxjBoUMsbX6hjofVDbnTx9gAw+3Kdntlwko/0U=; b=tXbZq3MTH8LxBnr32CnmiPxqe2GIRR22IUZjGk6aOHsIwkES5G3MfFju+FWJuFiiZ0 I1pngqbC4v1L2Tr7WbPcOnniSH3bTXNW77fDFAcNqKNUZxvRJfZaelPX4RoPd9as0jbn pZ7qJVVGJD2z1MjJ5xWIZEol4n5/11YiE+lXQ/SfMOPeecBvGuL/re+T0hbAgk3cxVdZ YnSf4zmJKcmOxHKCvTML2/g0gId1jg/TAJT9OlpesU4X02FOiSR9ZDfEqJojcXHEUjTM KUvAc6yTHIXoeEBrqT6FE5vnBtAwpf1SSd45fUUf5suzsXWL1FdTkyQQ2KrzoQiVgNkG 16MA== ARC-Authentication-Results: i=1; mx.google.com; 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 gy3si3251123ejb.557.2021.03.08.07.00.29; Mon, 08 Mar 2021 07:00:52 -0800 (PST) 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; 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 S231270AbhCHO5P (ORCPT + 99 others); Mon, 8 Mar 2021 09:57:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbhCHO5A (ORCPT ); Mon, 8 Mar 2021 09:57:00 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B0F0C06174A for ; Mon, 8 Mar 2021 06:57:00 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJHJZ-000549-3n; Mon, 08 Mar 2021 15:56:57 +0100 Received: from pengutronix.de (unknown [IPv6:2a03:f580:87bc:d400:743f:a98a:1069:4286]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 3E2A55F0CBC; Mon, 8 Mar 2021 14:56:54 +0000 (UTC) Date: Mon, 8 Mar 2021 15:56:53 +0100 From: Marc Kleine-Budde To: Boqun Feng Cc: Andrea Righi , Pavel Machek , Dan Murphy , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, schuchmann@schleissheimer.de Subject: Re: [PATCH] leds: trigger: fix potential deadlock with libata Message-ID: <20210308145653.mechsganlrvpzyym@pengutronix.de> References: <20201102104152.GG9930@xps-13-7390> <20210306203954.ya5oqgkdalcw45c4@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gp7ccw4en57i62vl" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --gp7ccw4en57i62vl Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 07.03.2021 10:02:32, Boqun Feng wrote: > On Sat, Mar 06, 2021 at 09:39:54PM +0100, Marc Kleine-Budde wrote: > > Hello *, > >=20 > > On 02.11.2020 11:41:52, Andrea Righi wrote: > > > We have the following potential deadlock condition: > > >=20 > > > =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=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=3D=3D=3D=3D=3D=3D > > > WARNING: possible irq lock inversion dependency detected > > > 5.10.0-rc2+ #25 Not tainted > > > -------------------------------------------------------- > > > swapper/3/0 just changed the state of lock: > > > ffff8880063bd618 (&host->lock){-...}-{2:2}, at: ata_bmdma_interrupt+= 0x27/0x200 > > > but this lock took another, HARDIRQ-READ-unsafe lock in the past: > > > (&trig->leddev_list_lock){.+.?}-{2:2} > > >=20 > > > and interrupts could create inverse lock ordering between them. > >=20 > > [...] > >=20 > > > --- > > > drivers/leds/led-triggers.c | 5 +++-- > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > >=20 > > > diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c > > > index 91da90cfb11d..16d1a93a10a8 100644 > > > --- a/drivers/leds/led-triggers.c > > > +++ b/drivers/leds/led-triggers.c > > > @@ -378,14 +378,15 @@ void led_trigger_event(struct led_trigger *trig, > > > enum led_brightness brightness) > > > { > > > struct led_classdev *led_cdev; > > > + unsigned long flags; > > > =20 > > > if (!trig) > > > return; > > > =20 > > > - read_lock(&trig->leddev_list_lock); > > > + read_lock_irqsave(&trig->leddev_list_lock, flags); > > > list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) > > > led_set_brightness(led_cdev, brightness); > > > - read_unlock(&trig->leddev_list_lock); > > > + read_unlock_irqrestore(&trig->leddev_list_lock, flags); > > > } > > > EXPORT_SYMBOL_GPL(led_trigger_event); > >=20 > > meanwhile this patch hit v5.10.x stable and caused a performance > > degradation on our use case: > >=20 > > It's an embedded ARM system, 4x Cortex A53, with an SPI attached CAN > > controller. CAN stands for Controller Area Network and here used to > > connect to some automotive equipment. Over CAN an ISOTP (a CAN-specific > > Transport Protocol) transfer is running. With this patch, we see CAN > > frames delayed for ~6ms, the usual gap between CAN frames is 240=C2=B5s. > >=20 > > Reverting this patch, restores the old performance. > >=20 > > What is the best way to solve this dilemma? Identify the critical path > > in our use case? Is there a way we can get around the irqsave in > > led_trigger_event()? > >=20 >=20 > Probably, we can change from rwlock to rcu here, POC code as follow, > only compile tested. Marc, could you see whether this help the > performance on your platform? Please note that I haven't test it in a > running kernel and I'm not that familir with led subsystem, so use it > with caution ;-) >=20 > (While at it, I think maybe we miss the leddev_list_lock in net/mac80211 > in the patch) I can confirm, this patch basically restores the old performance. Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --gp7ccw4en57i62vl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEK3kIWJt9yTYMP3ehqclaivrt76kFAmBGOzIACgkQqclaivrt 76nW3Qf/eyK3mOUT5t9BpkibwM2Ud0Kra3YZ+jvIg3UtRx4w2CmcSXpG2n77/EZv S7hHXDnAoqDdPtTRFl+WW6idddlzTA/psg1ODQgyug6UzlEUR0za2vWePVsCLv47 vyIkJ5pe6SY/Ddi3/1eJgrZhjNNQa6fkOjKztGIYdzCY6gCMgZvUfb31qi2YOXZ5 FNl9gLy4TvygC2NCV28YbUsRwPNDHA3Qw8E9IJJFoLAfqQG/YFWhM1uONk98hMqO kgqdMJIBGYLVcrCnnlMTECAE/DasLl9mIT8PbeiE6S+EMwymd+RDjXTg1ZBurKj1 KlCuP3BhmQBLtsiqpVIOiQxSBPcZfg== =kDN4 -----END PGP SIGNATURE----- --gp7ccw4en57i62vl--