2012-11-18 11:05:28

by Krzysztof Mazur

[permalink] [raw]
Subject: vt: regression caused by "Fix line garbage in virtual.."

Hi,

commit 81732c3b2fede049a692e58a7ceabb6d18ffb18c
(tty vt: Fix line garbage in virtual console on command line edition)
introduced some regression in deleting characters/clearing line during
selecting previous command in bash by using "up" arrow.


The problem can be reproduced by two following commands:

echo -n "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
echo -e "\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x1b\x5b\x33\x50\x64\x72\x69\x76\x65\x72\x73\x2f\x69\x6e\x70\x75\x74\x2f\x6d\x6f\x75\x73\x65\x64\x65\x76\x2e\x63"

(the first command generates just some garbage, the second command
generates string captured by strace when the issue occured).


On Linux v3.6 the resulting line is:

...AAAdrivers/input/mousedev.c

with fbcon on inteldrmfb and v3.7-rc6
...AAAdrivers/input/mousedev.c A

with fbcon on radeondrmfb and v3.7-rc6
...AAAdrivers/input/mousedev.cAAA


There are some garbage after mousedev.c not present on older kernels.

Reverting commit 81732c in v3.7-rc6 fixes the issue.

Krzysiek


2012-11-19 11:36:12

by Alan

[permalink] [raw]
Subject: Re: vt: regression caused by "Fix line garbage in virtual.."


> There are some garbage after mousedev.c not present on older kernels.
>
> Reverting commit 81732c in v3.7-rc6 fixes the issue.

Then we should drop this for 3.7 until a fixed one is provided IMHO.
Its not relevant to most platforms.

2012-11-19 19:21:33

by Jean-Francois Moine

[permalink] [raw]
Subject: Re: vt: regression caused by "Fix line garbage in virtual.."

On Mon, 19 Nov 2012 11:38:28 +0000
Alan Cox <[email protected]> wrote:

> > There are some garbage after mousedev.c not present on older kernels.
> >
> > Reverting commit 81732c in v3.7-rc6 fixes the issue.
>
> Then we should drop this for 3.7 until a fixed one is provided IMHO.
> Its not relevant to most platforms.

Sorry, juggling with the byte offsets and the character indexes was not
so obvious.

Here is a patch towards the kernel 3.7.

Krzysztof, may you check it?

Thanks.

--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -539,25 +539,25 @@
{
unsigned short *p = (unsigned short *) vc->vc_pos;

- scr_memmovew(p + nr, p, vc->vc_cols - vc->vc_x);
+ scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2);
scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
vc->vc_need_wrap = 0;
if (DO_UPDATE(vc))
do_update_region(vc, (unsigned long) p,
- (vc->vc_cols - vc->vc_x) / 2 + 1);
+ vc->vc_cols - vc->vc_x + 1);
}

static void delete_char(struct vc_data *vc, unsigned int nr)
{
unsigned short *p = (unsigned short *) vc->vc_pos;

- scr_memcpyw(p, p + nr, vc->vc_cols - vc->vc_x - nr);
+ scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2);
scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char,
nr * 2);
vc->vc_need_wrap = 0;
if (DO_UPDATE(vc))
do_update_region(vc, (unsigned long) p,
- (vc->vc_cols - vc->vc_x) / 2);
+ vc->vc_cols - vc->vc_x);
}

static int softcursor_original;

--
Ken ar c'hentaƱ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/

2012-11-19 21:15:58

by Krzysztof Mazur

[permalink] [raw]
Subject: Re: vt: regression caused by "Fix line garbage in virtual.."

On Mon, Nov 19, 2012 at 08:21:49PM +0100, Jean-Francois Moine wrote:
> On Mon, 19 Nov 2012 11:38:28 +0000
> Alan Cox <[email protected]> wrote:
>
> > > There are some garbage after mousedev.c not present on older kernels.
> > >
> > > Reverting commit 81732c in v3.7-rc6 fixes the issue.
> >
> > Then we should drop this for 3.7 until a fixed one is provided IMHO.
> > Its not relevant to most platforms.
>
> Sorry, juggling with the byte offsets and the character indexes was not
> so obvious.

That's why I even did not try to fix it.

>
> Here is a patch towards the kernel 3.7.
>
> Krzysztof, may you check it?
>

That patch fixed the original issue, but I noticed another artifact
(I tested only v3.7-rc6 after your fix, I didn't check if the same
problems exists in v3.7).

After:

for ((i = 0; i < 40; i++)); do
echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
done
echo -e -n "\x0d\x1b[2@"

(also generated by bash during command line editing, this time by CTRL-r
+ something)

the first character on screen (first column and first row) is cleared.


I think it's too late for fixing it in 3.7 and it's better, like Alan
proposed, to just revert it for now.

Thanks,

Krzysiek
-- >8 --
Subject: [PATCH] Revert "tty vt: Fix line garbage in virtual console on
command line edition"

This reverts commit 81732c3b2fede049a692e58a7ceabb6d18ffb18c.

This commit introduced frequent display artifacts during simple
command line editing in bash, at least with framebuffer
console on top inteldrmfb and radeondrmfb framebuffers.

Signed-off-by: Krzysztof Mazur <[email protected]>
---
drivers/tty/vt/vt.c | 78 +++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 61 insertions(+), 17 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index f87d7e8..3e89dba 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -537,27 +537,45 @@ void complement_pos(struct vc_data *vc, int offset)

static void insert_char(struct vc_data *vc, unsigned int nr)
{
- unsigned short *p = (unsigned short *) vc->vc_pos;
+ unsigned short *p, *q = (unsigned short *)vc->vc_pos;

- scr_memmovew(p + nr, p, vc->vc_cols - vc->vc_x);
- scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
+ p = q + vc->vc_cols - nr - vc->vc_x;
+ while (--p >= q)
+ scr_writew(scr_readw(p), p + nr);
+ scr_memsetw(q, vc->vc_video_erase_char, nr * 2);
vc->vc_need_wrap = 0;
- if (DO_UPDATE(vc))
- do_update_region(vc, (unsigned long) p,
- (vc->vc_cols - vc->vc_x) / 2 + 1);
+ if (DO_UPDATE(vc)) {
+ unsigned short oldattr = vc->vc_attr;
+ vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x, vc->vc_y, vc->vc_x + nr, 1,
+ vc->vc_cols - vc->vc_x - nr);
+ vc->vc_attr = vc->vc_video_erase_char >> 8;
+ while (nr--)
+ vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y, vc->vc_x + nr);
+ vc->vc_attr = oldattr;
+ }
}

static void delete_char(struct vc_data *vc, unsigned int nr)
{
- unsigned short *p = (unsigned short *) vc->vc_pos;
+ unsigned int i = vc->vc_x;
+ unsigned short *p = (unsigned short *)vc->vc_pos;

- scr_memcpyw(p, p + nr, vc->vc_cols - vc->vc_x - nr);
- scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char,
- nr * 2);
+ while (++i <= vc->vc_cols - nr) {
+ scr_writew(scr_readw(p+nr), p);
+ p++;
+ }
+ scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
vc->vc_need_wrap = 0;
- if (DO_UPDATE(vc))
- do_update_region(vc, (unsigned long) p,
- (vc->vc_cols - vc->vc_x) / 2);
+ if (DO_UPDATE(vc)) {
+ unsigned short oldattr = vc->vc_attr;
+ vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x + nr, vc->vc_y, vc->vc_x, 1,
+ vc->vc_cols - vc->vc_x - nr);
+ vc->vc_attr = vc->vc_video_erase_char >> 8;
+ while (nr--)
+ vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y,
+ vc->vc_cols - 1 - nr);
+ vc->vc_attr = oldattr;
+ }
}

static int softcursor_original;
@@ -1154,26 +1172,45 @@ static void csi_J(struct vc_data *vc, int vpar)
case 0: /* erase from cursor to end of display */
count = (vc->vc_scr_end - vc->vc_pos) >> 1;
start = (unsigned short *)vc->vc_pos;
+ if (DO_UPDATE(vc)) {
+ /* do in two stages */
+ vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
+ vc->vc_cols - vc->vc_x);
+ vc->vc_sw->con_clear(vc, vc->vc_y + 1, 0,
+ vc->vc_rows - vc->vc_y - 1,
+ vc->vc_cols);
+ }
break;
case 1: /* erase from start to cursor */
count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
start = (unsigned short *)vc->vc_origin;
+ if (DO_UPDATE(vc)) {
+ /* do in two stages */
+ vc->vc_sw->con_clear(vc, 0, 0, vc->vc_y,
+ vc->vc_cols);
+ vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
+ vc->vc_x + 1);
+ }
break;
case 3: /* erase scroll-back buffer (and whole display) */
scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
vc->vc_screenbuf_size >> 1);
set_origin(vc);
+ if (CON_IS_VISIBLE(vc))
+ update_screen(vc);
/* fall through */
case 2: /* erase whole display */
count = vc->vc_cols * vc->vc_rows;
start = (unsigned short *)vc->vc_origin;
+ if (DO_UPDATE(vc))
+ vc->vc_sw->con_clear(vc, 0, 0,
+ vc->vc_rows,
+ vc->vc_cols);
break;
default:
return;
}
scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
- if (DO_UPDATE(vc))
- do_update_region(vc, (unsigned long) start, count);
vc->vc_need_wrap = 0;
}

@@ -1186,22 +1223,29 @@ static void csi_K(struct vc_data *vc, int vpar)
case 0: /* erase from cursor to end of line */
count = vc->vc_cols - vc->vc_x;
start = (unsigned short *)vc->vc_pos;
+ if (DO_UPDATE(vc))
+ vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
+ vc->vc_cols - vc->vc_x);
break;
case 1: /* erase from start of line to cursor */
start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
count = vc->vc_x + 1;
+ if (DO_UPDATE(vc))
+ vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
+ vc->vc_x + 1);
break;
case 2: /* erase whole line */
start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
count = vc->vc_cols;
+ if (DO_UPDATE(vc))
+ vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
+ vc->vc_cols);
break;
default:
return;
}
scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
vc->vc_need_wrap = 0;
- if (DO_UPDATE(vc))
- do_update_region(vc, (unsigned long) start, count);
}

static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */
--
1.8.0.283.gc57d856

2012-11-20 08:54:00

by Jean-Francois Moine

[permalink] [raw]
Subject: Re: vt: regression caused by "Fix line garbage in virtual.."

On Mon, 19 Nov 2012 22:15:53 +0100
Krzysztof Mazur <[email protected]> wrote:

> That patch fixed the original issue, but I noticed another artifact
> (I tested only v3.7-rc6 after your fix, I didn't check if the same
> problems exists in v3.7).
>
> After:
>
> for ((i = 0; i < 40; i++)); do
> echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
> done
> echo -e -n "\x0d\x1b[2@"
>
> (also generated by bash during command line editing, this time by CTRL-r
> + something)
>
> the first character on screen (first column and first row) is cleared.
>
>
> I think it's too late for fixing it in 3.7 and it's better, like Alan
> proposed, to just revert it for now.

Thanks for testing. This time, the fix was easy.

But anyway, as it seems that my patch fixes only the Cubox machine and
as we are still using a kernel 3.5 with specific patches, the fix may
be delayed.

--->8 ---
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -539,25 +539,25 @@
{
unsigned short *p = (unsigned short *) vc->vc_pos;

- scr_memmovew(p + nr, p, vc->vc_cols - vc->vc_x);
+ scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2);
scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
vc->vc_need_wrap = 0;
if (DO_UPDATE(vc))
do_update_region(vc, (unsigned long) p,
- (vc->vc_cols - vc->vc_x) / 2 + 1);
+ vc->vc_cols - vc->vc_x);
}

static void delete_char(struct vc_data *vc, unsigned int nr)
{
unsigned short *p = (unsigned short *) vc->vc_pos;

- scr_memcpyw(p, p + nr, vc->vc_cols - vc->vc_x - nr);
+ scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2);
scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char,
nr * 2);
vc->vc_need_wrap = 0;
if (DO_UPDATE(vc))
do_update_region(vc, (unsigned long) p,
- (vc->vc_cols - vc->vc_x) / 2);
+ vc->vc_cols - vc->vc_x);
}

static int softcursor_original;

--
Ken ar c'hentaƱ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/

2012-11-20 15:21:01

by Krzysztof Mazur

[permalink] [raw]
Subject: Re: vt: regression caused by "Fix line garbage in virtual.."

On Tue, Nov 20, 2012 at 09:54:21AM +0100, Jean-Francois Moine wrote:
> Thanks for testing. This time, the fix was easy.
>
> But anyway, as it seems that my patch fixes only the Cubox machine and
> as we are still using a kernel 3.5 with specific patches, the fix may
> be delayed.
>
> --->8 ---
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -539,25 +539,25 @@
> {
> unsigned short *p = (unsigned short *) vc->vc_pos;
>
> - scr_memmovew(p + nr, p, vc->vc_cols - vc->vc_x);
> + scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2);
> scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
> vc->vc_need_wrap = 0;
> if (DO_UPDATE(vc))
> do_update_region(vc, (unsigned long) p,
> - (vc->vc_cols - vc->vc_x) / 2 + 1);
> + vc->vc_cols - vc->vc_x);
> }
>
> static void delete_char(struct vc_data *vc, unsigned int nr)
> {
> unsigned short *p = (unsigned short *) vc->vc_pos;
>
> - scr_memcpyw(p, p + nr, vc->vc_cols - vc->vc_x - nr);
> + scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2);
> scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char,
> nr * 2);
> vc->vc_need_wrap = 0;
> if (DO_UPDATE(vc))
> do_update_region(vc, (unsigned long) p,
> - (vc->vc_cols - vc->vc_x) / 2);
> + vc->vc_cols - vc->vc_x);
> }
>
> static int softcursor_original;

Tested-by: Krzysztof Mazur <[email protected]>

Thanks,

Krzysiek