linux-ppp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: remove disc_data_lock in ppp line discipline
@ 2020-12-28  7:15 Gao Yan
  2020-12-31 10:00 ` 答复: [PATCH] net: remove disc_data_lock in =?utf-8?Q?_ppp_line_discipl Gaoyan
  2021-01-01  1:37 ` [PATCH] net: remove disc_data_lock in ppp line discipline Xie He
  0 siblings, 2 replies; 3+ messages in thread
From: Gao Yan @ 2020-12-28  7:15 UTC (permalink / raw)
  To: paulus, davem, kuba; +Cc: linux-ppp, netdev, linux-kernel, Gao Yan

In tty layer, it use tty->ldisc_sem to proect tty_ldisc_ops.
So I think tty->ldisc_sem can also protect tty->disc_data;
For examlpe,
When cpu A is running ppp_synctty_ioctl that hold the tty->ldisc_sem,
at the same time  if cpu B calls ppp_synctty_close, it will wait until
cpu A release tty->ldisc_sem. So I think it is unnecessary to have the
disc_data_lock;

cpu A                           cpu B
tty_ioctl                       tty_reopen
 ->hold tty->ldisc_sem            ->hold tty->ldisc_sem(write), failed
 ->ld->ops->ioctl                 ->wait...
 ->release tty->ldisc_sem         ->wait...OK,hold tty->ldisc_sem
                                    ->tty_ldisc_reinit
                                      ->tty_ldisc_close
                                        ->ld->ops->close

Signed-off-by: Gao Yan <gao.yanB@h3c.com>
---
 drivers/net/ppp/ppp_async.c   | 11 ++---------
 drivers/net/ppp/ppp_synctty.c | 12 ++----------
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index 29a0917a8..20b50facd 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -127,17 +127,13 @@ static const struct ppp_channel_ops async_ops = {
  * FIXME: this is no longer true. The _close path for the ldisc is
  * now guaranteed to be sane.
  */
-static DEFINE_RWLOCK(disc_data_lock);
 
 static struct asyncppp *ap_get(struct tty_struct *tty)
 {
-	struct asyncppp *ap;
+	struct asyncppp *ap = tty->disc_data;
 
-	read_lock(&disc_data_lock);
-	ap = tty->disc_data;
 	if (ap != NULL)
 		refcount_inc(&ap->refcnt);
-	read_unlock(&disc_data_lock);
 	return ap;
 }
 
@@ -214,12 +210,9 @@ ppp_asynctty_open(struct tty_struct *tty)
 static void
 ppp_asynctty_close(struct tty_struct *tty)
 {
-	struct asyncppp *ap;
+	struct asyncppp *ap = tty->disc_data;
 
-	write_lock_irq(&disc_data_lock);
-	ap = tty->disc_data;
 	tty->disc_data = NULL;
-	write_unlock_irq(&disc_data_lock);
 	if (!ap)
 		return;
 
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index 0f338752c..53fb68e29 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -129,17 +129,12 @@ ppp_print_buffer (const char *name, const __u8 *buf, int count)
  *
  * FIXME: Fixed in tty_io nowadays.
  */
-static DEFINE_RWLOCK(disc_data_lock);
-
 static struct syncppp *sp_get(struct tty_struct *tty)
 {
-	struct syncppp *ap;
+	struct syncppp *ap = tty->disc_data;
 
-	read_lock(&disc_data_lock);
-	ap = tty->disc_data;
 	if (ap != NULL)
 		refcount_inc(&ap->refcnt);
-	read_unlock(&disc_data_lock);
 	return ap;
 }
 
@@ -213,12 +208,9 @@ ppp_sync_open(struct tty_struct *tty)
 static void
 ppp_sync_close(struct tty_struct *tty)
 {
-	struct syncppp *ap;
+	struct syncppp *ap = tty->disc_data;
 
-	write_lock_irq(&disc_data_lock);
-	ap = tty->disc_data;
 	tty->disc_data = NULL;
-	write_unlock_irq(&disc_data_lock);
 	if (!ap)
 		return;
 
-- 
2.17.1

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

* 答复: [PATCH] net: remove disc_data_lock in =?utf-8?Q?_ppp_line_discipl
  2020-12-28  7:15 [PATCH] net: remove disc_data_lock in ppp line discipline Gao Yan
@ 2020-12-31 10:00 ` Gaoyan
  2021-01-01  1:37 ` [PATCH] net: remove disc_data_lock in ppp line discipline Xie He
  1 sibling, 0 replies; 3+ messages in thread
From: Gaoyan @ 2020-12-31 10:00 UTC (permalink / raw)
  To: paulus, davem, kuba; +Cc: linux-ppp, netdev, linux-kernel

RGVhciBhbGzvvJoNCg0KQ291bGQgSSBnZXQgeW91ciBjb21tZW50cyBmb3IgdGhlIHVwZGF0ZXM/
ICBJZiBJIGNhbiBnZXQgYSByZXBseSwgaXQgd2lsbCBoZWxwIG1lIGEgbG90IC4gVGhhbmtzDQoN
Cmh0dHBzOi8vbGttbC5vcmcvbGttbC8yMDIwLzEyLzI4LzE5DQoNCg0KDQoqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqDQoNCg0KLS0tLU9yaWdpbmFsIG1haWwgLS0tLS0NCuWPkeS7tuS6
ujogZ2FveWFuIChSRCkgDQrlj5HpgIHml7bpl7Q6IDIwMjDlubQxMuaciDI45pelIDE1OjE2DQrm
lLbku7bkuro6IHBhdWx1c0BzYW1iYS5vcmc7IGRhdmVtQGRhdmVtbG9mdC5uZXQ7IGt1YmFAa2Vy
bmVsLm9yZw0K5oqE6YCBOiBsaW51eC1wcHBAdmdlci5rZXJuZWwub3JnOyBuZXRkZXZAdmdlci5r
ZXJuZWwub3JnOyBsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnOyBnYW95YW4gKFJEKSA8Z2Fv
LnlhbkJAaDNjLmNvbT4NCuS4u+mimDogW1BBVENIXSBuZXQ6IHJlbW92ZSBkaXNjX2RhdGFfbG9j
ayBpbiBwcHAgbGluZSBkaXNjaXBsaW5lDQoNCkluIHR0eSBsYXllciwgaXQgdXNlIHR0eS0+bGRp
c2Nfc2VtIHRvIHByb2VjdCB0dHlfbGRpc2Nfb3BzLg0KU28gSSB0aGluayB0dHktPmxkaXNjX3Nl
bSBjYW4gYWxzbyBwcm90ZWN0IHR0eS0+ZGlzY19kYXRhOyBGb3IgZXhhbWxwZSwgV2hlbiBjcHUg
QSBpcyBydW5uaW5nIHBwcF9zeW5jdHR5X2lvY3RsI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5kaXNjX2RhdGE7DQogCWlmIChhcCAhPSBOVUxM
KQ0KIAkJcmVmY291bnRfaW5jKCZhcC0+cmVmY250KTsNCi0JcmVhZF91bmxvY2soJmRpc2NfZGF0
YV9sb2NrKTsNCiAJcmV0dXJuIGFwOw0KIH0NCiANCkBAIC0yMTMsMTIgKzIwOCw5IEBAIHBwcF9z
eW5jX29wZW4oc3RydWN0IHR0eV9zdHJ1Y3QgKnR0eSkgIHN0YXRpYyB2b2lkICBwcHBfc3luY19j
bG9zZShzdHJ1Y3QgdHR5X3N0cnVjdCAqdHR5KSAgew0KLQlzdHJ1Y3Qgc3luY3BwcCAqYXA7DQor
CXN0cnVjdCBzeW5jcHBwICphcCA9IHR0eS0+ZGlzY19kYXRhOw0KIA0KLQl3cml0ZV9sb2NrX2ly
cSgmZGlzY19kYXRhX2xvY2spOw0KLQlhcCA9IHR0eS0+ZGlzY19kYXRhOw0KIAl0dHktPmRpc2Nf
ZGF0YSA9IE5VTEw7DQotCXdyaXRlX3VubG9ja19pcnEoJmRpc2NfZGF0YV9sb2NrKTsNCiAJaWYg
KCFhcCkNCiAJCXJldHVybjsNCiANCi0tDQoyLjE3LjENCg0K

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

* Re: [PATCH] net: remove disc_data_lock in ppp line discipline
  2020-12-28  7:15 [PATCH] net: remove disc_data_lock in ppp line discipline Gao Yan
  2020-12-31 10:00 ` 答复: [PATCH] net: remove disc_data_lock in =?utf-8?Q?_ppp_line_discipl Gaoyan
@ 2021-01-01  1:37 ` Xie He
  1 sibling, 0 replies; 3+ messages in thread
From: Xie He @ 2021-01-01  1:37 UTC (permalink / raw)
  To: Gao Yan; +Cc: paulus, davem, kuba, linux-ppp, netdev, linux-kernel

> In tty layer, it use tty->ldisc_sem to proect tty_ldisc_ops.
> So I think tty->ldisc_sem can also protect tty->disc_data;

It might help by CC'ing TTY people, so that we could get this reviewed by
people who are familiar with TTY code.

Greg Kroah-Hartman <gregkh@linuxfoundation.org> (supporter:TTY LAYER)
Jiri Slaby <jirislaby@kernel.org> (supporter:TTY LAYER)

Thanks!

> For examlpe,
> When cpu A is running ppp_synctty_ioctl that hold the tty->ldisc_sem,
> at the same time  if cpu B calls ppp_synctty_close, it will wait until
> cpu A release tty->ldisc_sem. So I think it is unnecessary to have the
> disc_data_lock;
> 
> cpu A                           cpu B
> tty_ioctl                       tty_reopen
>  ->hold tty->ldisc_sem            ->hold tty->ldisc_sem(write), failed
>  ->ld->ops->ioctl                 ->wait...
>  ->release tty->ldisc_sem         ->wait...OK,hold tty->ldisc_sem
>                                     ->tty_ldisc_reinit
>                                       ->tty_ldisc_close
>                                         ->ld->ops->close

IMHO an example might not be necessary. Examples are useful to show
incorrectness. But we cannot show correctness by examples because
examples are not exhaustive.

BTW, there're some typos:
"proect" -> "protect"
"examlpe" -> "example"
"that hold ..." -> "that holds ..."
"cpu A release ..." -> "cpu A releases ..."

>   * FIXME: this is no longer true. The _close path for the ldisc is
>   * now guaranteed to be sane.
>   */

>   *
>   * FIXME: Fixed in tty_io nowadays.
>   */

Since you are removing "disc_data_lock", please update (or remove) these
two comments. Thanks!

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

end of thread, other threads:[~2021-01-01  1:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28  7:15 [PATCH] net: remove disc_data_lock in ppp line discipline Gao Yan
2020-12-31 10:00 ` 答复: [PATCH] net: remove disc_data_lock in =?utf-8?Q?_ppp_line_discipl Gaoyan
2021-01-01  1:37 ` [PATCH] net: remove disc_data_lock in ppp line discipline Xie He

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).