Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3297015lfo; Mon, 23 May 2022 01:01:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+Vdrhye6KtcL/q2X0rQyrNV9T5NpJ6SsmqyUlZtLfB5sT1PJ9+wHZG9aJx32HwX2Bxt1D X-Received: by 2002:a63:531c:0:b0:3fa:5856:2fa2 with SMTP id h28-20020a63531c000000b003fa58562fa2mr3182542pgb.198.1653292862378; Mon, 23 May 2022 01:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292862; cv=none; d=google.com; s=arc-20160816; b=soDDqMrtThVIxvUX8dLXHi8Anw43+s5Phy6MMf4AF9On0JmMrEmMlNRRy9YoM3uyFa GbVW2Uk5h5WoA8B505jxWrauveWaLs/WDBPXQAgo8shUFXMrKBe9/x/wJ1MYjhUgsUWG lbInM0Y5R742/9lIA7HPT48htxn3bklkYFA8TTz1qV7yi79o+76hevamOwZ0LsBiRf5z kUQ+S+jgwIwqoX7sYLrRW4ZlHxLqPKb0qKdIk0N7fwHsnq/edc2a6pvf7e2EhsnlN0Sc Gw5v1sVY4nxo2MLxZXKv8t4pa8ygwmFU5pLySbMOSb6/oq3Ek0rDUgUsm6toZ9lplVEH 5oWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=MMha9YDnPw3mR5pGs4DIuaKROKDxNWOYK4oruaf1i2o=; b=m6ycBRYVB7xk+6W5JYSlcg1KwfoTJEj0cKZIRPZXhpzC1D7DxoCUJRa/XDRROcLqWC gTG3+j+TMmOJRvxmbfydX7IsxDYTCEFmhACEZUZu1F+2PjO4Ru+CgNv3U9SF41x3qjAU 0g48rOTPr2tsjg+8W3RV/4Y+wYf6kBVpzvkyKa3sCix25T7AN3L1KPdcdMdQR2v3ET8e 54aPQn9RM5XnDlC1WDZU9Z17AtZRRm8ErmY744vZSes0G+2DVSSlQJWAtlB+mzCuNklq wjjeB8OEHx2WtuYjOZvcESFujHU+h1ODd8Tje/bv6q8GFCA+E8grKpP0NHLOPRzAAqu/ LWMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=RXIoVGnR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m6-20020a632606000000b003f667dd5faasi9306891pgm.82.2022.05.23.01.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=RXIoVGnR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C624E0E4; Mon, 23 May 2022 00:00:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241403AbiESPzO (ORCPT + 99 others); Thu, 19 May 2022 11:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240863AbiESPzM (ORCPT ); Thu, 19 May 2022 11:55:12 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 132878FD72 for ; Thu, 19 May 2022 08:55:11 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id r6-20020a1c2b06000000b00396fee5ebc9so2940212wmr.1 for ; Thu, 19 May 2022 08:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=MMha9YDnPw3mR5pGs4DIuaKROKDxNWOYK4oruaf1i2o=; b=RXIoVGnRRoM9d3gTn8wc341hXhMv9hwXRZfxF1qb2cTR4ACvDdEbFwd8oz+hHJVtkQ 0y+7kmPKRyoC4OtnGaUdI8Z3tTWVDKlt0EA34/NJWF5nsfq8JnxDCsqCOkM38LRpIZia 6vKegdWf5cZznNpHMf+thRVgt9O/z6Eh7ojrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=MMha9YDnPw3mR5pGs4DIuaKROKDxNWOYK4oruaf1i2o=; b=PEy6BRevQmfpSkAciBMcgV6agRoF4emXCI64p/brenAFGlOZeSYJKE3McdE9O23owZ xMwx3ZQoRiqE6K2Ht7DFdGASJnMy065fC++SlhDd7QHqUeDcRw7xQYO3RYdVQlbTPYxF Gwy5yhwf8Xf0nPDp+C6g+EwnFhULRNe+JcAf8CW3xvaepigwO9fl0QqS5X9y0D9CkdAx gOfqox0w7pFmSj/7aCLWLGrq0oif34LHFt1pMiWKfxZWp7wx6qFn3Pih4oaJCKs4EwYv lQPAmS/WpRzZ+4DkBxEIMHmm4zeeGJxTSjh7ZhHwD4Nbg5Qg/MUIuQGgnIB4DX72gcLM ktWg== X-Gm-Message-State: AOAM531rv/Wx1AtVkO4x/8IXAaUFMARNkrZ2+6ZivCw/UfhK0nIiWz9J xQ1rICwq7ijhcjtiHr5vgeffRw== X-Received: by 2002:a7b:c114:0:b0:394:47d3:693f with SMTP id w20-20020a7bc114000000b0039447d3693fmr5145198wmi.42.1652975709442; Thu, 19 May 2022 08:55:09 -0700 (PDT) Received: from localhost ([2620:10d:c092:400::4:c1eb]) by smtp.gmail.com with ESMTPSA id s22-20020a1cf216000000b00397369667e6sm171569wmc.39.2022.05.19.08.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 08:55:08 -0700 (PDT) Date: Thu, 19 May 2022 16:55:08 +0100 From: Chris Down To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Petr Mladek , kernel-team@fb.com Subject: Re: [RFC PATCH] printk: console: Allow each console to have its own loglevel Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.4 (c3baa83e) (2022-04-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Greg Kroah-Hartman writes: >On Thu, May 19, 2022 at 04:08:04PM +0100, Chris Down wrote: >> Greg Kroah-Hartman writes: >> > > struct console { >> > > char name[16]; >> > > void (*write)(struct console *, const char *, unsigned); >> > > @@ -179,9 +173,11 @@ struct console { >> > > void *data; >> > > struct console *next; >> > > int level; >> > > - struct device classdev; >> > > + struct device *classdev; >> > >> > Ick, no, keep the real structure here. It can properly handle the >> > reference counting for the object. Just correctly clean up in the >> > release function, not anywhere else. >> >> Sorry, I'm getting more and more confused about what you're asking me to do, >> and less and less clear on the rationale. >> >> Can you please clarify what "correctly cleaning up" would mean for a >> non-pointer `struct device'? >> >> Is your concern that... >> >> register_console(c) >> device_initialize(c->d) >> device_add(c->d) >> unregister_console(c) >> device_unregister(c->d) console_classdev_release(c->d) >> register_console(c) >> device_initialize(c->d) <-- classdev was not previously zeroed out >> in console_classdev_release() and bad things may happen > >Note, you can not "recycle" a structure in the driver model. So when >the console is unregistered, it should be freed. When it is registered, >it should be created. Perhaps that is the confusion here? I suspect you're close to the source of the confusion. So your point is that the `struct console' should be freed when the driver refcount drops to 0 rather than trying to do it the other way around. Right? So, just to try to come to a solution, here's the lay of the land as I understand it. Currently pretty much all consoles are statically defined (and most of the non-static cases are false positives) % git grep 'struct console.*=' -- '*.c' | awk '/static/ { print "static"; } !/static/ { print "non-static" }' | sort | uniq -c 15 non-static 105 static These consoles are defined statically largely because they may come up early enough that we don't yet have the kmalloc() infrastructure ready. One might then think we could have these early consoles use memblock_alloc(), but there is a problem. memblock_alloc_try_nid() inside memblock_alloc() is __init, so while we can still use the memory later, we can't call memblock_alloc() after __init data is freed up. This is a problem because some consoles decide if they are early or not at runtime, not compile time: % git grep -E -- '->(write|read) = .*early' | wc -l 40 So depending on runtime configuration, those consoles may either be too early to allocate with kmalloc(), or too late to allocate with memblock_alloc(). This and other reasons are why I am really trying to avoid changing the way that the `struct console' lifecycle works -- it's already extremely complex, and the chance of breaking something is very high, which is made even worse by the fact that one can only test on a very small subset of available hardware. Maybe a driver is not the best thing to use here to expose things in sysfs? Is there something else you would recommend? Thanks again for all your help and advice. :-)