Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp675067ybk; Wed, 20 May 2020 09:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdZQAMzj8QA26LoCfu8ITFcZQ+9/McUqBoOFxespSzWvbLfFXgyShngtfJGqu+Lo0Re6bs X-Received: by 2002:a17:906:a843:: with SMTP id dx3mr4072143ejb.396.1589991002109; Wed, 20 May 2020 09:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589991002; cv=none; d=google.com; s=arc-20160816; b=zI3VnPTqa2Qx4X6qc+0w7fsu31rWFObZ5Xd1QnyrG1dPGBTnHDsNs/3/NrMtaHS1od df4Oavsi0WllMRLDxnbhcmyJEqIRKAx2fmt/2/KxD1geZJM2AVcenL60RS1fWsIpV5Qx xfUh7yHQTpWD8W841ntH9AAsAfEkecZyrv7fObyPL2P87Wlo9iKLgipAfz04hdwvU6Wd 74hY5t92iqHhzVslcb7k4E5Un+AmkSRe0/LDrrr3ZrB1x6RdMRbyHb0tqGLlcfNYpa79 RYp3YDNK20wXoQ3Ccx42l+A/v83puyzVVGRoveh4wBLnK7975dxXEcWjZiGy+L8zcJF2 9lKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9X29AKPgSRTeiMIz2DwlUf1mEfOfpjq4CbjeVik0R4o=; b=XzfTOu31E6J2m1lt8w+6Gw2KdTZa73zj7I09TyK2+jJwtcIhVVElVUjVpR8AprCXT2 SAa51tgUV89sq+gWEBHmRdwfS5o1Ykhw+S/r5aNOSHcpUirvAFpoKklrI8nhClThsr+/ MnU2032UQ66YY9B6Qp80BvrCk0hZpn/BZCNf+FicS4xJv2hQ2h3YV0ViyDdUIy3dbC9g DfFGGS8bhG7uS9TugK6XkZq3AIqOM4i+I13JBCUljJKibhU6cmjHbghjsqEGqIA8Afv5 yqPfm4U/+8PGQsACYDXKO4shAA9NVoJL72uzMsTo6PKFD+HcpVv3ZH+FfY+12BwozmTc UTyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iw+6J6Fg; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v12si1973675ejj.109.2020.05.20.09.09.38; Wed, 20 May 2020 09:10:02 -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=@linaro.org header.s=google header.b=Iw+6J6Fg; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726845AbgETQH7 (ORCPT + 99 others); Wed, 20 May 2020 12:07:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbgETQH6 (ORCPT ); Wed, 20 May 2020 12:07:58 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B78D5C061A0E for ; Wed, 20 May 2020 09:07:56 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id w7so3680019wre.13 for ; Wed, 20 May 2020 09:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9X29AKPgSRTeiMIz2DwlUf1mEfOfpjq4CbjeVik0R4o=; b=Iw+6J6FgX1lHR29lNCdTgOctq5/M7Gc0d38gi8K7OqpVloK49QPxDCTKzIY/SHf3pA NR86MiOyzSa5vRCPbMbvLcxjJArIpH2gSYW1aS17shpcS5qAvwCKuWYkI+ji3KfLFwoA uHzaoVbgnYn5ChYIsKYqAlTMC35pEzunaBn6WqVgps/MxaSOu75nxh49qsBaDBH3nZRh 2s4AgH6/jqE+uf3uCiY4nVMio7e0R9wVv3VenxJBHdb6KZ2u9pXQPG5D+0UojobEU8YZ FsqHotBSEBi8gOYOwH4hElS8aCTxk0CRVP9HTbxMBPB/BdEBZM2driwhM3f1J8vUPFk/ rHaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9X29AKPgSRTeiMIz2DwlUf1mEfOfpjq4CbjeVik0R4o=; b=t7r+RcuLninuw/X61+xoC7tUSInTQpjB8R3pJw8YwKjOqcl/Stc8luTRX7gyl/pOPs Mgu8UlsMv38f3ZyXGgdd6R74P2OIrHV4JMFGAs1nGrTEFDMAatIs/cqhScd5e6v4AO/A NfbdKQ/oAujk/ezh+Enzl/K9ELHEzve2Y9N32r9266i7gQH4MlaFBFsfBq7xhGwG4aAT 8RalH/UFUZqf+x9lUl2/8lXZZ/F7NcJ3szlDhtUT/LssHLCCqDy5xmT+8P4uI21WN8T6 ZtKuG8AhtrIxB0zrSwKSKlncfDkjA+uAA97Y1Ex9wOjIuAWabEy3VlMgB+WIe+NUnB/e vxhA== X-Gm-Message-State: AOAM533tCNpWMT52aYGBw8ALFBsXb5Gy5mA6ZjhXVaQbPF7Q5MjfN7e8 QnOHY5IrjOmmz7PYXpuqKq28PQ== X-Received: by 2002:adf:a151:: with SMTP id r17mr4676896wrr.161.1589990875413; Wed, 20 May 2020 09:07:55 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id j16sm3292414wru.13.2020.05.20.09.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 09:07:54 -0700 (PDT) Date: Wed, 20 May 2020 17:07:52 +0100 From: Daniel Thompson To: Petr Mladek Cc: Sergey Senozhatsky , Sumit Garg , Jason Wessel , Douglas Anderson , kgdb-bugreport@lists.sourceforge.net, Linux Kernel Mailing List , Arnd Bergmann , Andrew Morton , Peter Zijlstra , Steven Rostedt , John Ogness Subject: Re: [PATCH v2] printk/kdb: Redirect printk messages into kdb in any context Message-ID: <20200520160752.mnkpptc2efscolcs@holly.lan> References: <20200514084230.GO17734@linux-b0ei> <20200515085021.GS17734@linux-b0ei> <20200515103308.GD42471@jagdpanzerIV.localdomain> <20200515134806.5cw4xxnxw7k3223l@holly.lan> <20200518092139.GK7340@linux-b0ei> <20200520042102.GA938@jagdpanzerIV.localdomain> <20200520093557.lwwxnhvgmacipdce@holly.lan> <20200520102233.GC3464@linux-b0ei> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200520102233.GC3464@linux-b0ei> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 20, 2020 at 12:22:33PM +0200, Petr Mladek wrote: > kdb has to get messages on consoles even when the system is stopped. > It uses kdb_printf() internally and calls console drivers on its own. > > It uses a hack to reuse an existing code. It sets "kdb_trap_printk" > global variable to redirect even the normal printk() into the > kdb_printf() variant. > > The variable "kdb_trap_printk" is checked in printk_default() and > it is ignored when printk is redirected to printk_safe in NMI context. > Solve this by moving the check into printk_func(). > > It is obvious that it is not fully safe. But it does not make things > worse. The console drivers are already called in this context by > db_printf() direct calls. > > Reported-by: Sumit Garg > Tested-by: Sumit Garg > Signed-off-by: Petr Mladek Reviewed-by: Daniel Thompson > --- > Changes in v2: > > + more detailed commit message > > kernel/printk/printk.c | 14 +------------- > kernel/printk/printk_safe.c | 7 +++++++ > 2 files changed, 8 insertions(+), 13 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 9a9b6156270b..63a1aa377cd9 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -35,7 +35,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -2036,18 +2035,7 @@ EXPORT_SYMBOL(vprintk); > > int vprintk_default(const char *fmt, va_list args) > { > - int r; > - > -#ifdef CONFIG_KGDB_KDB > - /* Allow to pass printk() to kdb but avoid a recursion. */ > - if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) { > - r = vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); > - return r; > - } > -#endif > - r = vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); > - > - return r; > + return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); > } > EXPORT_SYMBOL_GPL(vprintk_default); > > diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c > index d9a659a686f3..7ccb821d0bfe 100644 > --- a/kernel/printk/printk_safe.c > +++ b/kernel/printk/printk_safe.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -359,6 +360,12 @@ void __printk_safe_exit(void) > > __printf(1, 0) int vprintk_func(const char *fmt, va_list args) > { > +#ifdef CONFIG_KGDB_KDB > + /* Allow to pass printk() to kdb but avoid a recursion. */ > + if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) > + return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); > +#endif > + > /* > * Try to use the main logbuf even in NMI. But avoid calling console > * drivers that might have their own locks. > -- > 2.26.1 >