From patchwork Mon Sep 10 13:08:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 10594133 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 2ABBA921 for ; Mon, 10 Sep 2018 13:09:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17E7629049 for ; Mon, 10 Sep 2018 13:09:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 145FF2905C; Mon, 10 Sep 2018 13:09:20 +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=-7.9 required=2.0 tests=BAYES_00,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 9F07129063 for ; Mon, 10 Sep 2018 13:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728310AbeIJSDT (ORCPT ); Mon, 10 Sep 2018 14:03:19 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:11678 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727269AbeIJSDT (ORCPT ); Mon, 10 Sep 2018 14:03:19 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CB4FFC24D8D33; Mon, 10 Sep 2018 21:09:14 +0800 (CST) Received: from szvp000100637.huawei.com (10.162.55.131) by smtp.huawei.com (10.3.19.209) with Microsoft SMTP Server (TLS) id 14.3.399.0; Mon, 10 Sep 2018 21:09:10 +0800 From: Gao Xiang To: "Theodore Y. Ts'o" , Jaegeuk Kim CC: Eric Biggers , , , Chao Yu , Miao Xie , , Gao Xiang Subject: [RFC PATCH v2 2/2] fscrypt: enable RCU-walk path for .d_revalidate Date: Mon, 10 Sep 2018 21:08:57 +0800 Message-ID: <1536584937-16960-1-git-send-email-gaoxiang25@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536584468-15695-2-git-send-email-gaoxiang25@huawei.com> References: <1536584468-15695-2-git-send-email-gaoxiang25@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.162.55.131] X-CFilter-Loop: Reflected Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch attempts to enable RCU-walk for fscrypt. It looks harmless at glance and could have better performance than do ref-walk only. Signed-off-by: Gao Xiang --- change log v2: - READ_ONCE(dir->d_parent) -> READ_ONCE(dentry->d_parent) fs/crypto/crypto.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index b38c574..9bd21c0 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -319,20 +319,24 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) { struct dentry *dir; int dir_has_key, cached_with_key; - - if (flags & LOOKUP_RCU) - return -ECHILD; - - dir = dget_parent(dentry); - if (!IS_ENCRYPTED(d_inode(dir))) { - dput(dir); + struct inode *dir_inode; + + rcu_read_lock(); +repeat: + dir = READ_ONCE(dentry->d_parent); + dir_inode = d_inode_rcu(dir); + if (!IS_ENCRYPTED(dir_inode)) { + rcu_read_unlock(); return 0; } + dir_has_key = (dir_inode->i_crypt_info != NULL); + if (unlikely(READ_ONCE(dir->d_lockref.count) < 0 || + READ_ONCE(dentry->d_parent) != dir)) + goto repeat; + rcu_read_unlock(); cached_with_key = READ_ONCE(dentry->d_flags) & DCACHE_ENCRYPTED_WITH_KEY; - dir_has_key = (d_inode(dir)->i_crypt_info != NULL); - dput(dir); /* * If the dentry was cached without the key, and it is a