Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp500213pxu; Fri, 4 Dec 2020 08:20:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyc9EleurilFZ3GzT5u5gbHqGT0rW8YUqqeYcRvG0x8fKXSM/NpZLMy1CSjR5u12WM3mzdE X-Received: by 2002:a17:906:170e:: with SMTP id c14mr7863660eje.117.1607098843211; Fri, 04 Dec 2020 08:20:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607098843; cv=none; d=google.com; s=arc-20160816; b=cZzSfQLcigaj4v7qfUvw6elfkJb3+O29u9CzmpxcpUfoZ9ru2N73MRa/CzQFyj4prp w/gZQoTIhhdF7pB3C3jL9zxESNJpHytCgqBeoXwAcE0P+UjrMNuYgSpt04wD5vABu4fW dTsQNCD/yDHQPQO83kMKySuz9xibgDKmls3NCCZ8ztalTluRqWFTKpFEXU90cFokG9YJ RTvHeQUKHTalVu8I7qo/WH9VNXbBf6/hTwbIHBoC8WFGUX/lp/v9moDEe35OLtNjk1V5 +q1G6MDQYRUOAHPzs18DTuoDnefeKjgVf654J8lZBFPNK6yziYlgVW2+scGIZvAK1hUa JOGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UyfSIUJD3A1xmg2RWmSd8HkdBVuOod7ZPB6QL2MeQ/Q=; b=ajtXKfLvpwZn1N2hBr3YFWOesm/iqDcJrj18/g2kF7BMfH5Q4aSFfiQMsOrpGD0BTS KxQf7PfPUWVacumq4cHFAOZq302RwdMsXIb04ZhFhDjYxtxIM61SVtLSzrIMcXiPo5c8 8qTIA7vM0ArbL40Zylit/A09zc3RtlRbnB3rWdjmsHmwaul6RmTp4ga5rAWbZeJfNdKR 2zK4EAt8ZfQ8ezzmEeQl8qOiWRYP38i5MKJ2S4Sea+/wXN1eUM208xFV6uhlfTM2IO/c nl4CyFzcowKwhkz//2o3WSju/Ol6KGhh6bGazZj+kzOLUMTbRSIRvaiuNvmChrtnU4up IVng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=E791E8NQ; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 88si3138237edr.151.2020.12.04.08.20.19; Fri, 04 Dec 2020 08:20:43 -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=@suse.com header.s=susede1 header.b=E791E8NQ; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727639AbgLDQQo (ORCPT + 99 others); Fri, 4 Dec 2020 11:16:44 -0500 Received: from mx2.suse.de ([195.135.220.15]:39382 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgLDQQn (ORCPT ); Fri, 4 Dec 2020 11:16:43 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1607098557; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UyfSIUJD3A1xmg2RWmSd8HkdBVuOod7ZPB6QL2MeQ/Q=; b=E791E8NQeGNAN7oLMkgqN6Ia12AifKYMZbvXkCeuz5A5fx4CuBAf5BxfYLV9W51XXdXOrV J5HUlADkWT63pjd7HXO6H5687bVvNtU1VYkeU3zWzDQC3WM896vjsFnlQ4jFNFlofgMBo8 xxYosajjTPvtIbejYgIG3V+BUnsQ/Uw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 386D9ACC1; Fri, 4 Dec 2020 16:15:57 +0000 (UTC) Date: Fri, 4 Dec 2020 17:15:56 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: vprintk_store: was: [PATCH next v2 3/3] printk: remove logbuf_lock, add syslog_lock Message-ID: References: <20201201205341.3871-1-john.ogness@linutronix.de> <20201201205341.3871-4-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201201205341.3871-4-john.ogness@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2020-12-01 21:59:41, John Ogness wrote: > Since the ringbuffer is lockless, there is no need for it to be > protected by @logbuf_lock. Remove @logbuf_lock. > > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -1867,40 +1890,75 @@ static inline u32 printk_caller_id(void) > 0x80000000 + raw_smp_processor_id(); > } > > -/* Must be called under logbuf_lock. */ > +static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lflags, > + const char *fmt, va_list args) > +{ > + char *orig_text = text; > + u16 text_len; > + > + text_len = vscnprintf(text, size, fmt, args); > + > + /* Mark and strip a trailing newline. */ > + if (text_len && text[text_len - 1] == '\n') { > + text_len--; > + *lflags |= LOG_NEWLINE; > + } We reserve the space for '\n' anyway. It would make sense to just store it and remove all these LOG_NEWLINE-specific hacks. Well, let's leave it as is now. It is still possible that people will not love this approach and we will need to format the message into some temporary buffer first. > + /* Strip kernel syslog prefix. */ Syslog actually uses: format. We are skipping log level and control flags here. > + if (facility == 0) { > + while (text_len >= 2 && printk_get_level(text)) { > + text_len -= 2; > + text += 2; > + } We should avoid two completely different approaches that handle printk_level prefix. One solution is to implement something like: static char *parse_prefix(text, &level, &flags) That would return pointer to the text after the prefix. And fill level and flags only when non-NULL pointers are passed. Another solution would be to pass this information from vprintk_store(). The prefix has already been parsed after all. > + > + if (text != orig_text) > + memmove(orig_text, text, text_len); > + } We should clear the freed space to make the ring buffer as human readable as possible when someone just dumps the memory. Sigh, I have to admit that I missed the problem with prefix and trailing '\n' when I suggested to avoid the temporary buffers. This memmove() and the space wasting is pity. Well, it is typically 3 bytes per message. And the copying would be necessary even with the temporary buffer. So, I am less convinced but I would still try to avoid the temporary buffers for now. > + > + return text_len; > +} > + > +__printf(4, 0) Best Regards, Petr