Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2977483imu; Mon, 19 Nov 2018 08:53:40 -0800 (PST) X-Google-Smtp-Source: AJdET5dfFI/auaT5xmzGgH6ANdjuTNsCNhECc5IVoCu9pnTeXIbzyWoQexUmPrffCeY74nMe6g1m X-Received: by 2002:a17:902:503:: with SMTP id 3-v6mr23543492plf.88.1542646420364; Mon, 19 Nov 2018 08:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646420; cv=none; d=google.com; s=arc-20160816; b=TSXEfZ+6LXM/SRJpB1n/NPiqe7JEfHPiBUlOzDfSSZcZmfoc4lMz8AmY2WlArnnw6v gXMxUN7ZInk+JEWylUZUe3kurh97TG0n9USjs7cLtCIMg1iaivWE+1tNT2SvtRRqnq1g Bd4gQe+APDTRGwD/vSvALP0TfrVoTMXRTrQsT0t1iw1fVdKT0YjFRUW5nd6SZa4sBb1P tI1jnVKwd+tSDCwligjsZ+QJXCW/HSHVrNIM9IlWGJx5QLRHfTfCLlToOuJoQZNUw9be jAfIKfY0suXtWC17WofI2saTZwjH01UvFjslJDucQw0AU09/26h0m0el8ZS1HaLuVu2K AihA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ja/qcHuRN4O6t2zS021aNjKhvJ74BgCk4Je2NVwuLcE=; b=dnWeCkRQ3w9BTCh/lnlTVeUq7MKTRS/d7983OzlP6JUHRVd8JoKDQfv353BFS4oDok IkTzTnq3Pov5IVucCZIQY/aoHZDfh5aP4BQg78AbcdqDwvfynJwYoEwe9aYWVm2WYUdt 0m3zBKB4flUM+jh72D9EXEJTxPdKC09Tc5Qr+PjE3ND5HfY/iEHV9/a9jRyxIUNyJR+J 5bQbzJBBI6zvh9oDw7Os1NkCIaG8kF2glbVCTJKMwSGweEepFYin68Zj44P/Ef16twc+ rbquc0YiwemEU7qE0KPm5EuKm4FpFESSQbd79nwqIY46vb/8dx9IJC0I8KxUF3ll2kei DbXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="P/GGycTr"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si37480973pgk.49.2018.11.19.08.53.25; Mon, 19 Nov 2018 08:53:40 -0800 (PST) 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=@kernel.org header.s=default header.b="P/GGycTr"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390574AbeKTDQi (ORCPT + 99 others); Mon, 19 Nov 2018 22:16:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:54592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389669AbeKTDQh (ORCPT ); Mon, 19 Nov 2018 22:16:37 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B93DF206BA; Mon, 19 Nov 2018 16:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646344; bh=ZaTqkRDzuX80bSaBw9o7WamHx8Cg2aMsEJ3I/uvKuCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P/GGycTr1wkyqrJgXhKhGhYlGgeWoulV30JkUH16KnrWjwWwcpUrxBFPLaznayEbT T8b1yIXHO9BfgDAGOwuegtAPSiFoQ/WPEJW+MbNRubh0wHZux3JQf9JHlYj8CZEPu5 CGLuAoNYTmsqtwayhe4Ln1yGCp11JrqEdvv3UsZE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, Tetsuo Handa Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergey Senozhatsky , Tejun Heo , akpm@linux-foundation.org, linux-mm@kvack.org, Cong Wang , Dave Hansen , Johannes Weiner , Mel Gorman , Michal Hocko , Vlastimil Babka , Peter Zijlstra , Linus Torvalds , Jan Kara , Mathieu Desnoyers , Byungchul Park , Pavel Machek , "Steven Rostedt (VMware)" , Petr Mladek , Sudip Mukherjee Subject: [PATCH 4.14 122/124] printk: Never set console_may_schedule in console_trylock() Date: Mon, 19 Nov 2018 17:29:36 +0100 Message-Id: <20181119162634.061753162@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162612.951907286@linuxfoundation.org> References: <20181119162612.951907286@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sergey Senozhatsky commit fd5f7cde1b85d4c8e09ca46ce948e008a2377f64 upstream. This patch, basically, reverts commit 6b97a20d3a79 ("printk: set may_schedule for some of console_trylock() callers"). That commit was a mistake, it introduced a big dependency on the scheduler, by enabling preemption under console_sem in printk()->console_unlock() path, which is rather too critical. The patch did not significantly reduce the possibilities of printk() lockups, but made it possible to stall printk(), as has been reported by Tetsuo Handa [1]. Another issues is that preemption under console_sem also messes up with Steven Rostedt's hand off scheme, by making it possible to sleep with console_sem both in console_unlock() and in vprintk_emit(), after acquiring the console_sem ownership (anywhere between printk_safe_exit_irqrestore() in console_trylock_spinning() and printk_safe_enter_irqsave() in console_unlock()). This makes hand off less likely and, at the same time, may result in a significant amount of pending logbuf messages. Preempted console_sem owner makes it impossible for other CPUs to emit logbuf messages, but does not make it impossible for other CPUs to append new messages to the logbuf. Reinstate the old behavior and make printk() non-preemptible. Should any printk() lockup reports arrive they must be handled in a different way. [1] http://lkml.kernel.org/r/201603022101.CAH73907.OVOOMFHFFtQJSL%20()%20I-love%20!%20SAKURA%20!%20ne%20!%20jp Fixes: 6b97a20d3a79 ("printk: set may_schedule for some of console_trylock() callers") Link: http://lkml.kernel.org/r/20180116044716.GE6607@jagdpanzerIV To: Tetsuo Handa Cc: Sergey Senozhatsky Cc: Tejun Heo Cc: akpm@linux-foundation.org Cc: linux-mm@kvack.org Cc: Cong Wang Cc: Dave Hansen Cc: Johannes Weiner Cc: Mel Gorman Cc: Michal Hocko Cc: Vlastimil Babka Cc: Peter Zijlstra Cc: Linus Torvalds Cc: Jan Kara Cc: Mathieu Desnoyers Cc: Byungchul Park Cc: Pavel Machek Cc: linux-kernel@vger.kernel.org Signed-off-by: Sergey Senozhatsky Reported-by: Tetsuo Handa Reviewed-by: Steven Rostedt (VMware) Signed-off-by: Petr Mladek Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- kernel/printk/printk.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1763,12 +1763,19 @@ asmlinkage int vprintk_emit(int facility /* If called from the scheduler, we can not call up(). */ if (!in_sched) { /* + * Disable preemption to avoid being preempted while holding + * console_sem which would prevent anyone from printing to + * console + */ + preempt_disable(); + /* * Try to acquire and then immediately release the console * semaphore. The release will print out buffers and wake up * /dev/kmsg and syslog() users. */ if (console_trylock()) console_unlock(); + preempt_enable(); } return printed_len; @@ -2083,20 +2090,7 @@ int console_trylock(void) return 0; } console_locked = 1; - /* - * When PREEMPT_COUNT disabled we can't reliably detect if it's - * safe to schedule (e.g. calling printk while holding a spin_lock), - * because preempt_disable()/preempt_enable() are just barriers there - * and preempt_count() is always 0. - * - * RCU read sections have a separate preemption counter when - * PREEMPT_RCU enabled thus we must take extra care and check - * rcu_preempt_depth(), otherwise RCU read sections modify - * preempt_count(). - */ - console_may_schedule = !oops_in_progress && - preemptible() && - !rcu_preempt_depth(); + console_may_schedule = 0; return 1; } EXPORT_SYMBOL(console_trylock);