Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1848543rdb; Wed, 31 Jan 2024 10:52:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/Xc30BNmGO/dZe9LJ3tgn1kLTg+o3DIBoj37vC0Nh8x91KaE0rwgeu7T1Py7aBUCrgNnp X-Received: by 2002:a17:90a:3009:b0:293:f954:5407 with SMTP id g9-20020a17090a300900b00293f9545407mr2566894pjb.15.1706727174351; Wed, 31 Jan 2024 10:52:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706727174; cv=pass; d=google.com; s=arc-20160816; b=Wzj6eHaLeskdTf0TJM0wsWROo1Rde07aBehVojVEmrp75GkUakbZT/lu86w+gcxzXY dTaow1ED5j9svBdYD9R5q74lUgIiwnsK6/d1SiDwAYR5Ai2x3a7TArBdTpkEiLz9HDsv LrWjP6tMInKj77UVastvp5G5s916OUS8ETsqiSnzdkpKkjGEFobiRY3aDDPz+jsHMRQn ewa82Vs43/BqBOlR5ta7T7o3MslWCroBF+e3IGDl3Km7bKhopHdXCqBtSJFG5BJMZnMw 2yIlPzJawGnBLRxXySlpzvBj+OnUaUPWLnAWbWBdlPlCvAaUbUzV2jfSTtvT3+DW55gp bzJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:organization:in-reply-to :subject:cc:to:from:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=nZh9bI2nucB4Tu4k5g98e4aelswvFCokcNSj9QwRR1o=; fh=a4u9AzraYaSbldI+HRaRBiw6ED20fxIZcrB0xjSMER4=; b=FbtklqfQJwJ6KTy89B61SPNEDV9SOAuo26svFSyzeeCGtPFerXO1QjBxSONtsvOj+b ai1wNBPPpGSA2bFULVwMUN+qZ1nrX6wJHaejOx7JBwEJBmKmu1zujxH6Wv3zFFe/Zhmy jkQQd30w1N47hq2Cokvg6vL33BWIGNuaI/QhQwaCGkmqBGOAcwOWEU8rOA4mHoJsku+H AGlC6Y5czNczD6L/8z3nQdUT/VdZaQ1zE20hWn1g+h+g3DJb/PAP0zWKxAyUYxfuqA2J AMLeprOhkcgPLdQIXMOzXdaRisuso7kBurUDCtNagb9m3MiijYTGwUbx4EtEO1Uhw+Kc Sehg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=zIC50bxi; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=j+jqCvSz; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=zIC50bxi; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1047-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=1; AJvYcCXStTbyVTBSdgSgGSy7fd3Ll2utvbTTvY15ATITsFF3yOl0YHe3aZ9Q5i3xDn2sRI1kjx5BWmdW/QHTLORILmZMZ1FQHPLsGkgBL5x0Ow== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id az21-20020a17090b029500b00290b198e3a3si1834678pjb.142.2024.01.31.10.52.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 10:52:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=zIC50bxi; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=j+jqCvSz; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=zIC50bxi; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1047-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B62A028FA45 for ; Wed, 31 Jan 2024 18:35:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EF2C17BD3; Wed, 31 Jan 2024 18:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="zIC50bxi"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="j+jqCvSz"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="zIC50bxi"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="j+jqCvSz" 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 4DE3017570; Wed, 31 Jan 2024 18:35:45 +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=1706726147; cv=none; b=jj5qEY5xpVU0pGqmP9GoEUXH2RgEvNpcRXovYGxTA/H76RgTA6iny5c4LTutlBjZtR+v5zU48vyLeRB/pRWSQTa6pvCPct6i8pYL1VFNXmAo4TquBwzBfJZ/01BLfqaze/r6hmrnuR6ALjVDA+jnswHgeDWtH3AsJztZ7SaqvkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706726147; c=relaxed/simple; bh=+JoJG7pRbDHijVXwiQYZPDo+9pZSH4Hb0WFUZddSJ1A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=OtClWv/Op5IYgy+uLs/f7hZNpQ8Y1i5yzyUSBiFvyU7MwtdGjX2Fs+TLv+gcSnDGLZU4h2MnFcJvLATvd4iSngK5djOm78mC4ccC7FHvOBqwmfmF/RRXPFPmH8QOwQ4jgyFKqEJ840Epo8ZMP3VWwjktFwS1BuklG53N4OzQXj4= 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; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=zIC50bxi; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=j+jqCvSz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=zIC50bxi; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=j+jqCvSz; 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 [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 85CDD1FB95; Wed, 31 Jan 2024 18:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706726143; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nZh9bI2nucB4Tu4k5g98e4aelswvFCokcNSj9QwRR1o=; b=zIC50bxiaXCsrC0a8NycfxSrLtttxTPUKEqhfr/fkjmRCCLKykep8hZ5fNkchvfwtXBxS+ wCHfZHe7cDhw0pku9rU7iebpI+rqpKrGa0XWl9NE+2ZzThCLJ59CxF48FusXICVQbCDxsP wn5ybbRHmqFUhurn4B9kLyxEBQaMLnw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706726143; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nZh9bI2nucB4Tu4k5g98e4aelswvFCokcNSj9QwRR1o=; b=j+jqCvSzcjrsvk/Y5XdBS+yuxLHBqVFJclQblqqLKQ7effDnO0wZvBlwfAChV8MHMrWn4d MkdS9gULamqN+BAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706726143; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nZh9bI2nucB4Tu4k5g98e4aelswvFCokcNSj9QwRR1o=; b=zIC50bxiaXCsrC0a8NycfxSrLtttxTPUKEqhfr/fkjmRCCLKykep8hZ5fNkchvfwtXBxS+ wCHfZHe7cDhw0pku9rU7iebpI+rqpKrGa0XWl9NE+2ZzThCLJ59CxF48FusXICVQbCDxsP wn5ybbRHmqFUhurn4B9kLyxEBQaMLnw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706726143; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nZh9bI2nucB4Tu4k5g98e4aelswvFCokcNSj9QwRR1o=; b=j+jqCvSzcjrsvk/Y5XdBS+yuxLHBqVFJclQblqqLKQ7effDnO0wZvBlwfAChV8MHMrWn4d MkdS9gULamqN+BAQ== 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 11BE5139B1; Wed, 31 Jan 2024 18:35:42 +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 faPhLv6SumVySwAAD6G6ig (envelope-from ); Wed, 31 Jan 2024 18:35:42 +0000 From: Gabriel Krisman Bertazi To: Eric Biggers Cc: viro@zeniv.linux.org.uk, jaegeuk@kernel.org, tytso@mit.edu, amir73il@gmail.com, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v5 04/12] fscrypt: Drop d_revalidate for valid dentries during lookup In-Reply-To: <20240131004724.GC2020@sol.localdomain> (Eric Biggers's message of "Tue, 30 Jan 2024 16:47:24 -0800") Organization: SUSE References: <20240129204330.32346-1-krisman@suse.de> <20240129204330.32346-5-krisman@suse.de> <20240131004724.GC2020@sol.localdomain> Date: Wed, 31 Jan 2024 15:35:40 -0300 Message-ID: <871q9x2vwj.fsf@mailhost.krisman.be> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[8]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[zeniv.linux.org.uk,kernel.org,mit.edu,gmail.com,vger.kernel.org,lists.sourceforge.net]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO Eric Biggers writes: > On Mon, Jan 29, 2024 at 05:43:22PM -0300, Gabriel Krisman Bertazi wrote: >> Unencrypted and encrypted-dentries where the key is available don't need >> to be revalidated with regards to fscrypt, since they don't go stale >> from under VFS and the key cannot be removed for the encrypted case >> without evicting the dentry. Mark them with d_set_always_valid, to > > "d_set_always_valid" doesn't appear in the diff itself. > >> diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h >> index 4aaf847955c0..a22997b9f35c 100644 >> --- a/include/linux/fscrypt.h >> +++ b/include/linux/fscrypt.h >> @@ -942,11 +942,22 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir, >> static inline void fscrypt_prepare_lookup_dentry(struct dentry *dentry, >> bool is_nokey_name) >> { >> - if (is_nokey_name) { >> - spin_lock(&dentry->d_lock); >> + spin_lock(&dentry->d_lock); >> + >> + if (is_nokey_name) >> dentry->d_flags |= DCACHE_NOKEY_NAME; >> - spin_unlock(&dentry->d_lock); >> + else if (dentry->d_flags & DCACHE_OP_REVALIDATE && >> + dentry->d_op->d_revalidate == fscrypt_d_revalidate) { >> + /* >> + * Unencrypted dentries and encrypted dentries where the >> + * key is available are always valid from fscrypt >> + * perspective. Avoid the cost of calling >> + * fscrypt_d_revalidate unnecessarily. >> + */ >> + dentry->d_flags &= ~DCACHE_OP_REVALIDATE; >> } >> + >> + spin_unlock(&dentry->d_lock); > > This makes lookups in unencrypted directories start doing the > spin_lock/spin_unlock pair. Is that really necessary? > > These changes also make the inline function fscrypt_prepare_lookup() very long > (when including the fscrypt_prepare_lookup_dentry() that's inlined into it). > The rule that I'm trying to follow is that to the extent that the fscrypt helper > functions are inlined, the inline part should be a fast path for unencrypted > directories. Encrypted directories should be handled out-of-line. > > So looking at the original fscrypt_prepare_lookup(): > > static inline int fscrypt_prepare_lookup(struct inode *dir, > struct dentry *dentry, > struct fscrypt_name *fname) > { > if (IS_ENCRYPTED(dir)) > return __fscrypt_prepare_lookup(dir, dentry, fname); > > memset(fname, 0, sizeof(*fname)); > fname->usr_fname = &dentry->d_name; > fname->disk_name.name = (unsigned char *)dentry->d_name.name; > fname->disk_name.len = dentry->d_name.len; > return 0; > } > > If you could just add the DCACHE_OP_REVALIDATE clearing for dentries in > unencrypted directories just before the "return 0;", hopefully without the > spinlock, that would be good. Yes, that does mean that > __fscrypt_prepare_lookup() will have to handle it too, for the case of dentries > in encrypted directories, but that seems okay. ok, will do. IIUC, we might be able to do without the d_lock provided there is no store tearing. But what was the reason you need the d_lock to set DCACHE_NOKEY_NAME during lookup? Is there a race with parallel lookup setting d_flag that I couldn't find? Or is it another reason? -- Gabriel Krisman Bertazi