Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2266246rdb; Wed, 21 Feb 2024 02:11:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXZaKqOOJh/KEoUUIDYr0NBoaMsTUgqvxQKHRX59iLabooKv/WCB5kwE4pVluAq6MtgjRqLJxvYbI3tRUC4kZYXSovWNgNxrntU1P/KoA== X-Google-Smtp-Source: AGHT+IHGfUot/izXdy6OMpNL9Y80QjXj/518om6dWcU4gmnJ5NFdUBpCyedVMP+1elJPFdrWAg3Y X-Received: by 2002:aa7:cf03:0:b0:564:fdf2:5d78 with SMTP id a3-20020aa7cf03000000b00564fdf25d78mr755757edy.14.1708510289638; Wed, 21 Feb 2024 02:11:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708510289; cv=pass; d=google.com; s=arc-20160816; b=cHl6GiAX2+fnZzOKdeJFTyVI/iYdv8DMY2JfF04uoesLsbMFTUw/1rWDGF/XFUQvyB UZCfA2h3tJ/dh7/uQIr4IesBWytsYXGgR/W55MKXjr1TwnMG/S69StrOnjHi+NXZ4edo FbzCa3SyzpFWGQxpLJ2rm6kR/iBwYHmhjPcq8dQHMYox2BpTSN7WzCfYTovqKae1a2zh 0OaMgpMi2gwakEEGJEAjz08RcUapoR+GzWWqF3ss0x3ZpRPUmgZFzSDjxUkU/DRZXQUP SqkqyfelobmtaEcJbdSrRUJNPfSVdNMz6cwNMHgSuPubgoFNLo+W0GB7YLZ3y8DnCXEx l0Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=tGWKi3XRrYtmuARfCajUNkylogiWFbJvSMiv0BOvGE0=; fh=LUC9hSUyGlGxaXBqAnF/J2ZBq7hIzhUn/v7IXHiq8Mw=; b=Z1hmQlAKqEcP0zCuJSDyeeYqSg6diHeWf6Vjc361RgrLgcmgkcITAFnNlUmM9B7neU aeYpTzpDXkFlFW9/IXNZTP1HL59pln5EzL3d3W6Z7a8V7Txv8T6J7eat9xxNF//GfRGk LLUZcpLRh6AyXcDaYpi2cSUVnuZR3Ni74nHN1y3qzbX2EC3UKfHRfLAgtvw/rMQCWlM2 QPSEUtmsNgIFSoRZml3EsENOgOU6sTa8MvswpqKZbqUx6faIFzxv8QejyrvrtK4H4j4I JtEmZRACDorZs19Lt4fWUw8UR1JE1iKDdqMHgjebxQeflxcPp7ihwE4z2ePuApKJERGk 16uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=CmKjDyny; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-74483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dg15-20020a0564021d0f00b0056454d63568si3252754edb.518.2024.02.21.02.11.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 02:11:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=CmKjDyny; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-74483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AC6E51F27B5A for ; Wed, 21 Feb 2024 10:02:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F4274CB23; Wed, 21 Feb 2024 09:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="CmKjDyny" Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E6F34C61B; Wed, 21 Feb 2024 09:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708509272; cv=none; b=lys0VGLjXYoj47V6Q8zCjWv48rIbVUVHrylavSTxj194fBIGBktE908AcPZPKX1fShlo7sN75EWaptGKFatnBZWQMktBEzH+VicoeHVnQNBokK0EVz0psWDetruN9DizNtCbTybahwPowIjy1ugCVxNpIrb174J2+m2L5GlUS5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708509272; c=relaxed/simple; bh=D4a6qDhm/r1zitj6K4QT5PaTygu+/3cz0YZaNV8v6hc=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=ZCwPbDh2mQLCd/rJfkDWS56niQxqsp/JzjgHZSc0fxaAycD79SBfmi4VkGSD/o3sfqTpi1qNBFh06ohb7frcCTpq3puTNaMDXyufjoosgDnqdKKYhivzNhyTFJ2RSkMq1jPuEBuQy3BZhkrQBircvstgO+sd7AZZLP6wt0Jxdu4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=CmKjDyny; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41L7H87L021527; Wed, 21 Feb 2024 10:54:07 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= selector1; bh=tGWKi3XRrYtmuARfCajUNkylogiWFbJvSMiv0BOvGE0=; b=Cm KjDyny3E82jh462D50nD6iH3WH8IaDkECoKy3+F033mPxLSmyHaUAygGk1paftxf MdF55AHvDGSZCeDkJW/NX1eyDd7G60FM75zwN9VQH4FtsyP1Np+yGhRaOCRrH3k2 Mo9dw/mXq3vDQ8AvOC8s1PkuL+No2LCrlfX+dY8fJL9zQ4qxywJ+oLKNkA1lKiXe 9bQX1nPAeNNote3eo1xc2jvtmV9FnPg+0FhXwiUL1CjPIREecsoC4koOcKLcubwY k/GZM3Azom3PgBwKH2L0+7c2tGXM9oHcQhtAIvVFuLRWITnPFx63KBf1eSJrSSC7 ygbIBPzWT4bfebdCkVsg== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3wd202tjj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 10:54:07 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 801B540051; Wed, 21 Feb 2024 10:53:49 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id A5ADB232FEA; Wed, 21 Feb 2024 10:53:13 +0100 (CET) Received: from [10.201.20.71] (10.201.20.71) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 21 Feb 2024 10:53:13 +0100 Message-ID: Date: Wed, 21 Feb 2024 10:53:12 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] serial: st-asc: don't get/put GPIOs in atomic context To: Bartosz Golaszewski , Greg Kroah-Hartman , Jiri Slaby , Dan Carpenter , Linus Walleij CC: , , Bartosz Golaszewski References: <20240220113410.16613-1-brgl@bgdev.pl> Content-Language: en-US From: Patrice CHOTARD In-Reply-To: <20240220113410.16613-1-brgl@bgdev.pl> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-20_01,2023-05-22_02 On 2/20/24 12:34, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > Since commit 1f2bcb8c8ccd ("gpio: protect the descriptor label with > SRCU") gpiod_set_consumer_name() calls synchronize_srcu() which led to > a "sleeping in atomic context" smatch warning. > > This function (along with gpiod_get/put() and all other GPIO APIs apart > from gpiod_get/set_value() and gpiod_direction_input/output()) should > have never been called with a spinlock taken. We're only fixing this now > as GPIOLIB has been rebuilt to use SRCU for access serialization which > uncovered this problem. > > Move the calls to gpiod_get/put() outside the spinlock critical section. > > Reported-by: Dan Carpenter > Closes: https://lore.kernel.org/linux-gpio/deee1438-efc1-47c4-8d80-0ab2cf01d60a@moroto.mountain/ > Signed-off-by: Bartosz Golaszewski > --- > v2 -> v3: > - we only need to change the GPIO configuration for RTS in certain situations > so use a separate variable for storing that information; if we don't then we > may end up putting the descriptor when setting a different option > - I dropped Linus tag as the code change significantly > > v1 -> v2: > - initialize the 'manual_rts' variable to false as we don't always get to > the place where it's set > > drivers/tty/serial/st-asc.c | 40 ++++++++++++++++++++++--------------- > 1 file changed, 24 insertions(+), 16 deletions(-) > > diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c > index bbb5595d7e24..a23e59551848 100644 > --- a/drivers/tty/serial/st-asc.c > +++ b/drivers/tty/serial/st-asc.c > @@ -465,6 +465,7 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, > const struct ktermios *old) > { > struct asc_port *ascport = to_asc_port(port); > + bool manual_rts, toggle_rts = false; > struct gpio_desc *gpiod; > unsigned int baud; > u32 ctrl_val; > @@ -518,25 +519,13 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, > > /* If flow-control selected, stop handling RTS manually */ > if (ascport->rts) { > - devm_gpiod_put(port->dev, ascport->rts); > - ascport->rts = NULL; > - > - pinctrl_select_state(ascport->pinctrl, > - ascport->states[DEFAULT]); > + toggle_rts = true; > + manual_rts = false; > } > } else { > /* If flow-control disabled, it's safe to handle RTS manually */ > - if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) { > - pinctrl_select_state(ascport->pinctrl, > - ascport->states[NO_HW_FLOWCTRL]); > - > - gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); > - if (!IS_ERR(gpiod)) { > - gpiod_set_consumer_name(gpiod, > - port->dev->of_node->name); > - ascport->rts = gpiod; > - } > - } > + if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) > + manual_rts = toggle_rts = true; > } > > if ((baud < 19200) && !ascport->force_m1) { > @@ -595,6 +584,25 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, > asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN)); > > uart_port_unlock_irqrestore(port, flags); > + > + if (toggle_rts) { > + if (manual_rts) { > + pinctrl_select_state(ascport->pinctrl, > + ascport->states[NO_HW_FLOWCTRL]); > + > + gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); > + if (!IS_ERR(gpiod)) { > + gpiod_set_consumer_name(gpiod, > + port->dev->of_node->name); > + ascport->rts = gpiod; > + } > + } else { > + devm_gpiod_put(port->dev, ascport->rts); > + ascport->rts = NULL; > + pinctrl_select_state(ascport->pinctrl, > + ascport->states[DEFAULT]); > + } > + } > } > > static const char *asc_type(struct uart_port *port) Reviewed-by: Patrice Chotard Thanks Patrice