From patchwork Tue Oct 23 16:34:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10653421 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 80E1214BB for ; Tue, 23 Oct 2018 16:35:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EE3F2A093 for ; Tue, 23 Oct 2018 16:35:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 620EB2A0AA; Tue, 23 Oct 2018 16:35:16 +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 C18C929FBD for ; Tue, 23 Oct 2018 16:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727612AbeJXA7V (ORCPT ); Tue, 23 Oct 2018 20:59:21 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:56101 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJXA7V (ORCPT ); Tue, 23 Oct 2018 20:59:21 -0400 Received: by mail-it1-f195.google.com with SMTP id c23-v6so2630010itd.5 for ; Tue, 23 Oct 2018 09:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=YU3gbjUyPDvjsXqDm9aNeApsNYewl+FJT20atCmnH5M=; b=N7MWQyBwubfxX2m0WXYyr+TAfVnDm2tsxHPMOvGSICgvh6mVd16K/NCcxmZCX/Re8g 6D7adE38JBO5O8Fvbwg3b+K+o3xBTNWwK6Fdcrggpurh6vXSqbHWs9jR9n5PcDaxSHt8 FJxaE7UiQNaXcN6oxfDdh25Uuy3G+ri8BFhPerJ4hkKGNUSGwSBggWuA3MqspP5r8oWD Tl+vboFmNG2Yspz/BqzfK5IEg/6AmP8tmbcsBO6bUrdz478VspFd3NcUKQjcr72PBshU QfdinXlgxt0pMcfgnBBBbZlZ0IVg/QfcweR0WoxHctMScsQuDuDXcYj7j8kthQXsB0Ad cikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=YU3gbjUyPDvjsXqDm9aNeApsNYewl+FJT20atCmnH5M=; b=hBDg8xCSnh5a/4iG9IAIho4h7AFMPa9CX8IiKRK+cukumEfb8nu0UbqNt3J04ExdFn F53mHc4YIFr4sFZjdOT1t/Lmwp/Mdui/YhdheB2XzPWb0OZNTJhwgWkMCbRU5udy0Dr3 LKF+cN9wH0s5mOM6mVT2sDH6DN0tKSscISoBtFuXjvG9ChSmPGKXJvIQVrA6/f4HV7I1 ZUNg7WO63/PQLJGVxDgap0PJwW7mrK4xhCMR8vuff/oehRjWUy0YtGtNTSz3vtypMOXI TO2iex54jpsSzmtx1YhJjFZ5jwixiL1gBy1Zy9dJdmab8aC1g7C6VzjDYUAgF/O3L3Kn 7EDQ== X-Gm-Message-State: ABuFfojnJjEl7gb6pCprN8NRYrnZ+/pg+YkcZT2K77rv8ULf3EGGNCqq DQGLkDHnjWP/utua0WLyT8AIdo0= X-Google-Smtp-Source: ACcGV62DsM6yNX2Bva4sObUZuJZW2nqR6JvcDHHXdPG7gt8v80Ga2gdqqdQLQ+kLZ97EeUv3uFq8AQ== X-Received: by 2002:a02:5f5a:: with SMTP id r87-v6mr38720411jab.22.1540312512909; Tue, 23 Oct 2018 09:35:12 -0700 (PDT) Received: from localhost.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id w20-v6sm573065ioa.82.2018.10.23.09.35.11 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 09:35:12 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 1/4] SUNRPC: Clean up the AUTH cache code Date: Tue, 23 Oct 2018 12:34:01 -0400 Message-Id: <20181023163404.27777-1-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.2 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 Signed-off-by: Trond Myklebust Signed-off-by: Dan Aloni Signed-off-by: Dan Aloni --- net/sunrpc/auth.c | 147 ++++++++++++++++++++++++----------------- net/sunrpc/auth_null.c | 2 +- 2 files changed, 87 insertions(+), 62 deletions(-) diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 32985aa515be..c1576b110974 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -291,25 +291,30 @@ rpcauth_release(struct rpc_auth *auth) static DEFINE_SPINLOCK(rpc_credcache_lock); -static void +/* + * On success, the caller is responsible for freeing the reference + * held by the hashtable + */ +static bool rpcauth_unhash_cred_locked(struct rpc_cred *cred) { + if (!test_and_clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags)) + return false; hlist_del_rcu(&cred->cr_hash); - smp_mb__before_atomic(); - clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags); + return true; } -static int +static bool rpcauth_unhash_cred(struct rpc_cred *cred) { spinlock_t *cache_lock; - int ret; + bool ret; + if (!test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags)) + return false; cache_lock = &cred->cr_auth->au_credcache->lock; spin_lock(cache_lock); - ret = atomic_read(&cred->cr_count) == 0; - if (ret) - rpcauth_unhash_cred_locked(cred); + ret = rpcauth_unhash_cred_locked(cred); spin_unlock(cache_lock); return ret; } @@ -388,6 +393,44 @@ void rpcauth_destroy_credlist(struct list_head *head) } } +static void +rpcauth_lru_add_locked(struct rpc_cred *cred) +{ + if (!list_empty(&cred->cr_lru)) + return; + number_cred_unused++; + list_add_tail(&cred->cr_lru, &cred_unused); +} + +static void +rpcauth_lru_add(struct rpc_cred *cred) +{ + if (!list_empty(&cred->cr_lru)) + return; + spin_lock(&rpc_credcache_lock); + rpcauth_lru_add_locked(cred); + spin_unlock(&rpc_credcache_lock); +} + +static void +rpcauth_lru_remove_locked(struct rpc_cred *cred) +{ + if (list_empty(&cred->cr_lru)) + return; + number_cred_unused--; + list_del_init(&cred->cr_lru); +} + +static void +rpcauth_lru_remove(struct rpc_cred *cred) +{ + if (list_empty(&cred->cr_lru)) + return; + spin_lock(&rpc_credcache_lock); + rpcauth_lru_remove_locked(cred); + spin_unlock(&rpc_credcache_lock); +} + /* * Clear the RPC credential cache, and delete those credentials * that are not referenced. @@ -407,13 +450,10 @@ rpcauth_clear_credcache(struct rpc_cred_cache *cache) head = &cache->hashtable[i]; while (!hlist_empty(head)) { cred = hlist_entry(head->first, struct rpc_cred, cr_hash); - get_rpccred(cred); - if (!list_empty(&cred->cr_lru)) { - list_del(&cred->cr_lru); - number_cred_unused--; - } - list_add_tail(&cred->cr_lru, &free); rpcauth_unhash_cred_locked(cred); + /* Note: We now hold a reference to cred */ + rpcauth_lru_remove_locked(cred); + list_add_tail(&cred->cr_lru, &free); } } spin_unlock(&cache->lock); @@ -447,7 +487,6 @@ EXPORT_SYMBOL_GPL(rpcauth_destroy_credcache); static long rpcauth_prune_expired(struct list_head *free, int nr_to_scan) { - spinlock_t *cache_lock; struct rpc_cred *cred, *next; unsigned long expired = jiffies - RPC_AUTH_EXPIRY_MORATORIUM; long freed = 0; @@ -456,32 +495,24 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan) if (nr_to_scan-- == 0) break; + if (atomic_read(&cred->cr_count) > 1) { + rpcauth_lru_remove_locked(cred); + continue; + } /* * Enforce a 60 second garbage collection moratorium * Note that the cred_unused list must be time-ordered. */ - if (time_in_range(cred->cr_expire, expired, jiffies) && - test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) { - freed = SHRINK_STOP; - break; - } - - list_del_init(&cred->cr_lru); - number_cred_unused--; - freed++; - if (atomic_read(&cred->cr_count) != 0) + if (!time_in_range(cred->cr_expire, expired, jiffies)) + continue; + if (!rpcauth_unhash_cred(cred)) continue; - cache_lock = &cred->cr_auth->au_credcache->lock; - spin_lock(cache_lock); - if (atomic_read(&cred->cr_count) == 0) { - get_rpccred(cred); - list_add_tail(&cred->cr_lru, free); - rpcauth_unhash_cred_locked(cred); - } - spin_unlock(cache_lock); + rpcauth_lru_remove_locked(cred); + freed++; + list_add_tail(&cred->cr_lru, free); } - return freed; + return freed ? freed : SHRINK_STOP; } static unsigned long @@ -595,6 +626,7 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred, if (cred == NULL) { cred = new; set_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags); + atomic_inc(&cred->cr_count); hlist_add_head_rcu(&cred->cr_hash, &cache->hashtable[nr]); } else list_add_tail(&new->cr_lru, &free); @@ -709,36 +741,29 @@ put_rpccred(struct rpc_cred *cred) { if (cred == NULL) return; - /* Fast path for unhashed credentials */ - if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) == 0) { + rcu_read_lock(); + if (atomic_dec_and_test(&cred->cr_count)) + goto destroy; + if (atomic_read(&cred->cr_count) != 1 || + !test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags)) + goto out; + if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0) { + cred->cr_expire = jiffies; + rpcauth_lru_add(cred); + /* Race breaker */ + if (unlikely(!test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags))) + rpcauth_lru_remove(cred); + } else if (rpcauth_unhash_cred(cred)) { + rpcauth_lru_remove(cred); if (atomic_dec_and_test(&cred->cr_count)) - cred->cr_ops->crdestroy(cred); - return; - } - - if (!atomic_dec_and_lock(&cred->cr_count, &rpc_credcache_lock)) - return; - if (!list_empty(&cred->cr_lru)) { - number_cred_unused--; - list_del_init(&cred->cr_lru); - } - if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) { - if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0) { - cred->cr_expire = jiffies; - list_add_tail(&cred->cr_lru, &cred_unused); - number_cred_unused++; - goto out_nodestroy; - } - if (!rpcauth_unhash_cred(cred)) { - /* We were hashed and someone looked us up... */ - goto out_nodestroy; - } + goto destroy; } - spin_unlock(&rpc_credcache_lock); - cred->cr_ops->crdestroy(cred); +out: + rcu_read_unlock(); return; -out_nodestroy: - spin_unlock(&rpc_credcache_lock); +destroy: + rcu_read_unlock(); + cred->cr_ops->crdestroy(cred); } EXPORT_SYMBOL_GPL(put_rpccred); diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c index 4b48228ee8c7..a7c00b4959f3 100644 --- a/net/sunrpc/auth_null.c +++ b/net/sunrpc/auth_null.c @@ -138,6 +138,6 @@ struct rpc_cred null_cred = { .cr_lru = LIST_HEAD_INIT(null_cred.cr_lru), .cr_auth = &null_auth, .cr_ops = &null_credops, - .cr_count = ATOMIC_INIT(1), + .cr_count = ATOMIC_INIT(2), .cr_flags = 1UL << RPCAUTH_CRED_UPTODATE, }; From patchwork Tue Oct 23 16:34:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10653423 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 E168C1709 for ; Tue, 23 Oct 2018 16:35:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3CEB29FBD for ; Tue, 23 Oct 2018 16:35:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7FE02A0AA; Tue, 23 Oct 2018 16:35:16 +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 6D5CC29FBD for ; Tue, 23 Oct 2018 16:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728225AbeJXA7W (ORCPT ); Tue, 23 Oct 2018 20:59:22 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:50831 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJXA7W (ORCPT ); Tue, 23 Oct 2018 20:59:22 -0400 Received: by mail-it1-f196.google.com with SMTP id k206-v6so2652079ite.0 for ; Tue, 23 Oct 2018 09:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8Z3o4QM1IxOGWHcDKPR0hMPuASNpttKTaXdBXsxzMn0=; b=A+eHMo7ojTfVFdEZaSBeb21u4l87+aXjnJf1EfRSrobOj0HhfEoQ/+zC0L40t0s3Ud valWQAervBomD1BIhWfa4RPWVw3WnHvjYqhXkyojEDkFyXBwi++5cay7PBK8OuWnymTm tv5b+lyd0HJD//IFCWg4xoS1ff1RnJMRRZpgSmwVZpi4mns9Eo/S0yIo7f32LNIhvxd8 lhHcxrq1WbGrLgfzilxp3+UnltGapUybJNQ12WLtnXIDkEKBBlrJDmvNQanXFhbBbu/9 dvFruFhaOqX208j9a3Dvw31s8MlQspAl1GpCFgiDpm0vbX0JP8jn19dmHAgywO0pALK5 dZWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Z3o4QM1IxOGWHcDKPR0hMPuASNpttKTaXdBXsxzMn0=; b=gB8vCglh1ASnde33DOlokWvDjnwD89Ocb3ZkglyHIKCJNeiN5wTj5wdnnFjFRu69W5 DipsS1bZxRx/jrUu5t34u8Pxkwo2D5dSxMmZychwNXibXQU6mB1zOt30iZ9wsm9vg8lN xS7Ma5I7/vGePGAfWaqeyzdXCRaR9LECx5fr51/IiPKp9HqGHC3llgPlCAAj408t5IRb Ub3/FxS+2/aX3wZyuExBHcHr8epi3raComg9nVqYlEnTjg9WSfKRbDklyDm9shbhRIBa jA97Q7Ht3RkuzlKQWQBYE6WOmHpJi0NZYoohgejuuzf5eJN7EiBvA7bqX6TLOJJSooIr gdqQ== X-Gm-Message-State: ABuFfohQgndFcfXB4tUOlqlJo+9im6I0pwa06J78Q0we41N/zYeq1305 ZpCOwIkZ96rl4uA7GMwdE18Lui0= X-Google-Smtp-Source: ACcGV62rBOXL7D+/kg4G6mUVNmXdc6ndVXI8JnLb5Y2qfpixrF8qt6zaAaZ/SXsWtKTRyf2fBlWzeA== X-Received: by 2002:a02:764c:: with SMTP id z73-v6mr4231401jab.73.1540312514179; Tue, 23 Oct 2018 09:35:14 -0700 (PDT) Received: from localhost.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id w20-v6sm573065ioa.82.2018.10.23.09.35.13 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 09:35:13 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 2/4] SUNRPC: Simplify lookup code Date: Tue, 23 Oct 2018 12:34:02 -0400 Message-Id: <20181023163404.27777-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181023163404.27777-1-trond.myklebust@hammerspace.com> References: <20181023163404.27777-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 We no longer need to worry about whether or not the entry is hashed in order to figure out if the contents are valid. We only care whether or not the refcount is non-zero. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/auth.h | 12 +++++------- net/sunrpc/auth.c | 19 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h index 2c97a3933ef9..a7fc8f5a2dad 100644 --- a/include/linux/sunrpc/auth.h +++ b/include/linux/sunrpc/auth.h @@ -206,11 +206,11 @@ bool rpcauth_cred_key_to_expire(struct rpc_auth *, struct rpc_cred *); char * rpcauth_stringify_acceptor(struct rpc_cred *); static inline -struct rpc_cred * get_rpccred(struct rpc_cred *cred) +struct rpc_cred *get_rpccred(struct rpc_cred *cred) { - if (cred != NULL) - atomic_inc(&cred->cr_count); - return cred; + if (cred != NULL && atomic_inc_not_zero(&cred->cr_count)) + return cred; + return NULL; } /** @@ -226,9 +226,7 @@ struct rpc_cred * get_rpccred(struct rpc_cred *cred) static inline struct rpc_cred * get_rpccred_rcu(struct rpc_cred *cred) { - if (atomic_inc_not_zero(&cred->cr_count)) - return cred; - return NULL; + return get_rpccred(cred); } #endif /* __KERNEL__ */ diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index c1576b110974..77748e572686 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -588,19 +588,15 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred, if (!entry->cr_ops->crmatch(acred, entry, flags)) continue; if (flags & RPCAUTH_LOOKUP_RCU) { - if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) && - !test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags)) - cred = entry; + if (test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags) || + atomic_read(&entry->cr_count) == 0) + continue; + cred = entry; break; } - spin_lock(&cache->lock); - if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) == 0) { - spin_unlock(&cache->lock); - continue; - } cred = get_rpccred(entry); - spin_unlock(&cache->lock); - break; + if (cred) + break; } rcu_read_unlock(); @@ -621,7 +617,8 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred, if (!entry->cr_ops->crmatch(acred, entry, flags)) continue; cred = get_rpccred(entry); - break; + if (cred) + break; } if (cred == NULL) { cred = new; From patchwork Tue Oct 23 16:34:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10653425 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 EB07514BB for ; Tue, 23 Oct 2018 16:35:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDAF92A093 for ; Tue, 23 Oct 2018 16:35:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1C2D2A0B6; Tue, 23 Oct 2018 16:35:17 +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 5A7D42A093 for ; Tue, 23 Oct 2018 16:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728259AbeJXA7X (ORCPT ); Tue, 23 Oct 2018 20:59:23 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:53029 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJXA7X (ORCPT ); Tue, 23 Oct 2018 20:59:23 -0400 Received: by mail-it1-f196.google.com with SMTP id 134-v6so2647745itz.2 for ; Tue, 23 Oct 2018 09:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=AGzVrNyvQxT4e0ShzHAkd+qHSRExjetCeA7b4UwYbFg=; b=ChntdTfZEBSY6WGZFG6ss2EWLMIpn9rz4Hauerh6QVplSRzCUZxOPBoR1SyI7+I4wf sxTTaOfLUwi0oY1waStwd2kuxq5tKtKKLxs2+GFfoM5bL1VKLz46YjooG+Y8Qrd/4RxK Rzi+Jv5DuHpNmeSRHQoygxXAwZ68+dAzK9GGxKac9WQkEgHSvAFVxFLdFPjLfDNIJYt1 7S0mtc1L6B3aLWbCA/6sniZuKkfZpjHYw9FFYn1IHK9q+ejp6Vu0UPYRJkxRMoV7+1QD +YyJw5+6drLpl+7p8ZddxrM77PdaFNv6keP6bUJZDlLEtKRMlAR62Gh9iVwxw2UdFKNj 1t8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AGzVrNyvQxT4e0ShzHAkd+qHSRExjetCeA7b4UwYbFg=; b=SUrIS+3PlRzOBlU3ChVLtqi7tR8BCVjR4/DBWL/NZyuWbsPbB/AhMr+/ehNyT4M6JB ETFgysrF0B2j3fXqvNkhTa4mZrvoJkwa3O98rgBcZ8BzDp6ekGPAZO6thsp9EmPxmluf hNr4UljnENyCAf210car8bu3pu16hMGuZSqUkkjmFHWewnwFZqBRfp8+FvirQkEDZfHV tcbz77uEJxZlugB/JsvovFwfRaRn9HklYVTt1aIsHVfRpqITj579f0mJoEvpOUBb1tG4 9ZillelNbStadqdvs6mkWpmyXllaPio4bwALj/2aYHq0zZyxWZSWHDfUCL1kAZcQRnT/ 9DYQ== X-Gm-Message-State: ABuFfojx5CRWp1WmvdXnx8952UO+YOluPT7rUS8dfHbkGfpnzSvQspHe b5LE1UQItUzP+1mzZQK1mKQahTo= X-Google-Smtp-Source: ACcGV62Mb+014WVeY5QKxEqdiPS0cxA9302yFRh0hnVpWZKs7+98C/ekxtwaSsr/ZWoWwzyW/8L9cQ== X-Received: by 2002:a24:9b83:: with SMTP id o125-v6mr6741755itd.66.1540312514968; Tue, 23 Oct 2018 09:35:14 -0700 (PDT) Received: from localhost.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id w20-v6sm573065ioa.82.2018.10.23.09.35.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 09:35:14 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 3/4] SUNRPC: Convert auth creds to use refcount_t Date: Tue, 23 Oct 2018 12:34:03 -0400 Message-Id: <20181023163404.27777-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181023163404.27777-2-trond.myklebust@hammerspace.com> References: <20181023163404.27777-1-trond.myklebust@hammerspace.com> <20181023163404.27777-2-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 Signed-off-by: Trond Myklebust --- include/linux/sunrpc/auth.h | 4 ++-- net/sunrpc/auth.c | 14 +++++++------- net/sunrpc/auth_null.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h index a7fc8f5a2dad..a71d4bd191e7 100644 --- a/include/linux/sunrpc/auth.h +++ b/include/linux/sunrpc/auth.h @@ -67,7 +67,7 @@ struct rpc_cred { const struct rpc_credops *cr_ops; unsigned long cr_expire; /* when to gc */ unsigned long cr_flags; /* various flags */ - atomic_t cr_count; /* ref count */ + refcount_t cr_count; /* ref count */ kuid_t cr_uid; @@ -208,7 +208,7 @@ char * rpcauth_stringify_acceptor(struct rpc_cred *); static inline struct rpc_cred *get_rpccred(struct rpc_cred *cred) { - if (cred != NULL && atomic_inc_not_zero(&cred->cr_count)) + if (cred != NULL && refcount_inc_not_zero(&cred->cr_count)) return cred; return NULL; } diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 77748e572686..4903eda5dd61 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -495,7 +495,7 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan) if (nr_to_scan-- == 0) break; - if (atomic_read(&cred->cr_count) > 1) { + if (refcount_read(&cred->cr_count) > 1) { rpcauth_lru_remove_locked(cred); continue; } @@ -589,7 +589,7 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred, continue; if (flags & RPCAUTH_LOOKUP_RCU) { if (test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags) || - atomic_read(&entry->cr_count) == 0) + refcount_read(&entry->cr_count) == 0) continue; cred = entry; break; @@ -623,7 +623,7 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred, if (cred == NULL) { cred = new; set_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags); - atomic_inc(&cred->cr_count); + refcount_inc(&cred->cr_count); hlist_add_head_rcu(&cred->cr_hash, &cache->hashtable[nr]); } else list_add_tail(&new->cr_lru, &free); @@ -670,7 +670,7 @@ rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred, { INIT_HLIST_NODE(&cred->cr_hash); INIT_LIST_HEAD(&cred->cr_lru); - atomic_set(&cred->cr_count, 1); + refcount_set(&cred->cr_count, 1); cred->cr_auth = auth; cred->cr_ops = ops; cred->cr_expire = jiffies; @@ -739,9 +739,9 @@ put_rpccred(struct rpc_cred *cred) if (cred == NULL) return; rcu_read_lock(); - if (atomic_dec_and_test(&cred->cr_count)) + if (refcount_dec_and_test(&cred->cr_count)) goto destroy; - if (atomic_read(&cred->cr_count) != 1 || + if (refcount_read(&cred->cr_count) != 1 || !test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags)) goto out; if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0) { @@ -752,7 +752,7 @@ put_rpccred(struct rpc_cred *cred) rpcauth_lru_remove(cred); } else if (rpcauth_unhash_cred(cred)) { rpcauth_lru_remove(cred); - if (atomic_dec_and_test(&cred->cr_count)) + if (refcount_dec_and_test(&cred->cr_count)) goto destroy; } out: diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c index a7c00b4959f3..ea816d7000a4 100644 --- a/net/sunrpc/auth_null.c +++ b/net/sunrpc/auth_null.c @@ -138,6 +138,6 @@ struct rpc_cred null_cred = { .cr_lru = LIST_HEAD_INIT(null_cred.cr_lru), .cr_auth = &null_auth, .cr_ops = &null_credops, - .cr_count = ATOMIC_INIT(2), + .cr_count = REFCOUNT_INIT(2), .cr_flags = 1UL << RPCAUTH_CRED_UPTODATE, }; From patchwork Tue Oct 23 16:34:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10653427 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 211A914BB for ; Tue, 23 Oct 2018 16:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 138DA2A093 for ; Tue, 23 Oct 2018 16:35:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07AC42A0B6; Tue, 23 Oct 2018 16:35:19 +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 810742A093 for ; Tue, 23 Oct 2018 16:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728270AbeJXA7Y (ORCPT ); Tue, 23 Oct 2018 20:59:24 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:41255 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJXA7Y (ORCPT ); Tue, 23 Oct 2018 20:59:24 -0400 Received: by mail-io1-f65.google.com with SMTP id q4-v6so1277505iob.8 for ; Tue, 23 Oct 2018 09:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=A7VqkDtVWSBBm7nEzV3r4sy8vlNe3DgqVll3Xu3cCMg=; b=UOGwD/4q7IQCT+yCvHbUWeZFmg3bYGE9nB6VsWd5TburQrK78MhHYichyQXI3yAi1u 8JaBwQAsRUrJ9dGSd4Ag6gowMMi8VxTjUiCGOq0DA+2etfu9VNNc2rw9FhqIcSc+AyVO TmiqK5F3X2ZeoF+qeQBObtVc/oInhzYAwR81tn9ZCmo3pR25uLjo91evQWAC0QEfoB5V ZsMysN6SV0wqZwnTOX4z2hE3WYug/aShS8GqHaBABMARTKj2+Vp2Cecx5w44CZQG0s78 bKOW28rgDl3keCQB4ax/GN4FClcC1cYe35aEL4PQxvycA5+dD8yoU9TSnfD3eUMQPJbr dKfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A7VqkDtVWSBBm7nEzV3r4sy8vlNe3DgqVll3Xu3cCMg=; b=TseRUDpWglm1ZHFiD1ZSH/gOevuvg8VOgABIeRkkQ1bmw5uvHgYci8Gnu9ICeOs4eh TmxRS5T+5PBR79JFbiBIgEOidTYelKQ88sHze3WL22097G2qhokrE9iQdOc2WHdD8pDO xAggj5cYOJYg8o0jydRiHpFqkpexWYp/QFMBbwGgCrk4jALDpWLPY3Co6W5zcsiVr7E3 wRKe2xc3YhyO8KrE4NgfNz7l77H4Jn6Om8WtQvN4yL4H/2laDAt0bTS1yWJKpf+6Xifr byJo4TMWWpCzkXDZhEE/8dyJh2PDwNvqbsmX15ngcpleLl5Tw5xWw2lr+DTygYpvrGx9 hXtw== X-Gm-Message-State: AGRZ1gIhzh7L7USvMu7a+hSKw1HhqBiWP7Vzz1vVQpvMcb54UlTTzqFx 4M4/QmEa/nYup3LVvgN/kQL8cP4= X-Google-Smtp-Source: AJdET5doa9ydGgeHCyO5Fevf7DLlDcoz4iGDNhzDYXdK/83LTLoU2BRpkyTSDTV/c0nNn5zb8Ofrhw== X-Received: by 2002:a6b:de1a:: with SMTP id v26-v6mr11033042iog.86.1540312516151; Tue, 23 Oct 2018 09:35:16 -0700 (PDT) Received: from localhost.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id w20-v6sm573065ioa.82.2018.10.23.09.35.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 09:35:15 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 4/4] SUNRPC: Convert the auth cred cache to use refcount_t Date: Tue, 23 Oct 2018 12:34:04 -0400 Message-Id: <20181023163404.27777-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181023163404.27777-3-trond.myklebust@hammerspace.com> References: <20181023163404.27777-1-trond.myklebust@hammerspace.com> <20181023163404.27777-2-trond.myklebust@hammerspace.com> <20181023163404.27777-3-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 Signed-off-by: Trond Myklebust --- include/linux/sunrpc/auth.h | 2 +- net/sunrpc/auth.c | 2 +- net/sunrpc/auth_generic.c | 2 +- net/sunrpc/auth_gss/auth_gss.c | 4 ++-- net/sunrpc/auth_null.c | 4 ++-- net/sunrpc/auth_unix.c | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h index a71d4bd191e7..c4db9424b63b 100644 --- a/include/linux/sunrpc/auth.h +++ b/include/linux/sunrpc/auth.h @@ -100,7 +100,7 @@ struct rpc_auth { * differ from the flavor in * au_ops->au_flavor in gss * case) */ - atomic_t au_count; /* Reference counter */ + refcount_t au_count; /* Reference counter */ struct rpc_cred_cache * au_credcache; /* per-flavor data */ diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 4903eda5dd61..ad8ead738981 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -284,7 +284,7 @@ EXPORT_SYMBOL_GPL(rpcauth_create); void rpcauth_release(struct rpc_auth *auth) { - if (!atomic_dec_and_test(&auth->au_count)) + if (!refcount_dec_and_test(&auth->au_count)) return; auth->au_ops->destroy(auth); } diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c index f1df9837f1ac..d8831b988b1e 100644 --- a/net/sunrpc/auth_generic.c +++ b/net/sunrpc/auth_generic.c @@ -274,7 +274,7 @@ static const struct rpc_authops generic_auth_ops = { static struct rpc_auth generic_auth = { .au_ops = &generic_auth_ops, - .au_count = ATOMIC_INIT(0), + .au_count = REFCOUNT_INIT(1), }; static bool generic_key_to_expire(struct rpc_cred *cred) diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c index c898a7c75e84..30f970cdc7f6 100644 --- a/net/sunrpc/auth_gss/auth_gss.c +++ b/net/sunrpc/auth_gss/auth_gss.c @@ -1058,7 +1058,7 @@ gss_create_new(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt) auth->au_flavor = flavor; if (gss_pseudoflavor_to_datatouch(gss_auth->mech, flavor)) auth->au_flags |= RPCAUTH_AUTH_DATATOUCH; - atomic_set(&auth->au_count, 1); + refcount_set(&auth->au_count, 1); kref_init(&gss_auth->kref); err = rpcauth_init_credcache(auth); @@ -1187,7 +1187,7 @@ gss_auth_find_or_add_hashed(const struct rpc_auth_create_args *args, if (strcmp(gss_auth->target_name, args->target_name)) continue; } - if (!atomic_inc_not_zero(&gss_auth->rpc_auth.au_count)) + if (!refcount_inc_not_zero(&gss_auth->rpc_auth.au_count)) continue; goto out; } diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c index ea816d7000a4..2694a1bc026b 100644 --- a/net/sunrpc/auth_null.c +++ b/net/sunrpc/auth_null.c @@ -21,7 +21,7 @@ static struct rpc_cred null_cred; static struct rpc_auth * nul_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt) { - atomic_inc(&null_auth.au_count); + refcount_inc(&null_auth.au_count); return &null_auth; } @@ -119,7 +119,7 @@ struct rpc_auth null_auth = { .au_flags = RPCAUTH_AUTH_NO_CRKEY_TIMEOUT, .au_ops = &authnull_ops, .au_flavor = RPC_AUTH_NULL, - .au_count = ATOMIC_INIT(0), + .au_count = REFCOUNT_INIT(1), }; static diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c index 185e56d4f9ae..4c1c7e56288f 100644 --- a/net/sunrpc/auth_unix.c +++ b/net/sunrpc/auth_unix.c @@ -34,7 +34,7 @@ unx_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt) { dprintk("RPC: creating UNIX authenticator for client %p\n", clnt); - atomic_inc(&unix_auth.au_count); + refcount_inc(&unix_auth.au_count); return &unix_auth; } @@ -239,7 +239,7 @@ struct rpc_auth unix_auth = { .au_flags = RPCAUTH_AUTH_NO_CRKEY_TIMEOUT, .au_ops = &authunix_ops, .au_flavor = RPC_AUTH_UNIX, - .au_count = ATOMIC_INIT(0), + .au_count = REFCOUNT_INIT(1), }; static