linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1 1/1] Serial: core: Add compat ioctl support
@ 2022-12-22  4:49 Viken Dadhaniya
  2022-12-22  5:49 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Viken Dadhaniya @ 2022-12-22  4:49 UTC (permalink / raw)
  To: gregkh, jirislaby, linux-serial, linux-kernel
  Cc: quic_msavaliy, quic_vnivarth, quic_vtanuku, quic_arandive,
	Viken Dadhaniya

Current serial core driver doesn't support compat_ioctl
due to which 32-bit application is not able to send
ioctls to driver on a 64-bit platform.

Added compat_ioctl support in serial core to handle
ioctls from 32-bit applications on a 64-bit platform.

Signed-off-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
---
 drivers/tty/serial/serial_core.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index b9fbbee598b8..5ffa0798db3b 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1601,6 +1601,22 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
 	return ret;
 }
 
+/**
+ * uart_compat_ioctl: uart compat IOCTL function.
+ * @tty: pointer to tty structure.
+ * @cmd: command code passed by user-space.
+ * @arg: argument  passed by user-space.
+ *
+ * This function will call normal uart IOCTL.
+ *
+ * Return: 0 for success, Negative number for error condition.
+ */
+static long
+uart_compat_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
+{
+	return (long)uart_ioctl(tty, cmd, arg);
+};
+
 static void uart_set_ldisc(struct tty_struct *tty)
 {
 	struct uart_state *state = tty->driver_data;
@@ -2670,6 +2686,7 @@ static const struct tty_operations uart_ops = {
 	.chars_in_buffer= uart_chars_in_buffer,
 	.flush_buffer	= uart_flush_buffer,
 	.ioctl		= uart_ioctl,
+	.compat_ioctl   = uart_compat_ioctl,
 	.throttle	= uart_throttle,
 	.unthrottle	= uart_unthrottle,
 	.send_xchar	= uart_send_xchar,
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V1 1/1] Serial: core: Add compat ioctl support
  2022-12-22  4:49 [PATCH V1 1/1] Serial: core: Add compat ioctl support Viken Dadhaniya
@ 2022-12-22  5:49 ` Greg KH
  2023-01-25 11:27   ` Viken Dadhaniya
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2022-12-22  5:49 UTC (permalink / raw)
  To: Viken Dadhaniya
  Cc: jirislaby, linux-serial, linux-kernel, quic_msavaliy,
	quic_vnivarth, quic_vtanuku, quic_arandive

On Thu, Dec 22, 2022 at 10:19:25AM +0530, Viken Dadhaniya wrote:
> Current serial core driver doesn't support compat_ioctl
> due to which 32-bit application is not able to send
> ioctls to driver on a 64-bit platform.

Are you sure?

> Added compat_ioctl support in serial core to handle
> ioctls from 32-bit applications on a 64-bit platform.
> 
> Signed-off-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
> ---
>  drivers/tty/serial/serial_core.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index b9fbbee598b8..5ffa0798db3b 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -1601,6 +1601,22 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
>  	return ret;
>  }
>  
> +/**
> + * uart_compat_ioctl: uart compat IOCTL function.
> + * @tty: pointer to tty structure.
> + * @cmd: command code passed by user-space.
> + * @arg: argument  passed by user-space.
> + *
> + * This function will call normal uart IOCTL.
> + *
> + * Return: 0 for success, Negative number for error condition.

Why create kernel doc for a static function?  uart_ioctl() does not have
this, right?

> + */
> +static long
> +uart_compat_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
> +{
> +	return (long)uart_ioctl(tty, cmd, arg);
> +};

Really?  Why has this never shown up before as an issue?

How was this tested?  What is currently broken that now works properly
(or the other way around?)

This patch implies that _every_ driver with an ioctl must create a
compat_ioctl() callback, are you sure that is the case?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH V1 1/1] Serial: core: Add compat ioctl support
  2022-12-22  5:49 ` Greg KH
@ 2023-01-25 11:27   ` Viken Dadhaniya
  2023-01-25 12:22     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Viken Dadhaniya @ 2023-01-25 11:27 UTC (permalink / raw)
  To: Greg KH, Viken Dadhaniya (QUIC)
  Cc: jirislaby, linux-serial, linux-kernel, Mukesh Savaliya (QUIC),
	Vijaya Krishna Nivarthi (Temp) (QUIC), Visweswara Tanuku (QUIC),
	Aniket RANDIVE (QUIC)

Hi Greg,

Please find response inline.

> -----Original Message-----
> From: Greg KH <gregkh@linuxfoundation.org>
> Sent: Thursday, December 22, 2022 11:19 AM
> To: Viken Dadhaniya (QUIC) <quic_vdadhani@quicinc.com>
> Cc: jirislaby@kernel.org; linux-serial@vger.kernel.org; linux-
> kernel@vger.kernel.org; Mukesh Savaliya (QUIC) <quic_msavaliy@quicinc.com>;
> Vijaya Krishna Nivarthi (Temp) (QUIC) <quic_vnivarth@quicinc.com>; Visweswara
> Tanuku (QUIC) <quic_vtanuku@quicinc.com>; Aniket RANDIVE (QUIC)
> <quic_arandive@quicinc.com>
> Subject: Re: [PATCH V1 1/1] Serial: core: Add compat ioctl support
> 
> WARNING: This email originated from outside of Qualcomm. Please be wary of
> any links or attachments, and do not enable macros.
> 
> On Thu, Dec 22, 2022 at 10:19:25AM +0530, Viken Dadhaniya wrote:
> > Current serial core driver doesn't support compat_ioctl due to which
> > 32-bit application is not able to send ioctls to driver on a 64-bit
> > platform.
> 
> Are you sure?
> 
> > Added compat_ioctl support in serial core to handle ioctls from 32-bit
> > applications on a 64-bit platform.
> >
> > Signed-off-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
> > ---
> >  drivers/tty/serial/serial_core.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/drivers/tty/serial/serial_core.c
> > b/drivers/tty/serial/serial_core.c
> > index b9fbbee598b8..5ffa0798db3b 100644
> > --- a/drivers/tty/serial/serial_core.c
> > +++ b/drivers/tty/serial/serial_core.c
> > @@ -1601,6 +1601,22 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd,
> unsigned long arg)
> >       return ret;
> >  }
> >
> > +/**
> > + * uart_compat_ioctl: uart compat IOCTL function.
> > + * @tty: pointer to tty structure.
> > + * @cmd: command code passed by user-space.
> > + * @arg: argument  passed by user-space.
> > + *
> > + * This function will call normal uart IOCTL.
> > + *
> > + * Return: 0 for success, Negative number for error condition.
> 
> Why create kernel doc for a static function?  uart_ioctl() does not have this,
> right?
> 

I will remove documentation in V2 patch.

> > + */
> > +static long
> > +uart_compat_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned
> > +long arg) {
> > +     return (long)uart_ioctl(tty, cmd, arg); };
> 
> Really?  Why has this never shown up before as an issue?
>

We have only seen this problem with 32-bit applications running on 64-bit kernels.
For the first time, we are combining a 64-bit kernel with a 32-bit user space application.
 
> How was this tested?  What is currently broken that now works properly (or the
> other way around?)
>

We are running 32-bit user-space application on 64-bit kernel, and vendor specific ioctl command issued by application is not reaching the vendor driver.
Without these changes, the IOCTL call was returning from the tty framework rather than reaching to the vendor driver. IOCTL call is successfully reaching the vendor uart driver via tty framework after adding compat ioctl and functionality is working as expected and below is the dump stack with compat ioctl.

[ 1265.554002] Hardware name: Qualcomm Technologies, Inc. Monaco IDP V1.0 (DT)
[ 1265.554008] Call trace:
[ 1265.554011] dump_backtrace.cfi_jt+0x0/0x8
[ 1265.554023] show_stack+0x1c/0x2c
[ 1265.554032] dump_stack_lvl+0x80/0xc8
[ 1265.554041] dump_stack+0x1c/0x2c
[ 1265.554049] msm_geni_serial_ioctl+0x2cc/0x3d0 [msm_geni_serial]
[ 1265.554099] uart_ioctl+0x1a4/0x1d8
[ 1265.554109] uart_compat_ioctl+0x14/0x28
[ 1265.554117] tty_compat_ioctl+0x1a8/0x2dc
[ 1265.554125] __arm64_compat_sys_ioctl+0x158/0x1d0
[ 1265.554132] invoke_syscall+0x60/0x150
[ 1265.554140] el0_svc_common.llvm.3148309083493694862+0xc8/0x114
[ 1265.554148] do_el0_svc_compat+0x20/0x30
[ 1265.554154] el0_svc_compat+0x28/0x90
[ 1265.554162] el0t_32_sync_handler+0x7c/0xbc
[ 1265.554169] el0t_32_sync+0x1b8/0x1bc
 
> This patch implies that _every_ driver with an ioctl must create a
> compat_ioctl() callback, are you sure that is the case?
> 

this depends on user application and kernel version. for 32-bit application to run on 64-bit kernel, compat_ioctl is requried.

> thanks,
> 
> greg k-h

Thanks
Viken Dadhaniya 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V1 1/1] Serial: core: Add compat ioctl support
  2023-01-25 11:27   ` Viken Dadhaniya
@ 2023-01-25 12:22     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2023-01-25 12:22 UTC (permalink / raw)
  To: Viken Dadhaniya
  Cc: Viken Dadhaniya (QUIC),
	jirislaby, linux-serial, linux-kernel, Mukesh Savaliya (QUIC),
	Vijaya Krishna Nivarthi (Temp) (QUIC), Visweswara Tanuku (QUIC),
	Aniket RANDIVE (QUIC)

On Wed, Jan 25, 2023 at 11:27:49AM +0000, Viken Dadhaniya wrote:
> Hi Greg,
> 
> Please find response inline.

As they should be :)

> > -----Original Message-----
> > From: Greg KH <gregkh@linuxfoundation.org>
> > Sent: Thursday, December 22, 2022 11:19 AM
> > To: Viken Dadhaniya (QUIC) <quic_vdadhani@quicinc.com>
> > Cc: jirislaby@kernel.org; linux-serial@vger.kernel.org; linux-
> > kernel@vger.kernel.org; Mukesh Savaliya (QUIC) <quic_msavaliy@quicinc.com>;
> > Vijaya Krishna Nivarthi (Temp) (QUIC) <quic_vnivarth@quicinc.com>; Visweswara
> > Tanuku (QUIC) <quic_vtanuku@quicinc.com>; Aniket RANDIVE (QUIC)
> > <quic_arandive@quicinc.com>
> > Subject: Re: [PATCH V1 1/1] Serial: core: Add compat ioctl support

That's horrible, please fix your email client.

> > How was this tested?  What is currently broken that now works properly (or the
> > other way around?)
> >
> 
> We are running 32-bit user-space application on 64-bit kernel, and vendor specific ioctl command issued by application is not reaching the vendor driver.
> Without these changes, the IOCTL call was returning from the tty framework rather than reaching to the vendor driver. IOCTL call is successfully reaching the vendor uart driver via tty framework after adding compat ioctl and functionality is working as expected and below is the dump stack with compat ioctl.

What in-kernel tty ioctl is having a problem that a compat ioctl layer
is needed?  Let's fix that up.

As you know, we can't do anything about out-of-tree drivers.  Nor do you
want us to, so this really feels like a broken driver, it should NOT be
creating random new ioctls on the tty device node, that is NOT what it
is there for.

> [ 1265.554002] Hardware name: Qualcomm Technologies, Inc. Monaco IDP V1.0 (DT)
> [ 1265.554008] Call trace:
> [ 1265.554011] dump_backtrace.cfi_jt+0x0/0x8
> [ 1265.554023] show_stack+0x1c/0x2c
> [ 1265.554032] dump_stack_lvl+0x80/0xc8
> [ 1265.554041] dump_stack+0x1c/0x2c
> [ 1265.554049] msm_geni_serial_ioctl+0x2cc/0x3d0 [msm_geni_serial]

This function is not in our kernel tree, so it looks to be a bug in that
driver, sorry.  Do NOT paper over out-of-tree driver bugs in the core
kernel (hint, are you sure you are even allowed to do that?)

> [ 1265.554099] uart_ioctl+0x1a4/0x1d8
> [ 1265.554109] uart_compat_ioctl+0x14/0x28
> [ 1265.554117] tty_compat_ioctl+0x1a8/0x2dc
> [ 1265.554125] __arm64_compat_sys_ioctl+0x158/0x1d0
> [ 1265.554132] invoke_syscall+0x60/0x150
> [ 1265.554140] el0_svc_common.llvm.3148309083493694862+0xc8/0x114
> [ 1265.554148] do_el0_svc_compat+0x20/0x30
> [ 1265.554154] el0_svc_compat+0x28/0x90
> [ 1265.554162] el0t_32_sync_handler+0x7c/0xbc
> [ 1265.554169] el0t_32_sync+0x1b8/0x1bc
>  
> > This patch implies that _every_ driver with an ioctl must create a
> > compat_ioctl() callback, are you sure that is the case?
> > 
> 
> this depends on user application and kernel version. for 32-bit application to run on 64-bit kernel, compat_ioctl is requried.

Again, what in-tree tty ioctls are affected by this?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-25 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-22  4:49 [PATCH V1 1/1] Serial: core: Add compat ioctl support Viken Dadhaniya
2022-12-22  5:49 ` Greg KH
2023-01-25 11:27   ` Viken Dadhaniya
2023-01-25 12:22     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).