Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8862702pxu; Sun, 27 Dec 2020 23:30:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjAwmY2RtjwmHKJPYlof7HPgfsj1yur3RikMNX7QySXQKQadloYNXDRQ3UwMsgIFZkR/zq X-Received: by 2002:a50:eb97:: with SMTP id y23mr41238986edr.29.1609140655106; Sun, 27 Dec 2020 23:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609140655; cv=none; d=google.com; s=arc-20160816; b=ovVMbK+cHKSUaeS4ZrDF8lH/HsqKnjboOMj50zRb1RHn8LT08pINSdDafd5QLLmtyP tspZVbXVJ2dXjfISR/lc9nlfpIY9QOwA+3ubf3joxb+zdUGiC9Tg+Dqci0bFzp+kieY7 Y7W8hzP4ETHyelXNpdG+O+xMTu1wAioXQn72SG/AcwlK11P2WQvmHLbLAsDkCzJJiTeZ ewiq+Lr00tFk5z1S+gt3OUXjpeuTBTqaBpKaeCAzljrEhy4gVUQx7BINZUz/hVu5xo3s C2dj2+rAlYf2+H0dxkFCm6++mgkwiV8Vdx6bShQdfD+at9f4HNIC7haYx3Fgeorb+zYN lBxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=T32UBBbAFPCGgRTmIcOIV4OQzoBlRg90htkdUN93dbo=; b=SdeSVkUjJtrPLqSkJFIq53uTf0z0EP6ZK/P1a90ZBhmj2Ln33CZ5fnj9of3zg/kZyW q/9R/CQmOB0HunjmB1jzCaEdtawJD3WeU190DOdkrS6JZfJrHbNGirVfxyDkIhNyD9Fg dwyajWfTZmjUSKV4xKBZUi4pXUsWo9chzBcTO1fQFwGD886n5qf3Edx25WLcTHh/hQGJ aH+Nq+nQRpLXUUxDr8cSimZmkejjDU6ZpjGO68B/b6cueKDrsmffc8ceWfzUvVAgYs/D oHuWGSINRBJJgD+CzgwM/OtzpM5i/7IUgYd3o5hxx1OylaRcxoyhjUDGWB9+gxWWOw/F 9qlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w29si19986909edl.176.2020.12.27.23.30.26; Sun, 27 Dec 2020 23:30:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726388AbgL1H25 (ORCPT + 99 others); Mon, 28 Dec 2020 02:28:57 -0500 Received: from smtp.h3c.com ([60.191.123.50]:29530 "EHLO h3cspam02-ex.h3c.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbgL1H25 (ORCPT ); Mon, 28 Dec 2020 02:28:57 -0500 Received: from DAG2EX08-IDC.srv.huawei-3com.com ([10.8.0.71]) by h3cspam02-ex.h3c.com with ESMTP id 0BS7QSOe066825; Mon, 28 Dec 2020 15:26:28 +0800 (GMT-8) (envelope-from gao.yanB@h3c.com) Received: from localhost.localdomain (10.99.212.201) by DAG2EX08-IDC.srv.huawei-3com.com (10.8.0.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 28 Dec 2020 15:26:30 +0800 From: Gao Yan To: , , CC: , , , Gao Yan Subject: [PATCH] net: remove disc_data_lock in ppp line discipline Date: Mon, 28 Dec 2020 15:15:50 +0800 Message-ID: <20201228071550.15745-1-gao.yanB@h3c.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.99.212.201] X-ClientProxiedBy: BJSMTP02-EX.srv.huawei-3com.com (10.63.20.133) To DAG2EX08-IDC.srv.huawei-3com.com (10.8.0.71) X-DNSRBL: X-MAIL: h3cspam02-ex.h3c.com 0BS7QSOe066825 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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