Re: [gentoo-user] Soft scrolling on framebuffer consoles - New versions of the patches.

2021-10-08 Thread Peter Humphrey
On Thursday, 7 October 2021 20:46:51 BST Alan Mackenzie wrote:

> Here are the latest versions of my soft scrolling patch for the kernel
> lines 5.10.xx and 5.14.xx.  They fix bugs where a PC would crash if it
> was initialised with a 25x80 console and later changed to a full
> resolution frame buffer screen.  It also now works (so I am told) for
> kernels initialised with parameters like vga=791.

--->8

Thank you for your efforts on all our behalf Alan.

-- 
Regards,
Peter.






[gentoo-user] Soft scrolling on framebuffer consoles - New versions of the patches.

2021-10-07 Thread Alan Mackenzie
Hello, Gentoo.

Here are the latest versions of my soft scrolling patch for the kernel
lines 5.10.xx and 5.14.xx.  They fix bugs where a PC would crash if it
was initialised with a 25x80 console and later changed to a full
resolution frame buffer screen.  It also now works (so I am told) for
kernels initialised with parameters like vga=791.

To use one of these (the right one for your kernel version) do:

(i) cd /usr/src/linux-5.10.61-gentoo, or similar.  Extract the right
  patch file to that directory.  (Don't worry about having > 61 for a
  kernel version.  Just use it!)
(ii) patch -p1 < 5.10.61-scroll.20211007.diff.
(iii) Configure the kernel in your usual way.  The extra items added by
  the patch are CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK and
  CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_SIZE, to be found in make
  menuconfig under Device Drivers/Graphic Support/Console display driver
  support.  The help items for these should explain them adequately.
(iv) Build the kernel.
(v) Put the new kernel into your usual boot manager.
(vi) Reboot and enjoy!

As far as I know this patch should be safe (apart from the mysterious
alleged security problem which caused the soft scrolling to be removed
from the kernel in the first place).  There is certainly nothing
malicous in it.  But if it does break anything for you, you get to keep
the pieces.  But if anything does go wrong, please tell me about it
(preferably here on the list, but by private email if you'd prefer), so
that I can try and fix it.

-- 
Alan Mackenzie (Nuremberg, Germany).

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 06757b1d4aec..c2061813c825 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -134,6 +134,11 @@ const struct consw *conswitchp;
 #define DEFAULT_BELL_DURATION  (HZ/8)
 #define DEFAULT_CURSOR_BLINK_MS200
 
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK
+static unsigned int console_soft_scrollback_size =
+   1024 * CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK_SIZE;
+#endif
+
 struct vc vc_cons [MAX_NR_CONSOLES];
 
 #ifndef VT_SINGLE_DRIVER
@@ -287,7 +292,7 @@ static inline unsigned short *screenpos(const struct 
vc_data *vc, int offset,
bool viewed)
 {
unsigned short *p;
-   
+
if (!viewed)
p = (unsigned short *)(vc->vc_origin + offset);
else if (!vc->vc_sw->con_screen_pos)
@@ -616,6 +621,218 @@ static void vc_uniscr_debug_check(struct vc_data *vc)
}
 }
 
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE_SOFT_SCROLLBACK
+static void con_update_softback(struct vc_data *vc)
+{
+   int l = vc->vc_softback_size / vc->vc_size_row;
+   if (l > 5)
+   {
+   vc->vc_softback_end = vc->vc_softback_buf + l * vc->vc_size_row;
+   vc->vc_softback_top = vc->vc_softback_buf;
+   }
+   else
+   /* Smaller scrollback makes no sense, and 0 would screw
+  the operation totally */
+   vc->vc_softback_top = 0;
+}
+
+static int concon_set_origin(struct vc_data *vc)
+{
+   if (vc->vc_softback_lines)
+   concon_scrolldelta(vc, vc->vc_softback_lines);
+   return 0;
+}
+
+#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) 
* vc->vc_size_row)
+
+static void con_redraw_softback(struct vc_data *vc, /* struct display *p, */
+   long delta)
+{
+   int count = vc->vc_rows;
+   unsigned short *d, *s;
+   unsigned long n;
+   int line = 0;
+
+   if (!vc->vc_softback_lines)
+   vc->vc_char_at_pos = scr_readw((u16 *)vc->vc_pos);
+
+   d = (u16 *) vc->vc_softback_curr;
+   if (d == (u16 *) vc->vc_softback_in)
+   d = (u16 *) vc->vc_origin;
+   n = vc->vc_softback_curr + delta * vc->vc_size_row;
+   vc->vc_softback_lines -= delta;
+   if (delta < 0) {
+   if (vc->vc_softback_curr < vc->vc_softback_top
+   && n < vc->vc_softback_buf) {
+   n += vc->vc_softback_end - vc->vc_softback_buf;
+   if (n < vc->vc_softback_top) {
+   vc->vc_softback_lines -=
+   (vc->vc_softback_top - n) / vc->vc_size_row;
+   n = vc->vc_softback_top;
+   }
+   } else if (vc->vc_softback_curr >= vc->vc_softback_top
+  && n < vc->vc_softback_top) {
+   vc->vc_softback_lines -=
+   (vc->vc_softback_top - n) / vc->vc_size_row;
+   n = vc->vc_softback_top;
+   }
+   } else {
+   if (vc->vc_softback_curr > vc->vc_softback_in
+   && n >= vc->vc_softback_end) {
+   n += vc->vc_softback_buf - vc->vc_softback_end;
+   if (n > vc->vc_softback_in) {
+   n = vc->vc_softback_in;
+   vc->v