Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp457030pxb; Wed, 27 Jan 2021 11:55:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlso4jh8k95hyVUZSynculvGPLNc6vtxDj9GCMBh54BG3UwDKKQxdNkA5h5W6KphAy2Hwj X-Received: by 2002:a05:6402:1bde:: with SMTP id ch30mr10603210edb.151.1611777321837; Wed, 27 Jan 2021 11:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611777321; cv=none; d=google.com; s=arc-20160816; b=iwEErb2L/9ya7T9yvm3Rslti14dkELm4h+od7Vkr20qcZ3WwpwQUqVBfQnM30pJDxJ 5Qa2tfM1toMGpC1WnoUCbetxV+DcR/325XdSZwEbWIP1OlwejlNnJRcO4wkDRnlCfw7O P9uCxfMFC86ZqQ3jT/Nh5gvfb9s4ZMXVTob1LN53IoIkwohtHjPwzpWhUBDH1EFvAero r5FoEMTTsL/Uz/Duxt1m48U2a/fPG0zYz7BP1K7JQyDy+Ih4i1liKqeCEaoyHIpfIYGt E5x9KaduCYckGmZ8FhWcTbzrEfBRvT+bpWI8aXfGWEHzpNqM3H7FFXUFKmLFSpbfujs0 BOrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=rFd6gMCO9KJuddyq2aIzeNhQ+6H7FzwTICOnI8G6dlo=; b=tfXt6DrChpNuFfwGg9xcjVcEni+2LgnAd7QkAn+sO+K3DQW6EqCCmll3cNNytZD1t6 g1qVwO8RW4GBgIYGyA9IhFdAtYPZgf0RUn7oOSgBN+5wrjJKEvDsqJYAgc/xepwA1JJM fzGziPAnWsCneyO3RPBae2ECZlll3gv10awmacNkVatlxQ4gVmSWuQKd1P9JQw+5/G5v MZ8fx9yGhlvQJaAbEKh473ELDCBNbtZlxVgpICWgvbY2eL7Ekh5pApyTClR5vPz6may3 R2FZ0yjdft+UEhmu8bfoGhd/JNlDSDpaqucIWXqFP8j6J4WWyXjNEvA5VkVhTxjQAGlb v9mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qIm2Tsmn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kw2si1255628ejc.366.2021.01.27.11.54.56; Wed, 27 Jan 2021 11:55:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qIm2Tsmn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236227AbhA0Ddb (ORCPT + 99 others); Tue, 26 Jan 2021 22:33:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729528AbhAZVTU (ORCPT ); Tue, 26 Jan 2021 16:19:20 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B4E7C061788 for ; Tue, 26 Jan 2021 13:15:57 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1611695756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rFd6gMCO9KJuddyq2aIzeNhQ+6H7FzwTICOnI8G6dlo=; b=qIm2TsmndTOyeAvfrh1LMF44U+/3LSdgcFA2vtKL1MTua0YiHK1aKi/n7XbB0pQI1HCQF9 ovHVszh7p4Xl0kEzudl6RHzk0AmOIMLLfsdn//KrRW1EeEhhV4ejjTyyz0v6sE+5aMaa0b +XYK4aVvOFI9TYuJUJkkCU9udmSSfzCpikWW9dCvMJzfa08sU+7B+w98f7OXZYMXbys4EV CcO2iLoHWs1cX0FuBmC0kXd9ZivV5C2RfOdi96JnVsSBr9nO7xjqsS7SHHqjA+1/tCoUKA qJwZGZdXFEv+xT2DY0bAJMpnQxWMdyf92Znq2sZADXeps6FyQN8hI9O3jfNEkA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1611695756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rFd6gMCO9KJuddyq2aIzeNhQ+6H7FzwTICOnI8G6dlo=; b=RPeTb0VVGWocwIRwUtyjRSCCTWZaNduzJA9oH74uyfKGFj7nGpS2ORss4ryo3axcMD2/ck XyX7HcXRuVluMxCA== To: Petr Mladek Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk-rework 09/12] um: synchronize kmsg_dumper Date: Tue, 26 Jan 2021 22:21:48 +0106 Message-Id: <20210126211551.26536-10-john.ogness@linutronix.de> In-Reply-To: <20210126211551.26536-1-john.ogness@linutronix.de> References: <20210126211551.26536-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for removing printk's @logbuf_lock, dumpers that have assumed to be protected against parallel calls must provide their own synchronization. Add a locally static spinlock to synchronize the kmsg_dump call and temporary buffer usage. Signed-off-by: John Ogness --- arch/um/kernel/kmsg_dump.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index f38349ad00ea..173999422ed8 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -9,8 +10,10 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason, struct kmsg_dumper_iter *iter) { + static DEFINE_SPINLOCK(lock); static char line[1024]; struct console *con; + unsigned long flags; size_t len = 0; /* only dump kmsg when no console is available */ @@ -25,11 +28,16 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, if (con) return; + if (!spin_trylock_irqsave(&lock, flags)) + return; + printf("kmsg_dump:\n"); while (kmsg_dump_get_line(iter, true, line, sizeof(line), &len)) { line[len] = '\0'; printf("%s", line); } + + spin_unlock_irqrestore(&lock, flags); } static struct kmsg_dumper kmsg_dumper = { -- 2.20.1