Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp311600rdh; Wed, 7 Feb 2024 05:41:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtqMMEHQWFgkmKrpFKbdcYRPdH4opSRq7f9GZ2R7rB+pXuuj9LbWMzMyrR4diYbAbPEyux X-Received: by 2002:a05:620a:2212:b0:785:969b:d16 with SMTP id m18-20020a05620a221200b00785969b0d16mr3118063qkh.54.1707313292066; Wed, 07 Feb 2024 05:41:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313292; cv=pass; d=google.com; s=arc-20160816; b=uHA+mufjxL/TxiMETePydGK5ngBkCaLsVq4rfcmyi2D6zxgxPHXGkin2v9lbfEzjNq T1j0TIDp4s8bYkOeewHaa89lCCMMBbxULmdKsJDNX5hij/73lz0XllRpQJzQvCqQ8J6J Y0OAx7Ffe4i0frM2f8OWBk9d4ycO2dLb0ld+z/mxPso29+Ie/rdnzy8NwI5oPE/RrW32 1CeCB7hJKJq31c0wlWaiUTHJdgldfrNJpW7nEbrtk8y2yo2Uo9VbBNPtdPOdwMzS7tWQ djRTFTjzzsmSRhENG/d1cb//niAD2QqXEzSy6xApc7b/+yb/cAZBJ20J+CDB50dYNWro s5Vw== 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=dB4x2YAiWkpWUFEErpVvECYT2gvhXDDDYfn89bPVRUg=; b=aMAeYe/nsxruA7gbGVYkqg+T1Wdlw3H/QL0Apw2bs2+tC8iU9L3kdd1jO60RLHF3Ce FZT9zsu6rcm+/TXWCQq3TlgQF1zCJ6x/iU6cQPbPV08q8eG8DTMSbTHSNwMZoa2PUWsb 7OZtqhuYxs4EBDad6fU5ttL8zRgnX9DrTKr8tSsppU2Ghh5LsmLo5pAwe8d+cU9hcOZg 6sHWMkmbBpc9t6ke4+Bc2Q3xbSckSSGBsVjJcfWe3WlKzWUZV/ybT3gec9d/H63n+Ibs K2Z/L+VDCfx7AnnNQLvw7LChVtK5js9Iq8ri3upzvjDO9jUyLthh3+i/Fp6hkoMUSiVs IGPg==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56561-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCW6oCMNgluFDL+Ziu2c15Io+OKbNNMjhZ+4/M/FF64YKgS4eYS3OlMvTKnpOD6+beElVzhX5P1+LNAA1KSNPOhWfqDxa+obojzDLe4Nxg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id k9-20020ae9f109000000b007835b80b398si1033668qkg.655.2024.02.07.05.41.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:41:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56561-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56561-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C1FFD1C22B30 for ; Wed, 7 Feb 2024 13:41:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF79179DB8; Wed, 7 Feb 2024 13:41:19 +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 Content-Transfer-Encoding: 8bit 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 */ -- 2.39.2