Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp921399pxb; Sat, 6 Mar 2021 23:48:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLu7vyz5uc2RuKpLHpUdd3X2ruLZnSxaTU2HlDJFK96arKG70ESyQqGo0oRcVIJyEm2yUc X-Received: by 2002:aa7:cf16:: with SMTP id a22mr16420989edy.288.1615103293244; Sat, 06 Mar 2021 23:48:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615103293; cv=none; d=google.com; s=arc-20160816; b=vYwdfipzCfUxVH9KNAeaGEIpk7r+EaaoXRU+Nz1CnTAdo48dNTxW0nGkq6O4rtQ/eP XFTz7vZOPqPtlAr6tDZFJLc98/NG5hCSqDCJQFlWV8EjXqxK3nOGx6Hv68jfzPSatJdq psUaNhLToLEZt08K9OQuwlJh5mh8OUbRP4DOXMRA4syL8QSBxauPUM9bSo/9Sm09K6iu sxjF5VRR20JTjes8qwiOeDeIsKzvQXWKPJ0mSnyUY0Zpa2vYSg2rVmR3DpF+l73wswuD ceM4pIR5o+RL23gMhwsVuzzghBhi+mG0DGJneK/1XbgS3ShPrpe960SYRV3ioANoj7uq 9Xow== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8RAwbWKs3D0TFja/bS8+raVCy0idj4NZ23+PF/iBrVs=; b=HndDpyCgarAm/mAsl7HAkd+rqUsGSH3PCa1V/ZvxSH1I8Lq11fZDP7XQoNqvBRjRSK p8eCB67aBll4wzScKRjZHKld0az50w0UYSkm1lRIwaBB+hA4Z4l/XjQSJgd9cVTTtg4G EQq0pnt0vuRVTO8OUsSmZ3Zsh5ILjVpJZymLK/vTjN+KoRCmdY804kO4Fm3vLWR3YEW5 z6C7DM9Be+VnhJkxU9ZP4ts2uaBpcmSp0KfzNZ4PLBWHD2Y+DVG52HxIrWpugXEZQSCa bsc51AfYizcfd6G6HWljBPZEABrOJhvtIdfosN6FSPbNk0UiOoWYStAlk5uj4qtOnkJG 8Bww== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p17si5208173edq.210.2021.03.06.23.47.50; Sat, 06 Mar 2021 23:48:13 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbhCGHPU (ORCPT + 99 others); Sun, 7 Mar 2021 02:15:20 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:45728 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231228AbhCGHO5 (ORCPT ); Sun, 7 Mar 2021 02:14:57 -0500 Received: from mail-ed1-f69.google.com ([209.85.208.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lInct-0002Kt-L4 for linux-kernel@vger.kernel.org; Sun, 07 Mar 2021 07:14:55 +0000 Received: by mail-ed1-f69.google.com with SMTP id cq11so3310625edb.14 for ; Sat, 06 Mar 2021 23:14:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=8RAwbWKs3D0TFja/bS8+raVCy0idj4NZ23+PF/iBrVs=; b=tF0nwcwnoxkMhQmZRzJRulhZqXk3IoCLxIJf9zD+ERyNrXGkqh1+Lj7amJTFZ6LVVk PWZhOMVHpiYs0os+ZneLtesT1ozAwO4Q788vcH0wy7C20xy5cR8cdlPKY3lbEeeSUhBP azd4wyDhineZgYvVSW8zDUtwhQXEw+1BU9tp2yAxOx8yA32a4I3nP3SMDggnBmnOHVXw JwhSVLCCE9xADQCcKqsNErLf08e3KHvJWsMoi/WFvH31x5TpnPtzwVxSxBtpmUTqeWHH 6MxKwf+Apxqb2UOB2GOLAIcOJunv1kR8PjqPS2wWqRimZZQY1gi1Gv3bleNom0DMnEST N0IQ== X-Gm-Message-State: AOAM530pRYzUNxQbn+Rc9u0W+u/6O2q5odgIzh5wZt+TJ2JxT4wwaBVV g1pSrVIutzQ+xhK9E03QTiyCJz/zpvWFFRd/4cfFg19LkgyGS8Lt/cvbV8SPaeCejfe58AoDH3q 2G+yxEVnHbUuCzUGVm9Ma9vG1c+8G76laY0QTLmDhlQ== X-Received: by 2002:a17:906:6c4:: with SMTP id v4mr9548304ejb.198.1615101295275; Sat, 06 Mar 2021 23:14:55 -0800 (PST) X-Received: by 2002:a17:906:6c4:: with SMTP id v4mr9548291ejb.198.1615101295073; Sat, 06 Mar 2021 23:14:55 -0800 (PST) Received: from localhost (host-79-43-122-37.retail.telecomitalia.it. [79.43.122.37]) by smtp.gmail.com with ESMTPSA id r4sm4856778edv.27.2021.03.06.23.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 23:14:54 -0800 (PST) Date: Sun, 7 Mar 2021 08:14:53 +0100 From: Andrea Righi To: Boqun Feng Cc: Marc Kleine-Budde , 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: References: <20201102104152.GG9930@xps-13-7390> <20210306203954.ya5oqgkdalcw45c4@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 07, 2021 at 10:02:32AM +0800, Boqun Feng wrote: > On Sat, Mar 06, 2021 at 09:39:54PM +0100, Marc Kleine-Budde wrote: > > Hello *, > > > > On 02.11.2020 11:41:52, Andrea Righi wrote: > > > We have the following potential deadlock condition: > > > > > > ======================================================== > > > 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} > > > > > > and interrupts could create inverse lock ordering between them. > > > > [...] > > > > > --- > > > drivers/leds/led-triggers.c | 5 +++-- > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > 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; > > > > > > if (!trig) > > > return; > > > > > > - 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); > > > > meanwhile this patch hit v5.10.x stable and caused a performance > > degradation on our use case: > > > > 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?s. > > > > Reverting this patch, restores the old performance. > > > > 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()? > > > > 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 ;-) If we don't want to touch the led subsystem at all maybe we could try to fix the problem in libata, we just need to prevent calling led_trigger_blink_oneshot() with &host->lock held from ata_qc_complete(), maybe doing the led blinking from another context (a workqueue for example)? -Andrea