From patchwork Mon Nov 19 15:21:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 10688771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 001E013BB for ; Mon, 19 Nov 2018 15:22:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E340129F7A for ; Mon, 19 Nov 2018 15:22:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A93329F78; Mon, 19 Nov 2018 15:22:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1777229F6D for ; Mon, 19 Nov 2018 15:22:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A47B6B1B00; Mon, 19 Nov 2018 10:22:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 05F966B1B01; Mon, 19 Nov 2018 10:22:06 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E35536B1B02; Mon, 19 Nov 2018 10:22:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 9BBE66B1B00 for ; Mon, 19 Nov 2018 10:22:05 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id m1-v6so23678108plb.13 for ; Mon, 19 Nov 2018 07:22:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:to:cc:from:date :message-id:mime-version:content-transfer-encoding; bh=hrZYv6HZjG2fIHjbGNDuCnicltBINIuOY8SNCieNqsI=; b=l8gTbmMSWWzChGL1VAx5pW6W54v6IEC0YnEKncb6I1u4bgQp61sTWbEpxRlGDrv3IG /zQehSmhBuIm3zZIxqZetvHOGdb+Vzt2EsxH+e1YiiUrri3YUVkrGktpt+iJA5rVkJA9 qcxqLIRvSqlpc8E0HtgPW91Pep3tqHtbLv/xUIcBk4DzuWfT2k6WasKLGpq3vtZjRYR6 CYkqPHXW0yuJaUr3ip8/1mJWr6GILbp8lvdvXL+cj4KMnZAyjbegk8ctJ2p5qtCGwyln R0aiKij5fU1NAFO8nYefKO/Bxn9GozHaSv0TAo+7KfRgo4tLaIbSLIAk9cDYlbFCF+mn FetA== X-Gm-Message-State: AA+aEWZ1+lAR9DUjQBYn0h+0TbkhWZAkqI/hDghd6z91LveFe17Fhx+P gEwdhLR0+INHnykt7gtL4Ao/BC+wxdRJwN5f88cWpBk1UQ7N4PGtvoPsAA0E45IFGCeYxVTi5EK So/6GVczxmEOvVpKp1Ufww0+h+lOvHnP/12xGYPxHLsg99/7Ncrfr6+flpX1Lf54= X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr10289052plb.192.1542640925246; Mon, 19 Nov 2018 07:22:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/WnM0WCeXgQ7jQMQAcl4bHNXJi40hUq/F83r9iGHhmOv49eSo38DpKK3CPrJrfkM/6xzEXh X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr10288985plb.192.1542640924206; Mon, 19 Nov 2018 07:22:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542640924; cv=none; d=google.com; s=arc-20160816; b=XpPP/iH59FKZDk8TMJclpFoJ+J2LsIJ1aHgkNIfXr3l9BSqLAJWyGTQDMbGGLEMwx6 4NoTdI5CI2R1zghanWLSgYG6gXgj345P2d+8qOCbjLXwJZJBeQsWQiyR3cmyWk6XJtlZ jf6l3hwDmnb3sXoGhzmu5GsgmGzz+rqZUo5Q3DXIJxeTYrC/pkC6Yc8SmdX+xqzm0D6q SDditsoeZvfQTHpwAdg036kk1/5dKlJrXt9hysta8YvDpczaEPcnim3L1HIhb5XW2xh+ KbP03BfGmjmlM7m2RaSI/KiBLbm1FDFsFe1ZLWdKAEUhk38DaR6oi2Aqb6kv45vKVc/3 nFAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:from:cc:to :subject:dkim-signature; bh=hrZYv6HZjG2fIHjbGNDuCnicltBINIuOY8SNCieNqsI=; b=Cum8GN5ZGtoMVaF/0QCRI/95vdLv0+Qy/lIib6LgcUVdzb9/EtGvLfVXo3XyKcR6Jx iMgHpi1ZeeE6L28DcntPTAjzl7g4zN717Fdp5hj7ULeVMsXTyCKfS20sxR/qnrHF7alI dqW3WHaf9xdolrOdxs0oaMvlsn4xzxHfFPNzzBJQIQx9KIa1tYi7URmoDYGPc7EgWP5o Zu2Vk7BnISg7ZP2Rn276B7KBoXebAxsCtJZK+0sCnGk6WV8QOO9bc0548tfrfS1b3Qgp 98vS9TpX5jAEoXIIwOARf79P6auautlow7HV8f0rtXGR2MmyFEsVeC0oHCAfAWvNxpmu BTZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c4wPYE99; spf=pass (google.com: domain of srs0=oxtl=n6=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom="SRS0=OXTl=N6=linuxfoundation.org=gregkh@kernel.org" Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id y188si24144395pfb.59.2018.11.19.07.22.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 07:22:04 -0800 (PST) Received-SPF: pass (google.com: domain of srs0=oxtl=n6=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c4wPYE99; spf=pass (google.com: domain of srs0=oxtl=n6=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom="SRS0=OXTl=N6=linuxfoundation.org=gregkh@kernel.org" 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 5B5C0206BB; Mon, 19 Nov 2018 15:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542640923; bh=44SeKNnufLD8HBZMZvRVppZHl4jizVoNr7eTbYJCRmw=; h=Subject:To:Cc:From:Date:From; b=c4wPYE99mZpGx1wloe8ASuhcP49JRP/dur5KKbHU5H+FypHueVOqIos0o68tP4BCS 9oGT5lh3Eybu/LJ47GFhi0luvNgrq+Ar7QoF4SO76vCPHPcBQP6Yso6uZVJ9gNS2D/ S8c6xFWf0qf8YV+qkybGN3AVakJctWaibP7UdpYo= Subject: Patch "printk: Never set console_may_schedule in console_trylock()" has been added to the 4.14-stable tree To: akpm@linux-foundation.org,byungchul.park@lge.com,dave.hansen@intel.com,gregkh@linuxfoundation.org,hannes@cmpxchg.org,jack@suse.cz,linux-mm@kvack.org,mathieu.desnoyers@efficios.com,mgorman@suse.de,mhocko@kernel.org,pavel@ucw.cz,penguin-kernel@I-love.SAKURA.ne.jp,peterz@infradead.org,pmladek@suse.com,rostedt@goodmis.org,sergey.senozhatsky.work@gmail.com,sergey.senozhatsky@gmail.com,sudipm.mukherjee@gmail.com,tj@kernel.org,torvalds@linux-foundation.org,vbabka@suse.cz,xiyou.wangcong@gmail.com Cc: From: Date: Mon, 19 Nov 2018 16:21:46 +0100 Message-ID: <154264090622177@kroah.com> MIME-Version: 1.0 X-stable: commit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This is a note to let you know that I've just added the patch titled printk: Never set console_may_schedule in console_trylock() to the 4.14-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: printk-never-set-console_may_schedule-in-console_trylock.patch and it can be found in the queue-4.14 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. From fd5f7cde1b85d4c8e09ca46ce948e008a2377f64 Mon Sep 17 00:00:00 2001 From: Sergey Senozhatsky Date: Tue, 16 Jan 2018 13:47:16 +0900 Subject: printk: Never set console_may_schedule in console_trylock() 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(-) Patches currently in stable-queue which might be from sergey.senozhatsky.work@gmail.com are queue-4.14/printk-never-set-console_may_schedule-in-console_trylock.patch --- 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);