[igt-dev] [PATCH i-g-t] lib/kmod: reimplement kmsg_dump()

Chris Wilson chris at chris-wilson.co.uk
Fri Sep 27 20:09:50 UTC 2019


Quoting Lucas De Marchi (2019-09-20 02:07:23)
> /dev/kmsg is record-oriented rather than line-oriented. A short read in
> which the record doesn't fit will return -EINVAL and getline() will stop
> working. This is in general not a problem since the (default) stdio
> buffer is bigger than the maximum record size (4096). However let's
> abide by the kernel ABI rather than relying on the libc buffer size.
> 
> While reimplementing, fix the following issues that made me look to the
> implementation in the first place:
> 
> 1) we were skipping 1 char in the message, producing messages like the
>    one below (see the missing i in intel_pch_type):
>         (i915_selftest:3861) igt_kmod-WARNING: ntel_pch_type [i915]] Found Tiger Lake LP PCH
> 
> 2) we were printing the key=val pair of kmsg as if it was part of the
> messsages, and even mangling the result looking for a ':':
>         (i915_selftest:3861) igt_kmod-WARNING: 000:00:02.0
> 
> The ABI for /dev/kmsg stands:
>         Accessing the buffer:
>                 Every read() from the opened device node receives one record
>                 of the kernel's printk buffer.
> 
>                 [ ... ]
> 
>                 Future extensions might add more comma separated values before
>                 the terminating ';'. Unknown fields and values should be
>                 gracefully ignored.
> 
>                 The human readable text string starts directly after the ';'
>                 and is terminated by a '\n'. Untrusted values derived from
>                 hardware or other facilities are printed, therefore
>                 all non-printable characters and '\' itself in the log message
>                 are escaped by "\x00" C-style hex encoding.
> 
>                 A line starting with ' ', is a continuation line, adding
>                 key/value pairs to the log message, which provide the machine
>                 readable context of the message, for reliable processing in
>                 userspace.
> 
> Now the line in (1) print as:
>         (i915_selftest:5070) igt_kmod-WARNING: [drm:intel_pch_type [i915]] Found Tiger Lake LP PCH
> 
> This also fixes a double close on fclose() already closes the file
> descriptor.
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>

Too bad it doesn't actually work and bails on the first read with EPIPE.
-Chris


More information about the igt-dev mailing list