From patchwork Sat Sep 29 03:10:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10620605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5715112B for ; Sat, 29 Sep 2018 03:11:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B68602B55A for ; Sat, 29 Sep 2018 03:11:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9B322B5CE; Sat, 29 Sep 2018 03:11:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C8492B549 for ; Sat, 29 Sep 2018 03:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727362AbeI2Jhy (ORCPT ); Sat, 29 Sep 2018 05:37:54 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:37470 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbeI2Jhy (ORCPT ); Sat, 29 Sep 2018 05:37:54 -0400 Received: by mail-it1-f194.google.com with SMTP id m9-v6so5141778ita.2 for ; Fri, 28 Sep 2018 20:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ly4RU8z70iWP0f2QroqVOvJgvITj0Stx+qoMDuiZq0A=; b=efbZzfxSnMiZcBP4R4B5g09ST9HaL8gT3Ul9wTvCPMlLUi2Iw+TFnYA45LxbB1t6Wv WtKnd6TqmwL0t11DxaH9G1RgJTSOnUP4DReSRZc6xMfjm5JuECnv156f8bCXL8xrySUt tmLgTkktHchEHosQ3BsMx1qzgy8goOFb+bcUFfZJEwIVN0K0L6k5Uh256rvw7lPN+Jlx x2AponS0NjVmUSKB8/LZAp6JIO9QUoJYfI5oLDktRVC2TCllTYt5+bdV6fzdllp+eEtF yAatO7KF9tXob9K482PH0oAyqupfcExAowr7JrXaNZxlCq4NqH5fQz4W74XYXq3oPj7a FIHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ly4RU8z70iWP0f2QroqVOvJgvITj0Stx+qoMDuiZq0A=; b=qOI/N4dTyF7yXcbA3A8QczhhuVeCfNaSh5RgnbJmA+kyJDCY6cklr3dkpsdM60pvE5 rC+KosVB3b8+E6LmzANaDhi6jadSVDdGj1uIv0b3mxtt3Bn39gPYpnLoadXf/btmxpoa XvKQ1ecpLrtrWB9F+cE0pj6PfUPlF4hvsEdNTH/n+ptafVW4YoVILWmu0Xv0SUt+TMnI b8rDQ/fMRboiPM0Tp1tGKtah4NQ60j0Vum8sTpihMnAVkiELm9s07hRZ43+4K+UtMAkj v4fYWKtRxB2GKxNAUykO4uOQlY+bW0Cm1/7wboIO8BNmvqgAnrNns5tu1xpxympsrcP2 HemA== X-Gm-Message-State: ABuFfohCfW/dzPrjBpXC8mg4kK7JMQEYHK8+GAh3kXvh4ShThpmOD+nY q2WF/YsIscBmrnYeMxCXDs0dxB8= X-Google-Smtp-Source: ACcGV62mY4ZHDvvp5O6LF235dlTRhi67LI5FKAoqxNWnhl0HOEg8n6SD7IGw9vZk4b4SuikiU9wWKw== X-Received: by 2002:a24:9:: with SMTP id 9-v6mr3494451ita.35.1538190670146; Fri, 28 Sep 2018 20:11:10 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id b14-v6sm2270878ioh.47.2018.09.28.20.11.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 20:11:09 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Bruce Fields Cc: linux-nfs@vger.kernel.org Subject: [PATCH] SUNRPC: Remove the server 'authtab_lock' and just use RCU Date: Fri, 28 Sep 2018 23:10:48 -0400 Message-Id: <20180929031048.72121-1-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Module removal is RCU safe by design, so we really have no need to lock the 'authtab[]' array. Signed-off-by: Trond Myklebust --- net/sunrpc/svcauth.c | 52 +++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/net/sunrpc/svcauth.c b/net/sunrpc/svcauth.c index bb8db3cb8032..915bd485b2d9 100644 --- a/net/sunrpc/svcauth.c +++ b/net/sunrpc/svcauth.c @@ -27,12 +27,32 @@ extern struct auth_ops svcauth_null; extern struct auth_ops svcauth_unix; -static DEFINE_SPINLOCK(authtab_lock); -static struct auth_ops *authtab[RPC_AUTH_MAXFLAVOR] = { - [0] = &svcauth_null, - [1] = &svcauth_unix, +static struct auth_ops __rcu *authtab[RPC_AUTH_MAXFLAVOR] = { + [RPC_AUTH_NULL] = (struct auth_ops __force __rcu *)&svcauth_null, + [RPC_AUTH_UNIX] = (struct auth_ops __force __rcu *)&svcauth_unix, }; +static struct auth_ops * +svc_get_auth_ops(rpc_authflavor_t flavor) +{ + struct auth_ops *aops; + + if (flavor >= RPC_AUTH_MAXFLAVOR) + return NULL; + rcu_read_lock(); + aops = rcu_dereference(authtab[flavor]); + if (aops != NULL && !try_module_get(aops->owner)) + aops = NULL; + rcu_read_unlock(); + return aops; +} + +static void +svc_put_auth_ops(struct auth_ops *aops) +{ + module_put(aops->owner); +} + int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp) { @@ -45,14 +65,11 @@ svc_authenticate(struct svc_rqst *rqstp, __be32 *authp) dprintk("svc: svc_authenticate (%d)\n", flavor); - spin_lock(&authtab_lock); - if (flavor >= RPC_AUTH_MAXFLAVOR || !(aops = authtab[flavor]) || - !try_module_get(aops->owner)) { - spin_unlock(&authtab_lock); + aops = svc_get_auth_ops(flavor); + if (aops == NULL) { *authp = rpc_autherr_badcred; return SVC_DENIED; } - spin_unlock(&authtab_lock); rqstp->rq_auth_slack = 0; init_svc_cred(&rqstp->rq_cred); @@ -82,7 +99,7 @@ int svc_authorise(struct svc_rqst *rqstp) if (aops) { rv = aops->release(rqstp); - module_put(aops->owner); + svc_put_auth_ops(aops); } return rv; } @@ -90,13 +107,14 @@ int svc_authorise(struct svc_rqst *rqstp) int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops) { + struct auth_ops *old; int rv = -EINVAL; - spin_lock(&authtab_lock); - if (flavor < RPC_AUTH_MAXFLAVOR && authtab[flavor] == NULL) { - authtab[flavor] = aops; - rv = 0; + + if (flavor < RPC_AUTH_MAXFLAVOR) { + old = cmpxchg((struct auth_ops ** __force)&authtab[flavor], NULL, aops); + if (old == NULL || old == aops) + rv = 0; } - spin_unlock(&authtab_lock); return rv; } EXPORT_SYMBOL_GPL(svc_auth_register); @@ -104,10 +122,8 @@ EXPORT_SYMBOL_GPL(svc_auth_register); void svc_auth_unregister(rpc_authflavor_t flavor) { - spin_lock(&authtab_lock); if (flavor < RPC_AUTH_MAXFLAVOR) - authtab[flavor] = NULL; - spin_unlock(&authtab_lock); + xchg((struct auth_ops ** __force)&authtab[flavor], NULL); } EXPORT_SYMBOL_GPL(svc_auth_unregister);