Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp864032rwl; Fri, 31 Mar 2023 03:38:49 -0700 (PDT) X-Google-Smtp-Source: AKy350Ytqi6e0sUBSoHqa6DA1sbu5NYOhn87vRZd9itbCt28peUmvz+IPFhfFi8GAVljc2b4S4Xh X-Received: by 2002:a17:906:2098:b0:930:7f40:c1bb with SMTP id 24-20020a170906209800b009307f40c1bbmr4359567ejq.4.1680259129127; Fri, 31 Mar 2023 03:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680259129; cv=none; d=google.com; s=arc-20160816; b=QxCgBMZwIQviFXBDQSe3Ay9GkvGv4HGzWrnmJXS7G2wWqZPypodhGYC+ECtyAmrWql wt9dV0WKp1tAuwN6isTW0c/3Np1+fIYapME7U3JohmNQ5PCy8Qchny3Afjx/j2ogpyn7 iOn1Tab1xhm0MrNYswTbdUnNw+A3+BqLd/N56SuBrH8HMvz0S4EbJ99ttKcYTcLhTygw KTmQSvteuF5gtpnvAy81Sl3gQK/+N1dkHYEKv028s+RPN4px1cr7eCnP9bvpNVhzn7oy +lavz8IIuQK9xtgWnJc3pulaL2MuFjI2upWuQa/eFtOs2C09NKLi6ioc0u8CFaA29JlX DpvA== 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=/SubNly6CNy9pHqgLfpvVWjY0D9U9M44eXnof6cb4U8=; b=0nPZqD1FQWOd+XAx90/apymp2EDzSl5uURjghgbXMOgUxXf9/POyxkrAtznLiWfEPG XTpaNGSeShpwqw5b2/6tg149XHNUqHuKHeaDMCMkovCss3ERgFr8/a9frnyuMSE8f7R7 x4ABnk5OiEXtVD40TcpFyy9+O7awmldjN1MKvwEldg4cSJWSHzTvnFMSMR/tF93sC1YG MZAhdzydyoYZ+/UxbU/6U0O6TpE6anmnVyQkn8VGYUIoGRm1g0fXMTi77j34qzEBjCDw lBcjv2EypB1QeTXvQ3RNTIEEuCtS1R7kTEsZhO8t2JmAQlBMtLDazkBtcEmLzNaQqquN Z0Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=YyN5ZLMe; 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 f5-20020a17090624c500b008b2712f79e8si384352ejb.940.2023.03.31.03.38.24; Fri, 31 Mar 2023 03:38:49 -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=@suse.com header.s=susede1 header.b=YyN5ZLMe; 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 S230112AbjCaKgK (ORCPT + 99 others); Fri, 31 Mar 2023 06:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjCaKgJ (ORCPT ); Fri, 31 Mar 2023 06:36:09 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EBE26A58 for ; Fri, 31 Mar 2023 03:36:04 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 24AA71FE0F; Fri, 31 Mar 2023 10:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680258963; 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=/SubNly6CNy9pHqgLfpvVWjY0D9U9M44eXnof6cb4U8=; b=YyN5ZLMeN5zxuWVUSTDLcPmuZPg0kv1H/eqWEU2sgqkwckKlpTYgNl+a+rmCgv3kY2Vyxp I2Kbi8kIKA3po/JqMoxjqTEb0AX0i6aiZNA7vPd+dVwLsPjycSYKNXTy0Bm0U3vdqTNa/W 364FZK8iEHV+PGUys43Yb3HzzoL4qRk= Received: from suse.cz (unknown [10.100.208.146]) (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 EDA8C2C141; Fri, 31 Mar 2023 10:36:02 +0000 (UTC) Date: Fri, 31 Mar 2023 12:36:02 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: semantic: Re: [PATCH printk v1 10/18] printk: nobkl: Add emit function and callback functions for atomic printing Message-ID: References: <20230302195618.156940-1-john.ogness@linutronix.de> <20230302195618.156940-11-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230302195618.156940-11-john.ogness@linutronix.de> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Thu 2023-03-02 21:02:10, John Ogness wrote: > From: Thomas Gleixner > > Implement an emit function for non-BKL consoles to output printk > messages. It utilizes the lockless printk_get_next_message() and > console_prepend_dropped() functions to retrieve/build the output > message. The emit function includes the required safety points to > check for handover/takeover and calls a new write_atomic callback > of the console driver to output the message. It also includes proper > handling for updating the non-BKL console sequence number. > > --- a/kernel/printk/printk_nobkl.c > +++ b/kernel/printk/printk_nobkl.c > +/** > + * cons_emit_record - Emit record in the acquired context > + * @wctxt: The write context that will be handed to the write function > + * > + * Returns: False if the operation was aborted (takeover or handover). > + * True otherwise > + * > + * When false is returned, the caller is not allowed to touch console state. > + * The console is owned by someone else. If the caller wants to print more > + * it has to reacquire the console first. > + * > + * When true is returned, @wctxt->ctxt.backlog indicates whether there are > + * still records pending in the ringbuffer, This is inconsistent and a bit confusing. This seems to be the only function returning "true" when there is no pending output. All the other functions cons_get_record(), console_emit_next_record(), and printk_get_next_message() return false in this case. It has to distinguish 3 different return states anyway, same as console_emit_next_record(). I suggest to use the same semantic and distinguish "no pending records" and "handed over lock" via a "handover" flag. Or maybe the caller should just check if it still owns the lock. > + */ > +static int __maybe_unused cons_emit_record(struct cons_write_context *wctxt) > +{ > + struct cons_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); > + struct console *con = ctxt->console; > + bool done = false; > + > + /* > + * @con->dropped is not protected in case of hostile takeovers so > + * the update below is racy. Annotate it accordingly. > + */ > + ctxt->dropped = data_race(READ_ONCE(con->dropped)); > + > + /* Fill the output buffer with the next record */ > + ctxt->backlog = cons_get_record(wctxt); > + if (!ctxt->backlog) > + return true; > + > + /* Safety point. Don't touch state in case of takeover */ > + if (!console_can_proceed(wctxt)) > + return false; > + > + /* Counterpart to the read above */ > + WRITE_ONCE(con->dropped, ctxt->dropped); > + > + /* > + * In case of skipped records, Update sequence state in @con. > + */ > + if (!wctxt->outbuf) > + goto update; > + > + /* Tell the driver about potential unsafe state */ > + wctxt->unsafe = ctxt->state.unsafe; > + > + if (!ctxt->thread && con->write_atomic) { I would expect this check in console_is_usable(), same as for legacy consoles. And what is actually the difference between con->write_atomic() and con->write_thread(), where write_thread() is added later in 11th patch? I guess that the motivation is that the kthread variant might sleep. But I do not see it described anywhere. Do we really need two callbacks? I would expect that the code would be basically the same. Maybe, the callback could call cond_resched() when running in kthread but this information might be passed via a flag. Or is this a preparation for tty code where the implementation would be really different? > + done = con->write_atomic(con, wctxt); > + } else { > + cons_release(ctxt); > + WARN_ON_ONCE(1); > + return false; > + } Best Regards, Petr