From patchwork Tue Jul 17 20:54:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10530645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 335AD600D0 for ; Tue, 17 Jul 2018 20:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24E012932E for ; Tue, 17 Jul 2018 20:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1970D29441; Tue, 17 Jul 2018 20:54:45 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C5E0B2932E for ; Tue, 17 Jul 2018 20:54:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BD3432098874C; Tue, 17 Jul 2018 13:54:44 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 40F06209605D9 for ; Tue, 17 Jul 2018 13:54:43 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 13:54:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,367,1526367600"; d="scan'208";a="65419057" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by FMSMGA003.fm.intel.com with ESMTP; 17 Jul 2018 13:54:32 -0700 Subject: [PATCH v5 05/12] keys: add call key_put_sync() to flush key_gc_work when doing a key_put(). From: Dave Jiang To: dan.j.williams@intel.com Date: Tue, 17 Jul 2018 13:54:32 -0700 Message-ID: <153186087257.27463.13382652631526471099.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153186061802.27463.14539931103401173743.stgit@djiang5-desk3.ch.intel.com> References: <153186061802.27463.14539931103401173743.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dhowells@redhat.com, alison.schofield@intel.com, keyrings@vger.kernel.org, keescook@chromium.org, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Adding key_put_sync() that calls flush_work on key_gc_work to ensure the key we want to remove is gone. Signed-off-by: Dave Jiang --- include/linux/key.h | 1 + security/keys/key.c | 35 +++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/linux/key.h b/include/linux/key.h index e58ee10f6e58..4dffbd23d4e4 100644 --- a/include/linux/key.h +++ b/include/linux/key.h @@ -253,6 +253,7 @@ extern struct key *key_alloc(struct key_type *type, extern void key_revoke(struct key *key); extern void key_invalidate(struct key *key); extern void key_put(struct key *key); +extern void key_put_sync(struct key *key); static inline struct key *__key_get(struct key *key) { diff --git a/security/keys/key.c b/security/keys/key.c index d97c9394b5dd..b6f3ec19ab0f 100644 --- a/security/keys/key.c +++ b/security/keys/key.c @@ -622,6 +622,19 @@ int key_reject_and_link(struct key *key, } EXPORT_SYMBOL(key_reject_and_link); +static void __key_put(struct key *key, bool sync) +{ + if (key) { + key_check(key); + + if (refcount_dec_and_test(&key->usage)) { + schedule_work(&key_gc_work); + if (sync) + flush_work(&key_gc_work); + } + } +} + /** * key_put - Discard a reference to a key. * @key: The key to discard a reference from. @@ -632,15 +645,25 @@ EXPORT_SYMBOL(key_reject_and_link); */ void key_put(struct key *key) { - if (key) { - key_check(key); - - if (refcount_dec_and_test(&key->usage)) - schedule_work(&key_gc_work); - } + __key_put(key, false); } EXPORT_SYMBOL(key_put); +/** + * key_put - Discard a reference to a key and flush the key gc work item. + * @key: The key to discard a reference from. + * + * Discard a reference to a key, and when all the references are gone, we + * schedule the cleanup task to come and pull it out of the tree in process + * context at some later time. This call flushes the clean up so we are sure + * that the key is gone. + */ +void key_put_sync(struct key *key) +{ + __key_put(key, true); +} +EXPORT_SYMBOL(key_put_sync); + /* * Find a key by its serial number. */