Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp501945rwb; Mon, 26 Sep 2022 01:50:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6oGdhudP/xYC9TeiaFpw7nH8/Nw3pGw37JYFyZeZerVulx9I5KPvMVrmQ6NudML9809XeJ X-Received: by 2002:a17:907:3e02:b0:782:1267:f2c8 with SMTP id hp2-20020a1709073e0200b007821267f2c8mr17015998ejc.585.1664182215115; Mon, 26 Sep 2022 01:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664182215; cv=none; d=google.com; s=arc-20160816; b=eNfplQJwms/hY12W9su25h7vfWJuPPb3gkGrLmhnEdEEyZaY9wGgG7LhhRja3mwpG5 oCem6VXP1jrjMZ7jCnKWxs01TmZfRSvBh95DIuFArBMaOcgycQGtmkfCekclzhAiJb3C kN+FbuYJdSBzkF3Sz8f9u1i/ImxveQv1IB+meVqQSx5GghLt2O0/BgvU808TZDh6MrRS hWQnOgyOj2hyeEA5leUKIQmGy/xe+bT9rot0MdK/7o6WVBuXFwfJruN6xzvuJ+gBuDOq hew4+oE0Qa6JlRWoz7PyrCbYAYgBLBu+J8fAkAabe4ML6ePYhO+NhcebJoVLwLYy2rDZ HUjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=NKhc8qFzuT7oDQPl2tzoXxQ/g8SoOYHWBX8Uw/Wsd50=; b=OzN/Rd3D6NvWg9bwVNil5YPKDXlBsGqR0IJES1ZTz9d7G0roe2q9mqz/92fAdkaU/0 Yqm5pqkikQWUlot9EsVX0XpFSMdMqB+bBcOa3VmVQiQ1wTIEOHw/KyJPALzt/TD35YFA p0dsdnrW6PFKi6eMsGsg8yqh9HUJOzKPRfTvHYFkU9iesnlp0OU97NQUe0AyVKeeBjQR 2u2e2d6QqVf14Wn5ThlvLCrEspaMM6/eUyCLHPaNv5oUZPw1hCrnj7+xsYMf353Nc4ig PaRfK9ptBjryVOG1/9bthhmKMXs+KYgQ6LEdPoWrdw/xF/MlAgkq5YDfMWDp58oXye6r QcSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=v9FTBr3E; dkim=neutral (no key) header.i=@linutronix.de header.b=upHGNdMZ; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht12-20020a170907608c00b00782e9b7305dsi7263383ejc.266.2022.09.26.01.49.50; Mon, 26 Sep 2022 01:50:15 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=v9FTBr3E; dkim=neutral (no key) header.i=@linutronix.de header.b=upHGNdMZ; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234375AbiIZH7B (ORCPT + 99 others); Mon, 26 Sep 2022 03:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234356AbiIZH62 (ORCPT ); Mon, 26 Sep 2022 03:58:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7396B63C0 for ; Mon, 26 Sep 2022 00:54:39 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1664178876; h=from:from:reply-to:subject:subject: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=NKhc8qFzuT7oDQPl2tzoXxQ/g8SoOYHWBX8Uw/Wsd50=; b=v9FTBr3EuhPm2Jwmd5X3M0K/acEkHtVcDz1OBdSFY5EjKENEaH90IxjyHomZy22Qsps1nl bzuXC3M0jlbGgarN/QCD8d1cfij3fnPCtRgsXS7i4+faexNWkI7n3yig1zioeJUSAnq+Yd ks74rJVvZni/cZH6cL0Hh5H9OdLV+Iw3trgeJAeFpvvCMouFJmpp4LjViCRckR0csDDltS FtJsYzJ5Z+M1ZKsC64tAdhThoH7o10/PQcbtRtCdcwux38CBjvunnHlLVbs4NXuUaNlFqa sFZJF5P9fknPyXi+wjJHG1DghDd0WFqrVK+EuVXGYaDbLJncDLlFCr9N1aCHJg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1664178876; h=from:from:reply-to:subject:subject: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=NKhc8qFzuT7oDQPl2tzoXxQ/g8SoOYHWBX8Uw/Wsd50=; b=upHGNdMZLwWXlLY4p6BkuV5IeciHUtWKnMnqr0DfpcMFbD3it4R3xHMF7Q0LOT0hW6CvH+ KtJ1O/piM2cK4ADw== To: Sergey Senozhatsky Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk 18/18] printk: Handle dropped message smarter In-Reply-To: References: <20220924000454.3319186-1-john.ogness@linutronix.de> <20220924000454.3319186-19-john.ogness@linutronix.de> Date: Mon, 26 Sep 2022 10:00:36 +0206 Message-ID: <87leq6d0zn.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, 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 2022-09-26, Sergey Senozhatsky wrote: > On (22/09/24 02:10), John Ogness wrote: >> +/** >> + * cons_print_dropped - Print 'dropped' message if required >> + * @desc: Pointer to the output descriptor >> + * >> + * Prints the 'dropped' message info the output buffer if @desc->dropped is >> + * not 0 and the regular format is requested. Extended format does not >> + * need this message because it prints the sequence numbers. >> + * >> + * In regular format the extended message buffer is not in use. >> + * So print into it at the beginning and move the resulting string >> + * just in front of the regular text buffer so that the message can >> + * be printed in one go. >> + * >> + * In case of a message this returns with @desc->outbuf and @desc->len >> + * updated. If no message is required then @desc is not modified. >> + */ >> +static void cons_print_dropped(struct cons_outbuf_desc *desc) >> +{ >> + struct cons_text_buf *txtbuf = desc->txtbuf; >> + size_t len; >> + >> + if (!desc->dropped || desc->extmsg) >> + return; >> + >> + if (WARN_ON_ONCE(desc->outbuf != txtbuf->text)) >> + return; >> + >> + /* Print it into ext_text which is unused */ >> + len = snprintf(txtbuf->ext_text, DROPPED_TEXT_MAX, >> + "** %lu printk messages dropped **\n", desc->dropped); >> + desc->dropped = 0; >> + >> + /* Copy it just below text so it goes out with one write */ >> + memcpy(txtbuf->text - len, txtbuf->ext_text, len); >> + >> + /* Update the descriptor */ >> + desc->len += len; >> + desc->outbuf -= len; > > Oh, hmm. This does not look to me as a simplification. Quite > the opposite, moving cons_text_buf::text pointer to point to > cons_text_buf::text - strlen("... dropped messages...") looks > somewhat fragile. It relies on @ext_text and @text being packed together, which yes, may be fragile. As an alternative we could memcpy the message text (@text) to the end of the dropped message text. There would be enough room. Generally speaking, the dropped text will be less text to copy. But since dropped messages are rare anyway, it might be worth copying more data so that the code is not fragile. It would also allow us to remove the __no_randomize_layout in "struct cons_text_buf". If the end of cons_print_dropped was changed to: memcpy(txtbuf->ext_text + len, txtbuf->text, desc->len); desc->len += len; desc->outbuf = txtbuf->ext_text; Would that be OK for you? > Is printing 'dropped' and outbuf messages in one go such an > important feature? I think it is a nice simplification. With the cons_text_buf, it makes it quite easy to implement. John