drm_coredump_printer(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ drm_coredump_printer ✨

okay so this is a page from the Kernel API Manual, and today's main character is drm_coredump_printer β€” the little helper that builds you a &drm_printer capable of writing out to a buffer straight from the read function for devcoredump. bestie, it's giving "glue code that slays" πŸ’…


πŸ’– NAME πŸ’–

drm_coredump_printer β€” construct a &drm_printer that can output to a buffer from the read function for devcoredump

πŸŽ€ SYNOPSIS πŸŽ€

struct drm_printer drm_coredump_printer (struct drm_print_iterator *iter
);

πŸ¦‹ ARGUMENTS πŸ¦‹

  • iter β€” a pointer to a struct drm_print_iterator for the read instance. that's the one, that's the whole arg 🫢

🌸 DESCRIPTION 🌸

so this wrapper lowkey extends drm_printf so it plays nice with a dev_coredumpm callback function. the drm_print_iterator struct you pass in is carrying the buffer pointer, the size and the offset, all exactly as they came in from devcoredump. no cap, that's it πŸ’–

for example:

void coredump_read(char *buffer, loff_t offset, size_t count,
        void *data, size_t datalen)
{
        struct drm_print_iterator iter;
        struct drm_printer p;

        iter.data = buffer;
        iter.start = offset;
        iter.remain = count;

        p = drm_coredump_printer(iter);

        drm_printf(p, "foo=d0, foo);
}

void makecoredump(...)
{
        ...
        dev_coredumpm(dev, THIS_MODULE, data, 0, GFP_KERNEL,
                coredump_read, ...)
}

okay so real talk about that example: it has a time complexity of O(N^2), where N is the size of the devcoredump. that's totally fine for small devcoredumps, but ngl it scales poorly for the big ones 😭

another use case for drm_coredump_printer is capturing the devcoredump into a saved buffer before the dev_coredump callback. this is a two-pass situation, bestie: one pass to figure out the size of the devcoredump, and another pass to print it into a buffer. then, in dev_coredump, you copy from the saved buffer into the devcoredump read buffer. iconic, honestly ✨

for example:

char *devcoredump_saved_buffer;

ssize_t __coredump_print(char *buffer, ssize_t count, ...)
{
        struct drm_print_iterator iter;
        struct drm_printer p;

        iter.data = buffer;
        iter.start = 0;
        iter.remain = count;

        p = drm_coredump_printer(iter);

        drm_printf(p, "foo=d0, foo);
        ...
        return count - iter.remain;
}

void coredump_print(...)
{
        ssize_t count;

        count = __coredump_print(NULL, INT_MAX, ...);
        devcoredump_saved_buffer = kvmalloc(count, GFP_KERNEL);
        __coredump_print(devcoredump_saved_buffer, count, ...);
}

void coredump_read(char *buffer, loff_t offset, size_t count,
                   void *data, size_t datalen)
{
        ...
        memcpy(buffer, devcoredump_saved_buffer + offset, count);
        ...
}

and that example has a time complexity of O(N*2), where N is the size of the devcoredump. way better scaling than the previous example for larger devcoredumps β€” we love a glow-up πŸ”₯

πŸ‘‘ RETURN πŸ‘‘

the drm_printer object. that's the whole vibe check result πŸ’…

🌈 SEE ALSO 🌈


and that's the page, bestie πŸŽ€ it came from ./include/drm, dated October 2026, and it's filed under drm_coredump_printer(9) β€” go forth and print your coredumps, mwah πŸ’œ

πŸ“¦ where this page comes from