From patchwork Mon Oct 1 14:41:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622255 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 29B551515 for ; Mon, 1 Oct 2018 14:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10852290FE for ; Mon, 1 Oct 2018 14:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04EEF29437; Mon, 1 Oct 2018 14:42:24 +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 E8E28290FE for ; Mon, 1 Oct 2018 14:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728979AbeJAVUa (ORCPT ); Mon, 1 Oct 2018 17:20:30 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:34962 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729412AbeJAVUa (ORCPT ); Mon, 1 Oct 2018 17:20:30 -0400 Received: by mail-it1-f193.google.com with SMTP id p64-v6so4680342itp.0 for ; Mon, 01 Oct 2018 07:42:21 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=oeW7mAQAuma2z4Ksiuh1ymQUPJ/EAwerpWX/+wfYyVk=; b=WdPhZ3D20b2QtPiC7y2FzzccaCJh0jV86LvGaC803Zf6GONYr82ysC6h8sgZcDWWm+ ZbY9+EQqZ97OJG4Zu/aW21ce6ZV7wIivoZlhWcuetclHuL1TyuV+/W0HhJkkpuIX//7S Yk6VjGhFRysPDYshKkyKnToOHrxS5+oceG8Be9R0HfgeqkLmfPiGsd4TI290IcvJ2zpR m3kWeNe1BjbdO8Hn63b0UWUqT/AFGssOUzuOXvHNfGUCaRNT3IcY9rgOD/ccjKWI8AmJ xoiFrs+gBCWLepKsmuzsUmHnHVRmBnCaOz1jscaiMVE41RKqZQAg8gtDLQnKZAbB4xcX vwEg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=oeW7mAQAuma2z4Ksiuh1ymQUPJ/EAwerpWX/+wfYyVk=; b=XfNckwqfAdMjOXAqfGdkHrCjTwHYvhn5ejnINiHmSEL0Hbdcm0D2j22W2Q1CHCRx4j Tf56W4/V6V317KIHed/U+FwBjyTVb5zUgyVDz4sKwqt6iyPprST16KvIKG1NsDSTHMDj nhirSpjIewuG8rSyOXzRBzzroGAD41GkzuXe5qtN3LDwFHGrkiJ8xQ8JYzWXNeZ6AFru BevM9oQnenumqkO+wgBaQ85C25zt20iior2c2QBpV9YPysQk18G5/M49VOeKpY2osWA5 n5W+MDUES82Zztl4HRLgYJr4kyfqvmpTqMFRYFjxdiuhEPEnbUOk19Y3A6GUC6oIl5Pc /Z5A== X-Gm-Message-State: ABuFfojyNStI+xbBv2J8VSAZQs2F7pVfitTsSKUOIv8v0tkpp1Wd6d3b wT+daidVXYrMEpbGwiTHqA== X-Google-Smtp-Source: ACcGV60utfQLTJa23Br2Tt0qJyAFhjDho30qx9H2mn+3o5xfQIfftRpGp60PD6XCguxT023ZTpcxxA== X-Received: by 2002:a24:6e90:: with SMTP id w138-v6mr10437920itc.50.1538404940823; Mon, 01 Oct 2018 07:42:20 -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 j75-v6sm2055597itj.33.2018.10.01.07.42.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:20 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 01/15] SUNRPC: Remove the server 'authtab_lock' and just use RCU Date: Mon, 1 Oct 2018 10:41:43 -0400 Message-Id: <20181001144157.3515-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-1-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> 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..f83443856cd1 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); + rcu_assign_pointer(authtab[flavor], NULL); } EXPORT_SYMBOL_GPL(svc_auth_unregister);