Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp369423lqp; Wed, 12 Jun 2024 04:18:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAke3XaSjD1W6EjCaeJV483BJs6px2oOjLh9kjR7IjvtLGfn+Ff/Et2jFhEf0b+rmMyp87nys9ufmq0RhE6Vxl7aPzgPwGIAS6lAjXYQ== X-Google-Smtp-Source: AGHT+IGEYxETV7T3NqoDrd0o9kcZ70YLldM2m07Uy9Xdd6loY4RNMfNONRcIp5wrFEhE4zrRdijg X-Received: by 2002:a17:902:eb82:b0:1f7:1bf3:5833 with SMTP id d9443c01a7336-1f83b5660ddmr15954925ad.13.1718191114078; Wed, 12 Jun 2024 04:18:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718191114; cv=pass; d=google.com; s=arc-20160816; b=GKJ9h9a5lMhdrlK8x5gCdFygI6nslfSGEsaJTS1qhUph2M+XEasbi/4HzZVbSaiIMW vHCvpnL6g8mFYYPw173NL+v0HNTnO3fY4Og/R8lrzsxTv7CPbf0TKBO4s8aI2Xc+wrCc xbEyL5+Q/uLQALdP1vnPDAwCxv5KNR2TTM+xpHd/YZ04+PKdypbSu3vDFZhosrxukVcU BUV5MUpxdHlqmcuZ+JxoAUedm6UmROoMXh6xmH7yS7bGveGTqZbKhtyXWRIyVWLWRtk9 M4Sl7u84KhvHhgpc41IqRpByWpKhd9LxzrwveTUXtLB/EWwEvOxEXhrWBChWCyirt7Ex y0xQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=9TfoN5fT9z1aWy6mZPAFxGaM3QQbIfdI9fl1+BkB0sA=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=XQg22rWBn16lj+sIzVRYwlTFF5R2fsHo3kqsfsLEP7Yjn3u7FHw64UQYrlxqacJZPM i9tRJBQbydViL3VDIcyzT85TSXLkiL4UceaL7FpkC3cWM5n2GucUaqEUcvLweIu1zIde ZaB1ZIPqYsQvHvWutBj0rWfcH4k5knMfeBkejhzsBgZnkH4LuU1xrPHQLZyEkokPcrVK qTCdW1opmGicQ5wvdr1cqgfQL588y+GljIvD0uhLp/uD0peYvbaiwcJW5l7c79WN5Tnw l1CVlbyPt0gld/kUyYlRtRJuEFv3/EBa7IYD+gJcFPtagR4kCsbq0vi+wSaqoocmjiEb 1o+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EGzRQKBj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-211404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f73b349424si24407325ad.452.2024.06.12.04.18.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:18:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EGzRQKBj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-211404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E976128743B for ; Wed, 12 Jun 2024 11:18:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB0F316F0DA; Wed, 12 Jun 2024 11:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EGzRQKBj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zpRLi3zK" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E7ED146017 for ; Wed, 12 Jun 2024 11:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718191107; cv=none; b=uwqo4r81RFlPsX4cwlrHcy7cKaUpL4M7yjN+o7qsasdWieQxxiAP0gPDUnQMWTcwE+TlQ+H7DolWRNsa6432RJwUuWKCISjsOiGHfAxmQXX36q3n421JivhPzcVRUG4qaE894fuGhpGuEFTqqyk0GTUNdIdlF8TtOZDLvbDqwLg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718191107; c=relaxed/simple; bh=PT6fOUf51ccBbvJb7+4E5fDv3MUsOjRKTM6YebMxFOA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=UXvLW1vN3eMgkEsYwYANpfBkNVhwKOJHmLARgSCdUyzueeCneZTZYuyQK6tLNZJ2NpsfvwcsNcMA1yeN9vnVu4ZwE25JFVbUggoL8E4aUqRQiy7UoSt1/hVn+ipzN+diXQh7cycWXyqmT2c7WyjnObk5I4uEpPgGZSSsVi9CTlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EGzRQKBj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zpRLi3zK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718191104; 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=9TfoN5fT9z1aWy6mZPAFxGaM3QQbIfdI9fl1+BkB0sA=; b=EGzRQKBjJvrI/FAVXDWKDfJecnRjDkJXRmXlXglaMqn51bf3npwvUEhoDkYIz4vzV3qjfG NxxF+tihkeElfCvIHVpImckIezkbdNRbBjW8ByDdYHeTm+4qP6c3i1sXlMYcwwwNdiQfMX 3LlCMUOrPTl1ZHO5XxD89PoiLleDuevbi3Ie0Ch1rGRUzz+zEypcndHTAo/LAcjLnfX74X TFiFlg2oLsmsxduqO4pi76zeFsxR6lsljPRRlX306mgjFSMYJg91XN27I4RvE6EMFLXW6t MoumbV2oOvpxuIKQGxHgSkoTHo8Cx2RyOtNBpP95Mw5p5ogxpRvfvgXzJLMqRw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718191104; 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=9TfoN5fT9z1aWy6mZPAFxGaM3QQbIfdI9fl1+BkB0sA=; b=zpRLi3zKrmqyDy+5eOEbIHGxmZUgW0nB3FaJp4f9rzCyqpmXehUQFAfEgqUZDy62OeoK7K nUErFvIUj/WPm8CQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk v2 04/18] printk: nbcon: Introduce printing kthreads In-Reply-To: References: <20240603232453.33992-1-john.ogness@linutronix.de> <20240603232453.33992-5-john.ogness@linutronix.de> <87ed95j8yh.fsf@jogness.linutronix.de> <87sexipmrk.fsf@jogness.linutronix.de> Date: Wed, 12 Jun 2024 13:24:24 +0206 Message-ID: <87plsmpfy7.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2024-06-12, Petr Mladek wrote: >> > After all, I would add two comments, like these: >> > >> > >> > /* >> > * Any access to the console device is serialized either by >> > * device_lock() or console context or both. >> > */ >> > kt = kthread_run(nbcon_kthread_func, con, "pr/%s%d", con->name, >> > con->index); >> > [...] >> > >> > /* >> > * Some users check con->kthread to decide whether to flush >> > * the messages directly using con->write_atomic(). But they >> > * do so only when the console is already in @console_list. >> > */ >> >> I do not understand how @console_list is related to racing between >> non-thread and thread. kthreads are not only created during >> registration. For example, they can be created much later when the last >> boot console unregisters. > > I had in mind two particular code paths: > > 1. The check of con->kthread in nbcon_device_release() before > calling __nbcon_atomic_flush_pending_con(). > > But it is called only when __uart_port_using_nbcon() returns true. > And it would fail when nbcon_kthread_create() is called because > > checks hlist_unhashed_lockless(&up->cons->node) > > would fail. Which checks of the console is in @console_list > > > 2. The following check in console_flush_all() > > if ((flags & CON_NBCON) && con->kthread) > continue; > > The result affects whether the legacy flush would call > nbcon_legacy_emit_next_record(). > > But this is called only for_each_console_srcu(con) > => it could not race with nbcon_kthread_create() > because this console is not in @console_list at this moment. > > By other words, I was curious whether some other code paths might > call con->write_atomic() while the kthread is already running. > > It is not that important because it would be safe anyway. > I was checking this before I realized that it would be safe. Yes, it must be safe because it can happen at any time. For example, when flushing after an emergency section. > Anyway, the information about that the console is not in @console_list > when we set con->kthread still looks useful. Except that it is not always true. If boot consoles are registered, the kthread is created later, after the console _is_ in @console_list. Setting con->kthread really has nothing to do with @console_list. > At minimum, the check would be racy if the console was on the list. The con->kthread check _is_ racey, but it doesn't matter. Perhaps you just want to make it clear that it is racey but it does not matter. How about: /* * Some users check con->kthread to decide whether to flush * the messages directly using con->write_atomic(). Although * racey, such a check for that purpose is safe because both * threaded and atomic printing are serialized by the * console context. */ con->kthread = kt; John