Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2058050ybg; Fri, 5 Jun 2020 04:39:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCQL5tLRA8icNFLbKBpIl9zV6lE4q5RDyfV7H9NtlN//77q05L9ZnVkQTOJyDD1L+D2mS1 X-Received: by 2002:a17:906:f0e:: with SMTP id z14mr8107383eji.375.1591357157086; Fri, 05 Jun 2020 04:39:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591357157; cv=none; d=google.com; s=arc-20160816; b=gYrm8ygfAhXyO869wq/lwWNvfu3LQy1zf/OQ1LY9/9kzg2/kXfi70Hd+O5Sg43vNqN RjKgNe9Tm7MHfDL24QSeir29ulc+LYdZV8m65Go1KO5+hq1ZnmRhbhOARAcwcHjQFGgA I5nxl7ckxitBZd6OXeoIRuJ5WbxrjR1/sqURv+ZCZkZ9JzGwnedb2Gxy+LsCJ9BCcFjP YkTju8PBvbeFlAEeZeYhRAduSjH73gQvXBU/uJxzeysdOINmMaWDNNiQfF/lWtjqTx5k khO55u9V1PrHEMxeuMSYx0CGmN92CfpoMftaUtYYoMmfvOH9JENcW2dVxFhZ/XBORzlb L4Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=9LSZ7i55NIBjM6PDkRqwLJgn/TdrxESAx7DDvuKZ3K0=; b=tDlvsYn+nt9fM9g71IwHnbEBCx81qGXNLmkoXdGdGHONDECHxhOLEmnk4ZqSRAlVgF BJy9XJY5clH6tIDRArsNJUrE2A2fD6562WMCIyXithNuAyytvU0fWj3tKJIci2P/y7Vb dZmm948uT3vfVzf3aYmk1nD9G9kbEv/janSHipAXA/kZve7fNYtwRnPj9p8tbBEbJqXF Jw9UlspanRfbfMl14M8HMcGoSKityUry5ubf8/mDp1s01a1Qzx3lLq5y1/rlUdRWKXkP l2lWO0k4XcfTZNpH6f3EWUNqVFuUmdmm+vETZ40309JhoFUBBDRaozcYZeePZKOXSGA8 YF/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x24si2661503ejs.448.2020.06.05.04.38.53; Fri, 05 Jun 2020 04:39: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726413AbgFELhB (ORCPT + 99 others); Fri, 5 Jun 2020 07:37:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:35686 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbgFELhB (ORCPT ); Fri, 5 Jun 2020 07:37:01 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1854AAD76; Fri, 5 Jun 2020 11:37:03 +0000 (UTC) Date: Fri, 5 Jun 2020 13:36:58 +0200 From: Petr Mladek To: "chengjian (D)" Cc: linux-kernel@vger.kernel.org, chenwandun@huawei.com, xiexiuqi@huawei.com, bobo.shaobowang@huawei.com, huawei.libin@huawei.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org Subject: Re: [RFC PATCH] panic: fix deadlock in panic() Message-ID: <20200605113658.GL22497@linux-b0ei> References: <20200603141915.38739-1-cj.chengjian@huawei.com> <20200604082947.GB22497@linux-b0ei> <7b6f8522-f9b2-29e8-2dde-3bbfac19335b@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7b6f8522-f9b2-29e8-2dde-3bbfac19335b@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2020-06-05 18:42:57, chengjian (D) wrote: > Hi, Petr > > On 2020/6/4 16:29, Petr Mladek wrote: > > > It might cause double unlock (deadlock) on architectures that did not > > use NMI to stop the CPUs. > > > > I have created a conservative fix for this problem for SLES, see > > https://github.com/openSUSE/kernel-source/blob/SLE15-SP2-UPDATE/patches.suse/printk-panic-Avoid-deadlock-in-printk-after-stopping-CPUs-by-NMI.patch > > It solves the problem only on x86 architecture. > > > > There are many hacks that try to solve various scenarios but it > > is getting too complicated and does not solve all problems. > > I have read your conservative fix and I have some question, > > 1-- does the console_sem need to be reinitialized ? No, it is not needed: + printk() itself does try_lock() and skips console handling when the semaphore is not available. + panic() tries to push the messages later in console_flush_on_panic(). It ignores the semaphore. Also most console drivers ignore their internal locks because oops_in_progress is set by bust_spinlocks(). > 2-- Other architectures without NMI, is there no such problem ? The situation is more complicated when NMI is not used. Non-stopped CPUs are in unknown state, most likely in a busy loop. Nobody knows whether printk() is repeatedly called in the loop. When it was called, re-initializing any lock would cause double unlock and deadlock. It would be possible to add some more hacks. One problem is that there are two groups of users. One prefer to risk a deadlock and have a chance to see the messages. Others prefer to always reach emergency_restart() and reboot the machine. This is one big motivation for working on lockless printk(). Best Regards, Petr