From patchwork Mon Sep 10 13:01:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 10594127 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 9AF64112B for ; Mon, 10 Sep 2018 13:01:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89B3F28FBA for ; Mon, 10 Sep 2018 13:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7478B28FCE; Mon, 10 Sep 2018 13:01:54 +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 2258128FBA for ; Mon, 10 Sep 2018 13:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728164AbeIJRzp (ORCPT ); Mon, 10 Sep 2018 13:55:45 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38942 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727269AbeIJRzp (ORCPT ); Mon, 10 Sep 2018 13:55:45 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7C07DD144F77F; Mon, 10 Sep 2018 21:01:36 +0800 (CST) Received: from szvp000100637.huawei.com (10.162.55.131) by smtp.huawei.com (10.3.19.214) with Microsoft SMTP Server (TLS) id 14.3.399.0; Mon, 10 Sep 2018 21:01:30 +0800 From: Gao Xiang To: "Theodore Y. Ts'o" , Jaegeuk Kim CC: Eric Biggers , , , Chao Yu , Miao Xie , , Gao Xiang Subject: [RFC PATCH 2/2] fscrypt: enable RCU-walk path for .d_revalidate Date: Mon, 10 Sep 2018 21:01:08 +0800 Message-ID: <1536584468-15695-2-git-send-email-gaoxiang25@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536584468-15695-1-git-send-email-gaoxiang25@huawei.com> References: <1536584468-15695-1-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 --- 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(dir->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