From patchwork Wed Feb 7 13:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2234571dyb; Wed, 7 Feb 2024 05:42:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBLCSgomw2CV9QGkN0TnVOTowOYM/mxkV1Ji5aeq8cGcj0oPg3jjgQXWBCQksgDjrs1wNU X-Received: by 2002:a05:6808:3c94:b0:3bf:ec83:890f with SMTP id gs20-20020a0568083c9400b003bfec83890fmr2006146oib.48.1707313335362; Wed, 07 Feb 2024 05:42:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313335; cv=pass; d=google.com; s=arc-20160816; b=J2Rj+hB3lhrfKsVqt4CANC/MV03tLQCnrOMdq16ybIJ8vrr0rlK94yv4L1lsKICRNp sEH0KEBA0EBELg+sy9tuTVYDf+qjrl69yXRTjU9zQDKqU3BRRt0UbYMPLTswIQwGdDJe RSxvfQVPtS/Nb1eKkAzYg5Z5usvWiMiuTwpjbsOPPcKaH/pwsBRT+0pxoIdqBqkLDWq4 cDXAQp96vShO+rJ4NRKQQN60G0S1kPkhX8bcqM+gmTpPRPSmPLUSKXwJUyx0Yh8a46sC yMA/jsndAPVDbpK0YFKpeuLJDt7Mmv6R1lgHpM1FNdRfwT/ANJW/YTutzZAmP8ay4Onv o9Lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=ScsgG7oUpi8nHhHjZW51uSVjZ6WQyvHjuWQxMED78mA=; fh=86/KsncyVh2phnytqCJ3Iuvm5d5dnADLmzuzhpcFmWM=; b=pO8RBzerw+TWDcLW63EeoSKfmWgWqbw8tooufhdidUCXJzb66xy6mfvkHCIVVioC5M WFv0aNiISzzS0+YHKfBh2D2fDLn81cb2hxnbuhTkieNP/Kq1vtkEl7OerhTLGyDEjxhF Z5zlxlmST+lWno6Kcc16Cbsw/7M4wHnY+tkUraK6RBeghywQJxLQunrb5MXtTbtEgeEA PatLCSK2NPMBz8wXtxGH3e749Lgpzaar7fcnfamPnQWtOgsjUmufF5/tfYYZfw1qPW0f zyibXWy6A9RMJRvhwtXUZvl7uPoV6KpnAfMPOexi9nUrl6l0JFzJfgvoKex12dMDkt/3 BcNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="n/La2GeV"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56561-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56561-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCV6SV7CDmbOzM+SCI+r9p2rgUKTiYsDKkUtNmNmIYjmd3NJ0QTWCcAcWzuB/V+D6Ve1ctPNqJictRVMQ0p7OjHyPiBjVQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a16-20020a05620a16d000b007832fdba75asi1095814qkn.356.2024.02.07.05.42.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:42:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56561-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="n/La2GeV"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56561-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56561-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 14F081C22988 for ; Wed, 7 Feb 2024 13:42:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31A007E115; Wed, 7 Feb 2024 13:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="n/La2GeV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S1qo3qxy" 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 64AE17764E for ; Wed, 7 Feb 2024 13:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313278; cv=none; b=b6bu/VYKnOlA+fh7VN0zrtDj436drxsNYXAe5g7Mt2/gjxMOd2vCysnEt1OaQArfatdeDvTl7h62OBPuCOt+d+K01LPcwE4CaBnnOg+Bw6NvDPSOVffxpJsdqHad0FdsopyoHqlDe15G2dd4RlZ89FAXTSvLgGTb7MrsTjMwrK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313278; c=relaxed/simple; bh=ckxb7Hs30aCftV5qiZnclb3QjFGEdy4s1Y9N5ksQnGg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RK1p/NuGumTtPLjU/0anEBTozIC8OEfTrOJdDkP2hH1glcZMVhABkHshxLpjWPPm2FxR0RnAnKhMhzMsxXqesyy3S2QYxabeSmiAXvKCD6wWXpRXspEUcwFB1WU4q3wl3pLfu0NHa41kae5ksvJXVAx6Nv5oj9X+3tmY7e5DKdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=n/La2GeV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=S1qo3qxy; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313274; 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=ScsgG7oUpi8nHhHjZW51uSVjZ6WQyvHjuWQxMED78mA=; b=n/La2GeVVhalB8C8GiJYaxU+bq6VVbovv5adfo9aG1KCxmereWpLNT9sRmBlBiFKVztb0t T9XEiVjWe4+gumVsyoV4EvG2bhpQaIgJ5ogxxyAXIp5vSzUtcYxCigYHidySwBuUQoFF/L jASogejwayOc6axN6Hsc2LdJKu1418+AAF+6tDmnTlgAqjgqbWc9kokdrcBsjsA+ZIsZKo UVhq5PWFm9B69BOn7UPNN4yMezkaRoUqKN3hZ8krK258aPG1K1CVIfkK+rXMN3A36u3Fps U4KveJKUoufJWPXFyHV9e9dnGJeH+RGU2SsdCfi3PHS3jKOhJKo3BDrRDR3Uww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313274; 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=ScsgG7oUpi8nHhHjZW51uSVjZ6WQyvHjuWQxMED78mA=; b=S1qo3qxye6E3wP0zkILPOmR6fe60n+3xfAYFNgYAoAWVa6uzBTPDLALsEuj+E4ke8xjsH5 cgiaywA/61Oo9cCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 01/14] printk: nbcon: Relocate 32bit seq macros Date: Wed, 7 Feb 2024 14:46:50 +0106 Message-Id: <20240207134103.1357162-2-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247787976085197 X-GMAIL-MSGID: 1790247787976085197 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 Wed Feb 7 13:40:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2234568dyb; Wed, 7 Feb 2024 05:42:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWW1UhF3tpC/n9cYMaJ7plXC8H3jU3wEm2uUPNB3xlHDCvNyjZpUoWpzr5tSF5p0FgomrVHGcnE8FAa/CDIdWuAQ4g6hA== X-Google-Smtp-Source: AGHT+IGuMAD7L7N2D+I05TYyODJ/ytwdIN7EX3RPALQRLApAABxvDEQoCsvETjTaTfPaECr0ghTr X-Received: by 2002:a17:902:ed46:b0:1d5:bc5c:7b6c with SMTP id y6-20020a170902ed4600b001d5bc5c7b6cmr4606787plb.55.1707313335496; Wed, 07 Feb 2024 05:42:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313335; cv=pass; d=google.com; s=arc-20160816; b=r5giSvHavr7bLatejgAvf5c7/4ASj7RcWljaNUipZR9qQwrSNsoQYEwmZqzggPNcmM JNHuLIV8SVKK5fObv1kmHS/K/aYcO7zIslseH9JqSliypa7r1EMi/kRUj/nkthl/Qkw3 Tg+3b4vfR9D8ZdkuyhsaFuOhITbuVMbw3eX2yCN/QuagEGPpCZ8N0HmwKgE7gQpEQnzD dy8ISuXO5k09NUfc2+pFrAYcv12t9cg31i55J08VLd2AN21sVQAhM5F4cs1YLC7jQK23 UAMBafXTOMtW11QMRWERjmttMw69KRgeBvz3jZhIqzQazf5VER4NV/vvqfPePnwKuW5g eBTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=hMI7qkQLotY/selAHG10OOY1svS/SpGuuqTiSxMDtnw=; fh=3sIBPDHOMRmUevT83rWq3l9aRe+SPBqeJM//2TQ1zTc=; b=Yfast7fQ20cJJnVDFYnjh2nTZVrNBX9LC7CoIqkdFMZYm/+0XMjs5MsH4H9lXYDsEP iQrqqDDZ4WzQOduycYmiIyyi2wssWFNQRTKbwYljBierLDW+VfrdetU/G+wJOZbCWk+k 08sZDxjyIygb8oK8e03n5mrWXHSh5cPbj/9fjIK9bEY/exbB3CSBNOFQceXbjeTU+J94 Rr2J2/cSsuJs0LFYOMhxnXBUyvwjQdbiTsi3pImnw8mhb7q9zER25p+Djd3B2bYamu3d Pfx5qILGAHQuDvX8ZoKxvQi6z7FVQWDMa1cC63fLaZS/a/qW3MsqCFViuGiclqrdn4yk mfpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1XG67EOg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56562-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56562-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWBW8ZA7VAv4YWkmvlMQ3LqGsxoxAOcGB7cetLuKAMQFCoDv3JSd0xHLmmNNCk0uOY3DAQM9qjJhWTmY1+wAnzsXHU8Nw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d10-20020a170902ceca00b001d8a6dc0308si1687897plg.452.2024.02.07.05.42.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:42:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56562-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=1XG67EOg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56562-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56562-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 3BEFF28621D for ; Wed, 7 Feb 2024 13:42:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43A507E56D; Wed, 7 Feb 2024 13:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1XG67EOg"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="03YKrbAF" 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 AB2F577F14 for ; Wed, 7 Feb 2024 13:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313278; cv=none; b=GQ4C4MttD73zn1PWTRCmwM/yEQPNZX6W9C7wkDKJqJ/t3o8eJpWkbXGJcJKnmEymWqEIkqxRA6BzwfRwRWfqXedfw36RNiuVvUyEDdTSquKlpogMcYDuk18Gp0lWpAt0OmN8zWJ/SVXThDtJLsFd8zULZNIvd1U2qp6whw6Mihs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313278; c=relaxed/simple; bh=GQCehcL6yhboRMDP0y/MXe78eGzvs0hF3ziXNMfK9rw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d2XKPkcdjlgA3BfBJW8OmWkkI+ftVHD1bmjZmEZeyYOVb4Se3FI/MT2qVz6WCkxri3gVKb6pP+KaEJSf6kwnBP+/4HwOyCOOW/LczGyAxG5TXCxH9/A5AhkoBklnk4Ebm2ii/51VsTbKTH8GAmK8jSerUWgei/ZvIhcHkg/cZ3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1XG67EOg; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=03YKrbAF; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313274; 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=hMI7qkQLotY/selAHG10OOY1svS/SpGuuqTiSxMDtnw=; b=1XG67EOg5kbZJ+oMrdcK6eXfeRTnhvIhtEryVT/AU1249nJWNYTwhpMRTAxYuWfl08drRl 2a62Zw0ykAeBX4qNl4cE09KfPDvRQ32LJw3py83pFE3+kZwveE9cIudS1sEva/TYRmJqAL GUaNc7RQN3Wgz2RU+W02OiD6c1eIzZaPaVsiC3GAFpXvoXVfs0TjaS0kLkgJ0bjZCOJi0S 9epYTlrM60GYG4pgc7r4jL0+5yBzJ0L4rijnPxJheNF0IbYnlOrKCY1ckYIdjsTnb/hrQM 2sUgEmcS0Fyo0QPQWH7jPOGq17K8eP+BO1gcvE1Ps8x7dGbfBkRVqhnSqw7JRw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313274; 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=hMI7qkQLotY/selAHG10OOY1svS/SpGuuqTiSxMDtnw=; b=03YKrbAFKwGaONJprswAKsS54u/aCmhX38LAqldWggW2SvwTYy17/nHb/AR7Ft6Zio8bdZ 0yMr+GEQusrMtPBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior , Francesco Dolcini , kernel test robot Subject: [PATCH printk v4 02/14] printk: Adjust mapping for 32bit seq macros Date: Wed, 7 Feb 2024 14:46:51 +0106 Message-Id: <20240207134103.1357162-3-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247788244958753 X-GMAIL-MSGID: 1790247788244958753 From: Sebastian Andrzej Siewior 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 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 Wed Feb 7 13:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2236839dyb; Wed, 7 Feb 2024 05:46:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVc0id+l+tIWvW/xdRRnLRLAVRkntIJlvo7ukANl19oHYdd8BkRd2pEYMAPll+JT3szjLZHDuxkSnLSdfyGh0FHFEHzXA== X-Google-Smtp-Source: AGHT+IHrIjY5PkdFxFZp/gw1pZjEUJ0q+9Rvsr0FUd0gkw4ljPfDV64PETyZjIKJMkCfjREL1mWY X-Received: by 2002:a05:6a20:a11e:b0:19e:aa08:1a0 with SMTP id q30-20020a056a20a11e00b0019eaa0801a0mr819271pzk.8.1707313576612; Wed, 07 Feb 2024 05:46:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313576; cv=pass; d=google.com; s=arc-20160816; b=uIEmby/uRJLvjklxsYZ8tUMQIalb8DliTdezhb1bepuCk2aZ9SfKNxv/Nr+f9AjEr8 +kk7/P1n/ZhG2NiGyK5LKxF7iwBH3N8hEZtseZxo3Lfqpp0RzW09UiKFq+MGiUaNfFyh klE+w0e8GO5q/BlEW4UVgcNWsjOr4HG30UA4sO9UjkgIDioTkw/FaTlZaDl9XeBW/Ean MpbdQshdRhnjNGCG0yuVrfUs9Bk51IVbRTbqtodCZVxdS6Vn+OdUld0BUPq2FV0ANSwY vRArhVTTW8ynV+QZhnDKmw3g9kKMgYKrSqRJTamFnuyOV5zkA6NHA524a6vmxWZi6Svq EYGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Ff+TzJ0o/pSPZIn7CSGIS2C7uqhdZISpglDMKsXmGyg=; fh=SUnoNy0/CXgScqCSJvAmuKzrG5xqZ9ScgjUXir0PVoY=; b=QcX1pJdGzSF3tOwWN143YYya6XNykqNPJlj4s3bXpbrbHyBaWDejCRPJyhylYWrAnA WLfnnmeooBy6JgOeJFoSX+Y7Asf7SanmSv5Sk1hrnOUJ2doNjk9BUbU7nHj8SH0Ld0Qt U4xANv2s/4FyhAytQeaRUuLtVVonSFMdRyNU/SHKynlo4PsrrNZdc7m1gQpUH0plNRSO dOE3XT8006Xisic9R8G+PPFRno/EF5AdbegulArUE9k/YJfxHJK48WrdjTrqq8YkaXBb rjMokqUzo2cbyM5TfA8YD9veikzMO9Fztw8JsjCm/DnFF4pZjLIHGmCjhJNffLevy3pR LQFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I86rzyaT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56564-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56564-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWrF08fj6vK02x0sqs4yIDIswXJAEyLHVWNi9ArTqQcwQaimICnCQD0xqwLEd9i76QX7clGj+SSl2SkKtIyPthcWCmOtw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r21-20020a638f55000000b005cfd6ba16f7si1528113pgn.647.2024.02.07.05.46.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:46:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56564-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=I86rzyaT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56564-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56564-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 93F4FB26465 for ; Wed, 7 Feb 2024 13:43:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F8547F7C8; Wed, 7 Feb 2024 13:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I86rzyaT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vOA14TGY" 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 91BA476C8A for ; Wed, 7 Feb 2024 13:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313280; cv=none; b=NI5JcV2zAxlYCnB355t6M09A+uHqKlCKwNzHQP/WnygDkFmrDcqLHR7HyBvNmSbBNanQb2Wkr5nB5nGJ4sQfK7mANSOz5gZxN2MTHnhNdTXlAbjBaXrMJkxLRot1uw1KMLk+mexKT28X0AgKH3911EtVhUKkynfxxZywDq76oFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313280; c=relaxed/simple; bh=6HLIesyzd6TYtnLLBRHlzGAgs2b2+AOfna8a9sUGBqU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F/54kh9P+W2+hNVpRd29d6bGjC5yZYChhCeQVYuAUzuqvE8puMXSQSquY3MvRXzo+OA+919aXRgNc8FNgeeldDFWqiiJTUikSYwppdbf4LhzBtLyReRfNL9Ava77HSE2iT1XXyH9M76NA8JFuvJXxny+czNPBep9KnyiChJUMuI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I86rzyaT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vOA14TGY; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313274; 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=Ff+TzJ0o/pSPZIn7CSGIS2C7uqhdZISpglDMKsXmGyg=; b=I86rzyaTjJH6jmu5xlB4+JhZ5XJagVhAbR0ZFxsZgREJILWfp+2t/b++0SPEcIcomw9Fdv YlvXdx78rB/Ehi0r9DPo/IpbKK88odtOSW7rX4Md+KCxlr8oTR2RrQ06Gj3/M2itjsvQ6d +Q6lWLxKgl+cieTr82M+UXxnhHzRSeDTtqy4HypfCfD0X7KFhYAsjlQE/6IxQwBXncC7WK b8J9YxFi18oDIxKevPsSykFxEokWVYo+Y55L9Ku2xSrlts/in5LHYnR965xkzRvKYuFdUi GW3sPl6N+ZW7bKYkXABxeXVaFZvC/+q+GSZY7Z/d7yfiMUpBdNgFSmjJuSnUiA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313274; 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=Ff+TzJ0o/pSPZIn7CSGIS2C7uqhdZISpglDMKsXmGyg=; b=vOA14TGYHeZPooXLLUGflPnRs+1CGMFT0XY+6bUFIurGNrfUMq20Ox8u0ljomgWrcwRuF5 K6dZXpx6IPMfqkAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 03/14] printk: Use prb_first_seq() as base for 32bit seq macros Date: Wed, 7 Feb 2024 14:46:52 +0106 Message-Id: <20240207134103.1357162-4-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790248041147387725 X-GMAIL-MSGID: 1790248041147387725 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 Wed Feb 7 13:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235253dyb; Wed, 7 Feb 2024 05:43:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1IUzKtNDruPL5++m0jU2J7pxzylIywrhlwHlQZuFvl0aCqjJBJw1eUFAgKwdeDULb8vF2 X-Received: by 2002:a9d:61c6:0:b0:6e1:f49:ef71 with SMTP id h6-20020a9d61c6000000b006e10f49ef71mr5611795otk.34.1707313410305; Wed, 07 Feb 2024 05:43:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313410; cv=pass; d=google.com; s=arc-20160816; b=UlHhvSkEYv1FtAC7T2TLowiezlPKAQeuCSNPeWboNPCQ81lyIQtEGZoznKTh/UMnxi KbShuff/Ry0+ijPcifnso4VeRgt6Fyz/SohxMZhkvNSEcD3bfx2ahlID9NrrF1AOW6DJ fn/YuEjNilSuOHjolt/j8EJKHKfdCOdlfC1oQ+ThTrN5D52NeF68iWzUd6qzjSjMT1vM TjYPnigEkdCRy71DEGcBdQc1VefdrPru7hey9c55bC8zGipRQeJin58i+07uAery2D4T A84Q0DsS11asgj+S2sxCmSikJvyC1iWZpwxasPaETqvHRRG4NN1W5fUZUB1zldQvJfRL EMfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=AnwPd7XIokQ/bLOcP3/FHbKObdxJLytnqkjXweQk6XQ=; fh=v1tCx0LB23T9pNy8TAHP7E5VyyD/Z6Lv58OJlXfIFME=; b=rvfRskkimWqBvJT1nkyFOAjikXprwTY+uPm2QdGXWF/kA+uhzvOcds2tV03yClNWTf ncmCVtAeS08A8R79pZ/6rlDHruimkcf8kweXisDJvqkyHVhkpjQPHSX6nZrBMk22NRx/ nOwLQ3OXFoxWDjkyVGtGKwzptUVft4oHOsQY80bdt00MWticeDetvVJXXtDCRSjpI6Qt 6QiA8ZaKMNhMc3HSnOf7vTniwzUdDpvZtKOJJ+RYp0AWymLRQpx17k0U4S0pJf4Nf9Jp hpBBpObX51vbZgHEHGxPz4d2VNWE8yqEfHvmM6GfBr0VxiUanOUzRjmN+YtqUYV4Fx9m FOOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D8YlcUXE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=uEVvplPu; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56563-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56563-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWLDgx2EhHAfvVvEjPcGFJSgczj7NVeAFCYmW3H+hNh5XUrtBpjz6YZkKy5QGlYAAsmUoqOtcFKxw1l++ak8jukgTkcOQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c28-20020a63725c000000b005cdf37c9c29si1519313pgn.703.2024.02.07.05.43.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:43:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56563-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=D8YlcUXE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=uEVvplPu; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56563-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56563-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 00C0928762D for ; Wed, 7 Feb 2024 13:43:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B79897FBA6; Wed, 7 Feb 2024 13:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="D8YlcUXE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uEVvplPu" 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 E59A177F15 for ; Wed, 7 Feb 2024 13:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313279; cv=none; b=hV39HYx70KCv0uhpNuigUaTlTyNyQVk9D3AigajVteAWuqswxPADHJZbZ8EHVmvI+WCmeZ+aENu7Tu6HRnZg41o1EDW7Y4GZ1IrjAcoKPBEzYBAjgKy/zpHdWlipwtBh9Wm4N5ajpH7CHabd8qnySreszaQZpnFQh/OKirI6mXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313279; c=relaxed/simple; bh=84ZwPCUVS2z9nqDi5OEQCqORFbm9LwMCCBhBJo4DvYk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cLz7dHt4bD2+wD+3Y1KGdB4gMCQYIDST5A6MobjCoBkbv3uZZvO65JV685veo15Isz3jz7thGrHZ1HWTiSDiC4rhFI9Hti0pIfwFsGMXSEz0w7bLipI5NIZj5JjthcWuNuyQEntM1k5SQ8kgRCq25Ty0pf6Q38RQHsPtTouliNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=D8YlcUXE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uEVvplPu; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313275; 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=D8YlcUXEF+8X6abdh/JWXv+hHpPTfgVMHn3ev8S38dfbgwKfww4CPVRhdd8Rgpzgsw9m0p nz9g5xt5nuXiy9VV/TWHaNrkshdPN8Y/WzNzaZvtdKd9cg0GzEdIvyKOY8fRA4LVBjfh2L H2NyN81QOv4T1P++D3oh7nvphgFiScu1c9irgzJK0roZPjJMDCVX+Y0mYiErmVK8Jyvn72 oJ5Hm0axke7hOSCFxDfihe+6h1KmZO4pbQ/0HSVJvrV7jwzEWF+X8vDhL1OE9/Mgtn6fD2 tGS7dgo1Heeh2ORtG9iSJOsT8XNT79zH8oMvjU+Qmp6mgHGqFJRgToxdtZMH1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313275; 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=uEVvplPuaomw79Vn5vOsrtEjdjMUHw/9rmauJqJ37JMUjGWtBI2emnZp1ygEtJpKYRqNhb MUl3dpG1dSRT6BCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Mukesh Ojha Subject: [PATCH printk v4 04/14] printk: ringbuffer: Do not skip non-finalized records with prb_next_seq() Date: Wed, 7 Feb 2024 14:46:53 +0106 Message-Id: <20240207134103.1357162-5-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247866585874267 X-GMAIL-MSGID: 1790247866585874267 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 Reviewed-by: Petr Mladek --- 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 Wed Feb 7 13:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235320dyb; Wed, 7 Feb 2024 05:43:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGX6uB9wE8JpTmyKjX2ppoZ8hLoQ41Up5LRVlr5Im3jc2ljFpIce5aKwMGf8CL9x5eUgm2H X-Received: by 2002:a17:906:40d9:b0:a37:aeab:76d0 with SMTP id a25-20020a17090640d900b00a37aeab76d0mr6252612ejk.3.1707313418521; Wed, 07 Feb 2024 05:43:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313418; cv=pass; d=google.com; s=arc-20160816; b=iY3rY90136VbVNTvwn9XXe6DNCzx0m73xc3DtIlYgowDm+W8sqQm3aSm9/OMeU+HKr SVXPNBXJE++gJ/uMTeVM/UzEDUWRKD7khqwh+7YZvaBBjgekGMgeQIqHQekVlzlr0+t2 6DbYfpgFZsUf6ydWJKAL1I80y80G5vPlURTb/5g4CXDxjDscfS9QVOBnCUo3cxBvxtXr us+cum83WBkyNd1t7PRQRSbBTjvhFk+zXwSIZotiWMaAgsU6FFA/pHue08v+GaXBqNhZ BPhXy9m+M0/2pSLyZnb/g73jx08tC75YPEPtvI0wuO63uz7YX7ZN7ZIDnFhqE+AQamqH Qaqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=TzU01CBQ+U6/10NpLEh7xrbRVSxOpjAkPvdRszZv9zc=; fh=FcdLMVhsYqU+j+aLTN3PIZVpTZQnysgHtqPwjkJ1ctM=; b=dK3M0AEC+qt3pbUK+ZvTiz59ApYWlKpjx15DMCLt1YL4p7qn9JQ0dIJ4StKH38a/O5 CJhbPYnGtoNIyIKjnlIuWqAKnEXe8KbpeopsZf08Dd9y5Y4h3mRZXqzFti/e064JmOya hKlBOVlXZtV2nPyz1BbJYbiKMV+WtkayzNrZSXhe2tR1Y5di9gC7LYOsbFnQPDRy8f8j 00nFyrQ4l+ZoZvATBLWCui6d2RodlLF4gS2wlZz670BCYqlDhbMI84C/nJ8KQG6/eeFO 2QK3NHXVYRfMbcoQCceNdrM1Hj5E3LmZe7EIfZiWvXy9iGIkTrfGTFC8Imz8LlzSblY/ qpYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="txWlce/V"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56565-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56565-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCW00D13QYOiP7/Z7CX0JcsrgC3Fihd0WzJGs1YiGLjc33/9jUgF1Ba0+FRedz8N3kvfa/HafO7EithcS0D9bCuQUzDCcA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lg10-20020a170906f88a00b00a35341252e6si922419ejb.1037.2024.02.07.05.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:43:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56565-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="txWlce/V"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56565-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56565-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 27A0F1F23BB6 for ; Wed, 7 Feb 2024 13:43:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14BD67FBC6; Wed, 7 Feb 2024 13:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="txWlce/V"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oSC6gHsw" 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 7296578B5B for ; Wed, 7 Feb 2024 13:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313281; cv=none; b=ROa5Eg+4YA/ukrHN2lue7wZkXzi+hhzzZu6xjEmXD8nD/pNtdJvv4+2cgKxue1C8dM5E3OdAkKjg2kwU1aa4gztcU+X1lcUFuL2zi7LzYO8Xb/YzkFhXUo22MJNMHEAD9DCWgrL9UrvxcTL26uuuXQ6WIEQGLFyHjdEYwPOuSww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313281; c=relaxed/simple; bh=+v9lcDo1j7EbJJddNqySiCuHHXP983V6j+dNnTQRZ8Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nKVB/jZwJatW9rNr/hO6WtDV+lpLnYABsMwd6KcngGqBgqUc+Zdz+JRkDRotVcUJuZTXZ65bPPa3Vs5xlh7S6bkBTcFo+xI3Iwcq8HK1NwnbclkSbVHKBX+Rg0UIst7rd2V/bT+pJNIXmMgF2COo2LXSZS/6c9rgulDsJzYAcCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=txWlce/V; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oSC6gHsw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313275; 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=TzU01CBQ+U6/10NpLEh7xrbRVSxOpjAkPvdRszZv9zc=; b=txWlce/Vii9hoEwPitzfHiLrHX8dYflO+WTZZa05ow6wxRxcyBi+r+e0zpCGJdFxKLgycP pETt1WlSUikiUaENDIARSd4XOGm3A3HNGGBo+RcSqc6R/5Qn6qvWjI80hEQ8QYhOQzeWc2 JCoW8dxaWgltKLXdeyssEr02UiLi8EDoa8gLixTFSuzr6+u0r61myBQTknbQZYpTyl5OLz ugD+OAiDdnsHD1TwpfnsG6SGOtEbC1N5Snq/kehB32KorrBdHAALY9T4Ms7JtPRzoNso2p tNVirLr+FojpGAgu6zEuXaWWp5iGWQ1CyI3Ecn3T/NhT4wS3tI/OpiycCeigWg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313275; 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=TzU01CBQ+U6/10NpLEh7xrbRVSxOpjAkPvdRszZv9zc=; b=oSC6gHswbJBnqJT4l/nL8NzZGpH8R0m3uRxt0HMyndu/ErXEmIuHdJ0BlrMdR6bSDLs45D YWtUOTBd1n22L9Aw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 05/14] printk: ringbuffer: Clarify special lpos values Date: Wed, 7 Feb 2024 14:46:54 +0106 Message-Id: <20240207134103.1357162-6-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247874992898200 X-GMAIL-MSGID: 1790247874992898200 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 Wed Feb 7 13:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2236945dyb; Wed, 7 Feb 2024 05:46:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4P62TMxRD2y+9kuxfFlfzQ5LRhPszdlz3MygMEnvoj7TH8GCWKYR30rd8Z7NvxNwE3kMl X-Received: by 2002:a17:903:2b0e:b0:1d8:ef8d:a7ec with SMTP id mc14-20020a1709032b0e00b001d8ef8da7ecmr6755475plb.2.1707313587197; Wed, 07 Feb 2024 05:46:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313587; cv=pass; d=google.com; s=arc-20160816; b=Rq1R3tXOBY0Brx4QwISy4oZGAjfnUSKqvPEMZ83iz/lZV/9YgCZwQFVNlfYqjOHtKX efckwfBD5SzQOpCFY+ggMRUDzGEor4B3cznEQ4UYt4vuoLobVcoXrFeYhf+xANhgAtkg 60HJSAr8Sh48AZNaXHZhO0jRZhAly/BJBpzBfgmrcdFjvD0FZtgtY7DSK0kMg5cLJoYD fH5XFTl1oKkf0thAnmVDwhQQ/Eo61UrXHmlX+Q8s6i0+erB0KUcaedUs0Rbfu8t/GD4V 0NlYdCkBGjbRz9YG9C+luuqC9nP9wCFqMVWB/sATVXo9dFfMG8hHWshoa1vpkUGEu0kM rovA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=krH2QkxdJALvXRu9Bq+Fw3gs7PqsPIKkUheQqZKkVK0=; fh=BHCq7kHQ9iSGtspaFFtgNDNJ2N97pRo0SIOyL2QBfiE=; b=ULWi/IaWmBTdO28XFAGgJTdHTNCoafh2bpuZaMy/RfCbqE78GOIYiCxhzdcIHwvXKJ fMuO/I2MSrECCdLJ4aKRf6+otFrjb13THtqTyxIfcdEpGTqAL9Lchh/KXQpl+8wpaW7w lQBgaGFMgunyVptqB3Dq61F2XxMFglSdpyOADf4juoQILe+CLgvzAUWgwnSSnKdzXI1U /HvQ4JXT+a6T67a3deXXaYjg5iIyioHYqT4eTqUFnGz/aZwAMGDqA26AXNf/NQcQE+Zp doM1WsJ0EyKrCxN60scF2YO9sO7oV5BlmqfWB42la0sizltcZqQHMuJuNSVg10PKZsST A4qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WRiRArBf; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56566-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56566-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCVF/d5o2Jo5p1hvBtcOx1cICnpzVqydZLEVN5x+JO9I6laZLZB5jh6IfYnES6+zDE9Uhv9fDcIH18wfBNm+LMpSzDiBlw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i18-20020a17090332d200b001d9f57ef641si830534plr.425.2024.02.07.05.46.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:46:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56566-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=WRiRArBf; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56566-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56566-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 777FBB2660E for ; Wed, 7 Feb 2024 13:43:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5E937FBA5; Wed, 7 Feb 2024 13:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WRiRArBf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rQSEKUb6" 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 AF0065A118 for ; Wed, 7 Feb 2024 13:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313281; cv=none; b=nx1GgXbXrRAcGJ4HNYLK6q/kM6ue6BB2drtXgTzGAOq+O23xGXh2SrSEOKdUMlc33/GAPRGVN1+s7kvlXkM+0xFQNoxw1EgncKrZxJKv2jUM3TJOSDP/WLVL6/aLt4h9PCmqxrL1LaCLtrpZujF5Vw/NmAB1PKzR51CzbRxc7CE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313281; c=relaxed/simple; bh=vJqxW1p5ntcV7Q8gHg+dKNeHrRgOFCslGbsANTaGJrE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SN0pI/PIuaQZW7hD+h4+xjmhS8tzAW/fuA2UVi75SGmgF+bv01DIpYmfqVrSUq/Thu40RBh/j9Ii/e2grr69prwq3JNFR4zRZeDuRkge3Y/eUBNh3fyPxYDw0DYgMWQhRfJ7BUmc0MbvusFx/ktLbvu4IF4rfqNR/6Mmx4+br1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WRiRArBf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rQSEKUb6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313275; 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=WRiRArBfTTPvencS3aNMh6U5Jll4BkBh3TxSXBL1CoGcfofnV9slVz9bHirftVZ+t5pBg4 EzczG4kxp49nz9+pUSB4YoXGZTnDRuG6ME5AcfuTctIYW4mDScQitWszFD8lECQe2H7WoU nGfzxZUpCCqfHaDeBxsbe+QZq+adxDbr6xjQlnoZ6qFQuiKmigH3jZLfkFgD5ZvuefAKm1 wzW2N8S4c/1K0gcv5fcVI7Puhg+2fsKyx/UnTuOoozrgOJ8eqKb8GeeC4GrkUEbuqBHWOQ V5ASb+cBWeAX8yEibld4K2JztthP83EiGMLCwkkbA1qdo9OtMD3Vu6TO3gDMog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313275; 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=rQSEKUb6LAdrLfbf/3uTISwSZSFmtlWYYHbFqF+X6t3mynIvhmFajaM7vSkWMB6D6NzSZj yM0rb7CMTdLBeWDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 06/14] printk: For @suppress_panic_printk check for other CPU in panic Date: Wed, 7 Feb 2024 14:46:55 +0106 Message-Id: <20240207134103.1357162-7-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790248051941336581 X-GMAIL-MSGID: 1790248051941336581 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 Wed Feb 7 13:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235423dyb; Wed, 7 Feb 2024 05:43:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEP9kM39eWPFIuQDG04o/mS2r44ZOCVXW0a0ORYLhxfpmnDrYpoLNXiRDXdorG4fhe3tAiC X-Received: by 2002:a05:620a:462a:b0:785:a011:f662 with SMTP id br42-20020a05620a462a00b00785a011f662mr1033544qkb.14.1707313427881; Wed, 07 Feb 2024 05:43:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313427; cv=pass; d=google.com; s=arc-20160816; b=d8IoOMEXnXpYg8RcaakTLbXLWttEC9wklvn9sypFnBS9tI48naGvUEpxXzu2Blehhh LPRWrwMqHBDLpIc+n/6GdgFqliBRFQI03EOdrFAW+5Lr3wU3Z/HNKO5O8H981546z99X HXP1Sli5eFmrmhJCwPnIxQZASsaxCUAGNtvPwilKbKeALmbkObzopp86Zc0+DonAHe/K QjT+fUZ6LGqZk4Ptw5776ahPOMKkKTHzbDRxIbR2UyHUZYkSfUZ0mztdnRPOIp3iqCJB +dIrv1YHCgy+T8b/63/RhRsyO2OGhOJwyeOYiat7p50tMnRhLulnjY8d1cKCqF2yvNr6 m5sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; fh=DxVLId4Go2x73hbhB145SHMaKpubSGjggwBmetF6gZg=; b=F0hsAKjrhiQtjplUc8NcK++rSEHlah4Xj5ctieMS+KcoiT2yFvoENt+sOWbhB3vrXH rmVWM06g1fEyhSNPLgpwlFXt4DGrRomqjWa4k/ox8FLI+gVExHiuwNPg6RKR1J7CG6g0 FlMXgVam2k1Rs8IxSaaEdiw3BRbTlQ7P85sYOw18UOw5kMj/YhsElf2X3OX0GOx+obeJ HyEd1smdekjjvzR8DB05Z/55VjfB8aLR1ZM2DO3ZgQB3IEpni8TW1mVh8q7phREqWaSq J2KTEdvWjmlsAf0+y7UeIkB0XPT5SBrLp2NOwj8FTjwI0ohjfEUw7o1Pcxs+Wnu53JMg NewA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="uxq/6dVE"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56567-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCX4o88KwCWEsMObG1ACrl+R0FPH1KMCv7ayFSwaXJ8hxQOaSpja/tSlkHQn9n+PkrgNgZMVoG4wQgH2mHfAbT+U4AHviQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s18-20020ae9f712000000b00783577b7501si1079356qkg.357.2024.02.07.05.43.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:43:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56567-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="uxq/6dVE"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56567-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 9BDA41C22B5C for ; Wed, 7 Feb 2024 13:43:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65B4180025; Wed, 7 Feb 2024 13:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uxq/6dVE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BdlvPSC8" 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 2679B7A720 for ; Wed, 7 Feb 2024 13:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313282; cv=none; b=nl9he+8QHHMczTJK5XFTX0oVeGX6LVP/RI7JFB4erDNST3J40BuqcxVGaa7i+3w5cz4V2I6lm1z7e1DrEsePoYqWpgbrWRQJQFH7lEmU4fNlukxn52iyLfH93E2xKCCZ7la5rUmkMHz/C/GqJ/9Mq90Ge2QmU+j1RX8eA5GzICw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313282; c=relaxed/simple; bh=pLiQvlJlgDBEc8pKrVIe9E9OdNeQXjek3j2d6X2PiC4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K6NiKbN68y6GcYS6weManlqyZ1EAANkMGyyW+RN5nP+Ck8nYBQLxzidHmDyba7sBhkwkZa/+YBVPJqnTaFn+e1JkzxwAnk9SPH6haE2+9nsxz1Y6csaek3TX48ozu8ihgInmvkR/oYWxgaNstqznfKOBk+THdc+jF8KVJcKTeIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uxq/6dVE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BdlvPSC8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313276; 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=uxq/6dVEvZ37HS80Hjl/vLmUowIdMGNG0hnAoQnu3K+bjeH/0sOnBtzakxA0IzW6cVNL3t 7ZfegUL77aQJqqUviE5RemwOyw3m2rcrZ6dXNm7IaY72d7Ve7pmpl7yOcID6pKxSu8RgAv W8g6ZO4SU8TbWUxTHQOiohh+dF7SeZXD6uO2orChx/8vFbglOqNIXahY13nJi/OTyAojoJ ujBzqhCdvuycWQjX4Bmpip+8lxEiskvouWWhyYPSJ9GskpskSsG+9zxwt4nTAScZBjPqB8 4CX492ci8Ap8YtZ7E1bMBObhd+nArjR9MI2Fn2heY1WfK06VFUTLnFosqc+Enw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313276; 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=BdlvPSC8OAZuBClMDP+9MvJQiYBjLXPNQBmQ2WX/Xsk5C//z4EHRDNcPx20FzIVugyf+WM Mp5PFQTn0R8jD2CQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 07/14] printk: Add this_cpu_in_panic() Date: Wed, 7 Feb 2024 14:46:56 +0106 Message-Id: <20240207134103.1357162-8-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247884647408341 X-GMAIL-MSGID: 1790247884647408341 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 Wed Feb 7 13:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197947 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2250453dyb; Wed, 7 Feb 2024 06:06:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnkpYEwmBCEOofXzffrW1VKzzR6UdiOW0zZs2w8sBLbxHezxcgo2sUQOkwSFgYNFNa3ecq X-Received: by 2002:a05:6830:603:b0:6e2:afd2:cd62 with SMTP id w3-20020a056830060300b006e2afd2cd62mr5223480oti.22.1707314790345; Wed, 07 Feb 2024 06:06:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707314790; cv=pass; d=google.com; s=arc-20160816; b=ecPapHmDTj8MM82om0+3K267jxsSBokxTgglP+0eVEPfmW1sH15nH52FOkjONCGYja cOE2hJlbXjIS2VFS58yyxdNfelHg1eH7XMze68XVnanP/igzEfE/4eLJL/Xz/2Dj5D9D 3tpIeUAE8+Gpetb82xs5oZLv1+coU2R3dcKwOvM4/euQ8bSQyRWwjeeHSm+an1BD0yEU n0AaK+FuIGru8qDCWnWOBzb1souc1ByhwR4R17/OREF8tGZF78YjhcLe0YWU2Nz21gNN 5uH+49lhsazjL/kNYWRkfPtwuzmB9T1pYSxoCYd5a0NPsSp+DKWcg5hQ1kkWKNMY9im5 D8Ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=zhO6JKJB/J3Qv7bq/QRbOX1jB95B7+7hKvBX2b3MyxY=; fh=V6bDs6uvAyve/ow/cqMVdu5I1HYrAZcqk9d2jistKOc=; b=iGnLZM8NaFZUlZC5tUa3CmhFKvLL7rXUkG/0JuKsstkLR1l8V+YSPJOFgrb+sSk4v0 HN06/kh6C5n010t4U2gZRoTLv+iyDqxPX+Y/kuhNkbsrXxSaSD3yHfykpuDQEj4j2khF n5MuTj7YBsdpxj/YqHMZHjyMcn6HOZIxv9+XdNx40WsyK6SSo3fkJ4MIbcKYBamH7qEt k4zGyqbwE6P7sqoqcotzY0SExMy+Vuwh2GeVjQ4bx/efxQJrRXCFGB5B7gBxjDQ51nXV UMau2EGFzUVtwsQAbuUn2eErLKLdRIPzCGr515ONgL4ZBJF//SxUOOexW2HnbgDuQPk6 0NIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sk6Ms0ah; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56569-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56569-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCXFXXM8P9BkncU1hFHD8+71oEAtOKXVpTjMKWboBIbmYLh8O2Lh950Ypvn/ZumHXqAMJjjIjzbjiGIlaD4Ar6eiLJsURw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a18-20020a9d3e12000000b006e2bac7c0c2si391493otd.136.2024.02.07.06.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:06:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56569-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=sk6Ms0ah; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56569-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56569-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 EEC7E28D72E for ; Wed, 7 Feb 2024 13:44:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E391D80045; Wed, 7 Feb 2024 13:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sk6Ms0ah"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EzNArgF2" 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 416A87A727 for ; Wed, 7 Feb 2024 13:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; cv=none; b=n4uqSMga4yBK/KMAhqqWvcYsHiBAUGDoCNgXXwKhsHAmygtY7KPKb6rmMDRzeo0ekJvOXCyJ5OTFjThH337BEISEufOwaE1mk91COsrPc0KnNik8S8Oc41hlsmu6YUiCnYxmGoZ9hRwJN+VaSUt65sn461YAQmSW/b/ltOUvDNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; c=relaxed/simple; bh=9pKhdcb4U6Kn6n57q/bMFfBnJsOtwwB+U+IocoT8FII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JW1UnS9RCf/A8Ho+BuJnRzdBgut+Xn98rkc3kIjQQn2oZUaRtASwfSJC2dG9zbXevEpoMH+9Gwv0GSVvzeFW7iP8zcI9/vP+bDPyE4SVbeuSOnJJaJzBTXwXRWbzwIL31vOYBok6y0T5TW1dlqb1ODt0lBmToR5ITmd1VWBHcYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sk6Ms0ah; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EzNArgF2; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313276; 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=zhO6JKJB/J3Qv7bq/QRbOX1jB95B7+7hKvBX2b3MyxY=; b=sk6Ms0ahQUVB/nEPquFAjN6fJ+FmlGtBFidV6ykTNk8cDu9P+zUJdrmD29YSeyOoCKwWNN i2j/AiEGYeJhZZCfKmXy4m3x1PDJGWQi1audu+RIQ26QS2plgyd6uz6nKO1XqxCuLCvdpf HMBvCOZVltSgZo7mEAeDtUsiiTHkBRIvweHT2DS9j0t9x5VreEdBLdubnFDPseaL+k9Alv XF2bT+TBqb2d3GnTLzQMwoBBvJye4leOaMZfDS8P5VVIMa8AEp4VWQzjvvfEBYRl5WPTpc Uq4RNrFOsfuLS5NyVPuZJNybblwXqClF/a/n1aOKNnzFgpZwQg3oz392lhBItw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313276; 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=zhO6JKJB/J3Qv7bq/QRbOX1jB95B7+7hKvBX2b3MyxY=; b=EzNArgF2dx+iI6Bd/8fC6sLYUZBQZEAag54Ig93WG0ie99hdhNAAK/aCcjMGrk0y37TuR5 bSGXdlnCd/hAZyBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 08/14] printk: ringbuffer: Cleanup reader terminology Date: Wed, 7 Feb 2024 14:46:57 +0106 Message-Id: <20240207134103.1357162-9-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790249313384413269 X-GMAIL-MSGID: 1790249313384413269 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 Wed Feb 7 13:40:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235655dyb; Wed, 7 Feb 2024 05:44:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrffGEuSn2Vg+I+VElLZbnaKS0vZD0wN7CzPexqCINq6Yuf68fXIUu2I9fUSitv8i5uomz X-Received: by 2002:a05:620a:4413:b0:785:8dbb:89ee with SMTP id v19-20020a05620a441300b007858dbb89eemr5887238qkp.48.1707313451981; Wed, 07 Feb 2024 05:44:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313451; cv=pass; d=google.com; s=arc-20160816; b=YuW/TA0Ejr+P8ziL1vVXIMZAsrLz/dFfRafOMc6krQCEbjlU3oVjac89zVjVfRMmQ9 r8gb/ow6Nq/pJKJdTQFAeNQV7lDBIZXexsa1dJqJ8NUBpi3BDSm48wu+AuYq0zoZ+iuE yuA+MADP7DPfTG1npuBTTFupiR7Wj7xrQd/159CI0e2AJxzwpncFxXRGoRLw6NkbUzh1 66+uLXKiHA2qa0GwoNkwUIrLKLmt4fdbqOBNR67vaKHxcoyGU3dgfh6xjfTpUPJ//VQI WtY43G28qqMDhMQwpuSxExZJ1ZL6RLC8ZE/k2WkhHn65omaHqyaRv93dqUI/wdB0v67I wO2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=xT7zVJldSqDSwoUDq5kV0sG2up4ftkGgvjxHkX7b2JY=; fh=iwdrs06fEwGClT8E5tj/0bDNthUKVYSJAlV+w4P0m3U=; b=JjXZMEeonFW5QJlo8ULrwn/P/Cg24pW58wzAU0qmj2pbqXVIS4VhNgnfd2gtko1C3/ cOT8b1XbLTUKgUpMeECqwtAz9eB1mWMsHX6/i8kI8Fr3sCZgtYE8XVuqjYoQeL24Mf0O amjkQIT0s/vrkKXWPlsOOVNE3u5hBdH1L4LyNxqhIL4aGNsctRCY8WJk8WSjx/GRvJEF C30zCwE+SxyW4CylSGv+goWkoTwwIRAcoLDFrFQlIoSsEg8vz5Aq2zbeCsgioy5r2ylt zkiJsQ8yj4m8UDYhASZphih4K84ULpdvrjLyhOSpKjVD268NxjjYSbeVn9MmbF2BH3FP +SHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="iK/gRZVy"; dkim=neutral (no key) header.i=@linutronix.de header.b="2sK/GioH"; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56568-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56568-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCXXcLRyfQozVWdxFW7bUgmFZOlkxH/A1tPrpqNMpdLMFqbusGnVGRnSwRa0/1UUVc6oeo4L3gNF0V6RCqcb9+gAazsAeg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w17-20020ae9e511000000b00784069227d7si1109577qkf.626.2024.02.07.05.44.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:44:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56568-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="iK/gRZVy"; dkim=neutral (no key) header.i=@linutronix.de header.b="2sK/GioH"; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56568-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56568-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 B4FA11C22319 for ; Wed, 7 Feb 2024 13:44:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4948E7F7D5; Wed, 7 Feb 2024 13:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iK/gRZVy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2sK/GioH" 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 417D57A72F for ; Wed, 7 Feb 2024 13:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313282; cv=none; b=fKvkAuhlTymcycBX2d4DK1rZhuzbUirQLtjz9jU4OhaQeezgyGeguAGI1h9OPFI5G9NAN0+GRjFdrUikgpi5ebeTNXGK2EC7ziTuGF1flrotrg/8w0UVzuskzUmfj5hfxf6DP/vi8hregYcwUQVo5g3QENifUT0DIO+KcqofkmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313282; c=relaxed/simple; bh=jE0seAEC/xsUWMRtdK3YedzagSyj6mY+1emI8btEf4E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kzxciqblxtj05vKWVOh4YDimamGDY0KXAyUeL+JZ4SW22tMNdz/QipTXklxmaD+uLtzO/3c7OlOGhC2ii4Rv6JFMj7B4uXS0Rpx0YcPdHVxuBcqjRXr6Vt0B/MTBLe+HTk+swiAKd6sbHMNaSj0zYldsm6hB08Kmw3k7eT1AQ/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iK/gRZVy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2sK/GioH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313277; 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=xT7zVJldSqDSwoUDq5kV0sG2up4ftkGgvjxHkX7b2JY=; b=iK/gRZVy1yAsy2xKP2G9BqmZpuuGbm32s8UcXFG/hBTiagvYU6EoS/TBBVmV33diYWmUOM OTPByYacFZy0/RuqZnrT21N7r+qe4PnGixv6MXVLumcD72yaNRW594Sg0PWhgnGIyV/fcI 8tKt6cODKqTnDuJA3JRrOjma9eyroJSXhCnuwVWrYdwDtAKMVHc/u3plx9O7dr7OVHquv0 v9fNk+Ptha5BdRC9EgNN8Q5GcBX0L2Hmgtogv2UdpUEL8c9or8pFPg/ErqNapJvdsvWiR2 +wxxEvXPzYioktkLWU9dQyV3cRPnA//ynXONy7xWePvTmnqoBRvV6qrSMPP6Eg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313277; 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=xT7zVJldSqDSwoUDq5kV0sG2up4ftkGgvjxHkX7b2JY=; b=2sK/GioHV+lIq5/fwAQVa/ezEoivaOvGl1twa+slOYEw+QdPKUhyN3Q+1v8nZskiQAE+l3 VAWlM4oFIvQ2zHBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 09/14] printk: Wait for all reserved records with pr_flush() Date: Wed, 7 Feb 2024 14:46:58 +0106 Message-Id: <20240207134103.1357162-10-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247909870279455 X-GMAIL-MSGID: 1790247909870279455 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 | 105 ++++++++++++++++++++++++++++++ kernel/printk/printk_ringbuffer.h | 1 + 3 files changed, 107 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..24b484c221e8 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1986,6 +1986,111 @@ 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 points to the record with @last_finalized_seq or newer. + * + * 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) { + /* + * No record has been finalized or even reserved yet. + * + * The @head_id is initialized such that the first + * increment will yield the first record (seq=0). + * Handle it separately to avoid a negative @diff + * below. + */ + if (head_id == DESC0_ID(desc_ring->count_bits)) + return 0; + + /* + * One or more descriptors are already reserved. Use + * the descriptor ID of the first one (@seq=0) for + * the @diff below. + */ + last_finalized_id = DESC0_ID(desc_ring->count_bits) + 1; + } else { + /* Record must have been overwritten. Try again. */ + goto try_again; + } + } + + /* Diff of known descriptor IDs to compute related sequence numbers. */ + 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 Wed Feb 7 13:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2248847dyb; Wed, 7 Feb 2024 06:04:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGR/FU/ahPHIZWCGa2v0yZH2eilAHLBYYC+EBzqxNkHbOX05teMs5teTR6DFCXkf2hzKkU+ X-Received: by 2002:a05:6358:290b:b0:178:8a06:68e2 with SMTP id y11-20020a056358290b00b001788a0668e2mr3334402rwb.29.1707314683017; Wed, 07 Feb 2024 06:04:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707314682; cv=pass; d=google.com; s=arc-20160816; b=tPclCICt/v8Z9o5GnMC2idU8K6Yj7Mef2xLGwDJQkTSgg4+HQxegRSNejY/ODtMHWz vzzKE6nVzEGKBDirobhzHmCpH2sOyD2/pfYRbMgUA7Qg5uOyQXFo02ChP72Afvnc1QjR v//s4swbXPPh8vkCJMrpvKzHtokojY+/OLguIYXPZVEu8s3s8s3/CJglvtnFFq3iU9r/ LvfwQXrshZcH5uXCNq/tmoSWXnUdEBPNYBYD/mUkCVHx20w9umGCQqJdtH+3N4Lk7aCa AQ8hDEvEGNKd4K50yINeNlTW01e4RbsTGJ4cQjzBjK52IJ18wIXg0HASNrco8uMgjrat wyyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=8cOMblqM1UqBk6IDY0+aDtpsYhEPmwBpENMB0j8kk28=; fh=K2qgkKsagvs6g17zoPODGNht+AB4TLsWd0TCvspBe10=; b=x+wRNbm0nDi0adJQHZqSHEZU/1t5CI241Mxb7K3CuUC8pBWDYLEA08niwuAlA79ea8 Lcc1C7x/QQ9q3Z9rfPEIhak+dP9O638yhEqZTNDxU2BX94yyqSseRqmMZ0yp/ouweD0G 5OJODAtjcxQqJcqRaKNyL+ob10o0LkEfwO4N0lhpPHD7SXL3Noyh29sVTLYBUU2mV36b Ie/Nm3P+b4MYt4zA4s23TXTwCMY+Y7O+siMGkz/fESmLyqPg++1zZw4t9WFAip7HXB+j e2TDJl8hlCnKh978hYfS7kjPGbJIDc75UxH6U2Arc3WbgRLj6kIQKYAMHkN5bvJhA1re r8Pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="MJVAYK/8"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VeaaC2Sa; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56572-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56572-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCX9g8pVUnKq/qFhOMjFdaw31mh0FCLc/xiTUk796AyloIMWQ4B1z/w7PatJ4azJrPzkVIG8a+LXx0hQZyRgsNELdUVlHw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cb11-20020a056a02070b00b00589fcc39ef1si1751817pgb.365.2024.02.07.06.04.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:04:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56572-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="MJVAYK/8"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VeaaC2Sa; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56572-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56572-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 3B32D28E0F5 for ; Wed, 7 Feb 2024 13:44:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C1A68062D; Wed, 7 Feb 2024 13:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MJVAYK/8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VeaaC2Sa" 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 BD4A77C08C for ; Wed, 7 Feb 2024 13:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; cv=none; b=ePSyF8JRSfQkQjo+27qk0w/KqJUuAXkcg/2QyDtLFkJ+wrLCUhgB1GhYrHW1JguwZmIww95oj6SpivIBDxzSA5e6DA6/sjj9jF4lgr5dW7WKO3JE/6JvUd/nHR9sZE8OvwQ/ZtW3+bmmICsl521dTYO5z8hMK34yhTFim9TM57A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; c=relaxed/simple; bh=Bn8TIXFNy3nrR6EMlKeOogQoD3nNIaQmPzKytNHWvfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lQbX/6WSTR4KHKb5BzR+eRq1oeT/cReYJNjVmCnGiAdiyFvbdL8iB9ZxGnEn/JxUnOUQnpt0k/w4fpzsu5LKCAcZeea1445zPAn7UlywwiYAEPDidL64cNDGqjcBjhUrf/FAj3KvJmL456n7lxBNUPA3WPRPJubcLNaasEa3Z3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MJVAYK/8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VeaaC2Sa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313277; 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=8cOMblqM1UqBk6IDY0+aDtpsYhEPmwBpENMB0j8kk28=; b=MJVAYK/8B8rWBhPLduCIXQaBtKp9vcnlN9io5mD5r2rJxwFngbFDMi/th0WOB1+9Vz/hpa IVmVjklkR8lOyIRxbqBZ+sShA2MavoAVu3yb4sJv9HVG9rGQIIVYxVW1Fs3Y9lOIaOJ+dp 4ojca3GCz4a755r4SevT3vT9Xj96UcVWOLq9kDCXjnXYY5qI/dQrFsyfn+WxFEpHUKSEDi nkEFwjdnH18wwJvtBKeJU3dXBXtACBjlBpvFJVjvXmlsDV7wAJlJSHJikzWI9ROv3padVj HqBN+zcZ7KXYoQQHksqEbn+xx07Z/+Frfcr7SdRYICmDKNI5UOnhv9DfAh+ucg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313277; 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=8cOMblqM1UqBk6IDY0+aDtpsYhEPmwBpENMB0j8kk28=; b=VeaaC2SaSkOlJC7NiQORzUvNwmblPlIYafvBsfBZW5GZJyphx67eE865Bel0XHeYayVX0F wSO8A8uUFhEKEzAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 10/14] printk: ringbuffer: Skip non-finalized records in panic Date: Wed, 7 Feb 2024 14:46:59 +0106 Message-Id: <20240207134103.1357162-11-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790249201444449271 X-GMAIL-MSGID: 1790249201444449271 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 24b484c221e8..88e8f3a61922 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -2099,6 +2099,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) @@ -2121,8 +2125,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 Wed Feb 7 13:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235641dyb; Wed, 7 Feb 2024 05:44:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUt+SqfK3f/ZgzFN6L/J75NpTQD1B7mUSLuWSLzXevRkUQ7Ww8bqvkizI+4PJ/YoNG2nzytlLS6ZzqB/MineZvtp/T8JQ== X-Google-Smtp-Source: AGHT+IEH/nmsJ0axcaJ9o7Em01P9PBT7DazGC/0zLJTohXWaRwCDk7KYJXjMlJLKd9Hc2uo4w9hC X-Received: by 2002:a05:620a:219c:b0:785:91da:79ad with SMTP id g28-20020a05620a219c00b0078591da79admr6964984qka.12.1707313451013; Wed, 07 Feb 2024 05:44:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313451; cv=pass; d=google.com; s=arc-20160816; b=vjeo3rrw7TvvaPl0eZYgXfq62wTqCbokzyr2VlpNJWA+TRm8eMjWyeIr6po4hYmeOB /pJBgTm0/pGPF7211V00AWp8c09m5lF4aao48rL31s+Z6IBFe3iWsHen2dmGYOiK3X6J Zf8SFwrE1xkyXuci7Cbjz4gEXAeusDMVm+xro5cChLgqX8Fjs/zhvVdEJgbdZnAbmcVu Fb5nbOOHKZJAjYON04IweGv/d9IqoBgPqzAxj7XhohZeGSydq99SnzNt+pPKBV3bKST3 5OTEM1/NiZJ4+HK1drnqXWogREX9pSLTdAl1vOQQvXMPS5CNL7masORceiXUdx81OSGO 7c3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=5gccnnm0QINuqJ5Q69vjwoN8uCr8tb4sBQoCznhnpik=; fh=2q1QFYSvTuBxYpgERuGcWiPdK9ZcZVYv/wJLxSPYhr8=; b=usBTOho8e8REfs7EOX1CblQFqPkoGi1f7nY+brtKYoCXZtok1TkZWS98ovYeUn7m7u gm7XRL3VO2DPpEBw770OO1Fk5mESSyOBNRjjegcsAXHhHnloKOGcyE8myNDUiL1qyt9p g0lepDKzEFXaE9wzgenx5Y6XfxVtmMwJ4PFxaJOljdNGtgI+Sa+CPgwkQWFluaIeTQVg 4WLjozUF56t+//P+txtVIpy4E9/Y4hBffDlLwCxN0kX0HaqojKfzSwYGfFIYFAzAn2er HkMon4BO8GkU/fsMnaPjx80BV8zoSsVbEGX+aWZg7wWbSwsm0/1NT664sWownd17hnEZ eRUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=x8lxGR+u; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=1kvO3lbU; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56570-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWE+bPCtEddwGDizclZoahKadXNJrSZLxI6StGB5aJUhB/FFfm1l+Ml0f1dUxH5vKqynqmekqcYgXir1zfsgSVd6PFAtw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w17-20020ae9e511000000b00784069227d7si1109577qkf.626.2024.02.07.05.44.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:44:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56570-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=x8lxGR+u; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=1kvO3lbU; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56570-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 C9A6E1C22314 for ; Wed, 7 Feb 2024 13:44:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ADD48060D; Wed, 7 Feb 2024 13:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="x8lxGR+u"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1kvO3lbU" 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 B5E1B7C088 for ; Wed, 7 Feb 2024 13:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; cv=none; b=hKtSDrNTMIxjvUdrv7IEKi3971J4hP+gSxXtUVf7VW7rauA9XyGaJ/MLe4PJlJElpPCQf2yYYUlnbGL0J7V0Att6r8jclmGaV4fo7stydLz95gS4mJ8sySTvLQS8Nj8zzAuFVIJbgAaT4hLNofV8YMcjirnYoKqMUe3BruWHfrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; c=relaxed/simple; bh=X5giHqYzbgyJiLPkgkBV/8/LIFlyXyt3ukrqvKCTf3k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dBhLjGA9wftFxmrYDY9+wBVi8+cssghhNYXbNSSejcFTKwZvb2df86YBFA4ZRpLNcjK/8DqEIq1COZdUS+Ale74St6U4lwkyX6EfrXe4zDcbckfW6meoGwzvHBSejGJT/QVM3XUv5eVYWbx+EWxPUxrM0Z3KItiXYqErfNSPYMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=x8lxGR+u; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1kvO3lbU; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313277; 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=x8lxGR+uYndcXzOVgqTC99FKpgrOa+Ve0hYCCQTZr8nMUp8o6jEr0CKjipw/qU6mff9vnR GYnvTuS/uUEwKT/Py48VSZuf7qs6nowKKprCFFgYiSsYaBHSDebswtd41/jYFRvxNDLrxr uL+HxAZ0LyuFhMEVurzGth+cUjWys2b0xyAEBSIwbjVp25Ef6ZjVPfeCX2VSJP7fmjBkG7 JV+NO13i4cDJanV3HqwGJoU4Owp2JA2KT+nUdBGO4MirmaQzbNCe3wFTvx2OeXwNCe1bYO QNReJYQ/prxuI0w8SOj7UIKvXlR+TQIMkLEGDdWGhJGUiOOWDhyhCI0v3aQI6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313277; 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=1kvO3lbU1l2I7wX/zd4wnLhnyT7Bl5WP1W8cWsnqchY0kftxTd8CcDmfCYYLTwPQmR0BIA /ZFOD0cHPPltwFAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 11/14] printk: Disable passing console lock owner completely during panic() Date: Wed, 7 Feb 2024 14:47:00 +0106 Message-Id: <20240207134103.1357162-12-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247909029107985 X-GMAIL-MSGID: 1790247909029107985 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 Wed Feb 7 13:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235634dyb; Wed, 7 Feb 2024 05:44:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHksNSReffr4e250BVwwqXhpoZ17Iv8Thlq8UQBu8FPbMuz6Rsgdhe84J3Zz8q/dpTSPkZl X-Received: by 2002:a05:6122:31a1:b0:4c0:d43:f8a0 with SMTP id ch33-20020a05612231a100b004c00d43f8a0mr3052443vkb.13.1707313450563; Wed, 07 Feb 2024 05:44:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313450; cv=pass; d=google.com; s=arc-20160816; b=Ti9O/VLH6B1nvVFFUS5wQIe6FlwEJLzOxcrqXXSEGaTieTfP0Nfnu4K/RrrQZe1SIb BcoSXFuHtN1weoMPmqkBojuZpsOxONZDcSbRB7Bvr+oewtaIy3BOVWcOcn6UHHg9jTtf pcPZwER7GMr1gRgOgKmVIgfvyxWrzV86NjHJ7UKNDFvOAr/C8Z6c5jv+hnJaNO8OG1Tn ogfyOY15NUk1b4l9Xf+L73z4lV3YuMAIMmhBNN/d81NKZhRQHAbMlpz2enR/XiG+/XxP LFlXLleh/3djatcbTM28brFd2NVvlREFj5mJnzoJIRjWeg2ADog5tynpsHsSKDhtg9vF 4jyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Qr6+1j81aENvGfbCAyeGtVP3cfgAJxlpbRhW4IiDqto=; fh=DOe94SgO+PPHIstJ5W9gNXsaqZN8+DKUS9IwWCLZKVE=; b=eDCeQpgON7NSzqbxIT8YBVF3E5VQitGKNK5Ovlx9BpX9qET8sY8KR7CSpcEK9b5OWc GRSVYLMwHO4YC3svL4iXgqx4MHD4CgQjV59xhfjezcA7RVeglr3cptVnXGSDF+2cVp2b M5RQ4oblOoaPfHCVCHMkc3VeCKJ0OA0pgvI2kWy2iz70d1tZdJjNGoMIWJG6sPWCfiQl tk8TULO2QSSSX8UIwChgDueUq5Aql53pA6f7QwoYpAZQ1MolR3Ei4Ns14EKzE9SYvCvq X5Vmoif2+BqcctffW9RDZNZIg0IP60iNCGVqZtJeaTD7oOBF5IE3anMFXyrE1bgS6oEF qWjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UOWZLETl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56571-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56571-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWCPohc4XcZuANezXIqoD3XTBEbhXBwiZ1RPNTpmkV8juGcrPAD5nkOZQ50KX7DfcQKVyIRDVS8CIEZPavuscqLx7F/Pg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u18-20020a0562140b1200b0068cb9dfcf96si1083734qvj.569.2024.02.07.05.44.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:44:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56571-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=UOWZLETl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56571-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56571-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 5A62B1C22A81 for ; Wed, 7 Feb 2024 13:44:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3680880609; Wed, 7 Feb 2024 13:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UOWZLETl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8ZVlsQJP" 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 D22BB7C092 for ; Wed, 7 Feb 2024 13:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; cv=none; b=AVVdvwThAN6fVYiuxQnVjck3a+1LXihHiSp9ORXumOdCjwg0rUMSAbZRJe5yyWPngXCa2AdZBMbJUToFliAgDxyO3+Uigr3DtYaaSgYYVNPcCVpmeBjIYrPsgNYzZwevyG/hguIAwajeR8qLBz2edC7Fh5UXhE9dJxXT4+/C8fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313283; c=relaxed/simple; bh=LgqHmaayiIBzXTCRVfuLGbNqvjVYRa0vasgGK+33Hc8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GfMj6HJnxD1Ko6IJjlTPSp7+53JX65JIjNX3FH1WPWGVOm0TngV1du6lVOjkTGgMg3WV7HIJnXbS+fLzKe0ptFAeXmJ6UM73ix/MixTCfMyofS/P+/oB/hHN9J3aEWff6Y18gFNfXb1w3opWds03AaGa4JbAb6ED6ScoBSaj/YE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UOWZLETl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8ZVlsQJP; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313278; 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=Qr6+1j81aENvGfbCAyeGtVP3cfgAJxlpbRhW4IiDqto=; b=UOWZLETl5J68nJmWxOfvORvekRjA8gunoQq/j/rMaDOPt3K+o5KHeH9r+cdhcPw3p+iWGE y/yzKHYlXvEr74Z8VkYqkvjWy80B7Sz+hz/CFoy9IjTlLFB7ceKhB8NH0KTDvll4yInx/Z T2yRNLQnZZ20LIC3wH/CfUr+ihk442zy3anpH4vyzrO3ztDR3g2lylP0N2fqybBegyPrin MxIlixqUaW6ompHY7BpseLDGuusmJE6/R7dQ236hronWGNXG+e2oABU5bubwmOQE6+/mJ2 UfEpBtaNS33gjbIxF76bCYGHEdQeiLiTiI0Er5ZYcoJKLjvnsnHNFnq5E3EcTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313278; 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=Qr6+1j81aENvGfbCAyeGtVP3cfgAJxlpbRhW4IiDqto=; b=8ZVlsQJPNIK7aih4qE1pCWt2uBXwc7crk6HrxBoNG0qJi1dAqhS7aXEood5IQVdiN/gXK9 1myip7bxPQrnY+Bw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 12/14] printk: Avoid non-panic CPUs writing to ringbuffer Date: Wed, 7 Feb 2024 14:47:01 +0106 Message-Id: <20240207134103.1357162-13-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247909116459508 X-GMAIL-MSGID: 1790247909116459508 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. Another motivation is that non-finalized messages already might be skipped in panic(). In other words, random messages from non-panic CPUs might already get lost. It is better to ignore all to avoid confusion. 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 Wed Feb 7 13:41:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2251489dyb; Wed, 7 Feb 2024 06:07:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGza08SnFprHOumFIF6AEG5KCNitMrDnOzwHiJQJyA2EQI0FlKm7G1k+sb1ryfNBUbFgW00 X-Received: by 2002:a17:903:2b0e:b0:1d8:ef8d:a7ec with SMTP id mc14-20020a1709032b0e00b001d8ef8da7ecmr6849673plb.2.1707314864481; Wed, 07 Feb 2024 06:07:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707314864; cv=pass; d=google.com; s=arc-20160816; b=sH0CKa8rrTb+EbprhSiBlK7oIPEIacto5MMTSRSu6Z/9tGG2Qco8CbxrS9No6Q6jwu mTVYy035CGMOuNwWB5/+AL8ZKiDF8FhjmhbinRMUSkVH8PQx1UKAreQuYHMz9NEZjnF+ 7w/IGilWDoW5SDcgSqTtavQC/K2WvP+3wtEqXzYGC0PGJ9sT9k/DsLqeWpMu5lsUPWR/ T0LLeKaocEAHf2tTvfNM1HAFs76wqfFVGaTJtiOLTn6uwynhPXNJw/lMin98grrCHo9H ZiBUdWnXQpEGIltinkQCH0FfWFMWnFd3DWVhM0jjs79Rbqi+/T5CYOQc2CIagBn4vFOy hM7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=dglETRzgeJkpvG6OhED1NA4N4r3adrKLfLIWNwh3o/w=; fh=i4zs0yMXR6aCSvn7piRXDARPWTlefnWxznzau8aqmmk=; b=pz53dW3/5Sn2gzwK8OpqmHrNj2D/6LIonsdHDK2IZteuL22DRmwm74CRkK2OBFHDZX EtOqqDpnTD25FQ2cz+DElDmlTpJM/+Zb7cqj6YEsumHcU3hVkTRjEjrdvpFfdq74ibFH qZPLfHtGpl1Q6yVdeXtWzdQ9FTcYPDBwEklSZjxCNBjzL2hQ3v7TwCtRWBq81IvAOtRu RKLlPVudsidPNYJdjH/nL3jh1WD6u9ndKSrYeNQ7Psgh1jYC0NvM+ziXIkbNyRQoJ/LE d7/Kr62od8t8Xjzn6Eb2/YhW6SSrO4tp8pKNDIn8cRdFfO5ANSuy4KhBWK7dFqs19ULo QWlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cKTByp08; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56574-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56574-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCVfzWd2RH+P/zrzgUuiplpIPhLIqidm+pv2FmhYzwYaFE/YhHpPklex2m4+rSdYTZJ2kMAiSvVLvKL4Pu9VNr65jpuBRQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y12-20020a170902ed4c00b001d8fc816118si1666860plb.189.2024.02.07.06.07.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:07:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56574-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cKTByp08; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56574-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56574-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 6A87428E57E for ; Wed, 7 Feb 2024 13:44:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D492811F1; Wed, 7 Feb 2024 13:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cKTByp08"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dZo+Xyev" 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 95B107CF14 for ; Wed, 7 Feb 2024 13:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313284; cv=none; b=tJ4oMBD+nS2CnYIOEgFJLflhGDOSTK/3KUjCFRxbV3K0pUO+v8ni5F/kAZ75bq363AbTFYhETNNA5l+PVtSmqFDoxB5EYVHV4d5mdmsCWAf1yJqvAz0/QXtY73RLYQrqaDaCaoVtlsDYLQcnBpWVjGbeVoO0s14rmeYQd0UT/Kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313284; c=relaxed/simple; bh=CEW+1jm4Jjbzfoy5qe5W0Jz6zUqG9fMl4RYmnU5hdu0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ET86fwTN5phYFMr8g1mgJhlj4378Debrnrz3MkK/XmU9j5rqgQDxdqB8lS32sou9ReYRZ6naUXCgxPK6b3uJiMNCMUoYAWFx1P6qd3FGlA6J4EC/7iQ4z8YULJB0TnuK8PgNw4jzul91qPDhOQSEg0eyKKaOz9wtoXAcTfM/GQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cKTByp08; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dZo+Xyev; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313278; 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=dglETRzgeJkpvG6OhED1NA4N4r3adrKLfLIWNwh3o/w=; b=cKTByp08JTA4mBNGvjF+r3B+h3oDP2A/bF0kIDK3Of7rFF9xt19VJNvJ0cjRPTf4coBWLt xhneAgT1tON2UttA0t02eGIP02a8XH73ZdtOx454Km/3hruinbPpjpev802RB0kGNMsUgt spWQbaUob+Q81Ih2+sfFcDyzZ37e2xcY+FyUUT22Pwc7w51ZlTXoedt7bc/pRF3y3O2Hu/ 123aPrBb/FvH89xuwHWR/soP9zpojd7iaE+VQI1vPEFJc4Vzty3J7009D1pVc4avWYiYQs xTPqfwc38+1XZtET4wKjpxiD2Ohk+29ALcehkBstaM3XiGrX8FQRR/HuKP1Myw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313278; 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=dglETRzgeJkpvG6OhED1NA4N4r3adrKLfLIWNwh3o/w=; b=dZo+XyevsHtdYpqiRG8A+vejgzxI/quf3igei9fqL+qYK7ZnuJx9XroTnlhM7muuJQPKqJ o3H+KoZfFQN8xNBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , Josh Poimboeuf , "Peter Zijlstra (Intel)" , "Guilherme G. Piccoli" , Kefeng Wang , Uros Bizjak , Arnd Bergmann Subject: [PATCH printk v4 13/14] panic: Flush kernel log buffer at the end Date: Wed, 7 Feb 2024 14:47:02 +0106 Message-Id: <20240207134103.1357162-14-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790249391324474300 X-GMAIL-MSGID: 1790249391324474300 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(); From patchwork Wed Feb 7 13:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2249157dyb; Wed, 7 Feb 2024 06:05:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqzLdEZJyGcJ1jSkprSZGGQBOD31pH7H4qNDOn1/k3wrZGC7Z5IxwvoYf04zQlH2WJWoCmrScDS2tntGGFxDv38LZYig== X-Google-Smtp-Source: AGHT+IEV7Ow13UPsKEmikqt/By02zcX9/nHAzH+Cruqh3FG6K2l7t3ExopuKdYSBN8V/gnKlnWcq X-Received: by 2002:a17:90b:3616:b0:296:530:996e with SMTP id ml22-20020a17090b361600b002960530996emr4667989pjb.20.1707314701747; Wed, 07 Feb 2024 06:05:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707314701; cv=pass; d=google.com; s=arc-20160816; b=hdVZtIHFW3Ymt4TxT82eEaE1VVaVvXkzbScYlIrqASET9NUbz+6v7CnYuJbkcf9x4h cMiN47tKjeOXFtSZd5ytYrVa/jE3hqWMGo655xeXttjVF1hNg4lDwh2pJVfgBhF/+a5A Cy/SMZJ1EOzbo6u29Ivbw5Eo27bb6n78gkJfWFDhuqwvY2C8ZHDiAKAzKN7zxQGipjNi b7Mqskz0e0uLGRAcVJdJftVtIFIODo+biPXG0BacLp2fEiib2KsaFBJDA7L+xwZasTcu 3mnBcX78aMlawR8PDx3jmDZI1jgHTwsjhEobLnTwZdS+tt5blRQXUJuzYJIrZ4XpjoLz mGcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=3tOC9aXvX0QnLyHAZSaZBIUXi3xE4WWmBQ6mB2/+B2Y=; fh=fyxWiXYA8X2WZtayZDbdFsDOLUTwokQOErz1e/RrkuU=; b=un7Yu6BrNJB6jwwsdCadnQKbb0Wj4QVIl3kkoOvu0ExYB+nrB4rYd9nLNbwINsw84m 8csZzUfNCNdkYVNtQ2EPNuT/WyVQQxzlGY58xiulnbbh/CiKm9vIvCn9GlF24yGw+7Qx CJgyqkXXabGwyzS9M4F4AbC8BGOGF/yq05AK77vT5aeVRNDWRk7JYiLYu8/PV/x+fpiV Qmoz0kxXLBvS7ZPOvjmRG1EZDm2NcXEXYikf5enxdy79dNvCa/Y8LQVOR1US9c1VV7JC OoKaK2dcLwjRhpHACm657D5dHxQ3ODOlF1EytXY1tPM//u4rLWsswSsVwOW/8/rQd0hp D4Qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Zayr+TMU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56573-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56573-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWLQeT36pioWaIL8DwJ0sUlg4YQo8dpJ49zjkPhT7AuPou6m5eXY7x0jcqA9UliIc9aYgxncDxFXL3g+bdc06bQH6/TyA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x2-20020a17090a8a8200b00295b3f29c83si1640795pjn.108.2024.02.07.06.05.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:05:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56573-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Zayr+TMU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-56573-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56573-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 D8ED728E5C1 for ; Wed, 7 Feb 2024 13:44:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27F12811F2; Wed, 7 Feb 2024 13:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Zayr+TMU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KEnRLdtz" 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 94E5879DB5 for ; Wed, 7 Feb 2024 13:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313284; cv=none; b=IIzg8Tm5ng1Uh/BxbwlLZXwjGLGIN2QJ4uajTaOozttR3fwZfuDOGJzbBg7gDV/upJxtoExyXSR9fEQeLFOVWMH8zsFT3BXpSREHSSfwX5gZwwByzo142Qez5vdWsRsAJTrjXtSanwe4dr0An42K0baOfGaitqZA9zDNnzvxf18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313284; c=relaxed/simple; bh=rCdB1Pa4Tv7uSe3TR4FRXyAZD0vHyhOKHq0ldmSv8k8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F/B3krhaaehSr6dtC2Dk3qH15OiAqyUNcvXv10tlaqkR6fLpiMtle1aCvatBwOYZmyNp4yBu2/uZijreTNj0ajSBjoHAO2/4fPPHWzdxSgFeYDdUcSStV4vUe5JWAOHimmzpWOApK7KJqiu3WmpjU/CoKyArZQ2BYKNiI3QzsPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Zayr+TMU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KEnRLdtz; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707313278; 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=3tOC9aXvX0QnLyHAZSaZBIUXi3xE4WWmBQ6mB2/+B2Y=; b=Zayr+TMUy9c3T9cpC6eEj8Guy8iVZTBL0nRC/wsEBkxwClxISj9Y0K7hevXpYyXb9mSEfs fEa5b1XLAks7cSplbX1mKiPG9xRCkrGQhUrIa8vWkMlaCOedn43B018fDlF3Q3Kgwl6sWw yrghjQydHqV7B2GXQ05yMYMGS93JIOCOrxQiIWT+2xLgjVdqJ7NP4fJ9au+F/WrCZ6k86I rrrj4G138i+eKrdzhWfsBFrbyNe4PI8AMukgM5T0yYpyoSCpQm7KOgqz2A13ZzOHMyrCpB 8LzxmahywVV2coZTzWbZsW8Y7ARLSAY4/wpbrddoIr23kY4QZ4QGO+X3K0Dwxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313278; 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=3tOC9aXvX0QnLyHAZSaZBIUXi3xE4WWmBQ6mB2/+B2Y=; b=KEnRLdtzeybX5PwNYbgVrbGJe7LkxghZpjkKSvisgJ7mF5EhQRLRsx9T2aUMrRL7OkBTMU hd61myZeEmQTN/Ag== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 14/14] dump_stack: Do not get cpu_sync for panic CPU Date: Wed, 7 Feb 2024 14:47:03 +0106 Message-Id: <20240207134103.1357162-15-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790249220462997633 X-GMAIL-MSGID: 1790249220462997633 dump_stack() is called in panic(). If for some reason another CPU is holding the printk_cpu_sync and is unable to release it, the panic CPU will be unable to continue and print the stacktrace. Since non-panic CPUs are not allowed to store new printk messages anyway, there is no need to synchronize the stacktrace output in a panic situation. For the panic CPU, do not get the printk_cpu_sync because it is not needed and avoids a potential deadlock scenario in panic(). Link: https://lore.kernel.org/lkml/ZcIGKU8sxti38Kok@alley Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/printk.h | 2 ++ kernel/printk/internal.h | 1 - lib/dump_stack.c | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8ef499ab3c1e..955e31860095 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -273,6 +273,8 @@ static inline void printk_trigger_flush(void) } #endif +bool this_cpu_in_panic(void); + #ifdef CONFIG_SMP extern int __printk_cpu_sync_try_get(void); extern void __printk_cpu_sync_wait(void); diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index ac2d9750e5f8..6c2afee5ef62 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -130,7 +130,6 @@ 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/lib/dump_stack.c b/lib/dump_stack.c index 83471e81501a..222c6d6c8281 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c @@ -96,15 +96,25 @@ static void __dump_stack(const char *log_lvl) */ asmlinkage __visible void dump_stack_lvl(const char *log_lvl) { + bool in_panic = this_cpu_in_panic(); unsigned long flags; /* * Permit this cpu to perform nested stack dumps while serialising - * against other CPUs + * against other CPUs, unless this CPU is in panic. + * + * When in panic, non-panic CPUs are not permitted to store new + * printk messages so there is no need to synchronize the output. + * This avoids potential deadlock in panic() if another CPU is + * holding and unable to release the printk_cpu_sync. */ - printk_cpu_sync_get_irqsave(flags); + if (!in_panic) + printk_cpu_sync_get_irqsave(flags); + __dump_stack(log_lvl); - printk_cpu_sync_put_irqrestore(flags); + + if (!in_panic) + printk_cpu_sync_put_irqrestore(flags); } EXPORT_SYMBOL(dump_stack_lvl);