[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7f55fd6b-91ed-453c-902a-0f7c74e201f5@grenoble-inp.org>
Date: Mon, 25 Aug 2025 13:41:02 +0200
From: Calixte Pernot <calixte.pernot@...noble-inp.org>
To: Jiri Slaby <jirislaby@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org, linux-serial@...r.kernel.org
Subject: Re: [PATCH] vt: add support for smput/rmput escape codes
Hi, thanks for your response.
On 8/25/25 07:47, Jiri Slaby wrote:
> Hi,
>
> On 24. 08. 25, 16:20, Calixte Pernot wrote:
>> Support "\e[?1049h" and "\e[?1049l" escape codes.
>> This patch allows programs to enter and leave alternate screens.
>> This feature is widely available in graphical terminal emulators and
>> mostly
>> used by fullscreen terminal-based user interfaces such as text editors.
>> Most editors such as vim and nano assume this escape code in not
>> supported
>> and will not try to print the escape sequence if TERM=linux.
>> To try out this patch, run `TERM=xterm-256color vim` inside a VT.
>>
>> Signed-off-by: Calixte Pernot <calixte.pernot@...noble-inp.org>
> ...
>> --- a/drivers/tty/vt/vt.c
>> +++ b/drivers/tty/vt/vt.c
> ...
>> @@ -1878,6 +1883,46 @@ static int get_bracketed_paste(struct
>> tty_struct *tty)
>> return vc->vc_bracketed_paste;
>> }
>> +/* console_lock is held */
>> +static void enter_alt_screen(struct vc_data *vc)
>> +{
>> + unsigned int size = vc->vc_rows * vc->vc_cols * 2;
>> +
>> + if (vc->vc_saved_screen != NULL)
>> + return; /* Already inside an alt-screen */
>
> All this is protected by console_lock, right?
Yes. The 2 functions I added are called by csi_DEC_hl, itself protected
by console_lock.
console_lock() is called in do_con_write, and the call stack looks like
this:
do_con_write -> do_con_trol -> csi_DEC -> csi_DEC_hl ->
enter/leave_alt_screen
>> + vc->vc_saved_screen = kzalloc(size, GFP_NOWAIT);
>
> Why GFP_NOWAIT?
To be honest I used the same flags as vc->vc_screenbuf, but after
"reading the F-ing manual", this seems unappropriate here.
"GFP_KERNEL implies GFP_RECLAIM, which means that direct reclaim may be
triggered under memory pressure; the calling context must be allowed to
sleep"
I guess we are allowed to sleep here (please correct me if i'm wrong),
so GFP_KERNEL must be more appropriate.
>> + if (vc->vc_saved_screen == NULL)
>> + return;
>> + memcpy(vc->vc_saved_screen, (u16 *)vc->vc_origin, size);
>
> kmemdup();
>
>> ed_cols, vc->vc_cols);
>> + unsigned short *src, *dest;
>
> u16
>
>> +
>> + if (vc->vc_saved_screen == NULL)
>> + return; /* Not inside an alt-screen */
>> + for (int r = 0; r < rows; r++) {
>
> unsigned
>> --- a/include/linux/console_struct.h
>> +++ b/include/linux/console_struct.h
>> @@ -159,6 +159,9 @@ struct vc_data {
>> struct uni_pagedict *uni_pagedict;
>> struct uni_pagedict **uni_pagedict_loc; /* [!] Location of
>> uni_pagedict variable for this console */
>> u32 **vc_uni_lines; /* unicode screen content */
>> + unsigned short *vc_saved_screen;
>
> u16 *
>
>> + unsigned int vc_saved_cols;
>> + unsigned int vc_saved_rows;
>> /* additional information is in vt_kern.h */
>> };
>
> thanks,
Thanks for the review, I'll rewrite the patch with the suggested changes
and send it back.
Powered by blists - more mailing lists