Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp624822rdb; Mon, 29 Jan 2024 12:44:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfLyvi38wY96f3+mJF4sT10RNpVCY5JLuYpK7HWrmkZMIcBfW46AouIKG3y4MteZ8fZdw3 X-Received: by 2002:a17:906:261a:b0:a35:fb27:2e38 with SMTP id h26-20020a170906261a00b00a35fb272e38mr1334879ejc.34.1706561065351; Mon, 29 Jan 2024 12:44:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706561065; cv=pass; d=google.com; s=arc-20160816; b=QL4AwVX45tLULsawGBMHSL/kyjPgDydW7fvj2bS2QcuFwUvrSwua+f7Xa8/C7hazPW F7o3wL2pGSXYd9pVausnqEpkBDSp03Ukjrze2uOF7Lz/RbL9u51AZUQic0FcqavE2c2N Jb/myiNDuC8MdwfGxv2rneP0D0N+nhoxek+7JYfq8NpR3f3zCIqhw/IP43IHL3Ud6YLF AQF3eMmUAQre+pKUBa2Q2jo8DOCrdaZ+Qqpcc76QRZ2Q1Vuom6HsbouR54VJ2nU6VwlQ YufHeM5xGXUjGWXmiOaT80KUoOeucs+p77kDiPPBowoqsELVyIqrgZbiHRftnC++dG2V y+8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=ee/oWUNb4/zKYaB/G7ImZVRaz1EQk96VJ8QbjhzB4ZM=; fh=M648oune0DwZmCHpgeKmdqyNG9Pnhrh1APj5VeeCjyQ=; b=tJ3R8fjzbbFvl3x6UAdfkCOY3pZ45k6C4ejL8QN0fjgOlwis+GWI38/q+OTU5FXY7k dPf2yKzdD5bI2nvUbKC2jmh0VhTra9Z76aozbGUTUynHYZB9cO2D82hfDNqgqf4HTt5O mHyp3NN2ofujAdGUYmvDZqc2p023xvLS1iKxuLAEvurrPW3b93wEJ/ZzCYq4rTGxHlyM E+Wdn9N/Swx/IWgg7uFJLGjQjXsiJTG59A9wxENJ7Yi0q06g9b0+VQW4hHDcZQ7pwrsZ VhWHWTMxpo1CMX5E8td5eXF7V7ePwbB2Cfrhb4l7C7DSI0XmpFHsBoolQVWG2397nB4q YfsA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1004-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u9-20020a170906068900b00a31824d2553si3760177ejb.490.2024.01.29.12.44.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 12:44:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1004-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1004-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 206701F21880 for ; Mon, 29 Jan 2024 20:44:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E81441586E9; Mon, 29 Jan 2024 20:43:57 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1961B156967; Mon, 29 Jan 2024 20:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706561037; cv=none; b=kvApLIY69Hz0e2lH1ERXoAhtb8ueSRvM2CKpz7qM0Fk51pWJZAfos9e+HeE5gx18yGP+Mzw8A8aDjCs5YPeCMjRBQhGdtXxhyNylN9hUUrb+NGLCpWoVEq2oMMTkC5mYJ3jx/Tyx4R0j1EwpbEgP7/Uqi65cZd0/clvNlCj/1WU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706561037; c=relaxed/simple; bh=mjhq8Ydo934T4ky79O6NVA6saVt9Qh6FavIF4018Pxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xqa3xU8G2vUzQYD95NdW0mFVCJyZjChOhkA4F337UGP/zVO9uAS8Z9jwjjBR+liGD5TvKvWtVFtbPqy+GAmZn5q6WlegtjV7+h4Ik5fqpovM4U/2f8/izhLRHFDXnhYhgTCCS6wOW9aiTWz2689hUPKN7d6IhuDCa1TjECxkai8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 74F661F7F9; Mon, 29 Jan 2024 20:43:54 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CB98812FF7; Mon, 29 Jan 2024 20:43:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id F30VIAkOuGXYDAAAD6G6ig (envelope-from ); Mon, 29 Jan 2024 20:43:53 +0000 From: Gabriel Krisman Bertazi To: ebiggers@kernel.org, viro@zeniv.linux.org.uk, jaegeuk@kernel.org, tytso@mit.edu Cc: amir73il@gmail.com, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v5 05/12] fscrypt: Drop d_revalidate once the key is added Date: Mon, 29 Jan 2024 17:43:23 -0300 Message-ID: <20240129204330.32346-6-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129204330.32346-1-krisman@suse.de> References: <20240129204330.32346-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 74F661F7F9 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO From fscrypt perspective, once the key is available, the dentry will remain valid until evicted for other reasons, since keyed dentries don't require revalidation and, if the key is removed, the dentry is forcefully evicted. Therefore, we don't need to keep revalidating them repeatedly. Obviously, we can only do this if fscrypt is the only thing requiring revalidation for a dentry. For this reason, we only disable d_revalidate if the .d_revalidate hook is fscrypt_d_revalidate itself. It is safe to do it here because when moving the dentry to the plain-text version, we are holding the d_lock. We might race with a concurrent RCU lookup but this is harmless because, at worst, we will get an extra d_revalidate on the keyed dentry, which is will find the dentry is valid. Signed-off-by: Gabriel Krisman Bertazi --- Changes since v3: - Fix null-ptr-deref for filesystems that don't support fscrypt (ktr) Changes since v2: - Do it when moving instead of when revalidating the dentry. (me) Changes since v1: - Improve commit message (Eric) - Drop & in function comparison (Eric) --- include/linux/fscrypt.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index a22997b9f35c..c1e285053b3e 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -192,6 +192,8 @@ struct fscrypt_operations { unsigned int *num_devs); }; +int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags); + static inline struct fscrypt_inode_info * fscrypt_get_inode_info(const struct inode *inode) { @@ -221,15 +223,24 @@ static inline bool fscrypt_needs_contents_encryption(const struct inode *inode) } /* - * When d_splice_alias() moves a directory's no-key alias to its plaintext alias - * as a result of the encryption key being added, DCACHE_NOKEY_NAME must be - * cleared. Note that we don't have to support arbitrary moves of this flag - * because fscrypt doesn't allow no-key names to be the source or target of a - * rename(). + * When d_splice_alias() moves a directory's no-key alias to its + * plaintext alias as a result of the encryption key being added, + * DCACHE_NOKEY_NAME must be cleared and there might be an opportunity + * to disable d_revalidate. Note that we don't have to support the + * inverse operation because fscrypt doesn't allow no-key names to be + * the source or target of a rename(). */ static inline void fscrypt_handle_d_move(struct dentry *dentry) { dentry->d_flags &= ~DCACHE_NOKEY_NAME; + + /* + * Save the d_revalidate call cost during VFS operations. We + * can do it because, when the key is available, the dentry + * can't go stale and the key won't go away without eviction. + */ + if (dentry->d_op && dentry->d_op->d_revalidate == fscrypt_d_revalidate) + dentry->d_flags &= ~DCACHE_OP_REVALIDATE; } /** @@ -368,7 +379,6 @@ int fscrypt_fname_disk_to_usr(const struct inode *inode, bool fscrypt_match_name(const struct fscrypt_name *fname, const u8 *de_name, u32 de_name_len); u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name); -int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags); /* bio.c */ bool fscrypt_decrypt_bio(struct bio *bio); -- 2.43.0