From patchwork Sun Feb 18 18:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912406dyc; Sun, 18 Feb 2024 11:01:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUA+18shv0IZpoXtNGVKNHVox52wOJGux9i8wWgi0dh2cP0uo+7dVPZvW3toACduDAGegDJMQEjgYF5bn4mQqeM/ARFIw== X-Google-Smtp-Source: AGHT+IHsG2Xtn650NkQ+g481QkMUtba/FdfDKmpVnlK7lRk7wqLt4Wm0G5nvMSeLqmEj68G0iGmP X-Received: by 2002:a05:622a:1b8d:b0:42c:4e93:ac11 with SMTP id bp13-20020a05622a1b8d00b0042c4e93ac11mr13814202qtb.28.1708282876598; Sun, 18 Feb 2024 11:01:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282876; cv=pass; d=google.com; s=arc-20160816; b=tyxsuqW/jm3U6jJEj8Y55LiYl9zMEf75Up5Td5Rc2dO7S5WDM/q7Vq3W7Y0FhnszSb D7lQu0xiHC+o7TO+HMtEZT9rlCNbDmw4B/2qKchfJPTg7heh578jwbYeI1FjnbDiDebn T6UUkUxPAQXiP6fybZF74974MvpbDDGBfaU1G2Ch9vpGcGyswwXfljL09d2ROyQLfV/3 7zQRAhE78tfPTV5AqPsgAuZmGg8ZSa0dTERgPuEr+mN3kgemiV3wZyaQS6eZzqQJr5Ma lGt9E4xRIV7348yTQRdQGgmQz0ocpfNiem456qjIP5FnmzrWnFmjq5cjbUzRnk9bDjqk w/6g== 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=U8tKxZn6xYxnbLSfcQWQs6Fl73klYk0DkiEPSmtK48M=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=lK2WRxX4R5OnY97jrDZeJkpOVAha1HZJ9YJFep4Yf3pGkfZalMhFHw0QNiyl9auIBJ 8j/N9OcnWUjE/+8eWcdjODJhl/OFjcWkxDO4+csHZp1C2yb1MGxo5tlUvuZ3Ib2csncW fBv1bOMHVczX7+ylafrSuAFHz0IXEsOBxTsUGNdYNBrGWIymZQfRtFbguttd/VlQCQsh c48f+TdlVRP409zsJ3sREEVIHUeI1V/wBrrkEtI3dlbA1ErzQyCfsgHhe/1YatiO0OaO honDBhsx0+g1dsY19sRG8cjfWiBIdkh/4VaLCy+tlP8EROhY+yEZlrq6dqDZybDKSYY8 i1HQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ct5W9yD3; 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-70511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s22-20020a05622a019600b0042dd4c93593si4778393qtw.759.2024.02.18.11.01.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:01:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ct5W9yD3; 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-70511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70511-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5855E1C20F1F for ; Sun, 18 Feb 2024 19:01:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 249BB762FD; Sun, 18 Feb 2024 18:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ct5W9yD3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bUykeJ6U" 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 CEB9371B2F for ; Sun, 18 Feb 2024 18:57:55 +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=1708282677; cv=none; b=Y9mYu8xAWujFVHJL4YN45dcPm66F9YSqrRq/0uknJZazR7BDCC3xLdcyfXesUt5MLf7OlClVDuW+3bsgathwn/sq+uhKXsautDhq8kOOGvO3HCr9R113agEFc0npg1GsJuZtXmKpj2Po27X5qcQw15/BNB7++7fRr6vBojzCwK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282677; c=relaxed/simple; bh=cFmrlN6+bjkYvopWH2Q6A0YP81LxOASzKK6Wrrcc1LQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GZqveQ+1skRgw8If4+KeMTOF0wIiYzgaUwwN/GTTR8EbWpcSaUPL1R2zUdCrj7y83FFyVW5AZPO05buv+BK3g8X4qcJ9fSiOX5W/03DFVpNf/2Sq0MiOwmsKpqeQXBS+ICdv3kp6T3eAaOuByrW353Mj4JLIHoH4AyEYymul3mI= 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=ct5W9yD3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bUykeJ6U; 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=1708282673; 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=U8tKxZn6xYxnbLSfcQWQs6Fl73klYk0DkiEPSmtK48M=; b=ct5W9yD3PDE9b+waw7Odwy0FtNYmwplTQMHj7vKc38guEZ6Q2ZlG5ci0CehFfccgGPgjg1 xZqnIMdEJjovy2Okdt4hNLdtviWsJkQMQN0n2nbQhErdFGOYg9ZzTMrM0pi4amHME0hrye OH2RgT8hoFRLlY/Y8Z0zhTm4rclmFiZfaEFNwdyqZlXrtPDR3/GYFGD/x5ITcjV5KRtdfo vOiXdA4PZ4vk9m9eKs6Ttp/l3XIPTrOwAH5o3V5aZ/fZia2chddSqPEWmtjRNtdHyudDrf 4p+ewt98SR4bpsirn1cFSPTvkL3eaCPv3WXTHg2oz33OW7u5fbqc+gYE7z2jag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282673; 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=U8tKxZn6xYxnbLSfcQWQs6Fl73klYk0DkiEPSmtK48M=; b=bUykeJ6UlUC/VGxARJe/pHOyyjNV24ASEP11nA7i+rlF5J42Ds+TgwQLCsZcgLTvvgadip yi/pkG1662XnHSDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 17/26] printk: nbcon: Assign priority based on CPU state Date: Sun, 18 Feb 2024 20:03:17 +0106 Message-Id: <20240218185726.1994771-18-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264425591130387 X-GMAIL-MSGID: 1791264425591130387 Use the current state of the CPU to determine which priority to assign to the printing context. Note: The uart_port wrapper, which is responsible for non-console- printing activities, will always use NORMAL priority. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 2 ++ kernel/printk/nbcon.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index b34847ec6b0d..70e9a1ea75be 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -79,6 +79,7 @@ void nbcon_seq_force(struct console *con, u64 seq); bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); +enum nbcon_prio nbcon_get_default_prio(void); void nbcon_atomic_flush_all(void); bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, int cookie); @@ -136,6 +137,7 @@ static inline void nbcon_seq_force(struct console *con, u64 seq) { } static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } +static inline enum nbcon_prio nbcon_get_default_prio(void) { return NBCON_PRIO_NONE; } static inline void nbcon_atomic_flush_all(void) { } static inline bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, int cookie) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 747f5cbfe5ee..1a18549e43b8 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -961,6 +961,22 @@ static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) return ctxt->backlog; } +/** + * nbcon_get_default_prio - The appropriate nbcon priority to use for nbcon + * printing on the current CPU + * + * Context: Any context which could not be migrated to another CPU. + * Return: The nbcon_prio to use for acquiring an nbcon console in this + * context for printing. + */ +enum nbcon_prio nbcon_get_default_prio(void) +{ + if (this_cpu_in_panic()) + return NBCON_PRIO_PANIC; + + return NBCON_PRIO_NORMAL; +} + /** * nbcon_legacy_emit_next_record - Print one record for an nbcon console * in legacy contexts @@ -994,7 +1010,7 @@ bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, stop_critical_timings(); ctxt->console = con; - ctxt->prio = NBCON_PRIO_NORMAL; + ctxt->prio = nbcon_get_default_prio(); progress = nbcon_atomic_emit_one(&wctxt); @@ -1038,7 +1054,6 @@ static void __nbcon_atomic_flush_all(u64 stop_seq) memset(ctxt, 0, sizeof(*ctxt)); ctxt->console = con; ctxt->spinwait_max_us = 2000; - ctxt->prio = NBCON_PRIO_NORMAL; /* * Atomic flushing does not use console driver @@ -1047,9 +1062,14 @@ static void __nbcon_atomic_flush_all(u64 stop_seq) * disabled to avoid being interrupted and then * calling into a driver that will deadlock trying * acquire console ownership. + * + * This also disables migration in order to get the + * current CPU priority. */ local_irq_save(irq_flags); + ctxt->prio = nbcon_get_default_prio(); + any_progress |= nbcon_atomic_emit_one(&wctxt); local_irq_restore(irq_flags); @@ -1161,6 +1181,9 @@ static inline bool uart_is_nbcon(struct uart_port *up) * * If @up is an nbcon console, this console will be acquired and marked as * unsafe. Otherwise this function does nothing. + * + * nbcon consoles acquired via the port lock wrapper always use priority + * NBCON_PRIO_NORMAL. */ void uart_nbcon_acquire(struct uart_port *up) { @@ -1195,6 +1218,9 @@ EXPORT_SYMBOL_GPL(uart_nbcon_acquire); * * If @up is an nbcon console, the console will be marked as safe and * released. Otherwise this function does nothing. + * + * nbcon consoles acquired via the port lock wrapper always use priority + * NBCON_PRIO_NORMAL. */ void uart_nbcon_release(struct uart_port *up) {