From patchwork Thu Sep 17 12:03:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Eggers X-Patchwork-Id: 11782423 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39F4E746 for ; Thu, 17 Sep 2020 13:03:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A13A2083B for ; Thu, 17 Sep 2020 13:03:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbgIQMwE (ORCPT ); Thu, 17 Sep 2020 08:52:04 -0400 Received: from mailout06.rmx.de ([94.199.90.92]:53012 "EHLO mailout06.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726993AbgIQMid (ORCPT ); Thu, 17 Sep 2020 08:38:33 -0400 X-Greylist: delayed 1962 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 Sep 2020 08:37:38 EDT Received: from kdin02.retarus.com (kdin02.dmz1.retloc [172.19.17.49]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout06.rmx.de (Postfix) with ESMTPS id 4BsbGy2wP2z9x2S; Thu, 17 Sep 2020 14:04:10 +0200 (CEST) Received: from mta.arri.de (unknown [217.111.95.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by kdin02.retarus.com (Postfix) with ESMTPS id 4BsbGR4pKsz2TTN4; Thu, 17 Sep 2020 14:03:43 +0200 (CEST) Received: from N95HX1G2.wgnetz.xx (192.168.54.80) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 17 Sep 2020 14:03:43 +0200 From: Christian Eggers To: Jonathan Cameron CC: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , , , Christian Eggers , Subject: [PATCH v2] iio: trigger: Don't use RT priority Date: Thu, 17 Sep 2020 14:03:33 +0200 Message-ID: <20200917120333.2337-1-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Originating-IP: [192.168.54.80] X-RMX-ID: 20200917-140343-4BsbGR4pKsz2TTN4-0@kdin02 X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Triggers may raise transactions on slow busses like I2C. Using the original RT priority of a threaded IRQ may prevent other important IRQ handlers from being run. Signed-off-by: Christian Eggers Cc: stable@vger.kernel.org --- In my particular case (on a RT kernel), the RT priority of the sysfstrig threaded IRQ handler caused (temporarily) raising the prio of a user space process which was holding the I2C bus mutex. Due to a bug in the i2c-imx driver, this process spent 500 ms in a busy-wait loop and prevented all threaded IRQ handlers from being run during this time. v2: - Use sched_set_normal() instead of sched_setscheduler_nocheck() drivers/iio/industrialio-trigger.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 6f16357fd732..7ed00ad695c7 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -9,7 +9,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -245,6 +248,7 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig, int ret = 0; bool notinuse = bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER); + struct irq_desc *irq_desc; /* Prevent the module from being removed whilst attached to a trigger */ __module_get(pf->indio_dev->driver_module); @@ -264,6 +268,12 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig, if (ret < 0) goto out_put_irq; + /* Triggers may raise transactions on slow busses like I2C. Using the original RT priority + * of a threaded IRQ may prevent other threaded IRQ handlers from being run. + */ + irq_desc = irq_to_desc(pf->irq); + sched_set_normal(irq_desc->action->thread, 0); + /* Enable trigger in driver */ if (trig->ops && trig->ops->set_trigger_state && notinuse) { ret = trig->ops->set_trigger_state(trig, true);