Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11853563rwl; Tue, 3 Jan 2023 05:49:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXs/JaSvZJU/+iza0g9Qa2lj5KupUklWCcuW/p4HCkj30UaJXFIeWXPqCbeCt6BpeaeI+6lW X-Received: by 2002:a05:6a20:3c8a:b0:af:8128:757 with SMTP id b10-20020a056a203c8a00b000af81280757mr71407779pzj.61.1672753755883; Tue, 03 Jan 2023 05:49:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672753755; cv=none; d=google.com; s=arc-20160816; b=m7XGtNbU8nbME3DE6oQg2uTUdaCyhQ5An2mGrPhRN8SJqhGr8LzwlHgyeSZ+P3Q1Yf Y61O4AGcmFGSbL+/RNVyD5PkCVRtqCQ4b06BuUj6hhx+8LmaTwO95wgo2bNanRP3Mw4r wBETQQVzYUkA8jQTwLW/igmqolBNR2bwPCC/OqJDIoSrw7EN/S/bzNfI0cdEIF53CzN7 CAxRivACQE6zC+umd2czbbkDgc6GIQaK0iuDd8md1XC2KUwpUn1LdGdGdyEDupaFFCu8 ew6KovRBK1PVByIbQBBplfLe4SinFd3UvzZYyZJirSCFI6rbtsveCgcrMpl424p0JPmT dI/A== 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=MvNUKmd/+qxHXxT/ahmWS+4YBdwWe8ucOnQ6cM6C2XI=; b=ATRjDTrROEpNuXQrd32pWMarfWChDnfZySawA/EUJ75ArmTz5qz5LdNMhLbIgkQCpS IYoxx303t6xL6HSa3N3fN/GCqpaWqrD9Dp80je6koPktBKnLuSzGAiQNPELQiqZBy/DI Hd9LSfrV89QCyMB/5VcrWkPtvElgaO/2eSZpJ/X6CQZZ5f9p2YhuuvW+KKt6s99njfep 3qj0+J4sHadsEABc14DJPnsoVABbwjDCv6gXVv1mhzIyk73GuC69iGfJzalZKY+Cnb69 f5VedbR34pXPoiTLjwze3mMtIyRhPKFqaOujXKTB/VRWpKKRo3tYgjRRs/bEsbTpKzWw Z5dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=NO7NxCuI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s67-20020a632c46000000b004a4eae7c943si1867828pgs.535.2023.01.03.05.49.06; Tue, 03 Jan 2023 05:49:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=NO7NxCuI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233342AbjACN3f (ORCPT + 60 others); Tue, 3 Jan 2023 08:29:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233232AbjACN3d (ORCPT ); Tue, 3 Jan 2023 08:29:33 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0A1D10FFF for ; Tue, 3 Jan 2023 05:29:32 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 53BBF3EA8E; Tue, 3 Jan 2023 13:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1672752571; 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=MvNUKmd/+qxHXxT/ahmWS+4YBdwWe8ucOnQ6cM6C2XI=; b=NO7NxCuIdfqyNsl3gUDWScn2H0+9b+BpQDp5Goxtti5CwQ0qQhHPs8hlWlIXc44AqBE8Ak kzs7SX2pYEAHgK13K9gqLVvUtLQXKBhvriMNo9RXUX6zoRkFnMZVCYCxTGTLh1kHhxrV7y fMtM+Fo4PGcY7+vD0zk1Yjja6WutMtU= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 11B102C141; Tue, 3 Jan 2023 13:29:31 +0000 (UTC) Date: Tue, 3 Jan 2023 14:29:30 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v3 6/6] printk: introduce console_prepend_dropped() for dropped messages Message-ID: References: <20221221202704.857925-1-john.ogness@linutronix.de> <20221221202704.857925-7-john.ogness@linutronix.de> <87y1qjdimw.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87y1qjdimw.fsf@jogness.linutronix.de> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2023-01-03 11:26:23, John Ogness wrote: > On 2023-01-02, Petr Mladek wrote: > >> +static void console_prepend_dropped(struct console_message *cmsg, unsigned long dropped) > >> +{ > >> + struct console_buffers *cbufs = cmsg->cbufs; > >> + const size_t scratchbuf_sz = sizeof(cbufs->scratchbuf); > >> + const size_t outbuf_sz = sizeof(cbufs->outbuf); > >> + char *scratchbuf = &cbufs->scratchbuf[0]; > >> + char *outbuf = &cbufs->outbuf[0]; > >> + size_t len; > >> + > >> + len = snprintf(scratchbuf, scratchbuf_sz, > >> + "** %lu printk messages dropped **\n", dropped); > >> + > >> + /* > >> + * Make sure outbuf is sufficiently large before prepending. Space > >> + * for a terminator is also counted in case truncation occurs. > >> + */ > >> + if (WARN_ON_ONCE(len + 1 >= outbuf_sz)) > >> + return; > > > > Strictly speaking, this should be: > > > > if (WARN_ON_ONCE(len >= outbuf_sz)) > > return; > > > > The trailing '\0' will fit into the buffer when len < outbuf_sz. > > You are correct. > > My concern was that if "@len = @outbuf_sz - 1", the entire message will > be truncated and you will only see the dropped messages text. I wanted > at least 1 character from the message to survive. ;-) I see. > How about the commments: > > /* > * Make sure outbuf is sufficiently large before prepending. Space > * for a terminator and at least 1 byte of the message is also > * checked in case truncation is needed. > */ It is better than the original. Well, what about making sure that something more useful is always printed. For example: /* * Make sure outbuf is sufficiently large before prepending. * Keep at least the prefix when the message has to be truncated. * It is a rather theoretical problem when someone tries to * use a minimalist buffer. */ if (WARN_ON_ONCE(len + PREFIX_MAX + 1 >= outbuf_sz)) return; If we want to use this way. It would probably make sense to rename PREFIX_MAX to CONSOLE_PREFIX_MAX. Best Regards, Petr