Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp771855rdb; Sun, 18 Feb 2024 10:58:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJxaeK82wkM8+D5lXTvlkOvzZNS5f5xlXxuCPL3AbchxxBERtKMG8rVgK+UBBwfc55G0pLWzKWSmlFn9/KsMN6VJlQia3etROBTN60+A== X-Google-Smtp-Source: AGHT+IGM+N1YHrBS/pdC1vkQ2bACZHEJxU0+jRcB+HJ81GUTZheWj6LjO4EGAwRhKe2DbBU4R+PW X-Received: by 2002:a05:6358:57a0:b0:17a:e788:9dc6 with SMTP id m32-20020a05635857a000b0017ae7889dc6mr12684428rwf.9.1708282698054; Sun, 18 Feb 2024 10:58:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282698; cv=pass; d=google.com; s=arc-20160816; b=ENO/O0sNb6meyiMRMRjEW7oNy3sIClnnrJsc38xcu2BEiIWTxW3BdyS/iz9hUPKME0 u7cLNISa4yi3c0UexQMj8uzhhacACAPIwfHHv0y7EAMNaIObSavtWY2BBGW0J3NFg+ht TXR912CgvOaKSD8z7e6wlxjibkel6Z7CXCHl+JQ2L5W0ZmowbJaB1Q5GhFVhi20Cqqzy U7J7sDMb7eJOJg08wnOVQ9RGR/f8/ZtQ0xFlnPfPvfPGl27Z88p0KrNwOu837UC+3NOt AQGvZPmUDtW/prhvOyxsnOv6LPQ0U0JfbdzGFetUH9xdx8szLcsnQCq8Rh0JwX7A8Tng n41w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=3I1dHuUwYQfwJlbzcngwYe/b4Lctrl7m0BYdiHEdADM=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=oGGFANVl9+EDjn09XgsAAkJBhcgucj1FPDCIHj/798TyOlxSEt2qNXrYHrbwBBn7mG Cq54ZHj0mQmc5kVqxUiW+VKGotgAG2pVTLpAbL+J5Yt4fhe3HQNiANN5vEw0XaTxfV/8 zUEZbyxFLRoGkPfRdMhcMe/lWt/TvVkgLcjKuvk12Zipc9T1mJr602BE54W3Cm6xq4cf 0RntJ7NDNUyeDCs6bpjqQGaFjXIIITWVl9PR8TnUT8K2JA+RdeuVLZMVww1I0/9DCsh3 I13LKI1DFn4bgDOT8vQ0VwwjOjh46l/8vdmP9Mh2f92n2RhW3i/SC4uMk2mAdF3uP+yi wwuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bUvH6ld6; 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-70502-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70502-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. [139.178.88.99]) by mx.google.com with ESMTPS id sj4-20020a17090b2d8400b002995b9d7859si2653010pjb.36.2024.02.18.10.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 10:58:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70502-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bUvH6ld6; 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-70502-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70502-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 BC794281A06 for ; Sun, 18 Feb 2024 18:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B5966F53E; Sun, 18 Feb 2024 18:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bUvH6ld6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mv3bI0iZ" 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 DA5766F09C for ; Sun, 18 Feb 2024 18:57:52 +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=1708282674; cv=none; b=MrjfjejcyY12hoSJfICLYJEu1AXyJNGesjG6UCW+xUJTpm4HhSJGEThYqIyUoSlARYtlLqtH4hPldujSqoouE1T9/0M1kkrlxl/+3CzMZQnlDXqKnckVU59I3TFdA3qMiQ31rOSTd+aIQf7PXqW+atlv6YMo70MXs83plAhaxu8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282674; c=relaxed/simple; bh=vTgd2itv2WvqWfA2iHd5zEucMOb4GN4MKZQhbctg1CE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m+GfE/DmQ815XkHAIHAxqPE524y93tsrHQJ8lD8lnjKSwa7+5b6UtBpNCxafjwJf7sjMnOiaT7SE+ZpaWohlM/oK0BR9BSF9dMiOGndbtvLuk2ERdTFnbfks17SOp3hCYAcnk562lnwKIF/c3p6llGoXjy7dDiZ4VFk6KO405sE= 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=bUvH6ld6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mv3bI0iZ; 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=1708282671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3I1dHuUwYQfwJlbzcngwYe/b4Lctrl7m0BYdiHEdADM=; b=bUvH6ld6ZR2Lx7Xmdigmcn4lgfr2aDNvw4v/80RT0CXEAcaNRMKHc5jHO6u4d7wjSu/kLh xfbiIRlZLFennUA4anuz4ogw5nxq3uoQNdSr4AS9EpdIyuAyE6bm6xHKI8lP6pZSj0asaV jce8Tfn5LLyr7LDy4vYkcEfHQjv+rYzyi82pYP5oOd880wpNfwKafO0sh/KGE7/4hDp/CQ hAUPlz1qdkP9mi6CtrcL5wxhCsaz97b9WRlh33kGjePhNUgcYigxSKYU/xMeunxgaSt3Xo s3kOkTkSe7ie8C3PBR2rawdtpVOBYFIa9jCMKt4A3p5z5prM65E5vTdN5ubQkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3I1dHuUwYQfwJlbzcngwYe/b4Lctrl7m0BYdiHEdADM=; b=mv3bI0iZRBTmcWWJ3oT7jB7zGmwIkGzso/mTLeCK3sGCyUsHPvlz6U4660FUqUbnlE82tO 7rxsKqaEcP+w6OCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 09/26] printk: nbcon: Add detailed doc for write_atomic() Date: Sun, 18 Feb 2024 20:03:09 +0106 Message-Id: <20240218185726.1994771-10-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The write_atomic() callback has special requirements and is allowed to use special helper functions. Provide detailed documentation of the callback so that a developer has a chance of implementing it correctly. Signed-off-by: John Ogness --- include/linux/console.h | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index e4fc6f7c1496..5c55faa013e8 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -278,7 +278,7 @@ struct nbcon_write_context { /** * struct console - The console descriptor structure * @name: The name of the console driver - * @write: Write callback to output messages (Optional) + * @write: Legacy write callback to output messages (Optional) * @read: Read callback for console input (Optional) * @device: The underlying TTY device driver (Optional) * @unblank: Callback to unblank the console (Optional) @@ -295,7 +295,6 @@ struct nbcon_write_context { * @data: Driver private data * @node: hlist node for the console list * - * @write_atomic: Write callback for atomic context * @nbcon_state: State for nbcon consoles * @nbcon_seq: Sequence number of the next record for nbcon to print * @pbufs: Pointer to nbcon private buffer @@ -320,8 +319,35 @@ struct console { struct hlist_node node; /* nbcon console specific members */ - bool (*write_atomic)(struct console *con, - struct nbcon_write_context *wctxt); + + /** + * @write_atomic: + * + * NBCON callback to write out text in any context. (Optional) + * + * This callback is called with the console already acquired. The + * callback can use nbcon_can_proceed() at any time to verify that + * it is still the owner of the console. In the case that it has + * lost ownership, it is no longer allowed to go forward. In this + * case it must back out immediately and carefully. The buffer + * content is also no longer trusted since it no longer belongs to + * the context. + * + * If the callback needs to perform actions where ownership is not + * allowed to be taken over, nbcon_enter_unsafe() and + * nbcon_exit_unsafe() can be used to mark such sections. These + * functions are also points of possible ownership transfer. If + * either function returns false, ownership has been lost. + * + * This callback can be called from any context (including NMI). + * Therefore it must avoid usage of any locking and instead rely + * on the console ownership for synchronization. + * + * Returns true if all text was successfully written out and + * ownership was never lost, otherwise false. + */ + bool (*write_atomic)(struct console *con, struct nbcon_write_context *wctxt); + atomic_t __private nbcon_state; atomic_long_t __private nbcon_seq; struct printk_buffers *pbufs; -- 2.39.2