Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6367937imu; Sun, 2 Dec 2018 16:33:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vs2VpAAc4c3vJrwfGDs1bW/MNGZ3pmcXQWd9DQbTWVZiBNMb5K5T0iQ/aCRETMysI+BLx5 X-Received: by 2002:aa7:81d0:: with SMTP id c16mr13743146pfn.153.1543797192189; Sun, 02 Dec 2018 16:33:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543797192; cv=none; d=google.com; s=arc-20160816; b=gP/cik3OnT1A8T7VUggrFYliVge6I9B8UfrihABCnWQBNs37yWsX8hgDeXV8K2N2vf Z7Q7wvMg4zpFLH7qHtbJiG85ISHPK/+t2iJ9t5Dm6iJA3sG7TeGJToSiNWqN9BDK4Sdl 5Al0nBEGYsUSriuxfE+6trv2rV1PNxfIr60HkWlo+MnJA3apiBP+kZD22cNxXd8lzIOb 9qmcS9EWWkH3B2+PW7oXcyn2y2u5Mkbsc6QtG8nx2NNA/MNhOJtRU/EdrVncyB+pfFK3 6U8fE544cy7qgzDB3KQj2PWCCkSdmlz/0f8IqULDxh5qSSydcGuzp3bRYXfWOusJeSLx tKJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from; bh=XmK0Ut5HhedWuRyf/+XuOAxrNa68zeMXYryMWkx4jyQ=; b=HKyOl/To9DZDPrJ9NTykWWvAOkIWSShIc+S6RQGXrfo5/LTYDWIgV7P59MCOBDUFNT lhdlaEFzgnZnviVuFAF31KJGTocRSJkMwhyuiqCqZf6rFF81p6dKNojsH1G5sd/P6pAd ktgrkELAT4MVV2A5WyOW3Oy6RYcrZylPLW9JNBxFQnQGGgWaKi/jL9vzkaAzyVrZwGvz NGSqsXM0/iR6Wdp8hi3nYqSjqN9UGA/Mg6O5d7VfFMBff9XoqKAZDvZwggXkgv2SlY4D JX8bdSnby6Zw/R0/H20B4Jl48gi3oel4wytlu/zVgc9+DDo29a9UyEKq/dhh/iIIw/bE ON6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si12887191pfb.178.2018.12.02.16.32.57; Sun, 02 Dec 2018 16:33:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725917AbeLCAcP (ORCPT + 99 others); Sun, 2 Dec 2018 19:32:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:40824 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725785AbeLCAcO (ORCPT ); Sun, 2 Dec 2018 19:32:14 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E2EDFADBF; Mon, 3 Dec 2018 00:32:08 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Chuck Lever , Jeff Layton , Trond Myklebust , Anna Schumaker Date: Mon, 03 Dec 2018 11:30:30 +1100 Subject: [PATCH 02/23] cred: add get_cred_rcu() Cc: Linux NFS Mailing List , linux-kernel@vger.kernel.org Message-ID: <154379703011.28598.13362863726888068035.stgit@noble> In-Reply-To: <154379689752.28598.6750646657534626618.stgit@noble> References: <154379689752.28598.6750646657534626618.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes we want to opportunistically get a ref to a cred in an rcu_read_lock protected section. get_task_cred() does this, and NFS does as similar thing with its own credential structures. To prepare for NFS converting to use 'struct cred' more uniformly, define get_cred_rcu(), and use it in get_task_cred(). Signed-off-by: NeilBrown --- include/linux/cred.h | 11 +++++++++++ kernel/cred.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index f1085767e1b3..48979fcb95cf 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -252,6 +252,17 @@ static inline const struct cred *get_cred(const struct cred *cred) return get_new_cred(nonconst_cred); } +static inline const struct cred *get_cred_rcu(const struct cred *cred) +{ + struct cred *nonconst_cred = (struct cred *) cred; + if (!cred) + return NULL; + if (!atomic_inc_not_zero(&nonconst_cred->usage)) + return NULL; + validate_creds(cred); + return cred; +} + /** * put_cred - Release a reference to a set of credentials * @cred: The credentials to release diff --git a/kernel/cred.c b/kernel/cred.c index 0b3ac72bd717..ba60162249e8 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -195,7 +195,7 @@ const struct cred *get_task_cred(struct task_struct *task) do { cred = __task_cred((task)); BUG_ON(!cred); - } while (!atomic_inc_not_zero(&((struct cred *)cred)->usage)); + } while (!get_cred_rcu(cred)); rcu_read_unlock(); return cred;