Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp777652ybc; Sat, 16 Nov 2019 08:30:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyh8+pcK5NmCNAOdv+nLX7OC/Urb1W+Qs9p98XJHjjZ0SLOLodWAInZ8Ux1NFJh5ptC5A/0 X-Received: by 2002:a17:906:351b:: with SMTP id r27mr11328724eja.120.1573921856771; Sat, 16 Nov 2019 08:30:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921856; cv=none; d=google.com; s=arc-20160816; b=Bz5fdL8OzIH791iBZd0ejLqjacG+/3jUyxAetW85Sl9BnpK559IMmLT/B8JhIBWzHB tEHdDILQ5v17MqqaCICIGC4r0WjnfWn3gPDzLblBgejWSJoKkbbeEPfdix/fKeSVr5k/ Bdj/EgZo4bAtktL9jiNqAnmhq74SqnkHapWHCj40G/BNs8hAANBJEDKZppyJzVMndBfx o/gJmOZuVw2z0aKIRGxHQIpoGVG5Q+i76tvKF8UQ8DL8fLg5TT0ItQnUudwVUQbjbsdo CHVVq5NkEY197TOjqZlLmThYKf3+z1pT4XQjZUvzsX5HAGd3Pwo/oSWhxSSbLo2vmd/x Cgvw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DMnmUD70WwcdoUccND4tsRU+ojnObdM4NW4DvaNEko0=; b=r3+euEuy+51AVbAkeirwlmF/2tPtCEYuBj3T2DyFh/eGbUIg0i6v0ghLmGYkoIS57Y a9DMrKmuFv0a2B78GTl79C9Etik4nrPspEdBid1iPGh5R46sV49StTtmjbdRV2ZEMg54 bTD1AJSWNV6KmNejS4SzKlnBkDL2XSJpMqGrhFZ9xQ7yn22+Kn9CdlZYprHXkCKy/UJA M8jeLz4ZVoEjwHIlt0OCsTH5VGy2jRWN0Re4hZAp386WRfTJoKLL++2xFvjSmMejAOUV QRIMHp0zjO2gZph/b4TMV4I5ju2BmMOmRsnDC2kbuUk8rhVPCKqocOhaiPKdU/Z8Vx51 maoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LNqG2zev; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c36si9148757edb.58.2019.11.16.08.30.31; Sat, 16 Nov 2019 08:30:56 -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=LNqG2zev; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727832AbfKPPlU (ORCPT + 99 others); Sat, 16 Nov 2019 10:41:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:44208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727763AbfKPPlQ (ORCPT ); Sat, 16 Nov 2019 10:41:16 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 493F220733; Sat, 16 Nov 2019 15:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918875; bh=a3atx0pDJ6BtMgQLn3IDaJgOpT1UTvSQakhdCHeRKyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNqG2zevJiQaJAVKOa2Ta9dY9h6Pu04D8qyjXO6i/TW/xT/JF5KTFM0IkGPzDC3cQ UNKlUXFM9LVtTEeYJtBGZ6JbiiorwMu3v1/UKP19p5SnuqjSUo0UuDSAsQyN4PMbyq j704dUngPPQVf+mC8l42kU58ILxJkUilN4TWBZRw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sergey Senozhatsky , Andrew Morton , Dmitriy Vyukov , Tetsuo Handa , Tejun Heo , Peter Zijlstra , Sergey Senozhatsky , Petr Mladek , Sasha Levin Subject: [PATCH AUTOSEL 4.19 003/237] printk: lock/unlock console only for new logbuf entries Date: Sat, 16 Nov 2019 10:37:18 -0500 Message-Id: <20191116154113.7417-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Senozhatsky [ Upstream commit 3ac37a93fa9217e576bebfd4ba3e80edaaeb2289 ] Prior to commit 5c2992ee7fd8a29 ("printk: remove console flushing special cases for partial buffered lines") we would do console_cont_flush() for each pr_cont() to print cont fragments, so console_unlock() would actually print data: pr_cont(); console_lock(); console_unlock() console_cont_flush(); // print cont fragment ... pr_cont(); console_lock(); console_unlock() console_cont_flush(); // print cont fragment We don't do console_cont_flush() anymore, so when we do pr_cont() console_unlock() does nothing (unless we flushed the cont buffer): pr_cont(); console_lock(); console_unlock(); // noop ... pr_cont(); console_lock(); console_unlock(); // noop ... pr_cont(); cont_flush(); console_lock(); console_unlock(); // print data We also wakeup klogd purposelessly for pr_cont() output - un-flushed cont buffer is not stored in log_buf; there is nothing to pull. Thus we can console_lock()/console_unlock()/wake_up_klogd() only when we know that we log_store()-ed a message and there is something to print to the consoles/syslog. Link: http://lkml.kernel.org/r/20181002023836.4487-3-sergey.senozhatsky@gmail.com To: Steven Rostedt Cc: Andrew Morton Cc: Dmitriy Vyukov Cc: Tetsuo Handa Cc: Tejun Heo Cc: Peter Zijlstra Cc: LKML Cc: Sergey Senozhatsky Signed-off-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Signed-off-by: Sasha Levin --- kernel/printk/printk.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d0d03223b45b1..9ee6016a19fc8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1894,8 +1894,9 @@ asmlinkage int vprintk_emit(int facility, int level, const char *fmt, va_list args) { int printed_len; - bool in_sched = false; + bool in_sched = false, pending_output; unsigned long flags; + u64 curr_log_seq; if (level == LOGLEVEL_SCHED) { level = LOGLEVEL_DEFAULT; @@ -1907,11 +1908,13 @@ asmlinkage int vprintk_emit(int facility, int level, /* This stops the holder of console_sem just where we want him */ logbuf_lock_irqsave(flags); + curr_log_seq = log_next_seq; printed_len = vprintk_store(facility, level, dict, dictlen, fmt, args); + pending_output = (curr_log_seq != log_next_seq); logbuf_unlock_irqrestore(flags); /* If called from the scheduler, we can not call up(). */ - if (!in_sched) { + if (!in_sched && pending_output) { /* * Disable preemption to avoid being preempted while holding * console_sem which would prevent anyone from printing to @@ -1928,7 +1931,8 @@ asmlinkage int vprintk_emit(int facility, int level, preempt_enable(); } - wake_up_klogd(); + if (pending_output) + wake_up_klogd(); return printed_len; } EXPORT_SYMBOL(vprintk_emit); -- 2.20.1