Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1429663lqm; Thu, 2 May 2024 14:51:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9ceB76iZEw3e6tNeh5tMSRMjkvClo/VvvbWIGRVAAEKTN2XfEORxXwaJ/RJ/2DTnI/6v//OOvs4FRlsoTmhgyfeIx9DuXzG2RV/Y4Uw== X-Google-Smtp-Source: AGHT+IG/+puJ/2QJ5zEJVjGMd7biRcXvfiLk4ClAIMSEO1mfKeGXVI5S/WxcNQt073xvzsl1wc4e X-Received: by 2002:a05:6358:7c10:b0:186:2b1e:667c with SMTP id p16-20020a0563587c1000b001862b1e667cmr914488rwf.4.1714686710589; Thu, 02 May 2024 14:51:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714686710; cv=pass; d=google.com; s=arc-20160816; b=vkdBsxVbrc8h+54+m/cYoxM9Yaqc/PBU7tpl4ODpcqVlBKV4D1OuIc0cwXo3iH0Bm9 LB04RvbNYIOx0IfveZzB/t6U8KfJNNH5ZQ3rq/jt4UUdSwfE2x4+d6hZ5vnT58X0j0e7 gwGomkc9fYoj8yorZdEMpdmKnW2T4k1KFING6xHVmn831qCGCknMUfgh+amwyhEE2d+S 44DUCmOvY3hGKzN+EpVNo6Nx8zssaFx8PYpYo5HXqW/NBsLKuDTUCv/vUJKAU8Ys4eNG llA57UqWfLHf8gNXtL0/2qEKaQQtvDDMglGKlyTl7ss69nvGGp49ejof74PfmfUB9s0B NCsA== 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=ikaIBhkO9a0LJOxhudxcKYnEZt0PSHVLhaJwgBGZFyQ=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=CudVxneHKiPcHX57rWpwVe5AcDf+WC0+1xU55JeqAMO7XT3f2nHtUfcYXEJTAxrvFa zzk2K2FTEBKTbqUjsLiDW5GVegjbQWRd7fV4dKLDBuS1+rJwS9rqirPFMZ2qpJE7ABfn G3pm1f74k4wjUAnf6gem8v6CNw67W7KTSCS7vDyM10oZ19WTTlJ7/FtfplzocXXbhdu7 jIm5GoAfZpWIAJL6BfaX6+LZ3VUP9NqQ+Nt708Q/rfoyBvRft6rmKT+MFP7MlVfljnIz DDAQ084Nfv9q97udGbyfpM/dJdWpW/p8nJg/Osfsur2p/heMCRKlUffSgzjKcDtBrlVZ awOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Lnaxy3Mz; 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-166956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166956-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 v126-20020a632f84000000b0060a0858ea71si415673pgv.36.2024.05.02.14.51.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 14:51:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166956-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=Lnaxy3Mz; 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-166956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166956-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 01B95288CEF for ; Thu, 2 May 2024 21:39:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB3B61C232A; Thu, 2 May 2024 21:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Lnaxy3Mz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mHfXRFBh" 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 07422184139 for ; Thu, 2 May 2024 21:38:48 +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=1714685930; cv=none; b=gNTwFXQGTqKtuZA8x3wnTLQLTAD1pZcg9mFbNQK5yL8r/k+AoeY2xjiTKIsEdwwYKKNvY/ClR0kaTASCejTe6hIehUMvqISoI4unmjMUefRj9JwBgMzBIi90Gh+G3oPVhtjExuUvSEX4OfGSdyJMz/yXR6rQ2Kj+gVZbCJ1UpjY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685930; c=relaxed/simple; bh=nIpG4fXaTa8mSjCbv1ZSGShw/vQloUe1E2WzNi1qKkQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fuoYQdM3c3liYIYaJ71xaAiEVpqdmT8Tq3PBecM38Ee8WGgFZ+eHBwMBwU8Nv4rLTrIzH5jnIduuKTUdyg2KrC/1WNwpzWkZIuJn+xZoWAqk1fyDjmX7DwfXY4ZwnqM5Xe5N+f1mAja7b+NQW1VK9HrARTZ9Kko1uUY9X1HzjzI= 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=Lnaxy3Mz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mHfXRFBh; 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=1714685926; 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=ikaIBhkO9a0LJOxhudxcKYnEZt0PSHVLhaJwgBGZFyQ=; b=Lnaxy3MzelPLT6Dypxah9BXa9yO3bszXdMn0azEFPWwppEid3+frayfJxKp9U9cGCt8FDG rXe/yYr1kx7RzdFx13+DfajkQ6twUZghnjAjOnfiLR4qr1L55QmEJdxSJUWa7ywx45IhAu /07sihJQB2B+7Jtmf1HVQheYsxWMED4/5JmonRfMUE4zBManaqthVmtbiMDiRpiToJ4Aew PEurfjsu7hsSyVhwMov3axLiLO4k94mKBtScwfcLN7q0FaEVJphXCouBijZR3prtiKPlaP Y+MpEs0gCbAfjOG86biT4FSJP8xkhtMKQLaTuNYN9+kuaMIm3hOswQZ6y5IDWw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1714685926; 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=ikaIBhkO9a0LJOxhudxcKYnEZt0PSHVLhaJwgBGZFyQ=; b=mHfXRFBhR+Y1FEepmsSL098XTQAXcNo0Rhv+48QUKQYIWB7luDPWPkbNpRv0NK9WroEoEh tXQm21rVwqRWZqCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v5 06/30] printk: nbcon: Add callbacks to synchronize with driver Date: Thu, 2 May 2024 23:44:15 +0206 Message-Id: <20240502213839.376636-7-john.ogness@linutronix.de> In-Reply-To: <20240502213839.376636-1-john.ogness@linutronix.de> References: <20240502213839.376636-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 Console drivers typically must deal with access to the hardware via user input/output (such as an interactive login shell) and output of kernel messages via printk() calls. To provide the necessary synchronization, usually some driver-specific locking mechanism is used (for example, the port spinlock for uart serial consoles). Until now, usage of this driver-specific locking has been hidden from the printk-subsystem and implemented within the various console callbacks. However, for nbcon consoles, it is necessary that the printk-subsystem uses the driver-specific locking so that nbcon console ownership can be acquired _after_ the driver-specific locking has succeeded. This allows for lock contention to exist on the more context-friendly driver-specific locking rather than nbcon console ownership (for non-emergency and non-panic cases). Require nbcon consoles to implement two new callbacks (device_lock(), device_unlock()) that will use whatever synchronization mechanism the driver is using for itself. Signed-off-by: John Ogness --- include/linux/console.h | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 3291cc340f1a..33a029d976c3 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -354,6 +354,49 @@ struct console { */ void (*write_atomic)(struct console *con, struct nbcon_write_context *wctxt); + /** + * @device_lock: + * + * NBCON callback to begin synchronization with driver code. + * + * Console drivers typically must deal with access to the hardware + * via user input/output (such as an interactive login shell) and + * output of kernel messages via printk() calls. This callback is + * called by the printk-subsystem whenever it needs to synchronize + * with hardware access by the driver. It should be implemented to + * use whatever synchronization mechanism the driver is using for + * itself (for example, the port lock for uart serial consoles). + * + * The callback is always called from task context. It may use any + * synchronization method required by the driver. + * + * IMPORTANT: The callback MUST disable migration. The console driver + * may be using a synchronization mechanism that already takes + * care of this (such as spinlocks). Otherwise this function must + * explicitly call migrate_disable(). + * + * The flags argument is provided as a convenience to the driver. It + * will be passed again to device_unlock(). It can be ignored if the + * driver does not need it. + */ + void (*device_lock)(struct console *con, unsigned long *flags); + + /** + * @device_unlock: + * + * NBCON callback to finish synchronization with driver code. + * + * It is the counterpart to device_lock(). + * + * This callback is always called from task context. It must + * appropriately re-enable migration (depending on how device_lock() + * disabled migration). + * + * The flags argument is the value of the same variable that was + * passed to device_lock(). + */ + void (*device_unlock)(struct console *con, unsigned long flags); + atomic_t __private nbcon_state; atomic_long_t __private nbcon_seq; struct printk_buffers *pbufs; -- 2.39.2