From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3370AC43334 for ; Tue, 28 Jun 2022 08:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242781AbiF1IcR (ORCPT ); Tue, 28 Jun 2022 04:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241877AbiF1IcP (ORCPT ); Tue, 28 Jun 2022 04:32:15 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9CE62D1D8; Tue, 28 Jun 2022 01:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656405133; x=1687941133; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=2kqXa/uuLryKUFs3CLbGBD4etwbcUy4VHXIUo9tYGK4=; b=LEVPB3/vXo+at6YRCU8O0vDKzzxD2b8WiylDwv6IZ/j3wVXsKiTELTAL 6AdS0clRVgvYc0bNHuq1g3iHegZW+qx4yODv3caqZ6GSLYCTbjxRLGg+k n1QfU5pl04jkfCfW6dBY7lPGRbiM69X1U7AUQ5GxXSgjRqLXFHWrSi3oy LAE5ZXaHtAE3PW89P86ITAjX1vw7xPyDl/PT0v2n8aYuRzC3sagdu467e CJd45vSeabwfhL65mPsq+5TKHWi7xnyjpFuejxSdBXihKKcEMSI++gHTc 3utqS9PDS6voCnP4fk2fRPYkzqBb75c5u+05B+lX9NMwlFZqrE0W78HtF A==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="264716123" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="264716123" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 01:32:13 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="646818234" Received: from iannetti-mobl.ger.corp.intel.com ([10.251.216.215]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 01:32:09 -0700 Date: Tue, 28 Jun 2022 11:31:50 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Lino Sanfilippo cc: Lukas Wunner , Greg Kroah-Hartman , Jiri Slaby , robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, Andy Shevchenko , vz@mleia.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-serial , LKML , p.rosenberger@kunbus.com, Lino Sanfilippo Subject: Re: [PATCH 2/8] serial: core, 8250: set RS485 termination gpio in serial core In-Reply-To: <067e6fa2-6015-2eea-5719-8b75fb08882c@gmx.de> Message-ID: <9239f2ea-1a1c-ff27-70b9-931ab99c16@linux.intel.com> References: <20220622154659.8710-1-LinoSanfilippo@gmx.de> <20220622154659.8710-3-LinoSanfilippo@gmx.de> <20220625195844.GB2879@wunner.de> <067e6fa2-6015-2eea-5719-8b75fb08882c@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Sun, 26 Jun 2022, Lino Sanfilippo wrote: > On 25.06.22 at 21:58, Lukas Wunner wrote: > > On Wed, Jun 22, 2022 at 05:46:53PM +0200, Lino Sanfilippo wrote: > >> From: Lino Sanfilippo > >> > >> In serial8250_em485_config() the termination GPIO is set with the uart_port > >> spinlock held. This is an issue if setting the GPIO line can sleep (e.g. > >> since the concerning GPIO expander is connected via SPI or I2C). > >> > >> Fix this by setting the termination line outside of the uart_port spinlock > >> in the serial core. > > [...] > >> --- a/drivers/tty/serial/serial_core.c > >> +++ b/drivers/tty/serial/serial_core.c > >> @@ -1400,6 +1411,7 @@ static int uart_set_rs485_config(struct uart_port *port, > >> if (ret) > >> return ret; > >> uart_sanitize_serial_rs485(port, &rs485); > >> + uart_set_rs485_termination(port, &rs485); > >> > >> spin_lock_irqsave(&port->lock, flags); > >> ret = port->rs485_config(port, &rs485); > > > > That's one way to solve the issue. Another would be to push > > acquisition of the port spinlock down into drivers. > > > > I think in most drivers we don't need to take the port spinlock at all > > or only for a few specific register accesses. So taking the lock here > > in the midlayer is likely unwarranted. However, changing that requires > > going through every single driver's ->rs485_config() callback and > > checking whether it needs the lock or not. > > As a first step its sufficient to take the lock in each drivers rs485_config() > function and remove it from uart_set_rs485_config(). Then after time sort out > the drivers that dont require the lock and remove it from their function. > > However the point of this patch was also to generalize the handling of the > termination GPIO, so I would still see this placed in uart_set_rs485_config(). Additional thing to consider is that core currently handles also the port->rs485 assignment under spinlock when ->rs485_config() was successful. TIOCSRS485 ioctl calls are synchronized by other primitives wrt. each other (port mutex and now also termios_rwsem) but drivers probably would like to see consistent rs485 which can only be realized by holding port->lock. -- i.