Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2012623imu; Fri, 14 Dec 2018 04:30:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/V7uTEzsjDs5t9qjm57qn44LNSbUF9H3IoC9grAkOl4S0WVRKolT6uEMplWQMFlC5COsjas X-Received: by 2002:a17:902:720c:: with SMTP id ba12mr2705833plb.79.1544790615997; Fri, 14 Dec 2018 04:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544790615; cv=none; d=google.com; s=arc-20160816; b=a9HDJOARimP14dA3M0ddzrORg6FznZtQRWGHwiRngx5tbwgCY+EDYwOW9sqoZpQYFu U67DpbeNpInQSCMXknDhcKs6E150hoUcZ3hpD75JzKNYfwTE/tG5yMeO/7mctamaJMRN KrBr07BrN3b0hC7sBxRMZKv0oiK2TJZm8OS4BHsTIqScZf+s1rOtsknjzElUaOnO8AQn Xqfml1uG9WqJesIDq1tgnT0erjGBglUAE+bRqr2If8MAxVC1RpLxCCEs4Z5/EB0QlHKL xsApETI+ERdrOLKRRnW4jDRLtCXPUPzHhFPRNaGQPX0qwh+mYqMsXnXGb3UHBdZNfFfG CNJg== 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=qywUVztQnacg8XzFKhAx6ijF/zAfgkmFWlKT7G69Dp4=; b=SbR99bYDQ+PlKxfn7bSxWT89ZUj2a3G5Y/KLlMFQumxla7SArO0sAmiEoiXk0Vkeme GMnn2fHZ0eZX6Okm2OoXRhUq3ivYIQ0SCw7aAN5ZM8M+Cmhdj35zL+xpDax9HoI7HHfq /fqjNrrpoinIIpP3kEi6jGYtlQeBDF0TrG7zeMsWJM1hs6pqVSVEk5K5kosYcw3Yl+OK epIxRVm05XViSBysskmbikwtUc5ZHKuo+Xewd3TGz+6Gxip4cJOD6SPn+CKAYw4C7mbm Oc5NbLv3awsm9c0e2qmlNBLUWzp3cYl4vpx3HHOR3EXrr+sVGsCtOcWh4ZCK0hWE+pTZ RevQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Bp/xMW6I"; 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 x66si4198550pfk.73.2018.12.14.04.30.01; Fri, 14 Dec 2018 04:30:15 -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="Bp/xMW6I"; 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 S1731751AbeLNM3M (ORCPT + 99 others); Fri, 14 Dec 2018 07:29:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:56718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731632AbeLNMKh (ORCPT ); Fri, 14 Dec 2018 07:10: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 F0103214C4; Fri, 14 Dec 2018 12:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789436; bh=hUSKX6QtDMM/2yYfXlWLjmNJTy3gjSXKRYg9BbN04W0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bp/xMW6IIQcop6u0QvZiZ+ZuAeQ6sF5T92QWHd3E+YruMgnewJL2K//i+PeUvYu9U zKrzq3bZd1/KW0MCbANDZyIhqjHWXG3wPbnS1Js+SPYjULWUFZM1OwA5WtOMPRKBS8 yLEH+4w6NP70/YQrktUj3g1Sd79CWrXipLiVy+gA= 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 , Sasha Levin Subject: [PATCH 4.14 82/89] printk: Never set console_may_schedule in console_trylock() Date: Fri, 14 Dec 2018 13:00:35 +0100 Message-Id: <20181214115733.737137210@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115729.658859279@linuxfoundation.org> References: <20181214115729.658859279@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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. ------------------ [ Upstream commit fd5f7cde1b85d4c8e09ca46ce948e008a2377f64 ] 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: Sasha Levin --- kernel/printk/printk.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2d1c2700bd85..2f654a79f80b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1902,6 +1902,12 @@ asmlinkage int vprintk_emit(int facility, int level, /* 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 @@ -1909,6 +1915,7 @@ asmlinkage int vprintk_emit(int facility, int level, */ if (console_trylock_spinning()) console_unlock(); + preempt_enable(); } return printed_len; @@ -2225,20 +2232,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); -- 2.19.1