All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serdev: Restore serdev_device_write_buf for atomic context
@ 2017-04-28 11:47 Stefan Wahren
  2017-05-02  9:06 ` Johan Hovold
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Wahren @ 2017-04-28 11:47 UTC (permalink / raw)
  To: Rob Herring
  Cc: Greg Kroah-Hartman, Jiri Slaby, Sebastian Reichel, Guenter Roeck,
	Andy Shevchenko, Andrey Smirnov, linux-serial, linux-kernel,
	Stefan Wahren

Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
subroutine") the function serdev_device_write_buf cannot be used in
atomic context anymore (mutex_lock is sleeping). So restore the old
behavior.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Fixes: 6fe729c4bdae ("serdev: Add serdev_device_write subroutine")
---
 drivers/tty/serdev/core.c | 12 ++++++++++++
 include/linux/serdev.h    | 14 +++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index 433de5e..f71b473 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -122,6 +122,18 @@ void serdev_device_write_wakeup(struct serdev_device *serdev)
 }
 EXPORT_SYMBOL_GPL(serdev_device_write_wakeup);
 
+int serdev_device_write_buf(struct serdev_device *serdev,
+			    const unsigned char *buf, size_t count)
+{
+	struct serdev_controller *ctrl = serdev->ctrl;
+
+	if (!ctrl || !ctrl->ops->write_buf)
+		return -EINVAL;
+
+	return ctrl->ops->write_buf(ctrl, buf, count);
+}
+EXPORT_SYMBOL_GPL(serdev_device_write_buf);
+
 int serdev_device_write(struct serdev_device *serdev,
 			const unsigned char *buf, size_t count,
 			unsigned long timeout)
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index cda76c6..e2a225b 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -195,6 +195,7 @@ int serdev_device_open(struct serdev_device *);
 void serdev_device_close(struct serdev_device *);
 unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int);
 void serdev_device_set_flow_control(struct serdev_device *, bool);
+int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_t);
 void serdev_device_wait_until_sent(struct serdev_device *, long);
 int serdev_device_get_tiocm(struct serdev_device *);
 int serdev_device_set_tiocm(struct serdev_device *, int, int);
@@ -236,6 +237,12 @@ static inline unsigned int serdev_device_set_baudrate(struct serdev_device *sdev
 	return 0;
 }
 static inline void serdev_device_set_flow_control(struct serdev_device *sdev, bool enable) {}
+static inline int serdev_device_write_buf(struct serdev_device *serdev,
+					  const unsigned char *buf,
+					  size_t count)
+{
+	return -ENODEV;
+}
 static inline void serdev_device_wait_until_sent(struct serdev_device *sdev, long timeout) {}
 static inline int serdev_device_get_tiocm(struct serdev_device *serdev)
 {
@@ -312,11 +319,4 @@ static inline struct device *serdev_tty_port_register(struct tty_port *port,
 static inline void serdev_tty_port_unregister(struct tty_port *port) {}
 #endif /* CONFIG_SERIAL_DEV_CTRL_TTYPORT */
 
-static inline int serdev_device_write_buf(struct serdev_device *serdev,
-					  const unsigned char *data,
-					  size_t count)
-{
-	return serdev_device_write(serdev, data, count, 0);
-}
-
 #endif /*_LINUX_SERDEV_H */
-- 
2.1.4

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-04-28 11:47 [PATCH] serdev: Restore serdev_device_write_buf for atomic context Stefan Wahren
@ 2017-05-02  9:06 ` Johan Hovold
  2017-05-02 12:41   ` Rob Herring
  0 siblings, 1 reply; 9+ messages in thread
From: Johan Hovold @ 2017-05-02  9:06 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: Rob Herring, Greg Kroah-Hartman, Jiri Slaby, Sebastian Reichel,
	Guenter Roeck, Andy Shevchenko, Andrey Smirnov, linux-serial,
	linux-kernel

On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
> subroutine") the function serdev_device_write_buf cannot be used in
> atomic context anymore (mutex_lock is sleeping). So restore the old
> behavior.

Yeah, preventing use in atomic context seems unnecessary, although any
clients writing must now deal with serialisation themselves (as before,
and as they should).

Calling wait_for_completion in the non-blocking case was also needlessly
inefficient.

> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> Fixes: 6fe729c4bdae ("serdev: Add serdev_device_write subroutine")

Reviewed-by: Johan Hovold <johan@kernel.org>

Thanks,
Johan

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-02  9:06 ` Johan Hovold
@ 2017-05-02 12:41   ` Rob Herring
  2017-05-02 13:18     ` Johan Hovold
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2017-05-02 12:41 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Stefan Wahren, Greg Kroah-Hartman, Jiri Slaby, Sebastian Reichel,
	Guenter Roeck, Andy Shevchenko, Andrey Smirnov, linux-serial,
	linux-kernel

On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
> On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
>> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
>> subroutine") the function serdev_device_write_buf cannot be used in
>> atomic context anymore (mutex_lock is sleeping). So restore the old
>> behavior.
>
> Yeah, preventing use in atomic context seems unnecessary, although any
> clients writing must now deal with serialisation themselves (as before,
> and as they should).

We could just remove the mutex for serdev_device_write and always make
the client responsible for serialization.

> Calling wait_for_completion in the non-blocking case was also needlessly
> inefficient.

It won't be called because count should be 0.

Rob

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-02 12:41   ` Rob Herring
@ 2017-05-02 13:18     ` Johan Hovold
  2017-05-04 16:22       ` Stefan Wahren
  0 siblings, 1 reply; 9+ messages in thread
From: Johan Hovold @ 2017-05-02 13:18 UTC (permalink / raw)
  To: Rob Herring
  Cc: Johan Hovold, Stefan Wahren, Greg Kroah-Hartman, Jiri Slaby,
	Sebastian Reichel, Guenter Roeck, Andy Shevchenko,
	Andrey Smirnov, linux-serial, linux-kernel

On Tue, May 02, 2017 at 07:41:34AM -0500, Rob Herring wrote:
> On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
> > On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
> >> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
> >> subroutine") the function serdev_device_write_buf cannot be used in
> >> atomic context anymore (mutex_lock is sleeping). So restore the old
> >> behavior.
> >
> > Yeah, preventing use in atomic context seems unnecessary, although any
> > clients writing must now deal with serialisation themselves (as before,
> > and as they should).
> 
> We could just remove the mutex for serdev_device_write and always make
> the client responsible for serialization.

That sounds reasonable.

> > Calling wait_for_completion in the non-blocking case was also needlessly
> > inefficient.
> 
> It won't be called because count should be 0.

That's not guaranteed; count would be nonzero whenever the tty
driver does not accept the full buffer and then we'd currently end up
calling wait_for_completion_timeout() with a zero-timeout instead of
just returning immediately.

Johan

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-02 13:18     ` Johan Hovold
@ 2017-05-04 16:22       ` Stefan Wahren
  2017-05-04 20:32         ` Rob Herring
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Wahren @ 2017-05-04 16:22 UTC (permalink / raw)
  To: Johan Hovold, Rob Herring
  Cc: Greg Kroah-Hartman, Jiri Slaby, Sebastian Reichel, Guenter Roeck,
	Andy Shevchenko, Andrey Smirnov, linux-serial, linux-kernel

Am 02.05.2017 um 15:18 schrieb Johan Hovold:
> On Tue, May 02, 2017 at 07:41:34AM -0500, Rob Herring wrote:
>> On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
>>> On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
>>>> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
>>>> subroutine") the function serdev_device_write_buf cannot be used in
>>>> atomic context anymore (mutex_lock is sleeping). So restore the old
>>>> behavior.
>>> Yeah, preventing use in atomic context seems unnecessary, although any
>>> clients writing must now deal with serialisation themselves (as before,
>>> and as they should).
>> We could just remove the mutex for serdev_device_write and always make
>> the client responsible for serialization.
> That sounds reasonable.

So it's unwanted to have 2 write functions (non-atomic, atomic)?

Stefan

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-04 16:22       ` Stefan Wahren
@ 2017-05-04 20:32         ` Rob Herring
  2017-05-08 15:18           ` Johan Hovold
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2017-05-04 20:32 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: Johan Hovold, Greg Kroah-Hartman, Jiri Slaby, Sebastian Reichel,
	Guenter Roeck, Andy Shevchenko, Andrey Smirnov, linux-serial,
	linux-kernel

On Thu, May 4, 2017 at 11:22 AM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
> Am 02.05.2017 um 15:18 schrieb Johan Hovold:
>> On Tue, May 02, 2017 at 07:41:34AM -0500, Rob Herring wrote:
>>> On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
>>>> On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
>>>>> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
>>>>> subroutine") the function serdev_device_write_buf cannot be used in
>>>>> atomic context anymore (mutex_lock is sleeping). So restore the old
>>>>> behavior.
>>>> Yeah, preventing use in atomic context seems unnecessary, although any
>>>> clients writing must now deal with serialisation themselves (as before,
>>>> and as they should).
>>> We could just remove the mutex for serdev_device_write and always make
>>> the client responsible for serialization.
>> That sounds reasonable.
>
> So it's unwanted to have 2 write functions (non-atomic, atomic)?

No, it's unwanted to have more than we need.

Looking closer, we'd also have to ensure the wait for completion is
not called also. So probably better to just leave it as you have done
it.

Acked-by: Rob Herring <robh@kernel.org>

Rob

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-04 20:32         ` Rob Herring
@ 2017-05-08 15:18           ` Johan Hovold
  2017-05-17 11:38             ` Stefan Wahren
  0 siblings, 1 reply; 9+ messages in thread
From: Johan Hovold @ 2017-05-08 15:18 UTC (permalink / raw)
  To: Rob Herring
  Cc: Stefan Wahren, Johan Hovold, Greg Kroah-Hartman, Jiri Slaby,
	Sebastian Reichel, Guenter Roeck, Andy Shevchenko,
	Andrey Smirnov, linux-serial, linux-kernel

On Thu, May 04, 2017 at 03:32:53PM -0500, Rob Herring wrote:
> On Thu, May 4, 2017 at 11:22 AM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
> > Am 02.05.2017 um 15:18 schrieb Johan Hovold:
> >> On Tue, May 02, 2017 at 07:41:34AM -0500, Rob Herring wrote:
> >>> On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
> >>>> On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
> >>>>> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
> >>>>> subroutine") the function serdev_device_write_buf cannot be used in
> >>>>> atomic context anymore (mutex_lock is sleeping). So restore the old
> >>>>> behavior.
> >>>> Yeah, preventing use in atomic context seems unnecessary, although any
> >>>> clients writing must now deal with serialisation themselves (as before,
> >>>> and as they should).
> >>> We could just remove the mutex for serdev_device_write and always make
> >>> the client responsible for serialization.
> >> That sounds reasonable.
> >
> > So it's unwanted to have 2 write functions (non-atomic, atomic)?
> 
> No, it's unwanted to have more than we need.
> 
> Looking closer, we'd also have to ensure the wait for completion is
> not called also. So probably better to just leave it as you have done
> it.

Indeed. Sorry if my reply above was unclear on that point (i.e. that
Stefan's patch is still needed regardless of whether we keep the mutex
or not).

Thanks,
Johan

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-08 15:18           ` Johan Hovold
@ 2017-05-17 11:38             ` Stefan Wahren
  2017-05-17 12:46               ` Greg Kroah-Hartman
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Wahren @ 2017-05-17 11:38 UTC (permalink / raw)
  To: Johan Hovold, Rob Herring, Greg Kroah-Hartman
  Cc: Jiri Slaby, Sebastian Reichel, Guenter Roeck, Andy Shevchenko,
	Andrey Smirnov, linux-serial, linux-kernel

Hi Greg,

Am 08.05.2017 um 17:18 schrieb Johan Hovold:
> On Thu, May 04, 2017 at 03:32:53PM -0500, Rob Herring wrote:
>> On Thu, May 4, 2017 at 11:22 AM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
>>> Am 02.05.2017 um 15:18 schrieb Johan Hovold:
>>>> On Tue, May 02, 2017 at 07:41:34AM -0500, Rob Herring wrote:
>>>>> On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
>>>>>> On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
>>>>>>> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
>>>>>>> subroutine") the function serdev_device_write_buf cannot be used in
>>>>>>> atomic context anymore (mutex_lock is sleeping). So restore the old
>>>>>>> behavior.
>>>>>> Yeah, preventing use in atomic context seems unnecessary, although any
>>>>>> clients writing must now deal with serialisation themselves (as before,
>>>>>> and as they should).
>>>>> We could just remove the mutex for serdev_device_write and always make
>>>>> the client responsible for serialization.
>>>> That sounds reasonable.
>>> So it's unwanted to have 2 write functions (non-atomic, atomic)?
>> No, it's unwanted to have more than we need.
>>
>> Looking closer, we'd also have to ensure the wait for completion is
>> not called also. So probably better to just leave it as you have done
>> it.
> Indeed. Sorry if my reply above was unclear on that point (i.e. that
> Stefan's patch is still needed regardless of whether we keep the mutex
> or not).
>
> Thanks,
> Johan

are you okay with this patch and can you please apply it?

Stefan

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

* Re: [PATCH] serdev: Restore serdev_device_write_buf for atomic context
  2017-05-17 11:38             ` Stefan Wahren
@ 2017-05-17 12:46               ` Greg Kroah-Hartman
  0 siblings, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2017-05-17 12:46 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: Johan Hovold, Rob Herring, Jiri Slaby, Sebastian Reichel,
	Guenter Roeck, Andy Shevchenko, Andrey Smirnov, linux-serial,
	linux-kernel

On Wed, May 17, 2017 at 01:38:40PM +0200, Stefan Wahren wrote:
> Hi Greg,
> 
> Am 08.05.2017 um 17:18 schrieb Johan Hovold:
> > On Thu, May 04, 2017 at 03:32:53PM -0500, Rob Herring wrote:
> >> On Thu, May 4, 2017 at 11:22 AM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
> >>> Am 02.05.2017 um 15:18 schrieb Johan Hovold:
> >>>> On Tue, May 02, 2017 at 07:41:34AM -0500, Rob Herring wrote:
> >>>>> On Tue, May 2, 2017 at 4:06 AM, Johan Hovold <johan@kernel.org> wrote:
> >>>>>> On Fri, Apr 28, 2017 at 01:47:21PM +0200, Stefan Wahren wrote:
> >>>>>>> Starting with commit 6fe729c4bdae ("serdev: Add serdev_device_write
> >>>>>>> subroutine") the function serdev_device_write_buf cannot be used in
> >>>>>>> atomic context anymore (mutex_lock is sleeping). So restore the old
> >>>>>>> behavior.
> >>>>>> Yeah, preventing use in atomic context seems unnecessary, although any
> >>>>>> clients writing must now deal with serialisation themselves (as before,
> >>>>>> and as they should).
> >>>>> We could just remove the mutex for serdev_device_write and always make
> >>>>> the client responsible for serialization.
> >>>> That sounds reasonable.
> >>> So it's unwanted to have 2 write functions (non-atomic, atomic)?
> >> No, it's unwanted to have more than we need.
> >>
> >> Looking closer, we'd also have to ensure the wait for completion is
> >> not called also. So probably better to just leave it as you have done
> >> it.
> > Indeed. Sorry if my reply above was unclear on that point (i.e. that
> > Stefan's patch is still needed regardless of whether we keep the mutex
> > or not).
> >
> > Thanks,
> > Johan
> 
> are you okay with this patch and can you please apply it?

I'll work to catch up on tty/serial patches soon...

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

end of thread, other threads:[~2017-05-17 12:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-28 11:47 [PATCH] serdev: Restore serdev_device_write_buf for atomic context Stefan Wahren
2017-05-02  9:06 ` Johan Hovold
2017-05-02 12:41   ` Rob Herring
2017-05-02 13:18     ` Johan Hovold
2017-05-04 16:22       ` Stefan Wahren
2017-05-04 20:32         ` Rob Herring
2017-05-08 15:18           ` Johan Hovold
2017-05-17 11:38             ` Stefan Wahren
2017-05-17 12:46               ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.