[PATCH v2][next] printk: ringbuffer: support dataless records

Petr Mladek pmladek at suse.com
Tue Aug 4 06:14:00 EDT 2020


On Tue 2020-07-21 15:31:28, John Ogness wrote:
> With commit ("printk: use the lockless ringbuffer"), printk()
> started silently dropping messages without text because such
> records are not supported by the new printk ringbuffer.
> 
> Add support for such records.
> 
> Currently dataless records are denoted by INVALID_LPOS in order
> to recognize failed prb_reserve() calls. Change the ringbuffer
> to instead use two different identifiers (FAILED_LPOS and
> NO_LPOS) to distinguish between failed prb_reserve() records and
> successful dataless records, respectively.
> 
> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
> index 7355ca99e852..0659b50872b5 100644
> --- a/kernel/printk/printk_ringbuffer.c
> +++ b/kernel/printk/printk_ringbuffer.c
>  static bool data_check_size(struct prb_data_ring *data_ring, unsigned int size)
>  {
>  	struct prb_data_block *db = NULL;
>  
> -	/*
> -	 * Writers are not allowed to write data-less records. Such records
> -	 * are used only internally by the ringbuffer to denote records where
> -	 * their data failed to allocate or have been lost.
> -	 */
>  	if (size == 0)
> -		return false;
> +		return true;

Nit: This might deserve a comment why size == 0 is handled
     a special way.specially. I think about something like:

	/*
	 * Empty data blocks are handled by special lpos values in
	 * the record descriptor. No space is needed in the data ring.
	 */

or simply

	/* Data-less records take no space in the data ring. */

>  	/*
>  	 * Ensure the alignment padded size could possibly fit in the data

> @@ -1025,6 +1020,10 @@ static char *data_alloc(struct printk_ringbuffer *rb,
>  static unsigned int space_used(struct prb_data_ring *data_ring,
>  			       struct prb_data_blk_lpos *blk_lpos)
>  {
> +	/* Data-less blocks take no space. */
> +	if (LPOS_DATALESS(blk_lpos->begin))
> +		return 0;

Nit: It seems that all the other locations check also blk_lpos->next,
     for example, get_data() does:

	if (LPOS_DATALESS(blk_lpos->begin) && LPOS_DATALESS(blk_lpos->next)) {


     Both approaches are error prone. I would either simplify the
     other locations and check only lpos->begin. But better might
     be to be on the safe side do a paranoid check, like:

bool is_dataless(struct prb_data_blk_lpos *blk_lpos)
{
	if (LPOS_DATALESS(blk_lpos->begin) || LPOS_DATALESS(blk_lpos->next)) {
		WARN_ON_ONCE(blk_lpos->begin != blk_lpos->next);
		return true;
	}

	return false;
}

> +
>  	if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next)) {
>  		/* Data block does not wrap. */
>  		return (DATA_INDEX(data_ring, blk_lpos->next) -

Anyway, the patch looks fine. It is already pushed in
printk/linux.git. So, if you agree with my nits, we should
solve them with separate patches on top of the existing ones.

Best Regards,
Petr



More information about the kexec mailing list