Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp987765pxj; Fri, 21 May 2021 03:58:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/u6oY1aJVKnI4f1oFmgoDFrmvZGvCxKh1EPOeyWXBr3xB57Z17/s7O/sxSRN9KNXgjE5l X-Received: by 2002:a17:907:2bf4:: with SMTP id gv52mr9603437ejc.271.1621594722943; Fri, 21 May 2021 03:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621594722; cv=none; d=google.com; s=arc-20160816; b=GLdNFjRmLPuPVzA00USqSqSHacwIGxU7Zzi2TmVO1WXi+uawR+jydcyjXJUrEBwXH+ 4XD1qusC2HbCJsow8RKV3GsAntTc+uxaKpvOQf2Jmp31LEqRtKmRj6AvEctEqDgbtNL4 2uRrTqIqPdxCsvvT/O44ga/Dv4oBy3T8H9T7IHLASwHvqSk9wJUwjxUVmIN08KtZ3iBY qZhw1R8qjcKkcR7XY0kjMPz/71zl4N3CEAYHdSgdD/lgiRZj7KvPikXrM9tKUrHqNl+0 f3zReIozXxfqh7/L4qBIdV0YJQ+Gpq/oghxryJSgPwGSvAT+sly+jWw2hDrKro6ZxYER Er/w== 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=/WOkzko59ZoeplUcGaGv6z7uNc1zbqjXgBWVfTdfOCQ=; b=EUeZnQO2DFabjvJHbUcUYtx/svwAkodwPPs3wvnGTLBI/6FEk2cmibgt6s52DEDrpL r+QwXME9dEgtNZmpRQuhdXVrarsDbe8Ay3fXtwO2mGMEf/jBDQLk4xEc/OrwR12jXGmP qaqEApWC+yn5iKbp/L0JDgjRmnyEcJkrMxOjwLvLAFQ9q6mV7m3/0tCZVHL8ZOtF87it gSoL5dZGvGDk7rXikyKQQ9khY2F7wMlGUjmzrBIekl0EKAUQ0H2JCMBS3RTyuyXg7k16 Wl54qMF+MURm+UAx60V+M4UbisZcfJodZBHLsyleoKUEOxCH9hbsOf/3581mFBVIQ/FY /A3Q== 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 p25si5103535ejf.696.2021.05.21.03.58.19; Fri, 21 May 2021 03:58:42 -0700 (PDT) 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 S236275AbhEUJXg (ORCPT + 99 others); Fri, 21 May 2021 05:23:36 -0400 Received: from smtp.h3c.com ([60.191.123.50]:19527 "EHLO h3cspam02-ex.h3c.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236200AbhEUJXc (ORCPT ); Fri, 21 May 2021 05:23:32 -0400 X-Greylist: delayed 4098 seconds by postgrey-1.27 at vger.kernel.org; Fri, 21 May 2021 05:23:31 EDT Received: from h3cspam02-ex.h3c.com (localhost [127.0.0.2] (may be forged)) by h3cspam02-ex.h3c.com with ESMTP id 14L8Dl6V037338 for ; Fri, 21 May 2021 16:13:47 +0800 (GMT-8) (envelope-from gao.yanB@h3c.com) Received: from DAG2EX08-IDC.srv.huawei-3com.com ([10.8.0.71]) by h3cspam02-ex.h3c.com with ESMTP id 14L8D35d035940; Fri, 21 May 2021 16:13:03 +0800 (GMT-8) (envelope-from gao.yanB@h3c.com) Received: from localhost.localdomain (10.99.222.162) 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.2242.4; Fri, 21 May 2021 16:13:05 +0800 From: Gao Yan To: , , , , , CC: Gao Yan Subject: [PATCH] net: remove unnecessary disc_data_lock in ppp line discipline Date: Fri, 21 May 2021 15:57:26 +0800 Message-ID: <20210521075726.20568-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.222.162] 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 14L8Dl6V037338 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In tty layer, it use tty->ldisc_sem(using tty_ldisc_ref_wait and tty_ldisc_deref) 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 define additional 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 | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c index 8b41aa3fb..7bc4846f5 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 576b6a93b..812f309c5 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -129,17 +129,13 @@ 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 +209,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