Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp947170ybb; Wed, 1 Apr 2020 12:37:01 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu34VgwvZ29oNyzoZl0HjcxDWouMbyW0pVRMw1+5OZdjyQjt9EJBABQV6spenYs72487pqo X-Received: by 2002:a9d:6744:: with SMTP id w4mr18171686otm.220.1585769821239; Wed, 01 Apr 2020 12:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585769821; cv=none; d=google.com; s=arc-20160816; b=al4936EiMOOnjsrpmGiI0xY2EnkrgsnufUaZ8vxC6xtIzE0JpHS8hhKetKuJXMX8ZX w/jcUbH+zbx1pWofAxGUDQ4e0e015+HXUFyVgpxN2PRwR/CJzGwQK4KseZ0/ov++R0wf VtPYQIkcUSdaHF9ZJODOGH31TrKoJKR82tx9M0WD5mLTJKcTV3JMC6nn/GeeZNXzrqnv qi7Ag7LXh2EmVrceSwPG6OxCshtzkjZBBYZLcKu861MfIhAzwFhVdMp8VD1Pg2txCC2r AsFxZ6rMRUjG3GCtQtX2BeACz/4nr+Ej72OhIq/aBU/XP8mZV6ia/iJBtATx4Yurv55M Gg1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=4k3vO/gmHNH9BUyuJdIiMLOYo/c54ufu3YUkaQPTZh0=; b=gLCvK4H+rwPYrIkyV6OSjfhnBbGr1ye4p6zu0gPaUFVFJkjWzjEIvbAxQnMTWbICTt 5CnAQYKiqDuUzKROZxlUwmobB5868l2Z2FFCpSwm1TZ3/OlVfWiU7XUR8tsub5s2vbRT 57T2PjnwSTnF0wZQDUt+GVSRfB173ZyHuujIgrFChy8rMXIls6zEQjRBgxqpTDk3DwnE SeNpe6aw2+KxjxWu9o8hVuz6Y8YUE4xYIwgxfSWzaSu7rls2iMGb5buaN5xlGdwR9mvN SqxtGRAsGJ74R0Aw0yYZ/4PX+kfQ7CVCX/8Hf34yDcIZnoNalnNJ5SmTYaWo8YkwA6Wg 5R4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="re/SlJNS"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si1229187oij.227.2020.04.01.12.36.30; Wed, 01 Apr 2020 12:37:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="re/SlJNS"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732737AbgDATe7 (ORCPT + 99 others); Wed, 1 Apr 2020 15:34:59 -0400 Received: from mail-lf1-f41.google.com ([209.85.167.41]:38053 "EHLO mail-lf1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732148AbgDATe7 (ORCPT ); Wed, 1 Apr 2020 15:34:59 -0400 Received: by mail-lf1-f41.google.com with SMTP id c5so720527lfp.5 for ; Wed, 01 Apr 2020 12:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4k3vO/gmHNH9BUyuJdIiMLOYo/c54ufu3YUkaQPTZh0=; b=re/SlJNSwxj4p7FegGdRYaiRGHLXkQdVNLPVVld1YPr2vq1CxKdQn3AovLURrdbajn 3Xo6b8vWorZ6qc+3hhX90ygDdQ95BBHcEpgZnx2YMbAbz5zp0UO5tDrBC09IV0Rz0AQZ mHZhB0f7sc10ksckpD7nlQp53AvGIdEHvhacVwZjkNxIQMn72xmomeUMQrrZtpmwlLob chVEzDTJ1uY9xDFRk4n3MOdVtR/MREJq1jjenkZl2XQfjkavvMyNIv34TYyipOR+TWl8 EoevKS+PUTr6mOau0aAQqzcNLxYILGS/uuB+QHlBCvZiTRGPfgIPLXxw3wufoeWYLpT1 SKDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4k3vO/gmHNH9BUyuJdIiMLOYo/c54ufu3YUkaQPTZh0=; b=JLjQiLMz7rz3VpP+sxmcNvHIplpjNQVLTI7W1fJtYNMJ9VdaznFTeGVsNoLaqYfH99 ScuFljbJio2U4AACvAxzAYBrCkr0zL7q7TrXazmvsov4YJX76tAgkQ4CpXFJV1aGXElN fCcm0dd9QeJ1KNHddbNn6R98gsZahZFrTfZrC/HgjMIHiuWUW0CT1NZDsai+DfC48TQ0 w+qM3r/+d/GO4zjRrWbJBer670sxZ8LEVxZfUl8UeU8eHBDdnihJfm3adZejVz9CJBzD gAPPQGiJ3BaD2cgH3ozAysBt5Nu4QTr6EpxFt5wiVeemfSR48n9NG1hosC0BWO0zrJ/x LnOg== X-Gm-Message-State: AGi0PuaSEdpWOEK2xp+1PtSDTTzeW0YI7n90oncXDgMFHmi8td4UVjg9 3blN3iC5bAALzpYChvtG5Sk++1tVV8eBjEhfX27dpb6X X-Received: by 2002:a19:6e47:: with SMTP id q7mr12252555lfk.164.1585769696172; Wed, 01 Apr 2020 12:34:56 -0700 (PDT) MIME-Version: 1.0 References: <20200303113002.63089-1-sergey.senozhatsky@gmail.com> In-Reply-To: <20200303113002.63089-1-sergey.senozhatsky@gmail.com> From: Jann Horn Date: Wed, 1 Apr 2020 21:34:29 +0200 Message-ID: Subject: Re: [PATCHv2] printk: queue wake_up_klogd irq_work only if per-CPU areas are ready To: Sergey Senozhatsky Cc: Petr Mladek , Steven Rostedt , kernel list , Lech Perczak , Greg Kroah-Hartman , "Theodore Ts'o" , John Ogness Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 3, 2020 at 12:30 PM Sergey Senozhatsky wrote: > printk_deferred(), similarly to printk_safe/printk_nmi, > does not immediately attempt to print a new message on > the consoles, avoiding calls into non-reentrant kernel > paths, e.g. scheduler or timekeeping, which potentially > can deadlock the system. Those printk() flavors, instead, > rely on per-CPU flush irq_work to print messages from > safer contexts. For same reasons (recursive scheduler or > timekeeping calls) printk() uses per-CPU irq_work in > order to wake up user space syslog/kmsg readers. > > However, only printk_safe/printk_nmi do make sure that > per-CPU areas have been initialised and that it's safe > to modify per-CPU irq_work. This means that, for instance, > should printk_deferred() be invoked "too early", that > is before per-CPU areas are initialised, printk_deferred() > will perform illegal per-CPU access. > > Lech Perczak [0] reports that after commit 1b710b1b10ef > ("char/random: silence a lockdep splat with printk()") > user-space syslog/kmsg readers are not able to read new > kernel messages. The reason is printk_deferred() being > called too early (as was pointed out by Petr and John). > > Fix printk_deferred() and do not queue per-CPU irq_work > before per-CPU areas are initialized. I ran into the same issue during some development work, and Sergey directed me to this patch. It fixes the problem for me. Thanks! Tested-by: Jann Horn