Re: [PATCH v2] tty: n_gsm: restrict tty devices to attach

From: Tetsuo Handa
Date: Sun Apr 21 2024 - 09:28:59 EST


On 2024/04/21 3:05, Linus Torvalds wrote:
> On Sat, 20 Apr 2024 at 11:02, Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> Most other normal tty devices just expect ->write() to be called in
>> normal process context, so if we do a line discipline flag, it would
> ^^^^^^^^^^^^^^^^^^^^
>> have to be something like "I'm ok with being called with interrupts
>> disabled", and then the n_gsm ->open function would just check that.
>
> Not line discipline - it would be a 'struct tty_operations' flag
> saying 'my ->write() function is ok with atomic context".

"struct tty_ldisc_ops" says that ->write() function (e.g. gsmld_write())
is allowed to sleep and "struct tty_operations" says that ->write() function
(e.g. con_write()) is not allowed to sleep. Thus, I initially proposed
https://lkml.kernel.org/r/9cd9d3eb-418f-44cc-afcf-7283d51252d6@xxxxxxxxxxxxxxxxxxx
which makes con_write() no-op when called with IRQs disabled.

My major/minor approach is based on a suggestion from Jiri that we just somehow
disallow attaching this line discipline to a console, with a concern from Starke
that introducing cross references is hard to maintain taken into account.
https://lkml.kernel.org/r/DB9PR10MB5881526A2B8F27FE36C49134E0CBA@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Now, your 'struct tty_operations' flag saying 'my ->write() function is OK with
atomic context' is expected to be set to all drivers.

Do we instead want to add 'struct tty_operations' flag saying 'my ->write() function
is NOT OK with atomic context' and turn on the flag for the console driver?