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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B9D2C433E0 for ; Fri, 15 May 2020 14:10:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F279206B6 for ; Fri, 15 May 2020 14:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726231AbgEOOKt (ORCPT ); Fri, 15 May 2020 10:10:49 -0400 Received: from mga14.intel.com ([192.55.52.115]:23237 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgEOOKt (ORCPT ); Fri, 15 May 2020 10:10:49 -0400 IronPort-SDR: Lvl0LWOKuTBWMprfi1yX22tZOyO0qrSB9ym2Q/OTsbcqKrj8+7rbdUtM9bcsdc0/MFu4U25FFW q8HtMsC4DO2w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2020 07:10:49 -0700 IronPort-SDR: 54TbqBR7CXjYDsu+yd9jQlAkaAjG99wMxI2ia8etFYijKsxS7dIc+1yj3hatPR1kLCRXXsU3Hi WXtG+gio5/OQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,395,1583222400"; d="scan'208";a="372701841" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga001.fm.intel.com with ESMTP; 15 May 2020 07:10:44 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jZb30-006sqV-VP; Fri, 15 May 2020 17:10:46 +0300 Date: Fri, 15 May 2020 17:10:46 +0300 From: Andy Shevchenko To: Serge Semin Cc: Thomas Bogendoerfer , Greg Kroah-Hartman , Jiri Slaby , Serge Semin , Alexey Malahov , Paul Burton , Ralf Baechle , Arnd Bergmann , Long Cheng , Maxime Ripard , Catalin Marinas , Will Deacon , Russell King , linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Heikki Krogerus , Kefeng Wang , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 4/4] serial: 8250_dw: Fix common clocks usage race condition Message-ID: <20200515141046.GF1634618@smile.fi.intel.com> References: <20200323024611.16039-1-Sergey.Semin@baikalelectronics.ru> <20200506233136.11842-1-Sergey.Semin@baikalelectronics.ru> <20200506233136.11842-5-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200506233136.11842-5-Sergey.Semin@baikalelectronics.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 02:31:35AM +0300, Serge Semin wrote: > The race condition may happen if the UART reference clock is shared with > some other device (on Baikal-T1 SoC it's another DW UART port). In this > case if that device changes the clock rate while serial console is using > it the DW 8250 UART port might not only end up with an invalid uartclk > value saved, but may also experience a distorted output data since > baud-clock could have been changed. In order to fix this lets at least > try to adjust the 8250 port setting like UART clock rate in case if the > reference clock rate change is discovered. The driver will call the new > method to update 8250 UART port clock rate settings. It's done by means of > the clock event notifier registered at the port startup and unregistered > in the shutdown callback method. I'm wondering if clock framework itself can provide such a notifier? > Note 1. In order to avoid deadlocks we had to execute the UART port update > method in a dedicated deferred work. This is due to (in my opinion > redundant) the clock update implemented in the dw8250_set_termios() > method. So, and how you propose to update the clock when ->set_termios() is called? > Note 2. Before the ref clock is manually changed by the custom > set_termios() function we swap the port uartclk value with new rate > adjusted to be suitable for the requested baud. It is necessary in > order to effectively disable a functionality of the ref clock events > handler for the current UART port, since uartclk update will be done > a bit further in the generic serial8250_do_set_termios() function. ... > + struct notifier_block clk_notifier; > + struct work_struct clk_work; Oh, this seems too much. Perhaps, the compatible based quirk with your initial approach is much better for time being. -- With Best Regards, Andy Shevchenko 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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 466D2C433E0 for ; Fri, 15 May 2020 14:11:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B36920759 for ; Fri, 15 May 2020 14:11:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="h4OhiGo+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B36920759 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1goix2+zZZHPr34UOQ2h+u6VwpWlaaJCx+EERzLrMRU=; b=h4OhiGo+PgPtAu thL2wGr9tvtaqq3TjpDK33oCuwMuk8RM2ZpbOZKtOWmJ/l+QhRDT5KWsTXebpgdc5DBLAbxZFvjeE X/+q5WsjuZJpAhl/tTUN23EfVStzNdqj7zhSQ3gwoIE/1M3YFeu286CizV35IUU6tw2c+jJZ3Ydkx P8Z3cIA6NIfC+AELvXKFMsVkeUe377Xhovna4zE63kOIxPC0uag7FpHICOUDvPR1vIeO8LdzcfKu8 bD5ZDEI6OuYlsFf0X3i6iDTAx7CR9u5k+vRaMycZgeFCHgIZn/pzIx4ILtyGc4j88GQPMvqiOWHAS 13e2DhVjimaGx1wW0FLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZb3G-0002Vt-7j; Fri, 15 May 2020 14:11:02 +0000 Received: from mga11.intel.com ([192.55.52.93]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZb34-0002Ek-Ij; Fri, 15 May 2020 14:10:51 +0000 IronPort-SDR: Uo6Fg5hh8bnsVlKrCQ7prmJHLHxgpWWe1d1isFlzh/3j8fOP80maXdVB3ArdRESTU7a7vHT5ZT mi0w51bTFxJA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2020 07:10:49 -0700 IronPort-SDR: 54TbqBR7CXjYDsu+yd9jQlAkaAjG99wMxI2ia8etFYijKsxS7dIc+1yj3hatPR1kLCRXXsU3Hi WXtG+gio5/OQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,395,1583222400"; d="scan'208";a="372701841" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga001.fm.intel.com with ESMTP; 15 May 2020 07:10:44 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jZb30-006sqV-VP; Fri, 15 May 2020 17:10:46 +0300 Date: Fri, 15 May 2020 17:10:46 +0300 From: Andy Shevchenko To: Serge Semin Subject: Re: [PATCH v3 4/4] serial: 8250_dw: Fix common clocks usage race condition Message-ID: <20200515141046.GF1634618@smile.fi.intel.com> References: <20200323024611.16039-1-Sergey.Semin@baikalelectronics.ru> <20200506233136.11842-1-Sergey.Semin@baikalelectronics.ru> <20200506233136.11842-5-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200506233136.11842-5-Sergey.Semin@baikalelectronics.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200515_071050_631871_3739419E X-CRM114-Status: GOOD ( 17.70 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Kefeng Wang , Thomas Bogendoerfer , Catalin Marinas , Arnd Bergmann , Paul Burton , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Russell King , Serge Semin , Alexey Malahov , Long Cheng , linux-mediatek@lists.infradead.org, Ralf Baechle , linux-serial@vger.kernel.org, Jiri Slaby , Heikki Krogerus , linux-mips@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Thu, May 07, 2020 at 02:31:35AM +0300, Serge Semin wrote: > The race condition may happen if the UART reference clock is shared with > some other device (on Baikal-T1 SoC it's another DW UART port). In this > case if that device changes the clock rate while serial console is using > it the DW 8250 UART port might not only end up with an invalid uartclk > value saved, but may also experience a distorted output data since > baud-clock could have been changed. In order to fix this lets at least > try to adjust the 8250 port setting like UART clock rate in case if the > reference clock rate change is discovered. The driver will call the new > method to update 8250 UART port clock rate settings. It's done by means of > the clock event notifier registered at the port startup and unregistered > in the shutdown callback method. I'm wondering if clock framework itself can provide such a notifier? > Note 1. In order to avoid deadlocks we had to execute the UART port update > method in a dedicated deferred work. This is due to (in my opinion > redundant) the clock update implemented in the dw8250_set_termios() > method. So, and how you propose to update the clock when ->set_termios() is called? > Note 2. Before the ref clock is manually changed by the custom > set_termios() function we swap the port uartclk value with new rate > adjusted to be suitable for the requested baud. It is necessary in > order to effectively disable a functionality of the ref clock events > handler for the current UART port, since uartclk update will be done > a bit further in the generic serial8250_do_set_termios() function. ... > + struct notifier_block clk_notifier; > + struct work_struct clk_work; Oh, this seems too much. Perhaps, the compatible based quirk with your initial approach is much better for time being. -- With Best Regards, Andy Shevchenko _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek 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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D54AFC433E0 for ; Fri, 15 May 2020 14:10:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A28E72054F for ; Fri, 15 May 2020 14:10:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XhO93iKb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A28E72054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=COL0iBeM7lhaiUnr3M2w/iY1CicCX9vnDPB9rf29l88=; b=XhO93iKbz5JTE4 w/uM8w42eGjKw7+eBUPExa/Ct1jph0xPd8FAEOslzTKygzgaGMlTJU0YkhRQrSABQMcc1vzXtRV7o iht75UE6IAZOtLiqhm+J/2quVgvmemzF8yejcA6sB7La8UXr1T7HIshEAhPeNuHrdq0B4gHnZP9aB qC3fhtir5eULmOHUKQzSyTqjdsCS4ARU8XjpW3+97TMt91U2zwaLA1cNBWAbjzYCa9Xg2D+R1fHE8 DfWFO/Ei51FfyoCgBbUr1YHcJ7Mum0UmP8LlBMpT6kj35EcmM/QHylgf6ljIGEuzgMG4U0EUYaOtf jhqWupKi5OXkqoxvrKZQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZb38-0002Ma-3N; Fri, 15 May 2020 14:10:54 +0000 Received: from mga11.intel.com ([192.55.52.93]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZb34-0002Ek-Ij; Fri, 15 May 2020 14:10:51 +0000 IronPort-SDR: Uo6Fg5hh8bnsVlKrCQ7prmJHLHxgpWWe1d1isFlzh/3j8fOP80maXdVB3ArdRESTU7a7vHT5ZT mi0w51bTFxJA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2020 07:10:49 -0700 IronPort-SDR: 54TbqBR7CXjYDsu+yd9jQlAkaAjG99wMxI2ia8etFYijKsxS7dIc+1yj3hatPR1kLCRXXsU3Hi WXtG+gio5/OQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,395,1583222400"; d="scan'208";a="372701841" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga001.fm.intel.com with ESMTP; 15 May 2020 07:10:44 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jZb30-006sqV-VP; Fri, 15 May 2020 17:10:46 +0300 Date: Fri, 15 May 2020 17:10:46 +0300 From: Andy Shevchenko To: Serge Semin Subject: Re: [PATCH v3 4/4] serial: 8250_dw: Fix common clocks usage race condition Message-ID: <20200515141046.GF1634618@smile.fi.intel.com> References: <20200323024611.16039-1-Sergey.Semin@baikalelectronics.ru> <20200506233136.11842-1-Sergey.Semin@baikalelectronics.ru> <20200506233136.11842-5-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200506233136.11842-5-Sergey.Semin@baikalelectronics.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200515_071050_631871_3739419E X-CRM114-Status: GOOD ( 17.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Kefeng Wang , Thomas Bogendoerfer , Catalin Marinas , Arnd Bergmann , Paul Burton , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Russell King , Serge Semin , Alexey Malahov , Long Cheng , linux-mediatek@lists.infradead.org, Ralf Baechle , linux-serial@vger.kernel.org, Jiri Slaby , Heikki Krogerus , linux-mips@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, May 07, 2020 at 02:31:35AM +0300, Serge Semin wrote: > The race condition may happen if the UART reference clock is shared with > some other device (on Baikal-T1 SoC it's another DW UART port). In this > case if that device changes the clock rate while serial console is using > it the DW 8250 UART port might not only end up with an invalid uartclk > value saved, but may also experience a distorted output data since > baud-clock could have been changed. In order to fix this lets at least > try to adjust the 8250 port setting like UART clock rate in case if the > reference clock rate change is discovered. The driver will call the new > method to update 8250 UART port clock rate settings. It's done by means of > the clock event notifier registered at the port startup and unregistered > in the shutdown callback method. I'm wondering if clock framework itself can provide such a notifier? > Note 1. In order to avoid deadlocks we had to execute the UART port update > method in a dedicated deferred work. This is due to (in my opinion > redundant) the clock update implemented in the dw8250_set_termios() > method. So, and how you propose to update the clock when ->set_termios() is called? > Note 2. Before the ref clock is manually changed by the custom > set_termios() function we swap the port uartclk value with new rate > adjusted to be suitable for the requested baud. It is necessary in > order to effectively disable a functionality of the ref clock events > handler for the current UART port, since uartclk update will be done > a bit further in the generic serial8250_do_set_termios() function. ... > + struct notifier_block clk_notifier; > + struct work_struct clk_work; Oh, this seems too much. Perhaps, the compatible based quirk with your initial approach is much better for time being. -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel