Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp607013rwb; Fri, 13 Jan 2023 01:46:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXtLRRJJTk4w0UvjKOX7DQfx64EZ1ttrIxYSF/wSQa8ma66uQ7ENHdhopnWNfJ7R07mrTU5q X-Received: by 2002:a05:6402:793:b0:493:597e:218b with SMTP id d19-20020a056402079300b00493597e218bmr22599612edy.39.1673603184450; Fri, 13 Jan 2023 01:46:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673603184; cv=none; d=google.com; s=arc-20160816; b=InlJuGqdouCNO3aJDRGvkxOB4IgGsLKdvo4vmTLnjNKVjeb3THC5RvkaojZdWmMx8l VF62J8GfeLq84nYjzFEPco4O3ym8Zw1ZkwXyYYALpzfSHwrRd31w3SGJI9mbmucFGs36 cqkhKw5ssjw324y+nrhmXVBTx/Ewucg1Vrdy7gUPgHDV1Qr1pEgEIHAXPNgzb0gn4Gdt 3VDEC2nG0Lta7ayXiTioWdlooShaRmE3Bc14dB/fiPx3pyBLR5co9/UMa4z4HfB6usM4 3mL34H92E5/ffETM5nV8Den4+yE0jjc8UmL7n+Ly/gWq75gZ13Wah9SrVpzWHFC4x9mF i6lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=22DFHnDxPptAxbZRoG0bfrp/Xo+pGFjmLGSMAbfetfs=; b=paLqj2tIha/1kvRP9+sPgiJWRGI7IKt9yHHhHLw7rIMtnHY41SYf5VDXfhhRUofdNq hwFc9gKGLgM8hs0Pn7lmzhJChVbkcrgI+qiy1eDddhHDXhG/7szz+L7qx77zXtgjGJAP qJnTnlyREq/efHCh0XqMaVY6L36LhXtemqRtP3Frb/54vGB0NR1lKFkqEzJYnUyw81vc ilGRvNOlZweeuHnRpyffrN21GGLUBfkyHK+lXgTqbYpBZU8sDk1GmAOlEOc50DuGN6WT 5YEkRj4dg1tt8MA4ZqyPWOcajO0ljWMXxUqndNENtkFBN8yJP8nlul6G4He/XYnzizOM hquA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=OeKmqSXK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a05640226d500b0046de8e02697si24834170edd.239.2023.01.13.01.46.12; Fri, 13 Jan 2023 01:46:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=OeKmqSXK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240593AbjAMJUN (ORCPT + 51 others); Fri, 13 Jan 2023 04:20:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233125AbjAMJTR (ORCPT ); Fri, 13 Jan 2023 04:19:17 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45BB8EA2 for ; Fri, 13 Jan 2023 01:14:02 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D131B4ECED; Fri, 13 Jan 2023 09:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673601240; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=22DFHnDxPptAxbZRoG0bfrp/Xo+pGFjmLGSMAbfetfs=; b=OeKmqSXK6BMh1+XSb4Yht+FwtZ3vbNAUYn424dWwVqnXft2E2H2qY4xnZSv22j+3Fcid6W qxBw9EAKsq2DQhg2mMhVMuPEGYRmGDmvhiXWmQmur3NNywDeUBr0Dmd35RlipU3MLxMox7 9MDbEt0p7ut324nkAcMAKEvRCh42KMQ= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 576AB2C141; Fri, 13 Jan 2023 09:14:00 +0000 (UTC) Date: Fri, 13 Jan 2023 10:13:59 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: Re: [PATCH v2] tty: serial: kgdboc: fix mutex locking order for configure_kgdboc() Message-ID: References: <20230112161213.1434854-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230112161213.1434854-1-john.ogness@linutronix.de> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2023-01-12 17:18:13, John Ogness wrote: > Several mutexes are taken while setting up console serial ports. In > particular, the tty_port->mutex and @console_mutex are taken: > > serial_pnp_probe > serial8250_register_8250_port > uart_add_one_port (locks tty_port->mutex) > uart_configure_port > register_console (locks @console_mutex) > > In order to synchronize kgdb's tty_find_polling_driver() with > register_console(), commit 6193bc90849a ("tty: serial: kgdboc: > synchronize tty_find_polling_driver() and register_console()") takes > the @console_mutex. However, this leads to the following call chain > (with locking): > > platform_probe > kgdboc_probe > configure_kgdboc (locks @console_mutex) > tty_find_polling_driver > uart_poll_init (locks tty_port->mutex) > uart_set_options > > This is clearly deadlock potential due to the reverse lock ordering. > > Since uart_set_options() requires holding @console_mutex in order to > serialize early initialization of the serial-console lock, take the > @console_mutex in uart_poll_init() instead of configure_kgdboc(). > > Since configure_kgdboc() was using @console_mutex for safe traversal > of the console list, change it to use the SRCU iterator instead. > > Add comments to uart_set_options() kerneldoc mentioning that it > requires holding @console_mutex (aka the console_list_lock). > > Fixes: 6193bc90849a ("tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console()") > Signed-off-by: John Ogness > Reviewed-by: Petr Mladek JFYI, the patch has been committed into printk/linux.git, branch rework/console-list-lock. I am going to give it few days in linux-next. If there is no problem I will send a pull request for 6.2-rc5 later the following week. Please, let me known if you have another preference. Best Regards, Petr