From patchwork Thu Dec 14 21:41:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8870402dys; Thu, 14 Dec 2023 13:43:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrm06qgiflhJm/n/XGFYvOYpnJTnt7/YxVSbgHmzhPNlx/4n7W9ckNIRIcY1PQP+vryOD+ X-Received: by 2002:a05:6214:1d28:b0:67f:143d:b8c1 with SMTP id f8-20020a0562141d2800b0067f143db8c1mr664658qvd.96.1702590183845; Thu, 14 Dec 2023 13:43:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590183; cv=none; d=google.com; s=arc-20160816; b=fdff+fxJ2dgdIPykWxexTqK6G8W/SCZhoLglv3UsrMVAKpzXajbjOqGgY3hLP5mC03 HZ4jwrwJtT+L9KMqowXHX9aZfiAMqB44pL7sFGsKsf+HBAf6+ueaHw/llTDUocc5NmQc ILJ1653uMuYaedPJfBxmCRdHLHJhfHqmpj4cMUIO3GZ8Js/8BiElitqj6N9UIq5yX5Sd 3Ru0eksOuxOcfPtJ8BRE9uHdNAv0ioydNM7G57QcytsHnGVTIQahnsNtaVC7z56g3AyB QSZ56qi9NJily53T5vmV9h0tIsNKAiep3x7zudgK+LJ7Mu4qHCly82cbFubVjFCBSJXP aRNg== ARC-Message-Signature: i=1; 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=P/NotbYcz70vb9TswAdSo/L8cfzqAV5DTPxEUBxk0c8=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=ehZH4WbOkD6ijvY5udK4M1n8pAfY/V/PoQeqKQLvR3UPhdGtaj6kxqbLLYHbI6Rpxk SlgEBlbRKuVzfFS6XZMTa7J/VKYll1J4YERZQPpWt3/5Hmyd/MEFCJ8SNowCybp1St0T qEz/g0Y3bav+oTIgTl8tf/+WTuOMT0bnbaS9K1Wyq34S3Rjg0QHJlDbFko3GleaU6zGn wuuFRTob0XM23tPriVbhmB0gRXns3FwVmhgHI/1kzd2qV/NWtHau1SalKFdzuXP/f3Tw 3OpzpqY5w3OTKtq9DFmaBbfyFovdADB0xTi/dI9B3JZVkY8TX9mEqWQNBxmGvFtVp6XT GH7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="yOcxR/U3"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-144-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144-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. [147.75.199.223]) by mx.google.com with ESMTPS id g27-20020a05620a13db00b0077d8f3a1596si15419193qkl.136.2023.12.14.13.43.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:43:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="yOcxR/U3"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-144-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144-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 8F7A61C20DCF for ; Thu, 14 Dec 2023 21:43:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FA986EB42; Thu, 14 Dec 2023 21:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yOcxR/U3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="29jZVYcn" X-Original-To: linux-kernel@vger.kernel.org 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 841086ABB3 for ; Thu, 14 Dec 2023 21:42:06 +0000 (UTC) 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=1702590124; 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=P/NotbYcz70vb9TswAdSo/L8cfzqAV5DTPxEUBxk0c8=; b=yOcxR/U3d0FPxIrFHLpGXYySVhpZMfr8I4Hwg/QRm4ZmNnim7rbVwus6zENdtjbEYhAAok ogs1XfQ9tfNvH7fxUr1+O49TWlfkwLfYVAmcVHAKTVM7HPz7t1UqtlaWJALqXp5iw7+VNf g4bwS+GDik7bOP2vg3GiQZxdsQacxZbqH5jHVV9A7x0IsVay2n7Zgy3RYunu6U9QwEtJ21 IGY+XPt4RlJo3O0oib/dknKxb/lFv54+LSseI/z4J/7ybeLK+WkkHVL7nrMsuJrsp4R3Ca 8ybVr0+0LtBDGI4yyWgQ2Pst+poQwDBu7kRIkNxnrl2m06JY0N5Y8r7lC90yPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590124; 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=P/NotbYcz70vb9TswAdSo/L8cfzqAV5DTPxEUBxk0c8=; b=29jZVYcnmRq2m2fajNwN2rkwlfR5X8Uq/N8rbSOC8BypMgCEoiI+HSyjdwf/tuPOIeV6I1 1r0swCE9anxCijBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 01/14] printk: nbcon: Relocate 32bit seq macros Date: Thu, 14 Dec 2023 22:47:48 +0106 Message-Id: <20231214214201.499426-2-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295204705402677 X-GMAIL-MSGID: 1785295204705402677 The macros __seq_to_nbcon_seq() and __nbcon_seq_to_seq() are used to provide support for atomic handling of sequence numbers on 32bit systems. Until now this was only used by nbcon.c, which is why they were located in nbcon.c and include nbcon in the name. In a follow-up commit this functionality is also needed by printk_ringbuffer. Rather than duplicating the functionality, relocate the macros to printk_ringbuffer.h. Also, since the macros will be no longer nbcon-specific, rename them to __u64seq_to_ulseq() and __ulseq_to_u64seq(). This does not result in any functional change. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/nbcon.c | 41 +++---------------------------- kernel/printk/printk_ringbuffer.h | 33 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index b96077152f49..c8093bcc01fe 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -140,39 +140,6 @@ static inline bool nbcon_state_try_cmpxchg(struct console *con, struct nbcon_sta return atomic_try_cmpxchg(&ACCESS_PRIVATE(con, nbcon_state), &cur->atom, new->atom); } -#ifdef CONFIG_64BIT - -#define __seq_to_nbcon_seq(seq) (seq) -#define __nbcon_seq_to_seq(seq) (seq) - -#else /* CONFIG_64BIT */ - -#define __seq_to_nbcon_seq(seq) ((u32)seq) - -static inline u64 __nbcon_seq_to_seq(u32 nbcon_seq) -{ - u64 seq; - u64 rb_next_seq; - - /* - * The provided sequence is only the lower 32 bits of the ringbuffer - * sequence. It needs to be expanded to 64bit. Get the next sequence - * number from the ringbuffer and fold it. - * - * Having a 32bit representation in the console is sufficient. - * If a console ever gets more than 2^31 records behind - * the ringbuffer then this is the least of the problems. - * - * Also the access to the ring buffer is always safe. - */ - rb_next_seq = prb_next_seq(prb); - seq = rb_next_seq - ((u32)rb_next_seq - nbcon_seq); - - return seq; -} - -#endif /* CONFIG_64BIT */ - /** * nbcon_seq_read - Read the current console sequence * @con: Console to read the sequence of @@ -183,7 +150,7 @@ u64 nbcon_seq_read(struct console *con) { unsigned long nbcon_seq = atomic_long_read(&ACCESS_PRIVATE(con, nbcon_seq)); - return __nbcon_seq_to_seq(nbcon_seq); + return __ulseq_to_u64seq(prb, nbcon_seq); } /** @@ -204,7 +171,7 @@ void nbcon_seq_force(struct console *con, u64 seq) */ u64 valid_seq = max_t(u64, seq, prb_first_valid_seq(prb)); - atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), __seq_to_nbcon_seq(valid_seq)); + atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), __u64seq_to_ulseq(valid_seq)); /* Clear con->seq since nbcon consoles use con->nbcon_seq instead. */ con->seq = 0; @@ -223,11 +190,11 @@ void nbcon_seq_force(struct console *con, u64 seq) */ static void nbcon_seq_try_update(struct nbcon_context *ctxt, u64 new_seq) { - unsigned long nbcon_seq = __seq_to_nbcon_seq(ctxt->seq); + unsigned long nbcon_seq = __u64seq_to_ulseq(ctxt->seq); struct console *con = ctxt->console; if (atomic_long_try_cmpxchg(&ACCESS_PRIVATE(con, nbcon_seq), &nbcon_seq, - __seq_to_nbcon_seq(new_seq))) { + __u64seq_to_ulseq(new_seq))) { ctxt->seq = new_seq; } else { ctxt->seq = nbcon_seq_read(con); diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index 18cd25e489b8..b82a96dc2ea2 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -381,4 +381,37 @@ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq, u64 prb_first_valid_seq(struct printk_ringbuffer *rb); u64 prb_next_seq(struct printk_ringbuffer *rb); +#ifdef CONFIG_64BIT + +#define __u64seq_to_ulseq(u64seq) (u64seq) +#define __ulseq_to_u64seq(rb, ulseq) (ulseq) + +#else /* CONFIG_64BIT */ + +#define __u64seq_to_ulseq(u64seq) ((u32)u64seq) + +static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq) +{ + u64 seq; + u64 rb_next_seq; + + /* + * The provided sequence is only the lower 32 bits of the ringbuffer + * sequence. It needs to be expanded to 64bit. Get the next sequence + * number from the ringbuffer and fold it. + * + * Having a 32bit representation in the console is sufficient. + * If a console ever gets more than 2^31 records behind + * the ringbuffer then this is the least of the problems. + * + * Also the access to the ring buffer is always safe. + */ + rb_next_seq = prb_next_seq(rb); + seq = rb_next_seq - ((u32)rb_next_seq - ulseq); + + return seq; +} + +#endif /* CONFIG_64BIT */ + #endif /* _KERNEL_PRINTK_RINGBUFFER_H */ From patchwork Thu Dec 14 21:41:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8870654dys; Thu, 14 Dec 2023 13:43:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWTGK3AZB1ZWLotTPRcWhjkrQR0QxN2G/5GSiM9zg0xqMqT8om9ExpzIKcpSKocip/kQpE X-Received: by 2002:a17:902:e789:b0:1d0:6ffd:e2d5 with SMTP id cp9-20020a170902e78900b001d06ffde2d5mr11893504plb.111.1702590218717; Thu, 14 Dec 2023 13:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590218; cv=none; d=google.com; s=arc-20160816; b=PZL9RMCQfV8OgCyYWKWCfEopH2aMLre9taeG6JFEVTtn0tABijLLADgAjUwcrALPz+ Yn5cra2YF33KuHCwHi+c/Z/Z77Eqp00Hbxn8L+ZmrB7r57pjVajX1dEsOTFYCUO543YW LAO4ZJMQIwPZ0oG9oXRwDhWy4tYJk8G6cN9EpRWgz99t86+94/2gloQ+4q4WCKY/CVug Q55L5AXnnGjxe1Kjlv1z59E0W85kfa07yswHLsAVRkoaS9yQPuE1kc7oj4ADQSb+l+JD 99SqCV6Cm9KtBavQrwTU+fqRAA7Zr09cAeXc+yNSeLkOH6Mzfuxi6FTnMXc5FlU46LsN Z05g== ARC-Message-Signature: i=1; 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=n7/AQ14CtAPSsdBF4bK1N6nAJCYWmYHbSVQMVRCyl58=; fh=FsZvNuK0qXzIHpKngach73/EWdkC91/zDh9w34lnxX4=; b=qERmMrusINe1IYGiJ4beM2r15O6VTx5ZFhDrK3ueA5fC0TEQm1mYz9wDzKzhksYoqc kwwRRWNjAG45ZmXDIgz6w8RoZC9/DO7gy7dSz58Tm5WzTSaA5qXZxRoJSY4zQJ5HdYUk Ui0XsbI0m6JmMRPS0tEJqNcxLUWDlX1xKa26fy2ZIktBIB3pbc1UeVzsFvtHobFwZMAl FnQYfkWhtpv497jCKHtyWaqmdV9GVmIU0P5rfgmFmNkVx/zTgBJdPYqBB3FUPPyo8psd +1+kf+B15He6KViV5V5CWRrMY2QQFvdVHf7lHMKlIe14AZgS/Q1JGxnWa/f4UA2nfkNt mfCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ELKFiU6Q; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-146-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b5-20020a170902d50500b001d0b5aa3000si451387plg.456.2023.12.14.13.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:43:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ELKFiU6Q; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-146-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 835D1B21B3B for ; Thu, 14 Dec 2023 21:43:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4232E6F630; Thu, 14 Dec 2023 21:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ELKFiU6Q"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="N18HNVVu" X-Original-To: linux-kernel@vger.kernel.org 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 37D636A34D for ; Thu, 14 Dec 2023 21:42:07 +0000 (UTC) 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=1702590125; 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=n7/AQ14CtAPSsdBF4bK1N6nAJCYWmYHbSVQMVRCyl58=; b=ELKFiU6QcHpmyjj4y3/ThWrC6NQsGQrxCPGsHKykjs/CeBfb1lK742gwL4JdDM8lCJjxFZ w+ymCW6goNmRY5vxbSXxHJ/onItb2M5fnM2QrmKkat5qnFhhrwKT8jrB4n+R6Ukd6zzinb 1jdOKuWs/T04n+S6Aou6k+sjVMrAS2iMYCfHDme3aNQKFJ3O1cdTPyagsQhPbkVA0wx2gR V5HQuORKoXg6WyYNjOyoMgwv1vDu+x9W84Rq46CcnV3SrIbOOOi5+btRwkOr9jrxFKuM2r 2u4tWmuFFrnavCGbKEMk/FpbZNgfhRGBR/Q8ByC4CaMGJNea1odvqekSvqiJNg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590125; 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=n7/AQ14CtAPSsdBF4bK1N6nAJCYWmYHbSVQMVRCyl58=; b=N18HNVVuiXztnaW/iSDFaWUXfIQT0nam9vm/nj3pVKOO4M1DD9GYxXgV0hGTwzBUbPMjDr 9e6CQjVJbikgkJCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Francesco Dolcini , kernel test robot , Sebastian Andrzej Siewior Subject: [PATCH printk v3 02/14] printk: Adjust mapping for 32bit seq macros Date: Thu, 14 Dec 2023 22:47:49 +0106 Message-Id: <20231214214201.499426-3-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295240938266427 X-GMAIL-MSGID: 1785295240938266427 Note: This change only applies to 32bit architectures. On 64bit architectures the macros are NOPs. __ulseq_to_u64seq() computes the upper 32 bits of the passed argument value (@ulseq). The upper bits are derived from a base value (@rb_next_seq) in a way that assumes @ulseq represents a 64bit number that is less than or equal to @rb_next_seq. Until now this mapping has been correct for all call sites. However, in a follow-up commit, values of @ulseq will be passed in that are higher than the base value. This requires a change to how the 32bit value is mapped to a 64bit sequence number. Rather than mapping @ulseq such that the base value is the end of a 32bit block, map @ulseq such that the base value is in the middle of a 32bit block. This allows supporting 31 bits before and after the base value, which is deemed acceptable for the console sequence number during runtime. Here is an example to illustrate the previous and new mappings. For a base value (@rb_next_seq) of 2 2000 0000... Before this change the range of possible return values was: 1 2000 0001 to 2 2000 0000 __ulseq_to_u64seq(1fff ffff) => 2 1fff ffff __ulseq_to_u64seq(2000 0000) => 2 2000 0000 __ulseq_to_u64seq(2000 0001) => 1 2000 0001 __ulseq_to_u64seq(9fff ffff) => 1 9fff ffff __ulseq_to_u64seq(a000 0000) => 1 a000 0000 __ulseq_to_u64seq(a000 0001) => 1 a000 0001 After this change the range of possible return values are: 1 a000 0001 to 2 a000 0000 __ulseq_to_u64seq(1fff ffff) => 2 1fff ffff __ulseq_to_u64seq(2000 0000) => 2 2000 0000 __ulseq_to_u64seq(2000 0001) => 2 2000 0001 __ulseq_to_u64seq(9fff ffff) => 2 9fff ffff __ulseq_to_u64seq(a000 0000) => 2 a000 0000 __ulseq_to_u64seq(a000 0001) => 1 a000 0001 [ john.ogness: Rewrite commit message. ] Reported-by: Francesco Dolcini Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202311171611.78d41dbe-oliver.sang@intel.com Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202311161555.3ee16fc9-oliver.sang@intel.com Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk_ringbuffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index b82a96dc2ea2..12f60c782e46 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -407,7 +407,7 @@ static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq) * Also the access to the ring buffer is always safe. */ rb_next_seq = prb_next_seq(rb); - seq = rb_next_seq - ((u32)rb_next_seq - ulseq); + seq = rb_next_seq - (s32)((u32)rb_next_seq - ulseq); return seq; } From patchwork Thu Dec 14 21:41:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8870525dys; Thu, 14 Dec 2023 13:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEtYCEOTl7vgd87aXI+5N0XI6E+t4XgcSYDccwdcIbU759NYux9mntPB5hAxmDdJ8FX3Xe X-Received: by 2002:a05:651c:2207:b0:2cc:21eb:f14b with SMTP id y7-20020a05651c220700b002cc21ebf14bmr3622361ljq.64.1702590200609; Thu, 14 Dec 2023 13:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590200; cv=none; d=google.com; s=arc-20160816; b=xLWri8WpJhxO3Ow0/ZvyU4+J1woB+IwxSN0GYj7JDMKdaUZWGyMWXKLKcWkxc1jN0q YvAqUvhJo8cHCHm6e+AJ+aZBquWwE9e3C3K/UCLbNnbteQM3va30V5hFjaFamQtv3PnE cVFKp0orV3lWtLKe73mfKAVs3YXVUX2zS1XC9z8yJlYKrmKgRxSf4LeF9GNlGwGXb2b/ 8HXF/pl0WzFJYYFQUEoGc7ubHuYtjr6SdWGEcd8e9J9lPBmTQOY0UnW+bImNeTRGd029 Gt+BF8wXWwJeCuxhDYKdISXLlR+DNyOemIrntnhq7Ix89a5m9v+41LfR+PuRY3iSZ806 KzRQ== ARC-Message-Signature: i=1; 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=muVNDGHsflpPS75QT30/xhAWDErFJBhvBumoamznaLA=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=jAydgz0qJ7r3sDuhZJq58OSagZGDKUR1rjWCezwl2T8fj1K8M2MVHLke9o3h/IVTTV 5cIJNk+BcEj89VfVPiLJLUeBOrd95iuIyaigghZoMSrDjTZ7p6S1Ezv+4qjvC8qKNlA8 EK6WIOSwrGhbkE+XqzdSDXPfpT1SvgXPIqfGs/ZLK3SlqfE+W09TXWs6HNFFeilRN+Rv jrZpjRdC/hyW9eHa/sR1wMiha8AZglO3v5leZTEJoqiif9n6d630X1N07t8czt7jTdj5 FVnEdws34ROG7wANrjof820gMQ/ZC54hXCi4J2W2TKNP4y6ALmc3GXQ3C7TbATJFuZ9b 84Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=b+oQS7ov; dkim=neutral (no key) header.i=@linutronix.de header.b=phT90Otf; spf=pass (google.com: domain of linux-kernel+bounces-145-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r24-20020a50c018000000b0054c5ef5de9esi6526278edb.579.2023.12.14.13.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=b+oQS7ov; dkim=neutral (no key) header.i=@linutronix.de header.b=phT90Otf; spf=pass (google.com: domain of linux-kernel+bounces-145-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 34D411F226B8 for ; Thu, 14 Dec 2023 21:43:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 189DD6F614; Thu, 14 Dec 2023 21:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b+oQS7ov"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="phT90Otf" X-Original-To: linux-kernel@vger.kernel.org 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 37E496ABB5 for ; Thu, 14 Dec 2023 21:42:07 +0000 (UTC) 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=1702590125; 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=muVNDGHsflpPS75QT30/xhAWDErFJBhvBumoamznaLA=; b=b+oQS7ovxSclsqr8szoXFqH5thsF+V/j7hxOLnR6shH6GCgYLVavhZbEycUD0bPh8KIsd3 /HQ8unq761Xz6A/zlKW0c1tqBwiK+RPYSw8z9b3h5Fag97ckFU1lZUqITRUv/S8r46v69P BCQGaJacgenSB1odluZ4hrYsY04KsCHBS8BmWKl/jka072/PNjXPSNQSd+5MzTOBt7Sr6C 6aD0jtwk9E1j9N8Z7odbKB2nM7msQTNTwU86Opx5sL9z3eT6Elac/AcyaHBTJHTLOTf2qA jUzNItuhD/asRLVfhBa/aDlLPiko1FuNfZqi2A01jZUn8r3708PYNY4WE1C9Lg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590125; 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=muVNDGHsflpPS75QT30/xhAWDErFJBhvBumoamznaLA=; b=phT90OtfDCug3ZR3eWCa6Yqoc+ndgc1bUViER55GRkZespCIz0VYuEMEEGNPQB0TvYN5gX 9z3IEeo8V9KuY7BA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 03/14] printk: Use prb_first_seq() as base for 32bit seq macros Date: Thu, 14 Dec 2023 22:47:50 +0106 Message-Id: <20231214214201.499426-4-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295221966911359 X-GMAIL-MSGID: 1785295221966911359 Note: This change only applies to 32bit architectures. On 64bit architectures the macros are NOPs. Currently prb_next_seq() is used as the base for the 32bit seq macros __u64seq_to_ulseq() and __ulseq_to_u64seq(). However, in a follow-up commit, prb_next_seq() will need to make use of the 32bit seq macros. Use prb_first_seq() as the base for the 32bit seq macros instead because it is guaranteed to return 64bit sequence numbers without relying on any 32bit seq macros. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk_ringbuffer.c | 2 +- kernel/printk/printk_ringbuffer.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index fde338606ce8..49a82ccce8e9 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1832,7 +1832,7 @@ static int prb_read(struct printk_ringbuffer *rb, u64 seq, } /* Get the sequence number of the tail descriptor. */ -static u64 prb_first_seq(struct printk_ringbuffer *rb) +u64 prb_first_seq(struct printk_ringbuffer *rb) { struct prb_desc_ring *desc_ring = &rb->desc_ring; enum desc_state d_state; diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index 12f60c782e46..ee294aaf4aeb 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -378,6 +378,7 @@ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq, bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq, struct printk_info *info, unsigned int *line_count); +u64 prb_first_seq(struct printk_ringbuffer *rb); u64 prb_first_valid_seq(struct printk_ringbuffer *rb); u64 prb_next_seq(struct printk_ringbuffer *rb); @@ -392,12 +393,12 @@ u64 prb_next_seq(struct printk_ringbuffer *rb); static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq) { + u64 rb_first_seq = prb_first_seq(rb); u64 seq; - u64 rb_next_seq; /* * The provided sequence is only the lower 32 bits of the ringbuffer - * sequence. It needs to be expanded to 64bit. Get the next sequence + * sequence. It needs to be expanded to 64bit. Get the first sequence * number from the ringbuffer and fold it. * * Having a 32bit representation in the console is sufficient. @@ -406,8 +407,7 @@ static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq) * * Also the access to the ring buffer is always safe. */ - rb_next_seq = prb_next_seq(rb); - seq = rb_next_seq - (s32)((u32)rb_next_seq - ulseq); + seq = rb_first_seq - (s32)((u32)rb_first_seq - ulseq); return seq; } From patchwork Thu Dec 14 21:41:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8870752dys; Thu, 14 Dec 2023 13:43:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOT20Xu8vfsEovkKkz76ZUW2FYRmVGrjFDFmjfaNM+sQxOCDcGf2/CUPXXmgxIBIK546nS X-Received: by 2002:a0d:d987:0:b0:5e2:f9d9:619c with SMTP id b129-20020a0dd987000000b005e2f9d9619cmr3054336ywe.39.1702590230153; Thu, 14 Dec 2023 13:43:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590230; cv=none; d=google.com; s=arc-20160816; b=L/cEbh2SKH3pHTjL/GmsZqH2nIQET3QcOOG2fW0zGs5BYNmJ7TJz2Z+x6qhT6pUBoW kuhp7VXT2Zn2tChoCINSl2/5namToZQbkM8BUsW6jvjFwq0MaRFI/sxjiL2J6zwp7Iyz 8PDwef5uu7Y41E2FVG7Py2pjJndZcID8CxmtdDziLhRelZO3ELaLdmz3sdgRrWcEhjOa IrK9UPncqN1kQWG0HOrmZHlxnBOia3g7/A+6dHCbg5naVI2wHtpg5auRsA7KWcdJRFh0 nFSp5+iXPDFDv73Mqi0XB+6IjjABePL/o0OUDfcX2nz1yeNviUGwBLI796m9DVKsL+l7 kcoA== ARC-Message-Signature: i=1; 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=AnwPd7XIokQ/bLOcP3/FHbKObdxJLytnqkjXweQk6XQ=; fh=SH94mmwiRuycNuXnyBv4dc1kk0FqoQ65LgesulXvwvo=; b=vjYaAeY8DL4RIs6bGTIvlB+PfG6xkTwyh/MDVEgvN56EUfeoAOZXKfOO5YQcVm4675 8bbr2LaoUu8T1Z4MtTzNpzBpYTubMatMiYjw5jxb1DhiOPFBOh0rFepKyWzX8OfP1cp/ vPACalsyGp48WNSI2NAnTNuF9BC5krDY56HXSruYQZAx30n9vDiSZA9xjkZwXEhOi49p kSeeastkXV02ZEbAiKHcbI8SDdS714tA7bVUM59TZZ1rfEz8/WZ+ETQUV/DJUz5NmrpD uwokhuyyDqXtnp4I+JygLT8TT6h8/yr0+tqLtrvq/9b5vHu93DKVcrfWVZjm3TLWmoXJ +jvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HkbtUXy9; dkim=neutral (no key) header.i=@linutronix.de header.b=WAOVSLxW; spf=pass (google.com: domain of linux-kernel+bounces-147-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147-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. [147.75.199.223]) by mx.google.com with ESMTPS id b23-20020a05620a04f700b0077eff47ebd6si14780434qkh.159.2023.12.14.13.43.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:43:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HkbtUXy9; dkim=neutral (no key) header.i=@linutronix.de header.b=WAOVSLxW; spf=pass (google.com: domain of linux-kernel+bounces-147-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147-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 D6AA51C21D24 for ; Thu, 14 Dec 2023 21:43:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94AF46F622; Thu, 14 Dec 2023 21:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HkbtUXy9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WAOVSLxW" X-Original-To: linux-kernel@vger.kernel.org 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 785526ABB7 for ; Thu, 14 Dec 2023 21:42:07 +0000 (UTC) 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=1702590125; 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=AnwPd7XIokQ/bLOcP3/FHbKObdxJLytnqkjXweQk6XQ=; b=HkbtUXy9HfPOvBlylkVursMQdKGv354mjRQZyCJHFNdsGMCBc5l+Sk2jJT/H4Bmi4gl1+d ZJwXdLmzoBIYC5FQPAktUaHHJN6cOOgpwZVZ/tEnpONSezyja3m5SY/EXSYasF7woZQSa8 zOLg7giGSXjvPPQ3F467bvougvrrb/7ghhjOb9x2FVx1S0tE5vNbMRmAqKEiNGxDqBvpzZ MIDnfHqML+U1C2sfrEhs2m34oKfZNrjBtxEPmXHFXblTM+PJsj0JpXfhTu9zVf6x6Bb2l0 wl2iJmC3RwFHnIJmy6K7eIynmkPVp8LWa/s+8tzNGSFd0Mv79oKyhcQlKdxC3A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590125; 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=AnwPd7XIokQ/bLOcP3/FHbKObdxJLytnqkjXweQk6XQ=; b=WAOVSLxW3hYnadim2qDrP1Rl3u5O4bI8RknF0VkzQUPexiJIia0vbqzSVCrK2qnTkdZW3s bzgv0EjaVs/9JNCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Mukesh Ojha Subject: [PATCH printk v3 04/14] printk: ringbuffer: Do not skip non-finalized records with prb_next_seq() Date: Thu, 14 Dec 2023 22:47:51 +0106 Message-Id: <20231214214201.499426-5-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295253456493091 X-GMAIL-MSGID: 1785295253456493091 Commit f244b4dc53e5 ("printk: ringbuffer: Improve prb_next_seq() performance") introduced an optimization for prb_next_seq() by using best-effort to track recently finalized records. However, the order of finalization does not necessarily match the order of the records. The optimization changed prb_next_seq() to return inconsistent results, possibly yielding sequence numbers that are not available to readers because they are preceded by non-finalized records or they are not yet visible to the reader CPU. Rather than simply best-effort tracking recently finalized records, force the committing writer to read records and increment the last "contiguous block" of finalized records. In order to do this, the sequence number instead of ID must be stored because ID's cannot be directly compared. A new memory barrier pair is introduced to guarantee that a reader can always read the records up until the sequence number returned by prb_next_seq() (unless the records have since been overwritten in the ringbuffer). This restores the original functionality of prb_next_seq() while also keeping the optimization. For 32bit systems, only the lower 32 bits of the sequence number are stored. When reading the value, it is expanded to the full 64bit sequence number using the 32bit seq macros, which fold in the value returned by prb_first_seq(). Fixes: f244b4dc53e5 ("printk: ringbuffer: Improve prb_next_seq() performance") Signed-off-by: John Ogness --- kernel/printk/printk_ringbuffer.c | 164 +++++++++++++++++++++++------- kernel/printk/printk_ringbuffer.h | 4 +- 2 files changed, 127 insertions(+), 41 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 49a82ccce8e9..04c26cca546f 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -6,6 +6,7 @@ #include #include #include "printk_ringbuffer.h" +#include "internal.h" /** * DOC: printk_ringbuffer overview @@ -303,6 +304,9 @@ * * desc_push_tail:B / desc_reserve:D * set descriptor reusable (state), then push descriptor tail (id) + * + * desc_update_last_finalized:A / desc_last_finalized_seq:A + * store finalized record, then set new highest finalized sequence number */ #define DATA_SIZE(data_ring) _DATA_SIZE((data_ring)->size_bits) @@ -1441,20 +1445,118 @@ bool prb_reserve_in_last(struct prb_reserved_entry *e, struct printk_ringbuffer return false; } +/* + * @last_finalized_seq value guarantees that all records up to and including + * this sequence number are finalized and can be read. The only exception are + * too old records which have already been overwritten. + * + * It is also guaranteed that @last_finalized_seq only increases. + * + * Be aware that finalized records following non-finalized records are not + * reported because they are not yet available to the reader. For example, + * a new record stored via printk() will not be available to a printer if + * it follows a record that has not been finalized yet. However, once that + * non-finalized record becomes finalized, @last_finalized_seq will be + * appropriately updated and the full set of finalized records will be + * available to the printer. And since each printk() caller will either + * directly print or trigger deferred printing of all available unprinted + * records, all printk() messages will get printed. + */ +static u64 desc_last_finalized_seq(struct printk_ringbuffer *rb) +{ + struct prb_desc_ring *desc_ring = &rb->desc_ring; + unsigned long ulseq; + + /* + * Guarantee the sequence number is loaded before loading the + * associated record in order to guarantee that the record can be + * seen by this CPU. This pairs with desc_update_last_finalized:A. + */ + ulseq = atomic_long_read_acquire(&desc_ring->last_finalized_seq + ); /* LMM(desc_last_finalized_seq:A) */ + + return __ulseq_to_u64seq(rb, ulseq); +} + +static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, + struct printk_record *r, unsigned int *line_count); + +/* + * Check if there are records directly following @last_finalized_seq that are + * finalized. If so, update @last_finalized_seq to the latest of these + * records. It is not allowed to skip over records that are not yet finalized. + */ +static void desc_update_last_finalized(struct printk_ringbuffer *rb) +{ + struct prb_desc_ring *desc_ring = &rb->desc_ring; + u64 old_seq = desc_last_finalized_seq(rb); + unsigned long oldval; + unsigned long newval; + u64 finalized_seq; + u64 try_seq; + +try_again: + finalized_seq = old_seq; + try_seq = finalized_seq + 1; + + /* Try to find later finalized records. */ + while (_prb_read_valid(rb, &try_seq, NULL, NULL)) { + finalized_seq = try_seq; + try_seq++; + } + + /* No update needed if no later finalized record was found. */ + if (finalized_seq == old_seq) + return; + + oldval = __u64seq_to_ulseq(old_seq); + newval = __u64seq_to_ulseq(finalized_seq); + + /* + * Set the sequence number of a later finalized record that has been + * seen. + * + * Guarantee the record data is visible to other CPUs before storing + * its sequence number. This pairs with desc_last_finalized_seq:A. + * + * Memory barrier involvement: + * + * If desc_last_finalized_seq:A reads from + * desc_update_last_finalized:A, then desc_read:A reads from + * _prb_commit:B. + * + * Relies on: + * + * RELEASE from _prb_commit:B to desc_update_last_finalized:A + * matching + * ACQUIRE from desc_last_finalized_seq:A to desc_read:A + * + * Note: _prb_commit:B and desc_update_last_finalized:A can be + * different CPUs. However, the desc_update_last_finalized:A + * CPU (which performs the release) must have previously seen + * _prb_commit:B. + */ + if (!atomic_long_try_cmpxchg_release(&desc_ring->last_finalized_seq, + &oldval, newval)) { /* LMM(desc_update_last_finalized:A) */ + old_seq = __ulseq_to_u64seq(rb, oldval); + goto try_again; + } +} + /* * Attempt to finalize a specified descriptor. If this fails, the descriptor * is either already final or it will finalize itself when the writer commits. */ -static void desc_make_final(struct prb_desc_ring *desc_ring, unsigned long id) +static void desc_make_final(struct printk_ringbuffer *rb, unsigned long id) { + struct prb_desc_ring *desc_ring = &rb->desc_ring; unsigned long prev_state_val = DESC_SV(id, desc_committed); struct prb_desc *d = to_desc(desc_ring, id); - atomic_long_cmpxchg_relaxed(&d->state_var, prev_state_val, - DESC_SV(id, desc_finalized)); /* LMM(desc_make_final:A) */ - - /* Best effort to remember the last finalized @id. */ - atomic_long_set(&desc_ring->last_finalized_id, id); + if (atomic_long_try_cmpxchg_relaxed(&d->state_var, &prev_state_val, + DESC_SV(id, desc_finalized))) { /* LMM(desc_make_final:A) */ + desc_update_last_finalized(rb); + } } /** @@ -1550,7 +1652,7 @@ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, * readers. (For seq==0 there is no previous descriptor.) */ if (info->seq > 0) - desc_make_final(desc_ring, DESC_ID(id - 1)); + desc_make_final(rb, DESC_ID(id - 1)); r->text_buf = data_alloc(rb, r->text_buf_size, &d->text_blk_lpos, id); /* If text data allocation fails, a data-less record is committed. */ @@ -1643,7 +1745,7 @@ void prb_commit(struct prb_reserved_entry *e) */ head_id = atomic_long_read(&desc_ring->head_id); /* LMM(prb_commit:A) */ if (head_id != e->id) - desc_make_final(desc_ring, e->id); + desc_make_final(e->rb, e->id); } /** @@ -1663,12 +1765,9 @@ void prb_commit(struct prb_reserved_entry *e) */ void prb_final_commit(struct prb_reserved_entry *e) { - struct prb_desc_ring *desc_ring = &e->rb->desc_ring; - _prb_commit(e, desc_finalized); - /* Best effort to remember the last finalized @id. */ - atomic_long_set(&desc_ring->last_finalized_id, e->id); + desc_update_last_finalized(e->rb); } /* @@ -2008,7 +2107,9 @@ u64 prb_first_valid_seq(struct printk_ringbuffer *rb) * newest sequence number available to readers will be. * * This provides readers a sequence number to jump to if all currently - * available records should be skipped. + * available records should be skipped. It is guaranteed that all records + * previous to the returned value have been finalized and are (or were) + * available to the reader. * * Context: Any context. * Return: The sequence number of the next newest (not yet available) record @@ -2016,34 +2117,19 @@ u64 prb_first_valid_seq(struct printk_ringbuffer *rb) */ u64 prb_next_seq(struct printk_ringbuffer *rb) { - struct prb_desc_ring *desc_ring = &rb->desc_ring; - enum desc_state d_state; - unsigned long id; u64 seq; - /* Check if the cached @id still points to a valid @seq. */ - id = atomic_long_read(&desc_ring->last_finalized_id); - d_state = desc_read(desc_ring, id, NULL, &seq, NULL); + seq = desc_last_finalized_seq(rb); - if (d_state == desc_finalized || d_state == desc_reusable) { - /* - * Begin searching after the last finalized record. - * - * On 0, the search must begin at 0 because of hack#2 - * of the bootstrapping phase it is not known if a - * record at index 0 exists. - */ - if (seq != 0) - seq++; - } else { - /* - * The information about the last finalized sequence number - * has gone. It should happen only when there is a flood of - * new messages and the ringbuffer is rapidly recycled. - * Give up and start from the beginning. - */ - seq = 0; - } + /* + * Begin searching after the last finalized record. + * + * On 0, the search must begin at 0 because of hack#2 + * of the bootstrapping phase it is not known if a + * record at index 0 exists. + */ + if (seq != 0) + seq++; /* * The information about the last finalized @seq might be inaccurate. @@ -2085,7 +2171,7 @@ void prb_init(struct printk_ringbuffer *rb, rb->desc_ring.infos = infos; atomic_long_set(&rb->desc_ring.head_id, DESC0_ID(descbits)); atomic_long_set(&rb->desc_ring.tail_id, DESC0_ID(descbits)); - atomic_long_set(&rb->desc_ring.last_finalized_id, DESC0_ID(descbits)); + atomic_long_set(&rb->desc_ring.last_finalized_seq, 0); rb->text_data_ring.size_bits = textbits; rb->text_data_ring.data = text_buf; diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index ee294aaf4aeb..2d948cc82b5b 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -75,7 +75,7 @@ struct prb_desc_ring { struct printk_info *infos; atomic_long_t head_id; atomic_long_t tail_id; - atomic_long_t last_finalized_id; + atomic_long_t last_finalized_seq; }; /* @@ -259,7 +259,7 @@ static struct printk_ringbuffer name = { \ .infos = &_##name##_infos[0], \ .head_id = ATOMIC_INIT(DESC0_ID(descbits)), \ .tail_id = ATOMIC_INIT(DESC0_ID(descbits)), \ - .last_finalized_id = ATOMIC_INIT(DESC0_ID(descbits)), \ + .last_finalized_seq = ATOMIC_INIT(0), \ }, \ .text_data_ring = { \ .size_bits = (avgtextbits) + (descbits), \ From patchwork Thu Dec 14 21:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8872101dys; Thu, 14 Dec 2023 13:46:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEz95zIP9PdJV4j1ntnH4gVYCkeggOb5WNe2LDpgtAauflcMbuePY4HV+98Ul7NrxzqzMxV X-Received: by 2002:a05:6a20:7fa0:b0:187:d4e3:c13a with SMTP id d32-20020a056a207fa000b00187d4e3c13amr13628631pzj.22.1702590404989; Thu, 14 Dec 2023 13:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590404; cv=none; d=google.com; s=arc-20160816; b=mpuOQAUr46cdI+ZXisqPq5L98R8WgAD1SvcACcfrnJqkofCsPUYYlCQJx7IfTrCn11 vYli3W4J5Gfwku1Sefz3z8uYWBMx//xZaFn01D2y/Rt0iEX9RvbNvrKktz0nGgPDpzNY 7j+KjckZgeL18gJN5djyHzo64mOX+80Lj9l16YssX2k7dm/WMa2n8gC30Vh2EhiFzJ27 2XHz7ww+zxyvlOjwFnD6ciApKw10ueM/t5l/oTf6cxPTOKd/kblRxTQQsNb52W6p/lE0 EoXKjN9zCnE7WVHxkYFuzsuuyraWlw4ZxCGqhkCr/2EXjC22UH5zTZcEXvU4EOUc1DW4 laqA== ARC-Message-Signature: i=1; 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=q48uIAB5AY2ApKCo1murQeJaZPOP9JBGkCMa5H/oZks=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=bmIGVkSZikYl91VC4lUD/RuONmrm+R8h7hF0ZPl+5I0hn0mYMqxQ3HwxboSlUlxAsO wZ3ZMQkvHOyz5DUTPnKKzvHWiKPfmFE6+rQ2GhVWGbY4usOBk5zsVx9C4txqpiq4MgKY KY0soXyPMYDZGsoiSK+q6Mm7bWeu0wt1K4kz7+Ut1bdlyvTcWAJ83IBJp3rKu9gCgggN i12uhs8flIF9pbRgbdXVwo4tIIdOdIfoYg9mFX7TW6RMLukP7jdhNsQZqm38o7bneupM 375RCQMylbme2lkjV9ClVzhVyblaWqAS9pMj+q9iV0WxFZckY85K1CnhzDj2uO6hmwwU ANxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zHOemZYY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-148-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c14-20020a63da0e000000b005c685a3f4acsi12150767pgh.887.2023.12.14.13.46.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:46:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zHOemZYY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-148-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 35385B22042 for ; Thu, 14 Dec 2023 21:44:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09C7B83AFA; Thu, 14 Dec 2023 21:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zHOemZYY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pr25KLwQ" X-Original-To: linux-kernel@vger.kernel.org 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 9C1FE6E2B5 for ; Thu, 14 Dec 2023 21:42:10 +0000 (UTC) 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=1702590126; 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=q48uIAB5AY2ApKCo1murQeJaZPOP9JBGkCMa5H/oZks=; b=zHOemZYYUinMd2+/7z/PQK/1U+igGlMmD7jmxS6Ujm81Or1gMFCOoM+izS3ovWoNVJ97tB uA9ukV2FOOOIUDQytwfsbYIR3+BauWy7FCDYOb5bgi64ehVTu/xqXo5XneymPobzurpnVE RZdwxZJpRAShbTVLBbFRYl7z5KBdCosXmU7FKu4A+V9vqd7EmhzTGAdqSz6Nld579vhFLj nC952Fb91S/HCwroykcAHUWkF4ek1Va1RdTgT42/tMrwnFSmIgR01Y+HQ+aOOL8AlFw+Kd QN/Z9vsLxsAaEnYxLJVRDSzZhLiJ3S6RjQtTnJvA+dMGeDVg739sMfCkW75cxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590126; 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=q48uIAB5AY2ApKCo1murQeJaZPOP9JBGkCMa5H/oZks=; b=pr25KLwQUYt7bJV24yRRf26QkQaWfQ8a2xyOsOekYXPINKQ2n8GiQESfD07H7wbe+Babal sq/QlnfnnIh5XTBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 05/14] printk: ringbuffer: Clarify special lpos values Date: Thu, 14 Dec 2023 22:47:52 +0106 Message-Id: <20231214214201.499426-6-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295436244852263 X-GMAIL-MSGID: 1785295436244852263 For empty line records, no data blocks are created. Instead, these valid records are identified by special logical position values (in fields of @prb_desc.text_blk_lpos). Currently the macro NO_LPOS is used for empty line records. This name is confusing because it does not imply _why_ there is no data block. Rename NO_LPOS to EMPTY_LINE_LPOS so that it is clear why there is no data block. Also add comments explaining the use of EMPTY_LINE_LPOS as well as clarification to the values used to represent data-less blocks. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk_ringbuffer.c | 20 ++++++++++++++++---- kernel/printk/printk_ringbuffer.h | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 04c26cca546f..244d991ffd73 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1034,9 +1034,13 @@ static char *data_alloc(struct printk_ringbuffer *rb, unsigned int size, unsigned long next_lpos; if (size == 0) { - /* Specify a data-less block. */ - blk_lpos->begin = NO_LPOS; - blk_lpos->next = NO_LPOS; + /* + * Data blocks are not created for empty lines. Instead, the + * reader will recognize these special lpos values and handle + * it appropriately. + */ + blk_lpos->begin = EMPTY_LINE_LPOS; + blk_lpos->next = EMPTY_LINE_LPOS; return NULL; } @@ -1214,10 +1218,18 @@ static const char *get_data(struct prb_data_ring *data_ring, /* Data-less data block description. */ if (BLK_DATALESS(blk_lpos)) { - if (blk_lpos->begin == NO_LPOS && blk_lpos->next == NO_LPOS) { + /* + * Records that are just empty lines are also valid, even + * though they do not have a data block. For such records + * explicitly return empty string data to signify success. + */ + if (blk_lpos->begin == EMPTY_LINE_LPOS && + blk_lpos->next == EMPTY_LINE_LPOS) { *data_size = 0; return ""; } + + /* Data lost, invalid, or otherwise unavailable. */ return NULL; } diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index 2d948cc82b5b..d49460f7578e 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -127,8 +127,22 @@ enum desc_state { #define DESC_SV(id, state) (((unsigned long)state << DESC_FLAGS_SHIFT) | id) #define DESC_ID_MASK (~DESC_FLAGS_MASK) #define DESC_ID(sv) ((sv) & DESC_ID_MASK) + +/* + * Special data block logical position values (for fields of + * @prb_desc.text_blk_lpos). + * + * - Bit0 is used to identify if the record has no data block. (Implemented in + * the LPOS_DATALESS() macro.) + * + * - Bit1 specifies the reason for not having a data block. + * + * These special values could never be real lpos values because of the + * meta data and alignment padding of data blocks. (See to_blk_size() for + * details.) + */ #define FAILED_LPOS 0x1 -#define NO_LPOS 0x3 +#define EMPTY_LINE_LPOS 0x3 #define FAILED_BLK_LPOS \ { \ From patchwork Thu Dec 14 21:41:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871191dys; Thu, 14 Dec 2023 13:44:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IELYNKkzHk3dvLPv+FO54hCORzOocRFRB28Pr2Gn1Fuq9x1JiFTm5ElfjTesXUo835ERRIG X-Received: by 2002:a05:620a:110c:b0:777:7906:a6e with SMTP id o12-20020a05620a110c00b0077779060a6emr11649261qkk.19.1702590289838; Thu, 14 Dec 2023 13:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590289; cv=none; d=google.com; s=arc-20160816; b=oTBdr6XoznoE+oqzhm/RCve2hT18GLuDmI5KYajU+GGTzbgxpEpIK6Zb6lGDH6PePa 8n09EGLicznCCxoUQBgUPqQIGwNlOJv4cC7Zzn37dAx3zMWJzzR4rLY0bKfy07SP5NyJ roClwsxdp6heiWV3nYPGfv/jFDo953gDhlr87xs4EVfthz8f6F7js5Wa5eTM6odC/BI3 RHzhdUUp+llEAWqHhjLq6wnn0jBjW7fL7ZsXIeMwKXmzUwJQOsnpDxf4kNpr8N4I0+N3 eliyQcUtLvA39ZYCTM9tND3wvYSrB5pPo/siSlKuLU0OwNfiZfUB84bF1Rih25sLnmPl eZwg== ARC-Message-Signature: i=1; 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=krH2QkxdJALvXRu9Bq+Fw3gs7PqsPIKkUheQqZKkVK0=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=d89FF7WYMBsa1pZC2OdZciNwjpzkeS+Ac0h+gLqloUPwVzua9O8SWYFeGCwIDs47u7 bo6Gbop1M43Ynfcc2BNL14z3DPRBSfEk7u3htHD45m21+ZV8GElXhLL7jlA5ugvSVmL0 EIQxgTHYIur+7uL/hI7TLwbmitBUbcJAx3sPLj4l+TFOcfJaIW02fBsu76FzYqUdbeTw 9POqDLZksGqYu1akfbyI8ycWFWT5rgaa/VYs4vsViCrgYIfw1V78/r8VmlJ4bi8OGX/C 71b6f+jOKZHDyk2g7viFl7JnqPVROXIykNQa6aMLjl6tqEhqxNbiMpJbwWWgIFMXsWM3 567w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qFYyVTuH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=BsC4fnb9; spf=pass (google.com: domain of linux-kernel+bounces-149-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149-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 dt32-20020a05620a47a000b007756fe9b8f6si15303739qkb.447.2023.12.14.13.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149-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=qFYyVTuH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=BsC4fnb9; spf=pass (google.com: domain of linux-kernel+bounces-149-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149-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 9891F1C21CB6 for ; Thu, 14 Dec 2023 21:44:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4FDE8182D; Thu, 14 Dec 2023 21:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qFYyVTuH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BsC4fnb9" X-Original-To: linux-kernel@vger.kernel.org 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 D9ED06E2BF for ; Thu, 14 Dec 2023 21:42:10 +0000 (UTC) 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=1702590126; 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=krH2QkxdJALvXRu9Bq+Fw3gs7PqsPIKkUheQqZKkVK0=; b=qFYyVTuHxgTC9QlqyN1QHK4WWfE+6QS+rbWzDp1kBMoZyEwL1jBrlUDxSBt83RF2jSKdlA 7yg9jBlzbenZo7mLyIr1X94I8l71A4kFMrVWwjuSQoVBE7UUdKn5C7q72xIHkRcsFipQ1p SUC0G6X64Ls7EHDGpIWHfWB2FOQ4Y+3YGhF9ezaXMQ0Oqy5tWZvSH7It2NZGDZ3mSbWHsA bGA5qd3r5PI28RTsZ/NPKam9jm18sp7LTL7YQtn8bR0womOuLsioiX3v5r8+F46kqNG0k9 DZYZqLCVOQzeq/o8a5LqDMlwuya6GYVe5l16p+R+mZSbncMtq82KHSTWy6JS4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590126; 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=krH2QkxdJALvXRu9Bq+Fw3gs7PqsPIKkUheQqZKkVK0=; b=BsC4fnb9tj450t5e44z0HhzQgechD4kbG8CjJvyXCEcSe27WZN0mvwHswe3ax+IlcCw2RX yGM+a1ZEl7KBdfAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 06/14] printk: For @suppress_panic_printk check for other CPU in panic Date: Thu, 14 Dec 2023 22:47:53 +0106 Message-Id: <20231214214201.499426-7-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295315328732615 X-GMAIL-MSGID: 1785295315328732615 Currently @suppress_panic_printk is checked along with non-matching @panic_cpu and current CPU. This works because @suppress_panic_printk is only set when panic_in_progress() is true. Rather than relying on the @suppress_panic_printk semantics, use the concise helper function other_cpu_in_progress(). The helper function exists to avoid open coding such tests. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index be95a6851164..22bb45d8f2f2 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2270,8 +2270,7 @@ asmlinkage int vprintk_emit(int facility, int level, if (unlikely(suppress_printk)) return 0; - if (unlikely(suppress_panic_printk) && - atomic_read(&panic_cpu) != raw_smp_processor_id()) + if (unlikely(suppress_panic_printk) && other_cpu_in_panic()) return 0; if (level == LOGLEVEL_SCHED) { From patchwork Thu Dec 14 21:41:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871722dys; Thu, 14 Dec 2023 13:45:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkotrywqPddwRG6dn+zbYq4BjYGLYm7YYOteXEsODd3WSjwCZRB1cbs0tLzpJ6yqEL67V1 X-Received: by 2002:a05:620a:ce5:b0:77e:fba3:a775 with SMTP id c5-20020a05620a0ce500b0077efba3a775mr7613714qkj.83.1702590355282; Thu, 14 Dec 2023 13:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590355; cv=none; d=google.com; s=arc-20160816; b=Ie+MuuDhXUH9MXVmvDORRXeVWdJGQIIhreK7lwiB/oAJ+Ru5pu9dsuqGcEXtqRo22p bwxGUXIGJS6f/TbvyUwdUm6PaUr7ieU1B8HJ/CNU3wKLNvE5JZJy3PyhxbGBU0X/UTvo D+yPQpKHoLVRPgcIPRlyMFPfCm8zcZkgkFO0D8eLjY55YmBLDPeIzVO1ljf0+klYBJyK y8YJ4/9+8ZGIipTaqqk4i/jjp6gGfc7KXuLs7eruCxLBGk52Bd1KyUgsr6EftsBj9xYh EiItb3yLnZGbBGEO0DDvEi2i2SFDsFcGbcgsHbVSPT6/CnUHvtlhTFb6Ju6OAya8KedA 2FEg== ARC-Message-Signature: i=1; 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=Vqu9Ussix9ubjDbCYbAbQXBzc4ORBqeOF0xoxnO9au9YWgJcSKtE92rNVOyMVDP7wj D1hCt/AMLobx8fvnudTJPYKp7S9CQ+bqlA6evkezrpqOQEj4LJyH+RovhsB0YX4lKIkq SaAFyqmo8MkwlDwCvW+WrBpZGizE21ysx47OQTxk0icmFFvc2Rkk2H2Pas/Nb9kXoFd/ V43+JVS7iSecz5vimdbJReSD3ozo+BYNvb76HBA/xI7LK1GoI+mnt1Q0x2I8V60o0OIp 6FcOD+6lpkeRuQxeYO7hMXqmfDOS0e3BVRv0Doy7DVdSI2IYjgzKVu4eRCiyHcq5olS4 5PrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Fl9EDpri; dkim=neutral (no key) header.i=@linutronix.de header.b="F1l2H1G/"; spf=pass (google.com: domain of linux-kernel+bounces-155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155-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. [147.75.199.223]) by mx.google.com with ESMTPS id u15-20020a05620a430f00b0077f76954d7esi10591247qko.102.2023.12.14.13.45.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Fl9EDpri; dkim=neutral (no key) header.i=@linutronix.de header.b="F1l2H1G/"; spf=pass (google.com: domain of linux-kernel+bounces-155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155-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 180F51C21D6D for ; Thu, 14 Dec 2023 21:45:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9240E2C6AB; Thu, 14 Dec 2023 21:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Fl9EDpri"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F1l2H1G/" X-Original-To: linux-kernel@vger.kernel.org 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 D9F646E2C1 for ; Thu, 14 Dec 2023 21:42:10 +0000 (UTC) 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=1702590126; 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; b=Fl9EDpriC4isCU/BtgR2fdrIobGrK+hq+Ifz9dlN3/a1ySYUNd1l8M8/WQCtjZso2uBmwY Uz7xWkah907tDY34I+G0Rv68veVCA64rwBs8UMzMFc+M92sG8xPSNeA0g6op0LWfTGnChz ITiH2Li9Zl2EVtitjdzhIS4aK60cshGIyCblZ1/0DdbZdVctvHoWpulv1yRRX2inGcKUBK DuyUZH6NSSFdU35rNVJz8t+vO+yF+rDyB7faIZxTKCYvBPVQTzwqbL6NX9AG3GTBfteHGz idEOWRMKsuB2x0026kUWgjX8jIZ91v8kZ5MXyoYvpq96CtrXV5MahJvvRB6Hug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590126; 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; b=F1l2H1G/fVUwDSZT60vtw3F6/tqAwdlqkl2Nn/lHaRx4HraBC0vfmiFsvJOZUmAE6vQqJM g6/09CwYWZ8gPIDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 07/14] printk: Add this_cpu_in_panic() Date: Thu, 14 Dec 2023 22:47:54 +0106 Message-Id: <20231214214201.499426-8-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295384092589192 X-GMAIL-MSGID: 1785295384092589192 There is already panic_in_progress() and other_cpu_in_panic(), but checking if the current CPU is the panic CPU must still be open coded. Add this_cpu_in_panic() to complete the set. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 1 + kernel/printk/printk.c | 43 +++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6c2afee5ef62..ac2d9750e5f8 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -130,6 +130,7 @@ struct printk_message { }; bool other_cpu_in_panic(void); +bool this_cpu_in_panic(void); bool printk_get_next_message(struct printk_message *pmsg, u64 seq, bool is_extended, bool may_supress); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 22bb45d8f2f2..82dc2c7949b7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -347,6 +347,29 @@ static bool panic_in_progress(void) return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID); } +/* Return true if a panic is in progress on the current CPU. */ +bool this_cpu_in_panic(void) +{ + /* + * We can use raw_smp_processor_id() here because it is impossible for + * the task to be migrated to the panic_cpu, or away from it. If + * panic_cpu has already been set, and we're not currently executing on + * that CPU, then we never will be. + */ + return unlikely(atomic_read(&panic_cpu) == raw_smp_processor_id()); +} + +/* + * Return true if a panic is in progress on a remote CPU. + * + * On true, the local CPU should immediately release any printing resources + * that may be needed by the panic CPU. + */ +bool other_cpu_in_panic(void) +{ + return (panic_in_progress() && !this_cpu_in_panic()); +} + /* * This is used for debugging the mess that is the VT code by * keeping track if we have the console semaphore held. It's @@ -2592,26 +2615,6 @@ static int console_cpu_notify(unsigned int cpu) return 0; } -/* - * Return true if a panic is in progress on a remote CPU. - * - * On true, the local CPU should immediately release any printing resources - * that may be needed by the panic CPU. - */ -bool other_cpu_in_panic(void) -{ - if (!panic_in_progress()) - return false; - - /* - * We can use raw_smp_processor_id() here because it is impossible for - * the task to be migrated to the panic_cpu, or away from it. If - * panic_cpu has already been set, and we're not currently executing on - * that CPU, then we never will be. - */ - return atomic_read(&panic_cpu) != raw_smp_processor_id(); -} - /** * console_lock - block the console subsystem from printing * From patchwork Thu Dec 14 21:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871603dys; Thu, 14 Dec 2023 13:45:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IF10Log9hKkBtpzhIfCPyZpPdtirpEImQVWlQAIDSSPADEPeNNUmAGNqZ3dXAW+SiVfGB/H X-Received: by 2002:a05:6512:1595:b0:50e:4b6:3127 with SMTP id bp21-20020a056512159500b0050e04b63127mr3950898lfb.127.1702590341104; Thu, 14 Dec 2023 13:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590341; cv=none; d=google.com; s=arc-20160816; b=Gj6ZLSsXDBMZsfMeYCt18/r70+j0/qKMV/pOHrM058JjboP6NkruUYGvY2v82ieT9Y dBvjWbNaLuhqvzI/Fb0KFMrjyQCqs+MAyC8eDWiTQ2qd7Dh2cQciFH0PrVO+4o/+mB0t cVLPeNGh+txcc/y10Tt5Weo/2FI97K4sex2bvq7Bvt6obg1NYdbgvL6MW45bSVaCNyzK lStLO0BFCnj0W+aMS9QAOiGSmj/5r1hE7uTWMB8QTZ2zR9LFHAcDfnjUpByphlKTLIfr 9ORX3y7+Y1R+E6VGnSdlBHoG67f5yRgHWW9sSUp/CZKt/l7Pg7cDkdZSL9PtEi1xBY20 ET3Q== ARC-Message-Signature: i=1; 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=dulH4uTFGHjZfiwmh5wTwYSUbBhMPUk3D6gHo+246W0=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=uR+dqgcKPKFGndMWLN6TI8WqoZGVZIBeE5bPwcAmbZyHu4YCEzbUemDs76OLddTBXZ IFlN7imDL3cTqWUlZ003Kd3jTwroO/zCJ5OV2Hro3AbQUwYVO7OjVDEXJtdhfWoyl3ON OmDqvtwc3Kswxe3pQXnI1CAf60BmJGh/K8RYAlO2C/rMAF4Ty8pDdRRpYmC9zJTu9Zpl xUHUzKUwCtqZYaEjyIhOLGqVvXUx4Ufxa3ULVd2vHThExRsa1FzbUEaphbLAY71pPxGu bpivl0rMKh8QpVTggJBVI4zeB7VqRrCLO6ZprEtr7hoZ6/v4/A0LETvFKe3gGAy5HaQ9 o74g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Um+KStAI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-150-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id de16-20020a056402309000b005528858beaasi454547edb.264.2023.12.14.13.45.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Um+KStAI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-150-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8AF671F22880 for ; Thu, 14 Dec 2023 21:45:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F330C2C690; Thu, 14 Dec 2023 21:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Um+KStAI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QiXbx7oE" X-Original-To: linux-kernel@vger.kernel.org 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 D9F086E2C0 for ; Thu, 14 Dec 2023 21:42:10 +0000 (UTC) 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=1702590127; 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=dulH4uTFGHjZfiwmh5wTwYSUbBhMPUk3D6gHo+246W0=; b=Um+KStAIeVeli6ubkyXVvhUMFOAS+CGHsj0pasba2RsNvgIJw6sMPi6+2Vl8+YxYNV55aQ Da1wq69Q1xiAHokJ9oILGdhGR5TZQxwJTSBizELnIG3HKzRamrshLvpLNA/+M1JmcR5q53 VxjgXE2dr8QYemoKKg7U5rxSrUgive0oXyomTR7Wf1vn0Z7Y75VR20+NmhymkVi7zOcevk lzUtmXaEyZCRhIPQPcU7V1y9BadI4EN8LaeawoE7tktDmktre7YG9MaCEu9TicCDFSeR/N iYmWkn0KTiQIgHKzgWKs7UzoUNtO13GD28o2yRJLQ7j0G8Ev4WFJlTN8NWIMOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590127; 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=dulH4uTFGHjZfiwmh5wTwYSUbBhMPUk3D6gHo+246W0=; b=QiXbx7oE4vDke9/uZ44k7k21fMsLQKRToJN9tPxb+hM7GI2qYu0A5+vThpVToe1d2Ki58B 5EpLq38dMFioq3DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 08/14] printk: ringbuffer: Cleanup reader terminology Date: Thu, 14 Dec 2023 22:47:55 +0106 Message-Id: <20231214214201.499426-9-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295369034879316 X-GMAIL-MSGID: 1785295369034879316 With the lockless ringbuffer, it is allowed that multiple CPUs/contexts write simultaneously into the buffer. This creates an ambiguity as some writers will finalize sooner. The documentation for the prb_read functions is not clear as it refers to "not yet written" and "no data available". Clarify the return values and language to be in terms of the reader: records available for reading. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk_ringbuffer.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 244d991ffd73..67ee1c62fcd6 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1987,11 +1987,13 @@ u64 prb_first_seq(struct printk_ringbuffer *rb) } /* - * Non-blocking read of a record. Updates @seq to the last finalized record - * (which may have no data available). + * Non-blocking read of a record. * - * See the description of prb_read_valid() and prb_read_valid_info() - * for details. + * On success @seq is updated to the record that was read and (if provided) + * @r and @line_count will contain the read/calculated data. + * + * On failure @seq is updated to a record that is not yet available to the + * reader, but it will be the next record available to the reader. */ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, struct printk_record *r, unsigned int *line_count) @@ -2010,7 +2012,7 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, *seq = tail_seq; } else if (err == -ENOENT) { - /* Record exists, but no data available. Skip. */ + /* Record exists, but the data was lost. Skip. */ (*seq)++; } else { @@ -2043,7 +2045,7 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, * On success, the reader must check r->info.seq to see which record was * actually read. This allows the reader to detect dropped records. * - * Failure means @seq refers to a not yet written record. + * Failure means @seq refers to a record not yet available to the reader. */ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq, struct printk_record *r) @@ -2073,7 +2075,7 @@ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq, * On success, the reader must check info->seq to see which record meta data * was actually read. This allows the reader to detect dropped records. * - * Failure means @seq refers to a not yet written record. + * Failure means @seq refers to a record not yet available to the reader. */ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq, struct printk_info *info, unsigned int *line_count) From patchwork Thu Dec 14 21:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8872817dys; Thu, 14 Dec 2023 13:48:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjLlj+XCOGA09g46olOl6RlRiCsPLk2KYSPrhuXa2XMFDdXdXQmYDBG9H4UbnzbA3SCjbx X-Received: by 2002:a05:6a20:918b:b0:190:61a1:3c04 with SMTP id v11-20020a056a20918b00b0019061a13c04mr7275708pzd.0.1702590501827; Thu, 14 Dec 2023 13:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590501; cv=none; d=google.com; s=arc-20160816; b=yPPdm0EbdUL35KxnNjuw914M4Vfn+7ypSIdJnVW1aTljub9MdrQ32caBQj+3n6qy/B 2gbFuzjc9HfaY+ba3hQQna4wkAMslCt1vNulU3x8yq4kFsYMX0cZ+3luvAZH6MVv84MJ Vw9894Dqvgb0ROnp82sYHkITjk3uenTRAG6OFo6ZDa8XW3P7gLaxdFbEC7tI896TJd7Q 2QreOsVqFyVSIw+jSJPo6eaH0K5sVQu/07lJKQQSa5/Fdo74gLEoTt6/u5P5S8FbuTpl ub9ITyEk+gMumtsH8wykaCzzBfzTt43WlvU5Bvfu5uUAJVHcJ/9CTET+k2vy8nsFMMzc PMpw== ARC-Message-Signature: i=1; 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=pUhEFAmqLD7ygnXJGj4vVb5QLJptqeAU+A1URy+61A8=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=N1uS9+NZ6zlQqe3/9CTf0oxAyGw+KP4r9u/Ly4PpBsv2Zei+UHElWZyMRRAeE1LhPO uUQqRNUPewf0S37WynCh7SS7qbhZHVuGtgMzmm6xn99tEXjxKQse4/3aQqFpsJHgxDe/ Uxq2AJcLTpRL7J7O2p7wDdaNRSFzMS15TxSDA5zvnTjQdPUu9/faQ1JczhnPZ8btWKFN e6iHErhfbefuav7gKn6A0hO0ALcWdSEvni+RTyga6VCdo8IIUyZ09ceeZbsgyXA0E0y3 t4YiqhYwTqj9rxRtNLfqAiJEGMe1G2ndUeUG4R4uD3x9REeVgPkGVuWpQcJws3FOH/5i LxuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BGFw4z8G; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-154-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y15-20020a17090aa40f00b0028681d132c8si13123217pjp.24.2023.12.14.13.48.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:48:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BGFw4z8G; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-154-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BC840B21CE6 for ; Thu, 14 Dec 2023 21:46:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA6872C6B9; Thu, 14 Dec 2023 21:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BGFw4z8G"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XW50EL5e" X-Original-To: linux-kernel@vger.kernel.org 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 42DDA6E2D7 for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590127; 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=pUhEFAmqLD7ygnXJGj4vVb5QLJptqeAU+A1URy+61A8=; b=BGFw4z8GXTG4+lXC2XhFYg47yYM3CZpM/hEavqQBtMYFlcUsezpwQwfgstX/dLMKaQPqAk Z3yLT4SaRfXts6yLQZpFODk385p9MjdU0/GUe2/Nzw7HLbwZk2hi8wBoRlChg4f6KWXSU2 BVNwX92MW37LW4liOvI1cd8eS7zfqoSHgqLAwdJ+YiJwf+EWP/bBiQSaNNKouagjbXNKqC r2BWFLDIMvrYexCKnv9hyAXUsE/mdpS7INtMSDM1hwVTqwvFpoQE+1Ml3xGSDNXuqiF4AT xeR8RozDa8ABAe0UJnJ5XgW4iU+PEVM88VH5lTcNagQNSd7Sb6e2y1oppm8/0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590127; 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=pUhEFAmqLD7ygnXJGj4vVb5QLJptqeAU+A1URy+61A8=; b=XW50EL5elAICRmd/Vsrw95l0aW3NnSv38FOMtMx45k9bOkCSWFuwpl8xYGdvVInIYvcT2O 3hpo244AZTdrJ5AA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 09/14] printk: Wait for all reserved records with pr_flush() Date: Thu, 14 Dec 2023 22:47:56 +0106 Message-Id: <20231214214201.499426-10-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295538051364798 X-GMAIL-MSGID: 1785295538051364798 Currently pr_flush() will only wait for records that were available to readers at the time of the call (using prb_next_seq()). But there may be more records (non-finalized) that have following finalized records. pr_flush() should wait for these to print as well. Particularly because any trailing finalized records may be the messages that the calling context wants to ensure are printed. Add a new ringbuffer function prb_next_reserve_seq() to return the sequence number following the most recently reserved record. This guarantees that pr_flush() will wait until all current printk() messages (completed or in progress) have been printed. Fixes: 3b604ca81202 ("printk: add pr_flush()") Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 2 +- kernel/printk/printk_ringbuffer.c | 113 ++++++++++++++++++++++++++++++ kernel/printk/printk_ringbuffer.h | 1 + 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 82dc2c7949b7..f3a7f5a6f6f8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3755,7 +3755,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre might_sleep(); - seq = prb_next_seq(prb); + seq = prb_next_reserve_seq(prb); /* Flush the consoles so that records up to @seq are printed. */ console_lock(); diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 67ee1c62fcd6..b7748d7c44c1 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1986,6 +1986,119 @@ u64 prb_first_seq(struct printk_ringbuffer *rb) return seq; } +/** + * prb_next_reserve_seq() - Get the sequence number after the most recently + * reserved record. + * + * @rb: The ringbuffer to get the sequence number from. + * + * This is the public function available to readers to see what sequence + * number will be assigned to the next reserved record. + * + * Note that depending on the situation, this value can be equal to or + * higher than the sequence number returned by prb_next_seq(). + * + * Context: Any context. + * Return: The sequence number that will be assigned to the next record + * reserved. + */ +u64 prb_next_reserve_seq(struct printk_ringbuffer *rb) +{ + struct prb_desc_ring *desc_ring = &rb->desc_ring; + unsigned long last_finalized_id; + atomic_long_t *state_var; + u64 last_finalized_seq; + unsigned long head_id; + struct prb_desc desc; + unsigned long diff; + struct prb_desc *d; + int err; + + /* + * It may not be possible to read a sequence number for @head_id. + * So the ID of @last_finailzed_seq is used to calculate what the + * sequence number of @head_id will be. + */ + +try_again: + last_finalized_seq = desc_last_finalized_seq(rb); + + /* + * @head_id is loaded after @last_finalized_seq to ensure that it is + * at or beyond @last_finalized_seq. + * + * Memory barrier involvement: + * + * If desc_last_finalized_seq:A reads from + * desc_update_last_finalized:A, then + * prb_next_reserve_seq:A reads from desc_reserve:D. + * + * Relies on: + * + * RELEASE from desc_reserve:D to desc_update_last_finalized:A + * matching + * ACQUIRE from desc_last_finalized_seq:A to prb_next_reserve_seq:A + * + * Note: desc_reserve:D and desc_update_last_finalized:A can be + * different CPUs. However, the desc_update_last_finalized:A CPU + * (which performs the release) must have previously seen + * desc_read:C, which implies desc_reserve:D can be seen. + */ + head_id = atomic_long_read(&desc_ring->head_id); /* LMM(prb_next_reserve_seq:A) */ + + d = to_desc(desc_ring, last_finalized_seq); + state_var = &d->state_var; + + /* Extract the ID, used to specify the descriptor to read. */ + last_finalized_id = DESC_ID(atomic_long_read(state_var)); + + /* Ensure @last_finalized_id is correct. */ + err = desc_read_finalized_seq(desc_ring, last_finalized_id, last_finalized_seq, &desc); + + if (err == -EINVAL) { + if (last_finalized_seq == 0) { + /* + * @last_finalized_seq still contains its initial + * value. Probably no record has been finalized yet. + * This means the ringbuffer is not yet full and the + * @head_id value can be used directly (subtracting + * off the id value corresponding to seq=0). + */ + + /* + * Because of hack#2 of the bootstrapping phase, the + * @head_id initial value must be handled separately. + */ + if (head_id == DESC0_ID(desc_ring->count_bits)) + return 0; + + /* + * The @head_id is initialized such that the first + * increment will yield the first record (seq=0). + * Therefore use the initial value +1 as the base to + * subtract from @head_id. + */ + last_finalized_id = DESC0_ID(desc_ring->count_bits) + 1; + } else { + /* Record must have been overwritten. Try again. */ + goto try_again; + } + } + + /* + * @diff is the number of records beyond the last record available + * to readers. + */ + diff = head_id - last_finalized_id; + + /* + * @head_id points to the most recently reserved record, but this + * function returns the sequence number that will be assigned to the + * next (not yet reserved) record. Thus +1 is needed. + */ + return (last_finalized_seq + diff + 1); +} + /* * Non-blocking read of a record. * diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index d49460f7578e..52626d0f1fa3 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -395,6 +395,7 @@ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq, u64 prb_first_seq(struct printk_ringbuffer *rb); u64 prb_first_valid_seq(struct printk_ringbuffer *rb); u64 prb_next_seq(struct printk_ringbuffer *rb); +u64 prb_next_reserve_seq(struct printk_ringbuffer *rb); #ifdef CONFIG_64BIT From patchwork Thu Dec 14 21:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871577dys; Thu, 14 Dec 2023 13:45:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2p+QZ7+7voLMcrSlxjFtmm5KDwxXzEgNUxB1utLScIs43OQTPF6DBubsrVtCugsWXu4Zb X-Received: by 2002:ad4:5f0f:0:b0:67a:91bf:28f0 with SMTP id fo15-20020ad45f0f000000b0067a91bf28f0mr12667301qvb.16.1702590338128; Thu, 14 Dec 2023 13:45:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590338; cv=none; d=google.com; s=arc-20160816; b=EJgi9G2RIlkFTjD96SkHJT9XRvJkbYXXcIt0V266RCgBKALBQ/h1g7rGo0sLtZ4KWY JUr5VevnJTYzB1s9qvqVSUo4Q1n34g17lAV4mAM3PG5Dq+mwHgk8Oca08OPEOUPjAzei 9MG++3T28T9ZyM6923ZDJtI55w7/cJ+oF6RZR46oHsa8VG61ZDDTT6lba+yqsC+H17J8 JdKqF6/pb4LkHYQe+OTmylJY/b/ewRp4MPr3/ktuoV9T7l8AIVMmUWB1c/lJvZ5qrdZf QEA4BgrNofqRcA+6Gi4Jge9ym6cWzrpmFSZe5vD0wY44x1uIVLgpDgUf2dDGc28qRWdH X+dQ== ARC-Message-Signature: i=1; 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=AOpz80KH0gOIPorBUANVFFuEUm2IlzR04QH0UC2n8ec=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=GKdyTtYKWQBhTYs/kIfAwnCX6m0uK4DLQJcQmsBxYcRVIuLETqY9mI+BQA4JrGkmT9 7dtOASyUbCND1bKgxCNOcTSqnGif2X6w0jbHbBrfjD0QUoO6x6zqim59+gW2an3cfWQ4 IVIgS5c3nluiXJyIeA9dB9yCyW2Sq/8nv3rF+7syCWI2hvxfWXoCtiotfYSQmJNJ9klO uqLkq9X+y0JwbK/2pbjdYPalAifKcCf1/O6GlVdzDKL623J+i7dKBXYYjMbP0lYfrWvX YdezllfDX+TNQQVnm6xOaI5qC7XGfPWMDUd3yEvCAKx8P6luX/AXNr316/YutF0bpfQk 38OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3XPgKbTY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153-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. [147.75.199.223]) by mx.google.com with ESMTPS id dz12-20020ad4588c000000b0067ef8d281bfsi4565524qvb.19.2023.12.14.13.45.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3XPgKbTY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153-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 E57461C21D23 for ; Thu, 14 Dec 2023 21:45:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9B512C68D; Thu, 14 Dec 2023 21:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3XPgKbTY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="y8/Gtj27" X-Original-To: linux-kernel@vger.kernel.org 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 42E446E2D9 for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590127; 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=AOpz80KH0gOIPorBUANVFFuEUm2IlzR04QH0UC2n8ec=; b=3XPgKbTYjsOSZZI8Z0yrQGgswsqfMiaE7LTZuoZlvjGuK0QB2uH+6eWXptBrjF0N1QXiNz XZ2QDMG0/8fkf4dRt8pddUR6G1VYuX2DjCbBCMX8gYVUUcM8YnZH9ZNil23NZ3KV7NIEAV oUXhE88cRwHF4MzdPo45kcwPU/vppvgtM8XkZdCtxDkeqEaIw3dD1t/nV6i41/WK7M58fn mGLa4m71D/jZOOCzeKiEbdBbVTAUPUHQqPVz7Rps+6UBq4XFf7GhhrIOAfhAxZ1VMy4mw3 lVw2boR0W/FUVmYQ17ZoQ8oOdAV2wh/pto+a4EDaVr00NGltAoAWE6pvIMEf4w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590127; 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=AOpz80KH0gOIPorBUANVFFuEUm2IlzR04QH0UC2n8ec=; b=y8/Gtj27CBD6NJc0FZUEREShj5VIVtIJaLWUgTsuCtS9F+eakMLN6S2Rqku02qW3KLc87y aGeNAXVmuQ5UbiAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 10/14] printk: ringbuffer: Skip non-finalized records in panic Date: Thu, 14 Dec 2023 22:47:57 +0106 Message-Id: <20231214214201.499426-11-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295366389041241 X-GMAIL-MSGID: 1785295366389041241 Normally a reader will stop once reaching a non-finalized record. However, when a panic happens, writers from other CPUs (or an interrupted context on the panic CPU) may have been writing a record and were unable to finalize it. The panic CPU will reserve/commit/finalize its panic records, but these will be located after the non-finalized records. This results in panic() not flushing the panic messages. Extend _prb_read_valid() to skip over non-finalized records if on the panic CPU. Fixes: 896fbe20b4e2 ("printk: use the lockless ringbuffer") Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk_ringbuffer.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index b7748d7c44c1..d6ed33683b8b 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -2107,6 +2107,10 @@ u64 prb_next_reserve_seq(struct printk_ringbuffer *rb) * * On failure @seq is updated to a record that is not yet available to the * reader, but it will be the next record available to the reader. + * + * Note: When the current CPU is in panic, this function will skip over any + * non-existent/non-finalized records in order to allow the panic CPU + * to print any and all records that have been finalized. */ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, struct printk_record *r, unsigned int *line_count) @@ -2129,8 +2133,28 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, (*seq)++; } else { - /* Non-existent/non-finalized record. Must stop. */ - return false; + /* + * Non-existent/non-finalized record. Must stop. + * + * For panic situations it cannot be expected that + * non-finalized records will become finalized. But + * there may be other finalized records beyond that + * need to be printed for a panic situation. If this + * is the panic CPU, skip this + * non-existent/non-finalized record unless it is + * at or beyond the head, in which case it is not + * possible to continue. + * + * Note that new messages printed on panic CPU are + * finalized when we are here. The only exception + * might be the last message without trailing newline. + * But it would have the sequence number returned + * by "prb_next_reserve_seq() - 1". + */ + if (this_cpu_in_panic() && ((*seq + 1) < prb_next_reserve_seq(rb))) + (*seq)++; + else + return false; } } From patchwork Thu Dec 14 21:41:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871538dys; Thu, 14 Dec 2023 13:45:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm8WhBSp64G4a21pGu+PXeEuBXkW4lsiyOj7uGVCIpiiPOcpgwwZtzxHbhvhUh6jgwgC9Q X-Received: by 2002:a05:620a:495b:b0:77d:a463:e9cc with SMTP id vz27-20020a05620a495b00b0077da463e9ccmr11086842qkn.19.1702590332395; Thu, 14 Dec 2023 13:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590332; cv=none; d=google.com; s=arc-20160816; b=MvQ3/x6GqhEYSwRPmxGC2ugx2M3M8PyZdiO8DZC3hEFblZu7k/s3pB25ysI70KnuxN omTcEBIjyCb5eNs20MwsGTHtfU3wPC1ucANGAWPklYmp+BIjnaWMAj6x09OlOvY8G59Z b21jjMiA08EtObLDQrC5uCC+JNWWG6xDUmc3vCStj0Ir2rrwWI0ic+1Fb6vupzy+degw Xp+y5bi4xID41HWzfU42Sn8hU7DWjUs/TAaot0wus//4n24yeh1l6ntVDckMhBz6EGfI ssTJQtjmiOEpMlY89KjaoeyBARacAiDlkd8quubvXmjy++Z9hdXjwj6hPBcaSR5ZppWc tabQ== ARC-Message-Signature: i=1; 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=w+Rj9ow8fovhfkl47C5quy90KNsRy8XmYEJxuaPSPxc=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=dAJKP4274iuhd0bw0Axe/VL7pp3B5b/ADY1X3nh80HHfXolnS7CyGCyTgA/+9M14dY ng4vYY7fHDsmNKxDYtwq+/P5A/mLHFwgCdPHmT9yw1N1uAmtkkkn7OwZhsmQs+cXoGTQ FMGVUv+THW/nGRnx5IkTcyrQTu9OKl95zGwO9wY9fGlLUNixpXUu6HEjjVK8PdFYSb0v DsCfkFxUBtCOslKyVYHvAT6pLiYCGxJOVsX2Fl8DWPJYLbISNLuq+DKjH2vNYevOqkxO lno0anwQZTUswUyn0d3hcZYOlWGvpHCrfVMZ94xXVegs7m33bMF8bo+pX6VgJC/QVx68 lMwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rYKzl1gL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=E4nJ9zge; spf=pass (google.com: domain of linux-kernel+bounces-151-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151-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 v2-20020a05620a440200b0077f357665d5si17063261qkp.400.2023.12.14.13.45.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151-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=rYKzl1gL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=E4nJ9zge; spf=pass (google.com: domain of linux-kernel+bounces-151-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151-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 34A661C21BD3 for ; Thu, 14 Dec 2023 21:45:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4D642C684; Thu, 14 Dec 2023 21:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rYKzl1gL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E4nJ9zge" X-Original-To: linux-kernel@vger.kernel.org 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 4572B6E2DB for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590128; 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=w+Rj9ow8fovhfkl47C5quy90KNsRy8XmYEJxuaPSPxc=; b=rYKzl1gLfyiH9IJP+TFLliwyltsoWallmmQO2rIWW8Z/fGewTSWXqFjmYrmYTF+CeN4zKV wPontEoTCZuXFuB3Ybr6bj8SPuuXyeVscircT/Ol/ro4/4dtG60znLbdixzbjBmpbJlFq3 J3TKHO8N6BO1RKK25l+KflE1Xq/GC2yT5PjTw3ZWCPgmMuFfXHba9D9gMifVHVXsifgcar /6IPOTBBy9xorvPK9ZfRGwCxypgXJ6rrybFNb9io6crG3P4hKA5Ph1junGYvzLOycp+ckA d1JYd/lzSbUDSdRQ2G9pcAEg7G9bpuDMUoSFxsEw+Kaq+kojiFKqWrbCnXIIhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590128; 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=w+Rj9ow8fovhfkl47C5quy90KNsRy8XmYEJxuaPSPxc=; b=E4nJ9zgeLAGTpX7uf+GwQSKNUOUmHjHZFCXuM4dmVdN4NYPZT8iNldWycwr5Ytv/BL7qeg JD1ZUoqpcg9ry0DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 11/14] printk: ringbuffer: Consider committed as finalized in panic Date: Thu, 14 Dec 2023 22:47:58 +0106 Message-Id: <20231214214201.499426-12-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295360232112656 X-GMAIL-MSGID: 1785295360232112656 A descriptor in the committed state means the record does not yet exist for the reader. However, for the panic CPU, committed records should be handled as finalized records since they contain message data in a consistent state and may contain additional hints as to the cause of the panic. Add an exception for records in the commit state to not be considered non-existing when reading from the panic CPU. Signed-off-by: John Ogness --- kernel/printk/printk_ringbuffer.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index d6ed33683b8b..e7b808b829a0 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1857,6 +1857,8 @@ static bool copy_data(struct prb_data_ring *data_ring, * descriptor. However, it also verifies that the record is finalized and has * the sequence number @seq. On success, 0 is returned. * + * For the panic CPU, committed descriptors are also considered finalized. + * * Error return values: * -EINVAL: A finalized record with sequence number @seq does not exist. * -ENOENT: A finalized record with sequence number @seq exists, but its data @@ -1875,16 +1877,25 @@ static int desc_read_finalized_seq(struct prb_desc_ring *desc_ring, /* * An unexpected @id (desc_miss) or @seq mismatch means the record - * does not exist. A descriptor in the reserved or committed state - * means the record does not yet exist for the reader. + * does not exist. A descriptor in the reserved state means the + * record does not yet exist for the reader. */ if (d_state == desc_miss || d_state == desc_reserved || - d_state == desc_committed || s != seq) { return -EINVAL; } + /* + * A descriptor in the committed state means the record does not yet + * exist for the reader. However, for the panic CPU, committed + * records are also handled as finalized records since they contain + * message data in a consistent state and may contain additional + * hints as to the cause of the panic. + */ + if (d_state == desc_committed && !this_cpu_in_panic()) + return -EINVAL; + /* * A descriptor in the reusable state may no longer have its data * available; report it as existing but with lost data. Or the record From patchwork Thu Dec 14 21:41:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871649dys; Thu, 14 Dec 2023 13:45:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZxVhZYrCUuhma97sEO/fs6otcCRDbUdRR9+tIU7VaK4GBZhVjg8WP1qc6NCIZNp2Ni9Un X-Received: by 2002:a17:907:944d:b0:9e6:f7c6:792f with SMTP id dl13-20020a170907944d00b009e6f7c6792fmr3170446ejc.17.1702590346294; Thu, 14 Dec 2023 13:45:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590346; cv=none; d=google.com; s=arc-20160816; b=nZ33Ef1ZpHTomx8dZ6hVX32u29kd/7+R+XygSzXvbuGWoCE8OdtiwrlOk5SzCZ9MPD Hn7bgLf5m/82YqZ7QrDTYSJ+4s0q99iybrEbcxg4fPcr7RPwXNOUX2bAeFw/7ecLNuy3 XLgcpRXtgbyY1Up74s45eojEKBHi+qaZV/7Dr2p3CQ7S2TqMzJ4oXYeoUSQCQQDduGGR md7Vpfzr8Yc0OK6da4d09N9pLpIMdiFA3y3xLgQLrN4KtdfM0qp5qibnfLLy8Dvjsb4b zfUyOxKwVuX5AcBp+DgGJVp2CEW6zuNBEaSeEQh7WTDx/74DMDlpZ2WCuVUk/xNrEjBp pFsg== ARC-Message-Signature: i=1; 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=5gccnnm0QINuqJ5Q69vjwoN8uCr8tb4sBQoCznhnpik=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=f7d4QYvKG/MyaMcTefcwTepk1V+nXzmMIH4KgtOKB4nvVy6lrI2T1ztfNchCGuZo9z gX9AtFF5mePz1eAowvxmHhox3MbSjVTBXczNeYMcH1E5+t9vRLWEx7x9S4TWwKL9B6Cq 9Ot300qjmjCD0kpmwh3KJ1o1nDJgbWozGgoeTmpGscrVX4XvdbPxlDOqUld092Pk3PTp jMJ7JBxqvOb6wPWH6rfzz58Liubp/c0WvannXloN9wdmehCwv9DePq5HEeFsXbCLggGB Y8m0iTXS95cjsXts/+nL4a+EnG8Jm+c83iI7zaWoWb6nJRRCyw/GATX2dTkGxORJmiMa Y8JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tv9svISY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="I/fIFq+C"; spf=pass (google.com: domain of linux-kernel+bounces-152-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j16-20020a170906831000b00a2318052c03si52328ejx.942.2023.12.14.13.45.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tv9svISY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="I/fIFq+C"; spf=pass (google.com: domain of linux-kernel+bounces-152-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152-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 am.mirrors.kernel.org (Postfix) with ESMTPS id E25DC1F222F6 for ; Thu, 14 Dec 2023 21:45:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3865F2C698; Thu, 14 Dec 2023 21:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tv9svISY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I/fIFq+C" X-Original-To: linux-kernel@vger.kernel.org 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 463FD6E2DD for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590128; 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=5gccnnm0QINuqJ5Q69vjwoN8uCr8tb4sBQoCznhnpik=; b=tv9svISYbQXkoRePsS+M089g14wfdhxM4HHUsK+JwLPSbUtHs9Oo4otPG1X4ctpuCo92lv +Egv1fOKFhbHDtSyvl3sGOiZjMm75TXwyiMqtkHdo/HTc3MHPt1H0sZvE+AiodYv1Jtq+m HhgCENbsxbC7YKL0n06eqds4KlnUdHLqj8Ai6CIgUdXMbv+nLP6yo+38BipdjZxa8UhgHC FNquv+2VA+vhroxEm255Xmi8Qmx4LeMFa1jKa4+4E1Ad5dtayOeNPHN4NNZWCxZoJTykqV mv3gIgoBgFaB2h3VF/HyNi7Abxgev8Qof7x7DL/z/Q0pr3KPslMpAkch1wJVrA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590128; 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=5gccnnm0QINuqJ5Q69vjwoN8uCr8tb4sBQoCznhnpik=; b=I/fIFq+CG8/UDnQj2JPgMa4ksS360/MfB8fZoC9axu75aBKifTSPv3TlZlcgKQJStcIqsE CKlnl5yoUg2E2BCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 12/14] printk: Disable passing console lock owner completely during panic() Date: Thu, 14 Dec 2023 22:47:59 +0106 Message-Id: <20231214214201.499426-13-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295375027180931 X-GMAIL-MSGID: 1785295375027180931 From: Petr Mladek The commit d51507098ff91 ("printk: disable optimistic spin during panic") added checks to avoid becoming a console waiter if a panic is in progress. However, the transition to panic can occur while there is already a waiter. The current owner should not pass the lock to the waiter because it might get stopped or blocked anytime. Also the panic context might pass the console lock owner to an already stopped waiter by mistake. It might happen when console_flush_on_panic() ignores the current lock owner, for example: CPU0 CPU1 ---- ---- console_lock_spinning_enable() console_trylock_spinning() [CPU1 now console waiter] NMI: panic() panic_other_cpus_shutdown() [stopped as console waiter] console_flush_on_panic() console_lock_spinning_enable() [print 1 record] console_lock_spinning_disable_and_check() [handover to stopped CPU1] This results in panic() not flushing the panic messages. Fix these problems by disabling all spinning operations completely during panic(). Another advantage is that it prevents possible deadlocks caused by "console_owner_lock". The panic() context does not need to take it any longer. The lockless checks are safe because the functions become NOPs when they see the panic in progress. All operations manipulating the state are still synchronized by the lock even when non-panic CPUs would notice the panic synchronously. The current owner might stay spinning. But non-panic() CPUs would get stopped anyway and the panic context will never start spinning. Fixes: dbdda842fe96 ("printk: Add console owner and waiter logic to load balance console writes") Signed-off-by: Petr Mladek Signed-off-by: John Ogness --- kernel/printk/printk.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f3a7f5a6f6f8..cb99c854a648 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1869,10 +1869,23 @@ static bool console_waiter; */ static void console_lock_spinning_enable(void) { + /* + * Do not use spinning in panic(). The panic CPU wants to keep the lock. + * Non-panic CPUs abandon the flush anyway. + * + * Just keep the lockdep annotation. The panic-CPU should avoid + * taking console_owner_lock because it might cause a deadlock. + * This looks like the easiest way how to prevent false lockdep + * reports without handling races a lockless way. + */ + if (panic_in_progress()) + goto lockdep; + raw_spin_lock(&console_owner_lock); console_owner = current; raw_spin_unlock(&console_owner_lock); +lockdep: /* The waiter may spin on us after setting console_owner */ spin_acquire(&console_owner_dep_map, 0, 0, _THIS_IP_); } @@ -1897,6 +1910,22 @@ static int console_lock_spinning_disable_and_check(int cookie) { int waiter; + /* + * Ignore spinning waiters during panic() because they might get stopped + * or blocked at any time, + * + * It is safe because nobody is allowed to start spinning during panic + * in the first place. If there has been a waiter then non panic CPUs + * might stay spinning. They would get stopped anyway. The panic context + * will never start spinning and an interrupted spin on panic CPU will + * never continue. + */ + if (panic_in_progress()) { + /* Keep lockdep happy. */ + spin_release(&console_owner_dep_map, _THIS_IP_); + return 0; + } + raw_spin_lock(&console_owner_lock); waiter = READ_ONCE(console_waiter); console_owner = NULL; From patchwork Thu Dec 14 21:42:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871691dys; Thu, 14 Dec 2023 13:45:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkIa1stHThds3F2d+6mG3mCUHxzM1wVk3maizaKzypDvmtyQdETRXYqGzIY0ekH//roRk0 X-Received: by 2002:a17:902:8a88:b0:1d0:6ffd:9e27 with SMTP id p8-20020a1709028a8800b001d06ffd9e27mr9423765plo.121.1702590351187; Thu, 14 Dec 2023 13:45:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590351; cv=none; d=google.com; s=arc-20160816; b=qShvnkR1GQSflb1nrLLcY9E8gPSg/3kt4R9QaMECyPsnt+KSuDI97aIahveCLc4U/X pXAYQ7U2Qr3lZLr0rVZqwGHpmXWN0InMCt0rQEgf3Our6os0jUrtegPb8tLcF7Ujpo6l ShePfvqLzn7XmKV8m41X4651ez+oph62UKmQsFzBmhfRsOu+AfncipfzN2u9LY/7VQ4f 6PSfEwJ65x8Og/O+ltkQpkaN4nbLiBsca+USAizPyazN3RoqviHW/Dacsd4xojQtTu5u W6/0HMg2p+Ak/T5Hj9L3a/O0lK3yGAvAUYBxTx5n11FUGzb43YMfDAwi7INZ4NGjNw9f mcYg== ARC-Message-Signature: i=1; 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=X4rvWoxnqgzEuAgNoYI/eGkAegsSWbGumqPznFMqF+U=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=D2fr60MrTFzdd47J4/RKhKB/PqLojFjSQ0q1Je+xyzbEWIrkmLbFIJER/XoKFHoCg0 7keGERDwOuSYA5VqVv7V0+oI8HMNt1GbrNoRp3xr4edvpCoNNim5hFZUfFCz1oRU9FdL /IulQnnnl9Mq/E15GV+BT+ZaYNVFGMpJgj+dM9Kf4VlwWD2WnboX/5maJ4esu/xeabIV xZjB2bE36GGDPdVlmW9UlWTebeoJ9xNfJJZxEciVGlsTZtBS18PzqVJz5RLQ4LUI+eP1 WwsuK8SGNclW+vUL/VRMyQAc9qhJhEzsbAHvUiChJ6dq/2huYzQXPgTQuYCfc8t6LC2k uHsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IczEGKqF; dkim=neutral (no key) header.i=@linutronix.de header.b="EZ/nLN6F"; spf=pass (google.com: domain of linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f18-20020a170902ce9200b001d36b1705f0si1565065plg.54.2023.12.14.13.45.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156-ouuuleilei=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=IczEGKqF; dkim=neutral (no key) header.i=@linutronix.de header.b="EZ/nLN6F"; spf=pass (google.com: domain of linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E392328371B for ; Thu, 14 Dec 2023 21:45:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ADDA2C6A2; Thu, 14 Dec 2023 21:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IczEGKqF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EZ/nLN6F" X-Original-To: linux-kernel@vger.kernel.org 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 DF1496E58E for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590128; 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=X4rvWoxnqgzEuAgNoYI/eGkAegsSWbGumqPznFMqF+U=; b=IczEGKqFD1oy+Qg8z9W3ASm1EtJPsy0YWe3mtabbGGlNNi+1YViu93FrmJd/s0YY/mjwVv IbjcDUoXwTMgDkjFvNEIMdAs3d2wRqq22t6BgChFhGJ/ipARopaROpvgZbQQiFta1P8oJ3 86G1akAsb0XQkl/xgOrcdboEkLI2tqDe+uIrsXsYhlxxKS+ThW6/LpoDksG4VC/MqlZeMW lUvFe1M6o66t4WVMSlikkgtaooz6ztl0xuVce+klfEvFeuvHqjDK68JtT5J63BuDEKsDO1 KeC3A2M09eVmkhhXjlCuT9ICK97N/q7lGJ4YzNcUFyHFIQPCKx9EIv1XvRbakA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590128; 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=X4rvWoxnqgzEuAgNoYI/eGkAegsSWbGumqPznFMqF+U=; b=EZ/nLN6FZnFW+QHK6HtPkCdu30khYWm1kLAFdRJgMDfIsfceHUVNIecPc9cscZ9BaccODt phCyLhtqdyFnt1Ag== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 13/14] printk: Avoid non-panic CPUs writing to ringbuffer Date: Thu, 14 Dec 2023 22:48:00 +0106 Message-Id: <20231214214201.499426-14-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295379974452857 X-GMAIL-MSGID: 1785295379974452857 Commit 13fb0f74d702 ("printk: Avoid livelock with heavy printk during panic") introduced a mechanism to silence non-panic CPUs if too many messages are being dropped. Aside from trying to workaround the livelock bugs of legacy consoles, it was also intended to avoid losing panic messages. However, if non-panic CPUs are writing to the ringbuffer, then reacting to dropped messages is too late. To avoid losing panic CPU messages, silence non-panic CPUs immediately on panic. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index cb99c854a648..1685a71f3f71 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -462,12 +462,6 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; static DEFINE_MUTEX(syslog_lock); #ifdef CONFIG_PRINTK -/* - * During panic, heavy printk by other CPUs can delay the - * panic and risk deadlock on console resources. - */ -static int __read_mostly suppress_panic_printk; - DECLARE_WAIT_QUEUE_HEAD(log_wait); /* All 3 protected by @syslog_lock. */ /* the next printk record to read by syslog(READ) or /proc/kmsg */ @@ -2322,7 +2316,12 @@ asmlinkage int vprintk_emit(int facility, int level, if (unlikely(suppress_printk)) return 0; - if (unlikely(suppress_panic_printk) && other_cpu_in_panic()) + /* + * The messages on the panic CPU are the most important. If + * non-panic CPUs are generating any messages, they will be + * silently dropped. + */ + if (other_cpu_in_panic()) return 0; if (level == LOGLEVEL_SCHED) { @@ -2799,8 +2798,6 @@ void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) bool printk_get_next_message(struct printk_message *pmsg, u64 seq, bool is_extended, bool may_suppress) { - static int panic_console_dropped; - struct printk_buffers *pbufs = pmsg->pbufs; const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); const size_t outbuf_sz = sizeof(pbufs->outbuf); @@ -2828,17 +2825,6 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq, pmsg->seq = r.info->seq; pmsg->dropped = r.info->seq - seq; - /* - * Check for dropped messages in panic here so that printk - * suppression can occur as early as possible if necessary. - */ - if (pmsg->dropped && - panic_in_progress() && - panic_console_dropped++ > 10) { - suppress_panic_printk = 1; - pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\n"); - } - /* Skip record that has level above the console loglevel. */ if (may_suppress && suppress_message_printing(r.info->level)) goto out; From patchwork Thu Dec 14 21:42:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8872805dys; Thu, 14 Dec 2023 13:48:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE419asuCziA3BTUtBFX9mrSlTRpB3f7cxv0lBaBlwVM1aDMAtVcMZsA/aD2W/E9zZNeMJp X-Received: by 2002:a05:6e02:320f:b0:35f:847c:1e4c with SMTP id cd15-20020a056e02320f00b0035f847c1e4cmr1370319ilb.89.1702590500311; Thu, 14 Dec 2023 13:48:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590500; cv=none; d=google.com; s=arc-20160816; b=SbCD29dBrZ4l++x2gkVr24GluMaKshdRJPSdyolZLQPBpVcioNfR9ug/96nhUtfYSA tgGJM1iFlRSd3Rq+/9GCI6isfFw3UZerDcAseSKl5SEgEFact7JLm7jhEtVbtR23auMV /GO+9pinKrH9PfJYwhpbKl7AfclSjyXSOH1GZ58+pIhEjlV7w0tH7ID4hpfDjotDHA/F 74H9HuhDUCjrzhzXmPQ5XLTC2JLwwO+ZEGWLNxftSTwSGcoxV7MDXAW9XTmQQymF/+c9 seYvmCkqbJXfpur+V1lxNJRQS8WV0r4RmQO7HpgO6KaFyyFjvSql2bs8g0BZChVNagXA AzfA== ARC-Message-Signature: i=1; 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=/oXCn644qxpD8FMpAqd87EWn4tyrdJdGrCu1+KrDVIM=; fh=Gi0dtl/7o9EpcVKFFrvrPRAxiUFnjabrs+V2y8yL/Ok=; b=UIoMaZkA143QJTIKsf8muUls1SUKcuZ7SDCPZZzxyAVZiK4T19lEal8U2g2KIhsLH4 mbOXUKC66sZHIHpIakLCCBhHSDdm0l5TOMog5KOO0fSk9xQba5MH5nCizY9uRX1B89an 4omFqNf1NIyXHcK6/A6POpwrhrnNp/IaE2qbUPIQQyAaOLQv6uC0+bRCgrq7vgjVhDeq Q1VbtYv9hQLQrOA1L1faobDNnmWipqSoFeO7kMWiS6qDYMJFoeUCO7/nyxiOS3VjkiT2 tPBlR2yJT4WaAHX236NGA7/4RDvWcssTHud75DyApHTW1zT0ceKyujUaCOmjAquiT8sX VJiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yErQmSVa; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h18-20020a63e152000000b005bdbd683601si11885089pgk.57.2023.12.14.13.48.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:48:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yErQmSVa; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B65A2B22657 for ; Thu, 14 Dec 2023 21:46:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0B7D2C6B6; Thu, 14 Dec 2023 21:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yErQmSVa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dDrnk0pC" X-Original-To: linux-kernel@vger.kernel.org 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 C54866E58B for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590129; 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=/oXCn644qxpD8FMpAqd87EWn4tyrdJdGrCu1+KrDVIM=; b=yErQmSVaMfHU6Ut0SEf2M9UrFhXD9j0kjQV3rjWR+rqsZaRuPnqIGH+/+FYhiB7Htqqb29 yxaTR7aEz/PPEAxvz2mSUJvMHkZGYz8RpgI4rAcnaUowr3ErKV0ABZpqnGVn7dz6R7zShG fqGLTasMEoAFZm7wtYSBs+AFqqs3nSn1KR8FnPxDNIY+vNTVBoMEFc1R5swNBo7n6TrQa1 MV86Wenak/8A6p4+FLFqBC8T3JbzuLCYF1MjRQDb0Z/zk8QBH3vkCOm3Ak7C+Q2M4kK9hj 6AYcNCsjG+jnCZ9RzJBFI5+EhKjf2YMkl3Gdf6N5KBS9d+HS8zrSZZ2FjXk0WA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590129; 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=/oXCn644qxpD8FMpAqd87EWn4tyrdJdGrCu1+KrDVIM=; b=dDrnk0pCjG5yxf/tj6SXs8Ji2aYRRfbnhY4f4NyzYMRs3Z1mUilD+Qi2DKWl2C+h99oUHp Y9t649zENTvgbxBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , Peter Zijlstra , Josh Poimboeuf , Ingo Molnar , "Guilherme G. Piccoli" , Kefeng Wang , Kees Cook , Uros Bizjak , Arnd Bergmann Subject: [PATCH printk v3 14/14] panic: Flush kernel log buffer at the end Date: Thu, 14 Dec 2023 22:48:01 +0106 Message-Id: <20231214214201.499426-15-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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: 1785295536121093932 X-GMAIL-MSGID: 1785295536121093932 If the kernel crashes in a context where printk() calls always defer printing (such as in NMI or inside a printk_safe section) then the final panic messages will be deferred to irq_work. But if irq_work is not available, the messages will not get printed unless explicitly flushed. The result is that the final "end Kernel panic" banner does not get printed. Add one final flush after the last printk() call to make sure the final panic messages make it out as well. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/panic.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index 2807639aab51..f22d8f33ea14 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -446,6 +446,14 @@ void panic(const char *fmt, ...) /* Do not scroll important messages printed above */ suppress_printk = 1; + + /* + * The final messages may not have been printed if in a context that + * defers printing (such as NMI) and irq_work is not available. + * Explicitly flush the kernel log buffer one last time. + */ + console_flush_on_panic(CONSOLE_FLUSH_PENDING); + local_irq_enable(); for (i = 0; ; i += PANIC_TIMER_STEP) { touch_softlockup_watchdog();