From patchwork Mon Sep 10 13:01:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 10594125 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 9FAFA921 for ; Mon, 10 Sep 2018 13:01:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 908FC28FB5 for ; Mon, 10 Sep 2018 13:01:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84EB728FC8; Mon, 10 Sep 2018 13:01:38 +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 26C6128FB5 for ; Mon, 10 Sep 2018 13:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727709AbeIJRz3 (ORCPT ); Mon, 10 Sep 2018 13:55:29 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:12092 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727269AbeIJRz3 (ORCPT ); Mon, 10 Sep 2018 13:55:29 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DCC9DA7FDF2DA; Mon, 10 Sep 2018 21:01:25 +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:20 +0800 From: Gao Xiang To: "Theodore Y. Ts'o" , Jaegeuk Kim CC: Eric Biggers , , , Chao Yu , Miao Xie , , Gao Xiang Subject: [RFC PATCH 1/2] fscrypt: remove d_lock on reading DCACHE_ENCRYPTED_WITH_KEY Date: Mon, 10 Sep 2018 21:01:07 +0800 Message-ID: <1536584468-15695-1-git-send-email-gaoxiang25@huawei.com> X-Mailer: git-send-email 1.9.1 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 It seems there is no need to take d_lock when accessing dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY in fscrypt_d_revalidate. It only needs to be serialized for updating. Signed-off-by: Gao Xiang --- Hi, At glance, I have no idea why fscrypt_d_revalidate disables RCU-lookup. Therefore I made patches to raise a question and do some basic test, and it seems to work. Thanks, fs/crypto/crypto.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index 0f46cf5..b38c574 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -329,9 +329,8 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) return 0; } - spin_lock(&dentry->d_lock); - cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY; - spin_unlock(&dentry->d_lock); + cached_with_key = READ_ONCE(dentry->d_flags) & + DCACHE_ENCRYPTED_WITH_KEY; dir_has_key = (d_inode(dir)->i_crypt_info != NULL); dput(dir);