drm/panic: Add a qr_code panic screen
Subsystems (4)
Jocelyn Falempe
maintainerv2 cover drm/panic: Add a qr_code panic screen
This series adds a new panic screen, with the kmsg data embedded in a QR-code.
The main advantage of QR-code, is that you can copy/paste the debug data to a bug report.
The QR-code encoder is written in rust, and is very specific to drm_panic.
The reason is that it is called in a panic handler, and thus can't allocate memory, or use locking. The rust code uses a few rust core API, and provides only two C entry points.
There is no particular reason to do it in rust, I just wanted to learn rust, and see if it can work in the kernel.
If you want to see what it looks like, I've put a few screenshots here:
https://github.com/kdj0c/panic_report/issues/1
v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Mark drm_panic_qr_generate() as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call to as_str_unchecked() (Alice Ryhl)
* Add a check for data_len <= data_size (Greg KH)
Jocelyn Falempe (4):
drm/panic: Add integer scaling to blit()
drm/rect: add drm_rect_overlap()
drm/panic: simplify logo handling
drm/panic: Add a qr_code panic screen
drivers/gpu/drm/Kconfig | 29 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 338 +++++++++-- drivers/gpu/drm/drm_panic_qr.rs | 1004 +++++++++++++++++++++++++++++++ include/drm/drm_panic.h | 4 + include/drm/drm_rect.h | 15 + 7 files changed, 1355 insertions(+), 39 deletions(-) create mode 100644 drivers/gpu/drm/drm_panic_qr.rs
base-commit: 5a716b06b329bd2108c95a4f04c71bbe491729f2
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 1/4 drm/panic: Add integer scaling to blit()
Add a parameter to the blit function, to upscale the image. This is necessary to draw QR-code, otherwise, the pixels are usually too small to be readable by most QR-code reader.
It can also be used later for drawing fonts on high-DPI display.
--- drivers/gpu/drm/drm_panic.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_panic.c +19 -14
@@ -249,20 +249,20 @@ static bool drm_panic_is_pixel_fg(const u8 *sbuf8, unsigned int spitch, int x, istatic void drm_panic_blit16 (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u16 fg16) +unsigned int scale,u16 fg16) {unsigned int y, x;for (y =0 ; y < height; y++)for (x =0 ; x < width; x++) -if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) +if (drm_panic_is_pixel_fg (sbuf8, spitch, x / scale, y / scale))iosys_map_wr (dmap, y * dpitch + x *sizeof (u16), u16, fg16); }static void drm_panic_blit24 (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u32 fg32) +unsigned int scale,u32 fg32) {unsigned int y, x;
@@ -270,7 +270,7 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,for (x =0 ; x < width; x++) {u32 off = y * dpitch + x *3 ; -if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) { +if (drm_panic_is_pixel_fg (sbuf8, spitch, x / scale, y / scale)) {/* write blue-green-red to output in little endianness */ iosys_map_wr (dmap, off, u8, (fg32 &0x000000FF ) >>0 );iosys_map_wr (dmap, off +1 , u8, (fg32 &0x0000FF00 ) >>8 );
@@ -283,24 +283,25 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,static void drm_panic_blit32 (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u32 fg32) +unsigned int scale,u32 fg32) {unsigned int y, x;for (y =0 ; y < height; y++)for (x =0 ; x < width; x++) -if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) +if (drm_panic_is_pixel_fg (sbuf8, spitch, x / scale, y / scale))iosys_map_wr (dmap, y * dpitch + x *sizeof (u32), u32, fg32); }static void drm_panic_blit_pixel (struct drm_scanout_buffer *sb,struct drm_rect *clip, -const u8 *sbuf8,unsigned int spitch,u32 fg_color) +const u8 *sbuf8,unsigned int spitch,unsigned int scale, +u32 fg_color) {unsigned int y, x;for (y =0 ; y <drm_rect_height (clip); y++)for (x =0 ; x <drm_rect_width (clip); x++) -if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) +if (drm_panic_is_pixel_fg (sbuf8, spitch, x / scale, y / scale)) sb->set_pixel (sb, clip->x1 + x, clip->y1 + y, fg_color); }
@@ -310,18 +311,22 @@ static void drm_panic_blit_pixel(struct drm_scanout_buffer *sb, struct drm_rect* @clip: destination rectangle * @sbuf8: source buffer, in monochrome format, 8 pixels per byte. * @spitch: source pitch in bytes +* @scale: integer scale, source buffer is scale time smaller than destination +* rectangle * @fg_color: foreground color, in destination format * * This can be used to draw a font character, which is a monochrome image, to a * framebuffer in other supported format. */ static void drm_panic_blit (struct drm_scanout_buffer *sb,struct drm_rect *clip, -const u8 *sbuf8,unsigned int spitch,u32 fg_color) +const u8 *sbuf8,unsigned int spitch, +unsigned int scale,u32 fg_color) + {struct iosys_map map;if (sb->set_pixel) -return drm_panic_blit_pixel (sb, clip, sbuf8, spitch, fg_color); +return drm_panic_blit_pixel (sb, clip, sbuf8, spitch, scale, fg_color); map = sb->map[0 ];iosys_map_incr (&map, clip->y1 * sb->pitch[0 ] + clip->x1 * sb->format->cpp[0 ]);
@@ -329,15 +334,15 @@ static void drm_panic_blit(struct drm_scanout_buffer *sb, struct drm_rect *clip,switch (sb->format->cpp[0 ]) {case 2 :drm_panic_blit16 (&map, sb->pitch[0 ], sbuf8, spitch, -drm_rect_height (clip),drm_rect_width (clip), fg_color); +drm_rect_height (clip),drm_rect_width (clip), scale, fg_color);break ;case 3 :drm_panic_blit24 (&map, sb->pitch[0 ], sbuf8, spitch, -drm_rect_height (clip),drm_rect_width (clip), fg_color); +drm_rect_height (clip),drm_rect_width (clip), scale, fg_color);break ;case 4 :drm_panic_blit32 (&map, sb->pitch[0 ], sbuf8, spitch, -drm_rect_height (clip),drm_rect_width (clip), fg_color); +drm_rect_height (clip),drm_rect_width (clip), scale, fg_color);break ;default :WARN_ONCE (1 ,"Can't blit with pixel width %d\n" , sb->format->cpp[0 ]);
@@ -477,7 +482,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,for (j =0 ; j < line_len; j++) { src =get_char_bitmap (font, msg[i].txt[j], font_pitch); rec.x2 = rec.x1 + font->width; -drm_panic_blit (sb, &rec, src, font_pitch, color); +drm_panic_blit (sb, &rec, src, font_pitch,1 , color); rec.x1 += font->width; } }
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 2/4 drm/rect: add drm_rect_overlap()
In reply to Jocelyn FalempeCheck if two rectangles overlap.
It's a bit similar to drm_rect_intersect() but this won't modify the rectangle.
Simplifies a bit drm_panic.
--- drivers/gpu/drm/drm_panic.c | 3 +-- include/drm/drm_rect.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic.c +1 -2
@@ -522,8 +522,7 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)/* Fill with the background color, and draw text on top */ drm_panic_fill (sb, &r_screen, bg_color); -if ((r_msg.x1 >= logo_width || r_msg.y1 >= logo_height) && - logo_width <= sb->width && logo_height <= sb->height) { +if (!drm_rect_overlap (&r_logo, &r_msg)) {if (logo_mono)drm_panic_blit (sb, &r_logo, logo_mono->data,DIV_ROUND_UP (logo_width,8 ), fg_color);
include/drm/drm_rect.h +15 -0
@@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct drm_rect *dst, drm_rect_height(src) >> 16); } +/** +* drm_rect_overlap - Check if two rectangles overlap +* @r1: first rectangle +* @r2: second rectangle +* +* RETURNS: +* %true if the rectangles overlap, %false otherwise. +*/ +static inline bool drm_rect_overlap (const struct drm_rect *r1, +const struct drm_rect *r2) +{ +return (r1->x2 > r2->x1 && r2->x2 > r1->x1 && + r1->y2 > r2->y1 && r2->y2 > r1->y1); +} +bool drm_rect_intersect (struct drm_rect *r,const struct drm_rect *clip);bool drm_rect_clip_scaled (struct drm_rect *src,struct drm_rect *dst,const struct drm_rect *clip);
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 3/4 drm/panic: simplify logo handling
In reply to Jocelyn FalempeMove logo rectangle initialisation, and logo drawing in separate functions, so they can be re-used by different panic screens. It prepares the introduction of the QR-code panic screen.
--- drivers/gpu/drm/drm_panic.c | 57 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_panic.c +33 -24
@@ -80,6 +80,7 @@ static struct drm_panic_line panic_msg[] = {PANIC_LINE ("" ), PANIC_LINE("Please reboot your computer."), }; +static const int panic_msg_lines =ARRAY_SIZE (panic_msg);static const struct drm_panic_line logo_ascii[] = { PANIC_LINE(" .--. _"),
@@ -90,6 +91,7 @@ static const struct drm_panic_line logo_ascii[] = {PANIC_LINE (" /'\\_ _/`\\ (_)" ), PANIC_LINE(" \\___)=(___/"), }; +static const int logo_ascii_lines =ARRAY_SIZE (logo_ascii);#if defined(CONFIG_LOGO ) && !defined(MODULE )static const struct linux_logo *logo_mono;
@@ -488,33 +490,45 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb, } } +static void drm_panic_logo_rect (struct drm_rect *rect,const struct font_desc *font) +{ +if (logo_mono) +drm_rect_init (rect,0 ,0 , logo_mono->width, logo_mono->height); +else { +int logo_width =get_max_line_len (logo_ascii, logo_ascii_lines) * font->width; + +drm_rect_init (rect,0 ,0 , logo_width, logo_ascii_lines * font->height); + } +} + +static void drm_panic_logo_draw (struct drm_scanout_buffer *sb,struct drm_rect *rect, +const struct font_desc *font,u32 fg_color) +{ +if (logo_mono) +drm_panic_blit (sb, rect, logo_mono->data, +DIV_ROUND_UP (drm_rect_width (rect),8 ),1 , fg_color); +else +draw_txt_rectangle (sb, font, logo_ascii, logo_ascii_lines, false, rect, + fg_color); +} +static void draw_panic_static_user (struct drm_scanout_buffer *sb) { -size_t msg_lines =ARRAY_SIZE (panic_msg); -size_t logo_ascii_lines =ARRAY_SIZE (logo_ascii);u32 fg_color =convert_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);u32 bg_color =convert_from_xrgb8888 (CONFIG_DRM_PANIC_BACKGROUND_COLOR , sb->format->format);const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg; -unsigned int logo_width, logo_height; +unsigned int panic_msg_width;if (!font)return ; r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height); - -if (logo_mono) { - logo_width = logo_mono->width; - logo_height = logo_mono->height; - }else { - logo_width =get_max_line_len (logo_ascii, logo_ascii_lines) * font->width; - logo_height = logo_ascii_lines * font->height; - } - - r_logo =DRM_RECT_INIT (0 ,0 , logo_width, logo_height); +drm_panic_logo_rect (&r_logo, font); + panic_msg_width =get_max_line_len (panic_msg, panic_msg_lines) * font->width; r_msg =DRM_RECT_INIT (0 ,0 , -min (get_max_line_len (panic_msg, msg_lines) * font->width, sb->width), -min (msg_lines * font->height, sb->height)); +min (panic_msg_width, sb->width), +min (panic_msg_lines * font->height, sb->height));/* Center the panic message */ drm_rect_translate (&r_msg, (sb->width - r_msg.x2) /2 , (sb->height - r_msg.y2) /2 );
@@ -522,15 +536,10 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)/* Fill with the background color, and draw text on top */ drm_panic_fill (sb, &r_screen, bg_color); -if (!drm_rect_overlap (&r_logo, &r_msg)) { -if (logo_mono) -drm_panic_blit (sb, &r_logo, logo_mono->data,DIV_ROUND_UP (logo_width,8 ), - fg_color); -else -draw_txt_rectangle (sb, font, logo_ascii, logo_ascii_lines, false, &r_logo, - fg_color); - } -draw_txt_rectangle (sb, font, panic_msg, msg_lines, true, &r_msg, fg_color); +if (!drm_rect_overlap (&r_logo, &r_msg)) +drm_panic_logo_draw (sb, &r_logo, font, fg_color); + +draw_txt_rectangle (sb, font, panic_msg, panic_msg_lines, true, &r_msg, fg_color); }/*
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 4/4 drm/panic: Add a qr_code panic screen
In reply to Jocelyn FalempeThis patch adds a new panic screen, with a QR code and the kmsg data embedded.
If DRM_PANIC_SCREEN_QR_CODE_URL is set, then the kmsg data will be compressed with zlib and encoded as a numerical segment, and appended to the url as a url parameter. This allows to save space, and put about ~7500 bytes of kmsg data, in a V40 QR code.
Linux distributions can customize the url, and put a web frontend to directly open a bug report with the kmsg data.
Otherwise the kmsg data will be encoded as binary segment (ie raw ascii) and only a maximum of 2953 bytes of kmsg data will be available in the QR code.
You can also limit the QR code size with DRM_PANIC_SCREEN_QR_VERSION.
v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Mark drm_panic_qr_generate() as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call to as_str_unchecked() (Alice Ryhl)
* Add a check for data_len <= data_size (Greg KH)
--- drivers/gpu/drm/Kconfig | 29 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 247 ++++++++ drivers/gpu/drm/drm_panic_qr.rs | 1004 +++++++++++++++++++++++++++++++ include/drm/drm_panic.h | 4 + 6 files changed, 1288 insertions(+) create mode 100644 drivers/gpu/drm/drm_panic_qr.rs
drivers/gpu/drm/Kconfig +29 -0
@@ -149,6 +149,35 @@ config DRM_PANIC_SCREEN or by writing to /sys/module/drm/parameters/panic_screen sysfs entry Default is "user" +config DRM_PANIC_SCREEN_QR_CODE + bool "Add a panic screen with a QR code" + depends on DRM_PANIC && RUST + help + This option adds a qr code generator, and a panic screen with a QR + code. The QR code will contain the last lines of kmsg and other debug + information. This should be easier for the user to report a kernel + panic, with all debug information available. + To use this panic screen, also set DRM_PANIC_SCREEN to "qr_code" + +config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base url of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base url to report the kernel panic. If it's set + the qr code will contain the url and the kmsg compressed with zlib as + url parameter. If it's empty, the qr code will contain the kmsg as + uncompressed text only. + +config DRM_PANIC_SCREEN_QR_VERSION + int "Maximum version (size) of the QR code." + depends on DRM_PANIC_SCREEN_QR_CODE + default 40 + help + This option limits the version (or size) of the QR code. QR code + version range from Version 1 (21x21) to Version 40 (177x177). + Smaller QR code are easier to read, but will contain less debugging + data. Default is 40. + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT
drivers/gpu/drm/Makefile +1 -0
@@ -89,6 +89,7 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ drm_privacy_screen_x86.o drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o drm-$(CONFIG_DRM_PANIC) += drm_panic.o +drm-$(CONFIG_DRM_PANIC_SCREEN_QR_CODE) += drm_panic_qr.o obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
drivers/gpu/drm/drm_drv.c +3 -0
@@ -1067,6 +1067,7 @@ static const struct file_operations drm_stub_fops = {static void drm_core_exit (void ) {drm_privacy_screen_lookup_exit (); +drm_panic_exit ();accel_core_exit ();unregister_chrdev (DRM_MAJOR ,"drm" );debugfs_remove (drm_debugfs_root);
@@ -1099,6 +1100,8 @@ static int __init drm_core_init(void)if (ret <0 ) goto error; +drm_panic_init (); +drm_privacy_screen_lookup_init (); drm_core_init_complete = true;
drivers/gpu/drm/drm_panic.c +247 -0
274 lines not on this page · raw message
drivers/gpu/drm/drm_panic_qr.rs new file +1004 -0
1,004 lines not on this page · raw message
include/drm/drm_panic.h +4 -0
@@ -150,11 +150,15 @@ struct drm_scanout_buffer {void drm_panic_register (struct drm_device *dev);void drm_panic_unregister (struct drm_device *dev); +void drm_panic_init (void ); +void drm_panic_exit (void );#else static inline void drm_panic_register (struct drm_device *dev) {}static inline void drm_panic_unregister (struct drm_device *dev) {} +static inline void drm_panic_init (void ) {} +static inline void drm_panic_exit (void ) {}#endif
Signature · 1 line
2.45.2
drivers/gpu/drm/Kconfig config DRM_PANIC_SCREEN · line 169
Quoted 8 lines · Jocelyn Falempe
drivers/gpu/drm/Kconfig +8
-0+config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base url of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base url to report the kernel panic. If it's set + the qr code will contain the url and the kmsg compressed with zlib as + url parameter. If it's empty, the qr code will contain the kmsg as + uncompressed text only.
meta-comment, should we by default do this on a kernel.org domain so that no specific distro has to worry about hosing this type of web service?
thanks,
greg k-h
Quoted 13 lines · Greg KH
drivers/gpu/drm/Kconfig config DRM_PANIC_SCREEN · line 169
Quoted 8 lines · Jocelyn Falempe
drivers/gpu/drm/Kconfig +8
-0+config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base url of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base url to report the kernel panic. If it's set + the qr code will contain the url and the kmsg compressed with zlib as + url parameter. If it's empty, the qr code will contain the kmsg as + uncompressed text only.meta-comment, should we by default do this on a kernel.org domain so that no specific distro has to worry about hosing this type of web service?
Also, do you have the backend source for this to show how anyone can host it themselves as well? We can't add features to the kernel that no one but closed-source implementations will use for obvious reasons.
thanks,
greg k-h
Jocelyn Falempe
maintainerQuoted 15 lines · Greg KH
Quoted 13 lines · Greg KH
drivers/gpu/drm/Kconfig config DRM_PANIC_SCREEN · line 169
Quoted 8 lines · Jocelyn Falempe
drivers/gpu/drm/Kconfig +8
-0+config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base url of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base url to report the kernel panic. If it's set + the qr code will contain the url and the kmsg compressed with zlib as + url parameter. If it's empty, the qr code will contain the kmsg as + uncompressed text only.meta-comment, should we by default do this on a kernel.org domain so that no specific distro has to worry about hosing this type of web service?
Quoted 3 lines
Also, do you have the backend source for this to show how anyone can host it themselves as well? We can't add features to the kernel that no one but closed-source implementations will use for obvious reasons.
I've made a proof of concept backend here:
https://github.com/kdj0c/panic_report/
And the javascript to decode the kmsg trace is here (under MIT licence):
https://github.com/kdj0c/panic_report/blob/main/docs/panic_report.js
It uses the pako js library to uncompress the zlib data, which is also under MIT/Zlib licence https://github.com/nodeca/pako/
If kernel.org want to host a default service for that, that would be great. It can be linked with https://bugzilla.kernel.org to easily create a bug, or look for similar bugs.
Best regards,
Signature · 1 line
Jocelyn
Quoted 5 lines
thanks,
greg k-h
Quoted 22 lines · Jocelyn Falempe
Quoted 15 lines · Greg KH
Quoted 13 lines · Greg KH
drivers/gpu/drm/Kconfig config DRM_PANIC_SCREEN · line 169
Quoted 8 lines · Jocelyn Falempe
drivers/gpu/drm/Kconfig +8
-0+config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base url of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base url to report the kernel panic. If it's set + the qr code will contain the url and the kmsg compressed with zlib as + url parameter. If it's empty, the qr code will contain the kmsg as + uncompressed text only.meta-comment, should we by default do this on a kernel.org domain so that no specific distro has to worry about hosing this type of web service?
Quoted 3 lines
Also, do you have the backend source for this to show how anyone can host it themselves as well? We can't add features to the kernel that no one but closed-source implementations will use for obvious reasons.
Quoted 5 lines
I've made a proof of concept backend here:
https://github.com/kdj0c/panic_report/And the javascript to decode the kmsg trace is here (under MIT licence):
https://github.com/kdj0c/panic_report/blob/main/docs/panic_report.js
SPDX lines are your friend, you might want to look into that for this stuff :)
Quoted 2 lines
It uses the pako js library to uncompress the zlib data, which is also under MIT/Zlib licence https://github.com/nodeca/pako/
Great, can you put that in the Kconfig help area for this option in your next version?
Quoted 3 lines
If kernel.org want to host a default service for that, that would be great. It can be linked with https://bugzilla.kernel.org to easily create a bug, or look for similar bugs.
Someone should at least propose it if this is going to be an option that the kernel supports.
thanks,
greg k-h
Jocelyn Falempe
maintainerQuoted 23 lines · Greg KH
Quoted 22 lines · Jocelyn Falempe
Quoted 18 lines · Greg KH
Quoted 13 lines · Greg KH
drivers/gpu/drm/Kconfig config DRM_PANIC_SCREEN · line 169
Quoted 8 lines · Jocelyn Falempe
drivers/gpu/drm/Kconfig +8
-0+config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base url of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base url to report the kernel panic. If it's set + the qr code will contain the url and the kmsg compressed with zlib as + url parameter. If it's empty, the qr code will contain the kmsg as + uncompressed text only.meta-comment, should we by default do this on a kernel.org domain so that no specific distro has to worry about hosing this type of web service?
Also, do you have the backend source for this to show how anyone can host it themselves as well? We can't add features to the kernel that no one but closed-source implementations will use for obvious reasons.
Quoted 8 lines
Quoted 5 lines
I've made a proof of concept backend here:
https://github.com/kdj0c/panic_report/And the javascript to decode the kmsg trace is here (under MIT licence):
https://github.com/kdj0c/panic_report/blob/main/docs/panic_report.jsSPDX lines are your friend, you might want to look into that for this stuff :)
Sure, I've added the SPDX header for this file.
Quoted 6 lines
Quoted 3 lines
It uses the pako js library to uncompress the zlib data, which is also under MIT/Zlib licence https://github.com/nodeca/pako/
Great, can you put that in the
Kconfighelp area for this option in your next version?
Yes, I will add a link to the panic_report github project.
Quoted 7 lines
Quoted 4 lines
If kernel.org want to host a default service for that, that would be great. It can be linked with https://bugzilla.kernel.org to easily create a bug, or look for similar bugs.
Someone should at least propose it if this is going to be an option that the kernel supports.
I hope someone will volunteer to do that, as I'm not really into web development. Also it's a bit early, drm panic is quite new, and needs more driver support to be really useful.
Quoted 4 lines
thanks,
greg k-h
Signature · 1 line
Jocelyn
Hi Jocelyn,
A quick docs-only review of the Rust side (some of these apply in several cases -- I just wanted to give an overview for you to consider).
drivers/gpu/drm/drm_panic_qr.rs line 5
Quoted 4 lines · Jocelyn Falempe
drivers/gpu/drm/drm_panic_qr.rs new file +3
-0+//! This is a simple qr encoder for DRM panic. +//! +//! Due to the Panic constraint, it doesn't allocate memory and does all
Perhaps clarify "Panic constraint" here?
drivers/gpu/drm/drm_panic_qr.rs line 7
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+//! the work on the stack or on the provided buffers. For +//! simplification, it only supports Low error correction, and apply the
"applies"?
Quoted 1 line
+//! first mask (checkboard). It will draw the smallest QRcode that can
"QR code"? "QR-code"?
In other places "QR-code" is used -- it would be ideal to be consistent. (Although, isn't the common spelling "QR code"?)
drivers/gpu/drm/drm_panic_qr.rs line 10
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+//! contain the string passed as parameter. To get the most compact +//! QR-code, the start of the url is encoded as binary, and the
Probably "URL".
drivers/gpu/drm/drm_panic_qr.rs line 14
Quoted 4 lines
drivers/gpu/drm/drm_panic_qr.rs new file +4
-0+//! compressed kmsg is encoded as numeric. +//! +//! The binary data must be a valid url parameter, so the easiest way is +//! to use base64 encoding. But this waste 25% of data space, so the
"wastes"
drivers/gpu/drm/drm_panic_qr.rs line 16
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+//! whole stack trace won't fit in the QR-Code. So instead it encodes +//! every 13bits of input into 4 decimal digits, and then use the
"uses"
drivers/gpu/drm/drm_panic_qr.rs line 20
Quoted 4 lines
drivers/gpu/drm/drm_panic_qr.rs new file +4
-0+//! efficient numeric encoding, that encode 3 decimal digits into +//! 10bits. This makes 39bits of compressed data into 12 decimal digits, +//! into 40bits in the QR-Code, so wasting only 2.5%. And numbers are +//! valid url parameter, so the website can do the reverse, to get the
"And the numbers are valid URL parameters"?
Quoted 1 line
+//! Inspired by this 3 projects, all under MIT license:
"these"
Quoted 1 line
+// Generator polynomials for QR Code, only those that are needed for Low quality
If possible, please remember to use periods at the end for both comments and docs. It is very pedantic, but if possible we would like to try to be consistent across subsystems on how the documentation looks etc. If everything looks the same, it is also easy to remember/check how to do it for new files and so on.
drivers/gpu/drm/drm_panic_qr.rs line 75
Quoted 6 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// QRCode parameter for Low quality ECC: +/// - Error Correction polynomial +/// - Number of blocks in group 1 +/// - Number of blocks in group 2 +/// - Block size in group 1 +/// (Block size in group 2 is one more than group 1)
We typically leave a newline after a list.
drivers/gpu/drm/drm_panic_qr.rs line 212
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+// Return the smallest QR Version than can hold these segments +fn from_segments (segments: &[&Segment <'_>]) ->Option <Version > {
Should be docs, even if private? i.e. ///?
Also third person and period.
drivers/gpu/drm/drm_panic_qr.rs line 301
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+// padding bytes +const PADDING : [u8 ;2 ] = [236 ,17 ];
///?
Quoted 1 line
+/// get the next 13 bits of data, starting at specified offset (in bits)
Please capitalize.
Quoted 1 line
+ // b is 20 at max (
bit_off<= 7 and size <= 13)
Please use Markdown for comments too.
drivers/gpu/drm/drm_panic_qr.rs line 481
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+/// EncodedMsg will hold the data to be put in the QR-Code, with correct segment +/// encoding, padding, and Error Code Correction.
Missing newline? In addition, for the title (i.e. first paragraph), we try to keep it short/simple, e.g. you could perhaps say something like:
/// Data to be put in the QR code (with correct segment encoding,
padding, and error code correction).
drivers/gpu/drm/drm_panic_qr.rs line 656
Quoted 3 lines
drivers/gpu/drm/drm_panic_qr.rs new file +3
-0+/// QrImage +/// +/// A QR-Code image, encoded as a linear binary framebuffer.
Please remove the title -- the second paragraph should be the title.
Quoted 1 line
+/// Max width is 177 for V40 QR code, so u8 is enough for coordinate.
u8
Quoted 1 line
+///
drm_panic_qr_generate()
You can remove this title.
drivers/gpu/drm/drm_panic_qr.rs line 916
Quoted 6 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// C entry point for the rust QR Code generator. +/// +/// Write the QR code image in the data buffer, and return the qrcode size, or 0 +/// if the data doesn't fit in a QR code. +/// +/// * `url` The base url of the QR code. It will be encoded as Binary segment.
Typically we would write a colon. after the key, e.g.
/// * `url`: the base URL of the QR code.
drivers/gpu/drm/drm_panic_qr.rs line 933
Quoted 6 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// # Safety +/// +/// * `url` must be null or point at a nul-terminated string. +/// * `data` must be valid for reading and writing for `data_size` bytes. +/// * `data_len` must be less than `data_size`. +/// * `tmp` must be valid for reading and writing for `tmp_size` bytes.
It would be nice to mention for which duration these need to hold, e.g. the call or something else.
Quoted 1 line
+ // Safety: url must be a valid pointer to a nul-terminated string.
Please use the // SAFETY: prefix instead, since it is how we tag these (i.e. differently from from the # Safety section).
Quoted 1 line
+/// *
versionQR code version, between 1-40.
If something like this happens to be used in several places, you may want to consider using transparent newtypes for them. This would allow you to avoid having to document each use point and it would enrich the signatures.
Thanks!
Cheers,
Miguel
Jocelyn Falempe
maintainerQuoted 5 lines · Miguel Ojeda
Hi Jocelyn,
A quick docs-only review of the Rust side (some of these apply in several cases -- I just wanted to give an overview for you to consider).
Thanks, I'll fix all typo/grammar you mentioned.
Quoted 14 lines · Jocelyn Falempe
drivers/gpu/drm/drm_panic_qr.rs line 5
Quoted 4 lines
drivers/gpu/drm/drm_panic_qr.rs new file +3
-0+//! This is a simple qr encoder for DRM panic. +//! +//! Due to the Panic constraint, it doesn't allocate memory and does all Perhaps clarify "Panic constraint" here?
drivers/gpu/drm/drm_panic_qr.rs line 7
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+//! the work on the stack or on the provided buffers. For +//! simplification, it only supports Low error correction, and apply the "applies"?
Quoted 6 lines
Quoted 1 line
+//! first mask (checkboard). It will draw the smallest QRcode that can
"QR code"? "QR-code"?
In other places "QR-code" is used -- it would be ideal to be consistent. (Although, isn't the common spelling "QR code"?)
Agreed, I will replace all with "QR code".
Quoted 5 lines
drivers/gpu/drm/drm_panic_qr.rs line 10
Quoted 3 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+//! contain the string passed as parameter. To get the most compact +//! QR-code, the start of the url is encoded as binary, and the Probably "URL".
Yes, I will run s/url/URL in the comments.
Quoted 24 lines
drivers/gpu/drm/drm_panic_qr.rs line 14
Quoted 5 lines
drivers/gpu/drm/drm_panic_qr.rs new file +4
-0+//! compressed kmsg is encoded as numeric. +//! +//! The binary data must be a valid url parameter, so the easiest way is +//! to use base64 encoding. But this waste 25% of data space, so the "wastes"
drivers/gpu/drm/drm_panic_qr.rs line 16
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+//! whole stack trace won't fit in the QR-Code. So instead it encodes +//! every 13bits of input into 4 decimal digits, and then use the "uses"
drivers/gpu/drm/drm_panic_qr.rs line 20
Quoted 4 lines
drivers/gpu/drm/drm_panic_qr.rs new file +4
-0+//! efficient numeric encoding, that encode 3 decimal digits into +//! 10bits. This makes 39bits of compressed data into 12 decimal digits, +//! into 40bits in the QR-Code, so wasting only 2.5%. And numbers are +//! valid url parameter, so the website can do the reverse, to get the "And the numbers are valid URL parameters"?
Quoted 1 line
+//! Inspired by this 3 projects, all under MIT license:
"these"
Quoted 7 lines
Quoted 1 line
+// Generator polynomials for QR Code, only those that are needed for Low quality
If possible, please remember to use periods at the end for both comments and docs. It is very pedantic, but if possible we would like to try to be consistent across subsystems on how the documentation looks etc. If everything looks the same, it is also easy to remember/check how to do it for new files and so on.
Sure, I will check this again.
Quoted 65 lines
drivers/gpu/drm/drm_panic_qr.rs line 75
Quoted 7 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// QRCode parameter for Low quality ECC: +/// - Error Correction polynomial +/// - Number of blocks in group 1 +/// - Number of blocks in group 2 +/// - Block size in group 1 +/// (Block size in group 2 is one more than group 1) We typically leave a newline after a list.
drivers/gpu/drm/drm_panic_qr.rs line 212
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+// Return the smallest QR Version than can hold these segments +fn from_segments (segments: &[&Segment <'_>]) ->Option <Version > {Should be docs, even if private? i.e.
///?Also third person and period.
drivers/gpu/drm/drm_panic_qr.rs line 301
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+// padding bytes +const PADDING : [u8 ;2 ] = [236 ,17 ];
///?Quoted 1 line
+/// get the next 13 bits of data, starting at specified offset (in bits)
Please capitalize.
Quoted 1 line
+ // b is 20 at max (
bit_off<= 7 and size <= 13)Please use Markdown for comments too.
drivers/gpu/drm/drm_panic_qr.rs line 481
Quoted 2 lines
drivers/gpu/drm/drm_panic_qr.rs new file +2
-0+/// EncodedMsg will hold the data to be put in the QR-Code, with correct segment +/// encoding, padding, and Error Code Correction. Missing newline? In addition, for the title (i.e. first paragraph), we try to keep it short/simple, e.g. you could perhaps say something like:
/// Data to be put in the QR code (with correct segment encoding,padding, and error code correction).
drivers/gpu/drm/drm_panic_qr.rs line 656
Quoted 3 lines
drivers/gpu/drm/drm_panic_qr.rs new file +3
-0+/// QrImage +/// +/// A QR-Code image, encoded as a linear binary framebuffer. Please remove the title -- the second paragraph should be the title.
Quoted 1 line
+/// Max width is 177 for V40 QR code, so u8 is enough for coordinate.
u8Quoted 1 line
+///
drm_panic_qr_generate()You can remove this title.
drivers/gpu/drm/drm_panic_qr.rs line 916
Quoted 6 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// C entry point for the rust QR Code generator. +/// +/// Write the QR code image in the data buffer, and return the qrcode size, or 0 +/// if the data doesn't fit in a QR code. +/// +/// * `url` The base url of the QR code. It will be encoded as Binary segment. Typically we would write a colon. after the key, e.g.
/// * `url`: the base URL of the QR code.
Quoted 9 lines
drivers/gpu/drm/drm_panic_qr.rs line 933
Quoted 6 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// # Safety +/// +/// * `url` must be null or point at a nul-terminated string. +/// * `data` must be valid for reading and writing for `data_size` bytes. +/// * `data_len` must be less than `data_size`. +/// * `tmp` must be valid for reading and writing for `tmp_size` bytes. It would be nice to mention for which duration these need to hold, e.g. the call or something else.
Yes, it's until the function returns, I will add this precision.
Quoted 6 lines
Quoted 2 lines
+ // Safety: url must be a valid pointer to a nul-terminated string.
Please use the
// SAFETY:prefix instead, since it is how we tag these (i.e. differently from from the# Safetysection).
Quoted 7 lines
Quoted 1 line
+/// *
versionQR code version, between 1-40.If something like this happens to be used in several places, you may want to consider using transparent newtypes for them. This would allow you to avoid having to document each use point and it would enrich the signatures.
I used to list all QR versions in an enum, but I find it a bit too much boilerplate to ensure the version is between 1 and 40. By transparent newtypes, you mean adding "#[repr(transparent)]" to a struct ?
I don't plan to add more "version" usage, so probably not worth it.
Quoted 5 lines
Thanks!
Cheers,
Miguel
Best regards,
Signature · 1 line
Jocelyn
Quoted 6 lines · Jocelyn Falempe
I used to list all QR versions in an enum, but I find it a bit too much boilerplate to ensure the version is between 1 and 40.
By transparent newtypes, you mean adding "#[repr(transparent)]" to a struct ?
I don't plan to add more "version" usage, so probably not worth it.
Yeah, that is what I meant. It may not be worth it in that case -- it is just something we should generally consider when we see "raw" types appear in parameters that need extra documentation/preconditions, but sometimes it simply does not make sense.
Thanks!
Cheers,
Miguel
Alice Ryhl
reviewerQuoted 24 lines · Jocelyn Falempe
This patch adds a new panic screen, with a QR code and the kmsg data embedded.
IfDRM_PANIC_SCREEN_QR_CODE_URLis set, then the kmsg data will be compressed with zlib and encoded as a numerical segment, and appended to the url as a url parameter. This allows to save space, and put about ~7500 bytes of kmsg data, in a V40 QR code.
Linux distributions can customize the url, and put a web frontend to directly open a bug report with the kmsg data.Otherwise the kmsg data will be encoded as binary segment (ie raw ascii) and only a maximum of 2953 bytes of kmsg data will be available in the QR code.
You can also limit the QR code size with
DRM_PANIC_SCREEN_QR_VERSION.v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Markdrm_panic_qr_generate()as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call toas_str_unchecked()(Alice Ryhl)
* Add a check fordata_len<=data_size(Greg KH)Signed-off-by Jocelyn Falempe <[email protected]>
[...]
Quoted 15 lines
drivers/gpu/drm/drm_panic_qr.rs new file +15
-0+/// drm_panic_qr_generate() +/// +/// C entry point for the rust QR Code generator. +/// +/// Write the QR code image in the data buffer, and return the qrcode size, or 0 +/// if the data doesn't fit in a QR code. +/// +/// * `url` The base url of the QR code. It will be encoded as Binary segment. +/// * `data` A pointer to the binary data, to be encoded. if url is NULL, it +/// will be encoded as binary segment, otherwise it will be encoded +/// efficiently as a numeric segment, and appended to the url. +/// * `data_len` Length of the data, that needs to be encoded. +/// * `data_size` Size of data buffer, it should be at least 4071 bytes to hold +/// a V40 QR-code. It will then be overwritten with the QR-code image. +/// * `tmp` A temporary buffer that the QR-code encoder will use, to write the
drivers/gpu/drm/drm_panic_qr.rs line 933
Quoted 10 lines
drivers/gpu/drm/drm_panic_qr.rs new file +10
-0+/// segments and ECC. +/// * `tmp_size` Size of the temporary buffer, it must be at least 3706 bytes +/// long for V40. +/// +/// # Safety +/// +/// * `url` must be null or point at a nul-terminated string. +/// * `data` must be valid for reading and writing for `data_size` bytes. +/// * `data_len` must be less than `data_size`. +/// * `tmp` must be valid for reading and writing for `tmp_size` bytes.
You don't allow data_len == data_size?
drivers/gpu/drm/drm_panic_qr.rs line 946
Quoted 12 lines
drivers/gpu/drm/drm_panic_qr.rs new file +12
-0+#[no_mangle] +pub unsafe extern "C" fn drm_panic_qr_generate ( + url: *const i8 , + data: *mut u8 , + data_len:usize , + data_size:usize , + tmp: *mut u8 , + tmp_size:usize , +) ->u8 { +if data_size <=4071 || tmp_size <=3706 || data_len > data_size { +return 0 ; + }
Since you explicitly check the data_len, it does not *need* to be a safety requirement (but it can be). Even if it's wrong, violating the requirement does not lead to memory safety.
drivers/gpu/drm/drm_panic_qr.rs line 950
Quoted 4 lines
drivers/gpu/drm/drm_panic_qr.rs new file +4
-0+// Safety: data must be a valid pointer for reading and writing data_size bytes. +let data_slice: &mut [u8 ] =unsafe { core::slice::from_raw_parts_mut (data, data_size) }; +// Safety: tmp must be a valid pointer for reading and writing tmp_size bytes. +let tmp_slice: &mut [u8 ] =unsafe { core::slice::from_raw_parts_mut (tmp, tmp_size) };
These safety comments explain why these calls are dangerous, but that's not what safety comments should do. They should explain why this particular call is okay. In this case, it's because the caller of drm_panic_qr_generate must follow the documented safety requirements of the current function. The wording could look like this:
// SAFETY: Due to the safety requirements on this function, the caller ensures that tmp is a valid pointer for reading and writing tmp_size bytes.
The wording is not much different, but it's an important distinction.
(Also, safety comments are written SAFETY: not Safety:)
drivers/gpu/drm/drm_panic_qr.rs line 961
Quoted 11 lines
drivers/gpu/drm/drm_panic_qr.rs new file +11
-0+if url.is_null () { +match EncodedMsg ::new (&[&Segment ::Binary (&data_slice[0 ..data_len])], tmp_slice) { +None =>0 , +Some (em) => { +let qr_image =QrImage ::new (&em, data_slice); + qr_image.width + } + } + }else { +// Safety: url must be a valid pointer to a nul-terminated string. +let url_cstr: &CStr =unsafe {CStr ::from_char_ptr (url) };
// SAFETY: The caller ensures that url is a valid pointer to a nul-terminated string.
drivers/gpu/drm/drm_panic_qr.rs line 974
Quoted 13 lines
drivers/gpu/drm/drm_panic_qr.rs new file +13
-0+let segments = &[ + &Segment ::Binary (url_cstr.as_bytes ()), + &Segment ::Numeric (&data_slice[0 ..data_len]), + ]; +match EncodedMsg ::new (segments, tmp_slice) { +None =>0 , +Some (em) => { +let qr_image =QrImage ::new (&em, data_slice); + qr_image.width + } + } + } +}
Alice
Jocelyn Falempe
maintainerQuoted 47 lines · Alice Ryhl
Quoted 24 lines · Jocelyn Falempe
This patch adds a new panic screen, with a QR code and the kmsg data embedded.
IfDRM_PANIC_SCREEN_QR_CODE_URLis set, then the kmsg data will be compressed with zlib and encoded as a numerical segment, and appended to the url as a url parameter. This allows to save space, and put about ~7500 bytes of kmsg data, in a V40 QR code.
Linux distributions can customize the url, and put a web frontend to directly open a bug report with the kmsg data.Otherwise the kmsg data will be encoded as binary segment (ie raw ascii) and only a maximum of 2953 bytes of kmsg data will be available in the QR code.
You can also limit the QR code size with
DRM_PANIC_SCREEN_QR_VERSION.v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Markdrm_panic_qr_generate()as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call toas_str_unchecked()(Alice Ryhl)
* Add a check fordata_len<=data_size(Greg KH)Signed-off-by Jocelyn Falempe <[email protected]>[...]
Quoted 19 lines
drivers/gpu/drm/drm_panic_qr.rs new file +19
-0+/// drm_panic_qr_generate() +/// +/// C entry point for the rust QR Code generator. +/// +/// Write the QR code image in the data buffer, and return the qrcode size, or 0 +/// if the data doesn't fit in a QR code. +/// +/// * `url` The base url of the QR code. It will be encoded as Binary segment. +/// * `data` A pointer to the binary data, to be encoded. if url is NULL, it +/// will be encoded as binary segment, otherwise it will be encoded +/// efficiently as a numeric segment, and appended to the url. +/// * `data_len` Length of the data, that needs to be encoded. +/// * `data_size` Size of data buffer, it should be at least 4071 bytes to hold +/// a V40 QR-code. It will then be overwritten with the QR-code image. +/// * `tmp` A temporary buffer that the QR-code encoder will use, to write the +/// segments and ECC. +/// * `tmp_size` Size of the temporary buffer, it must be at least 3706 bytes +/// long for V40. +///
Quoted 8 lines
drivers/gpu/drm/drm_panic_qr.rs line 933
Quoted 6 lines
drivers/gpu/drm/drm_panic_qr.rs new file +6
-0+/// # Safety +/// +/// * `url` must be null or point at a nul-terminated string. +/// * `data` must be valid for reading and writing for `data_size` bytes. +/// * `data_len` must be less than `data_size`. +/// * `tmp` must be valid for reading and writing for `tmp_size` bytes. You don't allow
data_len==data_size?
In fact, the QR code will always be larger than the data you want to put into, because it adds segment header/length and ECC, so it doesn't make sense in practice to have data_len == data_size. data_size must be at least 4071 bytes, and the maximum data_len you can put in a V40 is 3703 bytes.
Quoted 17 lines
drivers/gpu/drm/drm_panic_qr.rs line 946
Quoted 13 lines
drivers/gpu/drm/drm_panic_qr.rs new file +12
-0+#[no_mangle] +pub unsafe extern "C" fn drm_panic_qr_generate ( + url: *const i8 , + data: *mut u8 , + data_len:usize , + data_size:usize , + tmp: *mut u8 , + tmp_size:usize , +) ->u8 { +if data_size <=4071 || tmp_size <=3706 || data_len > data_size { +return 0 ; + }Since you explicitly check the
data_len, it does not *need* to be a safety requirement (but it can be). Even if it's wrong, violating the requirement does not lead to memory safety.
Ok, that makes sense, I will move it to the previous section.
Quoted 12 lines
drivers/gpu/drm/drm_panic_qr.rs line 950
Quoted 5 lines
drivers/gpu/drm/drm_panic_qr.rs new file +4
-0+// Safety: data must be a valid pointer for reading and writing data_size bytes. +let data_slice: &mut [u8 ] =unsafe { core::slice::from_raw_parts_mut (data, data_size) }; +// Safety: tmp must be a valid pointer for reading and writing tmp_size bytes. +let tmp_slice: &mut [u8 ] =unsafe { core::slice::from_raw_parts_mut (tmp, tmp_size) };These safety comments explain why these calls are dangerous, but that's not what safety comments should do. They should explain why this particular call is okay. In this case, it's because the caller of
drm_panic_qr_generatemust follow the documented safety requirements of the current function. The wording could look like this:
Quoted 5 lines
// SAFETY: Due to the safety requirements on this function, the caller ensures that tmp is a valid pointer for reading and writing
tmp_sizebytes.The wording is not much different, but it's an important distinction.
Ok, I will update it, and add the expected lifetime as Miguel pointed out.
Quoted 15 lines
(Also, safety comments are written SAFETY: not Safety:)
drivers/gpu/drm/drm_panic_qr.rs line 961
Quoted 11 lines
drivers/gpu/drm/drm_panic_qr.rs new file +11
-0+if url.is_null () { +match EncodedMsg ::new (&[&Segment ::Binary (&data_slice[0 ..data_len])], tmp_slice) { +None =>0 , +Some (em) => { +let qr_image =QrImage ::new (&em, data_slice); + qr_image.width + } + } + }else { +// Safety: url must be a valid pointer to a nul-terminated string. +let url_cstr: &CStr =unsafe {CStr ::from_char_ptr (url) };
Quoted 2 lines
// SAFETY: The caller ensures that url is a valid pointer to a nul-terminated string.
ok
Quoted 15 lines
Quoted 4 lines
drivers/gpu/drm/drm_panic_qr.rs new file +3
-0+let segments = &[ + &Segment ::Binary (url_cstr.as_bytes ()), + &Segment::Numeric(&data_slice[0..data_len]),drivers/gpu/drm/drm_panic_qr.rs line 974
Quoted 10 lines
drivers/gpu/drm/drm_panic_qr.rs new file +10
-0+ ]; +match EncodedMsg ::new (segments, tmp_slice) { +None =>0 , +Some (em) => { +let qr_image =QrImage ::new (&em, data_slice); + qr_image.width + } + } + } +}
Quoted 2 lines
Alice
Best regards,
Signature · 1 line
Jocelyn