Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2012374imu; Fri, 14 Dec 2018 04:30:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9HhKHV3UAypkq2Vd267CwJ13p+GWnJdQIhs8HWA1sS42DvgjF30kAuBfdj6zpemOluh3i X-Received: by 2002:a17:902:9a4c:: with SMTP id x12mr2657975plv.94.1544790603941; Fri, 14 Dec 2018 04:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544790603; cv=none; d=google.com; s=arc-20160816; b=QoDj3GkCuDY25nSAZb1EcmRhW0rpbuSW1+kT35NJ/XJxva3bvSuzg1FMj8e5yhssT5 SkkKedEvHwGHbbRIxwHo8wn0olz2/BksFsPRd0SWgi0vacXHkysz1ePppDkO/c7DY89E RBMrgivhCq4AEc3zejJueRoG6GzHcq7edn85i2casM4WmtvPmWZClKpcaXAhPLHwucR5 1ORxTxtx9sdW0zj0crPVzflFGXUpAw3HdkMqtpVBjr0guVtOdQrw6EdAxA4oO6lMtG8I 1zd7QFpXFUrpD/BDPLcyuXbOWYjs9siwZCgNPsWz2EKa/703o8NxT9SxoIEc2VRNdFJY Eogw== 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=C9cHyJN82la9SYGMuGCZLFrn6TkQET4QJmYrbCZOapI=; b=BvnJpDk3DvIcpxWToJFgLX9oU3OD+8hgUN4uEkNtKIMufgRGEY+12zVLBl/w8GQpkC omjfKVNhYfLtF2gZ9Moe0DmGTfErAQlB2vd+IJOrSKxtJmoR7LFMI6Nwh4KuVnHRt8Eq KWoTW38zg4EYPS0/ikYL0Ki3xC4WDCR3y9WCe4X1pJZtAU38W4J5Qvn+fzrJbaN65OTP u4Nb61TXBoeJdY6VNQj43E5lCBpp0rGb4WjdDjCKDSgNdI5j4cpyuoL3BZQh9shy//dB Axcc1Pf87NPSCcd9janI6an4+DKxzKYukBhmbgQ1VOeAQLwas7neRieywVge+7l/agqy Bjhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B7jMzzfC; 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 k135si2326189pgc.574.2018.12.14.04.29.49; Fri, 14 Dec 2018 04:30:03 -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=B7jMzzfC; 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 S1731760AbeLNM3B (ORCPT + 99 others); Fri, 14 Dec 2018 07:29:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:56850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730361AbeLNMKj (ORCPT ); Fri, 14 Dec 2018 07:10:39 -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 6E063214F1; Fri, 14 Dec 2018 12:10:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789438; bh=q3UXguVpNniudnn2cTofTtFHl8QeKdth9T/kDQEDu+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B7jMzzfCN829ylkvGQkGkbfNDHAhPkC/edqjc0+TEU7mTYZseBbqVuRCrvACUHT/N um0mLZxhODLQY3q+fO9/gAxm6U26Lw8PLKt1KJHu6kZZp7Hrh7O2af/VQwBk0FF0JI ePwIkMuZBqSP3L0oK/IXVNnh6lo++Ot08F+0EaGA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steven Rostedt , Tejun Heo , Sergey Senozhatsky , Petr Mladek , Sasha Levin Subject: [PATCH 4.14 83/89] printk: Wake klogd when passing console_lock owner Date: Fri, 14 Dec 2018 13:00:36 +0100 Message-Id: <20181214115733.788949088@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 c14376de3a1befa70d9811ca2872d47367b48767 ] wake_klogd is a local variable in console_unlock(). The information is lost when the console_lock owner using the busy wait added by the commit dbdda842fe96f8932 ("printk: Add console owner and waiter logic to load balance console writes"). The following race is possible: CPU0 CPU1 console_unlock() for (;;) /* calling console for last message */ printk() log_store() log_next_seq++; /* see new message */ if (seen_seq != log_next_seq) { wake_klogd = true; seen_seq = log_next_seq; } console_lock_spinning_enable(); if (console_trylock_spinning()) /* spinning */ if (console_lock_spinning_disable_and_check()) { printk_safe_exit_irqrestore(flags); return; console_unlock() if (seen_seq != log_next_seq) { /* already seen */ /* nothing to do */ Result: Nobody would wakeup klogd. One solution would be to make a global variable from wake_klogd. But then we would need to manipulate it under a lock or so. This patch wakes klogd also when console_lock is passed to the spinning waiter. It looks like the right way to go. Also userspace should have a chance to see and store any "flood" of messages. Note that the very late klogd wake up was a historic solution. It made sense on single CPU systems or when sys_syslog() operations were synchronized using the big kernel lock like in v2.1.113. But it is questionable these days. Fixes: dbdda842fe96f8932 ("printk: Add console owner and waiter logic to load balance console writes") Link: http://lkml.kernel.org/r/20180226155734.dzwg3aovqnwtvkoy@pathway.suse.cz Cc: Steven Rostedt Cc: linux-kernel@vger.kernel.org Cc: Tejun Heo Suggested-by: Sergey Senozhatsky Reviewed-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Signed-off-by: Sasha Levin --- kernel/printk/printk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2f654a79f80b..2e2c86dd226f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2393,7 +2393,7 @@ void console_unlock(void) if (console_lock_spinning_disable_and_check()) { printk_safe_exit_irqrestore(flags); - return; + goto out; } printk_safe_exit_irqrestore(flags); @@ -2426,6 +2426,7 @@ void console_unlock(void) if (retry && console_trylock()) goto again; +out: if (wake_klogd) wake_up_klogd(); } -- 2.19.1