Skip to content

Commit 5b73e70

Browse files
jognesspmladek
authored andcommitted
printk: nbcon: Relocate 32bit seq macros
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 <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
1 parent 2a80532 commit 5b73e70

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

kernel/printk/nbcon.c

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -140,39 +140,6 @@ static inline bool nbcon_state_try_cmpxchg(struct console *con, struct nbcon_sta
140140
return atomic_try_cmpxchg(&ACCESS_PRIVATE(con, nbcon_state), &cur->atom, new->atom);
141141
}
142142

143-
#ifdef CONFIG_64BIT
144-
145-
#define __seq_to_nbcon_seq(seq) (seq)
146-
#define __nbcon_seq_to_seq(seq) (seq)
147-
148-
#else /* CONFIG_64BIT */
149-
150-
#define __seq_to_nbcon_seq(seq) ((u32)seq)
151-
152-
static inline u64 __nbcon_seq_to_seq(u32 nbcon_seq)
153-
{
154-
u64 seq;
155-
u64 rb_next_seq;
156-
157-
/*
158-
* The provided sequence is only the lower 32 bits of the ringbuffer
159-
* sequence. It needs to be expanded to 64bit. Get the next sequence
160-
* number from the ringbuffer and fold it.
161-
*
162-
* Having a 32bit representation in the console is sufficient.
163-
* If a console ever gets more than 2^31 records behind
164-
* the ringbuffer then this is the least of the problems.
165-
*
166-
* Also the access to the ring buffer is always safe.
167-
*/
168-
rb_next_seq = prb_next_seq(prb);
169-
seq = rb_next_seq - ((u32)rb_next_seq - nbcon_seq);
170-
171-
return seq;
172-
}
173-
174-
#endif /* CONFIG_64BIT */
175-
176143
/**
177144
* nbcon_seq_read - Read the current console sequence
178145
* @con: Console to read the sequence of
@@ -183,7 +150,7 @@ u64 nbcon_seq_read(struct console *con)
183150
{
184151
unsigned long nbcon_seq = atomic_long_read(&ACCESS_PRIVATE(con, nbcon_seq));
185152

186-
return __nbcon_seq_to_seq(nbcon_seq);
153+
return __ulseq_to_u64seq(prb, nbcon_seq);
187154
}
188155

189156
/**
@@ -204,7 +171,7 @@ void nbcon_seq_force(struct console *con, u64 seq)
204171
*/
205172
u64 valid_seq = max_t(u64, seq, prb_first_valid_seq(prb));
206173

207-
atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), __seq_to_nbcon_seq(valid_seq));
174+
atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), __u64seq_to_ulseq(valid_seq));
208175

209176
/* Clear con->seq since nbcon consoles use con->nbcon_seq instead. */
210177
con->seq = 0;
@@ -223,11 +190,11 @@ void nbcon_seq_force(struct console *con, u64 seq)
223190
*/
224191
static void nbcon_seq_try_update(struct nbcon_context *ctxt, u64 new_seq)
225192
{
226-
unsigned long nbcon_seq = __seq_to_nbcon_seq(ctxt->seq);
193+
unsigned long nbcon_seq = __u64seq_to_ulseq(ctxt->seq);
227194
struct console *con = ctxt->console;
228195

229196
if (atomic_long_try_cmpxchg(&ACCESS_PRIVATE(con, nbcon_seq), &nbcon_seq,
230-
__seq_to_nbcon_seq(new_seq))) {
197+
__u64seq_to_ulseq(new_seq))) {
231198
ctxt->seq = new_seq;
232199
} else {
233200
ctxt->seq = nbcon_seq_read(con);

kernel/printk/printk_ringbuffer.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,37 @@ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq,
381381
u64 prb_first_valid_seq(struct printk_ringbuffer *rb);
382382
u64 prb_next_seq(struct printk_ringbuffer *rb);
383383

384+
#ifdef CONFIG_64BIT
385+
386+
#define __u64seq_to_ulseq(u64seq) (u64seq)
387+
#define __ulseq_to_u64seq(rb, ulseq) (ulseq)
388+
389+
#else /* CONFIG_64BIT */
390+
391+
#define __u64seq_to_ulseq(u64seq) ((u32)u64seq)
392+
393+
static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq)
394+
{
395+
u64 seq;
396+
u64 rb_next_seq;
397+
398+
/*
399+
* The provided sequence is only the lower 32 bits of the ringbuffer
400+
* sequence. It needs to be expanded to 64bit. Get the next sequence
401+
* number from the ringbuffer and fold it.
402+
*
403+
* Having a 32bit representation in the console is sufficient.
404+
* If a console ever gets more than 2^31 records behind
405+
* the ringbuffer then this is the least of the problems.
406+
*
407+
* Also the access to the ring buffer is always safe.
408+
*/
409+
rb_next_seq = prb_next_seq(rb);
410+
seq = rb_next_seq - ((u32)rb_next_seq - ulseq);
411+
412+
return seq;
413+
}
414+
415+
#endif /* CONFIG_64BIT */
416+
384417
#endif /* _KERNEL_PRINTK_RINGBUFFER_H */

0 commit comments

Comments
 (0)