Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4592177pxj; Wed, 12 May 2021 08:51:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaTGP6DpiTDvVLgU7w6Xwq9WORn52Pijf5HjvON/PFkCZhX5fkHV0M+FDz1GKRDwMJuUzI X-Received: by 2002:a17:906:5488:: with SMTP id r8mr10111486ejo.374.1620834677544; Wed, 12 May 2021 08:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834677; cv=none; d=google.com; s=arc-20160816; b=cFprVu0e2T3cfE2s1mVo9QJ3LkC78XrOq7TcT5MfMgjMnmpaeJZoGyc9BUXK2MXrxM 18fT887Q1SovF43HuXg/spFHAGpuYNyqOp58a/pHgnwgsQXf3RVkudEZpAjqy/t9ZPSB 5lgPoPM+Uzfv4TcbahYDYU2NtwHXLYaWhmIsnvyhW0Ke2+yHALujzPCiShlfIVH6ZJLp FDCJK5XlaI1SljaGrIsGRx1C/VLpui81Jl6BI1EY1egTwCKUi7ZJmAJATaJ/Dk+uFf6R Ujd4thsqmNmnGj/TgKBDUXMdcxTS7PS+g3pMn0cHGDczqBKm1C8Sebj/fpBDhQXl3S3U AO5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aMMS1ckOpoXhx0/3XEeIiAWFORkAky7IKmfw42Gdc5A=; b=oUVa/gdzfljztz4t7j14i9J1I3jnEqveP65aEAdEDex6/skoSUYB0A8gQoPOHwrPzi s99qknhzAcLEG47lhvXdc1UQzpnrKORQqm0tobfjsOpqB75RMPnpv5cKq4MggSKeHVa4 X6tBqQFRvkr2fKL9PyTmfchrbNMSGZGGNhqOjxuBAvi0BHgDevPqD7QHzGk5Kl8R3ldq vX949SX/AJZx7imFLf2d/LJvfKygTxIoTYsEt76lkqq//Lq+hCP62QXbhBiQj7Q6hllK EDXvbFeSrBd6FqUZNPw1cs2GjmPcxfnUBYZ6Cp5Op1v13dDHA1VKajbuOw9fKFbSM2vp 1FPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CrI4b69w; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh4si262903ejb.56.2021.05.12.08.50.53; Wed, 12 May 2021 08:51:17 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CrI4b69w; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235824AbhELPpT (ORCPT + 99 others); Wed, 12 May 2021 11:45:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:60306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234629AbhELPUH (ORCPT ); Wed, 12 May 2021 11:20:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8C0C2619A3; Wed, 12 May 2021 15:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832092; bh=4CyxnMvVLxRt5bRTu4GPSWoOUFR5aL5t4joZXO2w+PM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CrI4b69weaMiwOE44jj8GK760xk6eZAsH75f5PnaLzMBWA/nILRieP3d/Btg2lF0A r5MzDGMWXysI++/eeOTnQKhyDpb7tL74Kzb3LYsDZfHs5JEhsQSHLdCY56cDuynQK4 U9gUGdlFgx51obhp6qc18kr1h+VvhmBKMeunr+TM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erwan Le Ray , Sasha Levin Subject: [PATCH 5.10 137/530] serial: stm32: fix a deadlock in set_termios Date: Wed, 12 May 2021 16:44:07 +0200 Message-Id: <20210512144824.323816400@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Erwan Le Ray [ Upstream commit 436c97936001776f16153771ee887f125443e974 ] CTS/RTS GPIOs support that has been added recently to STM32 UART driver has introduced scheduled code in a set_termios part protected by a spin lock. This generates a potential deadlock scenario: Chain exists of: &irq_desc_lock_class --> console_owner --> &port_lock_key Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&port_lock_key); lock(console_owner); lock(&port_lock_key); lock(&irq_desc_lock_class); *** DEADLOCK *** 4 locks held by stty/766: Move the scheduled code after the spinlock. Fixes: 6cf61b9bd7cc ("tty: serial: Add modem control gpio support for STM32 UART") Signed-off-by: Erwan Le Ray Link: https://lore.kernel.org/r/20210304162308.8984-8-erwan.leray@foss.st.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/stm32-usart.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 85e9a4d4e91d..44522ddc7e6d 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -827,12 +827,6 @@ static void stm32_usart_set_termios(struct uart_port *port, cr3 |= USART_CR3_CTSE | USART_CR3_RTSE; } - /* Handle modem control interrupts */ - if (UART_ENABLE_MS(port, termios->c_cflag)) - stm32_usart_enable_ms(port); - else - stm32_usart_disable_ms(port); - usartdiv = DIV_ROUND_CLOSEST(port->uartclk, baud); /* @@ -914,6 +908,12 @@ static void stm32_usart_set_termios(struct uart_port *port, stm32_usart_set_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); spin_unlock_irqrestore(&port->lock, flags); + + /* Handle modem control interrupts */ + if (UART_ENABLE_MS(port, termios->c_cflag)) + stm32_usart_enable_ms(port); + else + stm32_usart_disable_ms(port); } static const char *stm32_usart_type(struct uart_port *port) -- 2.30.2