Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp133886pxb; Mon, 31 Jan 2022 17:23:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1nfnZDOH/O6YibIjVkrfMTt3MOsPqZFpHfjOdsfWd8xzHONndmmSTak27rq0rOjptDnCU X-Received: by 2002:a17:907:7f1b:: with SMTP id qf27mr18320233ejc.114.1643678583944; Mon, 31 Jan 2022 17:23:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643678583; cv=none; d=google.com; s=arc-20160816; b=iGrYv1g4I4vJCcSARaNvnDJ9qEPoO1M+h18HdNZ9azN0iDJkHfRJKBsHTYj/gGwZE1 4tqtiP9xfd2JpXQlEuTYWLRDkLEQdatslx33wvf14azmXwE8tdHwoq0BHsK/t3Lql3Pg Vae4U8CLVQzaDsvsn2qo/XosMOTK6QqlnNzPc+qOieui8lP59UR6JJ6Fdylpyup5z1Y+ 6AMPrGv+tf7vASB3J47tj5Z0zwofyk41bNfy54GQYBuvYbuPpu3zAyVSM9s5QCl5YDRX eKrIaEa+ReQ6iEm7MPMZ5mp/hf5dLS7qAykDAQnoPERh/f9TH1ipW4pEY6isFmso4uFq wscg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :mime-version:user-agent:date:message-id:cc:to:subject:from :dkim-signature; bh=e1+s0tV2NM8ycsoAVvvJcxRRSB8Uzk8N0RZeeZJQsso=; b=H2xMRizAntHTEuc5W71yTFjj4/D4zF6tNIz4SufosHhrWnlgjG13j/rK4nwyfa/lI1 PSbnuGbaGvnTbrpudcCakP1EdpXxEYcq/Tf4MdzwubT1X7EecYo8TTGGieBnnhSSpM+0 aS0SNCJWQCnXxRw7eIeZ7B3TRRcO1hWMTL74n8ijrC3ONOQZaQWvzaqHFnNITLqkA3Y2 E1AZ5H7Q47z37ENkWU9XyjxK/zWCxV2wlVeAirNwvdTseM6rZ9yd+kT4J1O0UZW/QSIM ynf/vkvOuoudli0SLz+5xXSaz+3j6yq8fwGYf4RyzRfh2zyturYPHlj+EQEaT9K9OMeZ nFog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kt6gKqVA; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si9785396edc.425.2022.01.31.17.22.37; Mon, 31 Jan 2022 17:23:03 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=kt6gKqVA; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234122AbiA2JeK (ORCPT + 99 others); Sat, 29 Jan 2022 04:34:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233096AbiA2JeI (ORCPT ); Sat, 29 Jan 2022 04:34:08 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF153C061714; Sat, 29 Jan 2022 01:34:08 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d187so8348996pfa.10; Sat, 29 Jan 2022 01:34:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=e1+s0tV2NM8ycsoAVvvJcxRRSB8Uzk8N0RZeeZJQsso=; b=kt6gKqVAY+cBpVjOfFNLBtBUEc8nMw7OglSpM5bVIByxFuPLATjnZfWszxFv4vLKFI HhcIjvxG58KoWPX1vd0lcVTpsESMIOrQkArVC5RgQQ3zm3A8vQlaCgpsoVNsAzbI/CU3 ofV7vEKM6gB/7JpRPSRS23+tnJ9swYc9/S896sL1V14fjVU33a/mgIj7PutG9sLIqmFC AxYxJ7Itm2400CqMSnWo2wk7V8CdNmiNe4FIPG1GoTuEAyu+PCJVfeKlt8oMHL/TsZab WWM9jvNmaOaErCNSoqGHe0pI3wtBv2/Cnm/bdZ6TAkD2qIQgsPnzlM8JcpJCR3Li4fEx AOAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=e1+s0tV2NM8ycsoAVvvJcxRRSB8Uzk8N0RZeeZJQsso=; b=RpzRgambnnmNhwTb+6rb/qXFzC8hP7yBsp7cRgIGcX/E5fYUAclNa7RmaOW7feqEML P7emCofh4slCsuhj0kV1zHL4KPuVsmfxtlSZiS8dF6lwBc7idD893n1YwlpS1HQNWICp steejZ3Y9Wu74tHO8dRHoPiceLxj5wNqbMnIJi/d4XljPts8HTfk762NXoX5s8ttIsbq J6n2CCv09RGy+Ceegrn8T0fpH8sZvpIR02GjAUkD0XY/6nyB3ILIK8ZGR7nl7c9Yb9w2 vl30//Ve21/Ba1+5QbcwUNn5ilXPW5NMRNvJT6wWWOQxbMCvmBe6ZVYEs4DCyUn08//t MeYg== X-Gm-Message-State: AOAM533VbrgLJcuw8MnIPXEtr3itAzTqarvozpbCkQ568Ya8ZxOqLz4J le5/f+XnHzP/2MP6TzwRcXLSLGS8gYY= X-Received: by 2002:aa7:95b2:: with SMTP id a18mr11718184pfk.39.1643448847776; Sat, 29 Jan 2022 01:34:07 -0800 (PST) Received: from [192.168.1.101] ([166.111.139.99]) by smtp.gmail.com with ESMTPSA id x17sm11160250pfu.135.2022.01.29.01.34.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Jan 2022 01:34:07 -0800 (PST) From: Jia-Ju Bai Subject: [BUG] tty: serial: possible deadlock in uart_remove_one_port() and uart_hangup() To: Greg KH , jirislaby@kernel.org Cc: linux-serial@vger.kernel.org, linux-kernel Message-ID: Date: Sat, 29 Jan 2022 17:34:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, My static analysis tool reports a possible deadlock in the tty driver in Linux 5.10: uart_remove_one_port()   mutex_lock(&port->mutex); --> Line 3017 (Lock A)   wait_event(state->remove_wait, ...); --> Line 3019 (Wait X)   mutex_unlock(&port->mutex); --> Line 3021 (Unlock A) uart_hangup()   mutex_lock(&port->mutex); --> Line 1667 (Lock A)   uart_flush_buffer()     uart_port_unlock()       uart_port_deref()         wake_up(&uport->state->remove_wait); --> Line 68 (Wake X)   mutex_unlock(&port->mutex); --> Line 1684 (Unlock A) When uart_remove_one_port() is executed, "Wait X" is performed by holding "Lock A". If uart_hangup() is executed at this time, "Wake X" cannot be performed to wake up "Wait X" in uart_remove_one_port(), because "Lock A" has been already hold by uart_remove_one_port(), causing a possible deadlock. I am not quite sure whether this possible problem is real and how to fix it if it is real. Maybe we can call wait_event() before mutex_lock() in uart_remove_one_port(). Any feedback would be appreciated, thanks :) Best wishes, Jia-Ju Bai