From patchwork Mon Nov 19 16:29:36 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: 10688913 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 9078413AD for ; Mon, 19 Nov 2018 16:52:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8173D2A291 for ; Mon, 19 Nov 2018 16:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F3B42A2A7; Mon, 19 Nov 2018 16:52:28 +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 81CE42A291 for ; Mon, 19 Nov 2018 16:52:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 910BB6B1B6C; Mon, 19 Nov 2018 11:52:26 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8C17F6B1B6D; Mon, 19 Nov 2018 11:52:26 -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 789666B1B6E; Mon, 19 Nov 2018 11:52:26 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 3376F6B1B6C for ; Mon, 19 Nov 2018 11:52:26 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id d6-v6so26767695pfn.19 for ; Mon, 19 Nov 2018 08:52:26 -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:from:to:cc:subject:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=Ja/qcHuRN4O6t2zS021aNjKhvJ74BgCk4Je2NVwuLcE=; b=jzKG3J2s0Eg5g5yBSssCPDlaYvDvtDHh9gSsVdmpsg9fQ2rSER/kfT44p3u6GiGKBL T4Wxs6Ch+nDTXLGqJzXKJTXX7aBvXf3PMvACVBON4RWrzh5PU0wRFYPKVWAfo1iztwZF nOubOsZ7UpCR06G2a7MwWYLf9jtELBR0ZvFOFbLXHHgOiTSgxXAGiiwxxIGvPBXLjXIY HV/b5VMMZ4T4Oqn+0+T+IO2hiCyHxhg/9w1d5dKU+vcf7PKQBe7S8gsX/tmzjUgzUTuF ZGd/X/7X8ec/Wmjwh26FYNwrtE0gu1ubj+11iyXsz3nQUmubpg0ZhGWSpi3SqqnxfCnt kxkA== X-Gm-Message-State: AGRZ1gKB+cOCvT9x8ZrkbNMZKnY144g7wrlwqzVH+ZApXRvS/Zm9rA5L amxSEbexzODp1in+Ye2M1XJBVE6F+/0zobqyovFN9+LDBaytBsg37u4X3x3ZkFbJlajdt3zCU8N H8wWNcOgrDzZpiSxOuHiLGJXQyAqFC5e7m4x1eauQO1bewbmWWPh818kbdd5SvbA= X-Received: by 2002:a62:1912:: with SMTP id 18-v6mr24552542pfz.194.1542646345747; Mon, 19 Nov 2018 08:52:25 -0800 (PST) X-Google-Smtp-Source: AJdET5cVHuUvZtUJenD0gBHxeFZYDR0jtBVSJKWrQEqZVCV8NzTK7oNo7G6pxWJ5kYyDlByQzXud X-Received: by 2002:a62:1912:: with SMTP id 18-v6mr24552476pfz.194.1542646344746; Mon, 19 Nov 2018 08:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646344; cv=none; d=google.com; s=arc-20160816; b=QBrfJ5JdKJbx6vyRfljvmpEyF+2LGjXCPmb+n6W2o9tBL9Yoz9kdOgctQQHaBWOE4G DpARJpBjD/ExPQkOrt+yiO0WkyJ4Z15ORWeh/xkQ4cda2MlaQIFhJk160mqbski5kVki UgldsJGC4/2grkeaKZZPNQ65wEfdiAQvONIMduwT8+d5nl51UXvHGXSWExkvWhqWEvMa FPcPTtNmftFcz84XWV92+UcJpbsKU93wKBUzaSJmkvEGEBKPoGUBzvhm9RbpPet8kT9z V51ntOJM8iQvpvKDYc/wnd/xWAHw3nTxJXcSnwyeKoSCWxQu5BZiGz3flhwFO4k5Migh 0mtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=Ja/qcHuRN4O6t2zS021aNjKhvJ74BgCk4Je2NVwuLcE=; b=rYaVI0dFNG9MX+qD9VdvE+i1ceNp+49K5a5IKsrL/dexopCnnf3hkNMz9fUYaN1APm qlzwUvUAeq4aOsP5gcsxUMT2VBSr7zsO47v8yARb9i4KvUPb38zXujZhM6VFfluinau8 +rv3qeWNzJMJY8p3sfOdj687XqUIw9S32tLmhyvNehD8piIy/ysmS/ej9f4HxD8q4YvN +BseRPs3S4tQfUDMDNOoIRhDHza/i+GsHVxy6Klxs0thTwrm2MTQb0BKeGQsTWjRYoD6 Xvq7Qh0nNVXraFXx21VkCOqjCrfOjbKpu6f97v1jsg8JvatC8bMv1xXyb2Ce+Pqpsi+V Ossw== 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: 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 m61si3516500plb.154.2018.11.19.08.52.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 08:52:24 -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="P/GGycTr"; 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 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 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 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);