From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A327C48BC4 for ; Thu, 15 Feb 2024 17:16:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1AB08D000E; Thu, 15 Feb 2024 12:16:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACA4D8D0001; Thu, 15 Feb 2024 12:16:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9470B8D000E; Thu, 15 Feb 2024 12:16:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 77C4D8D0001 for ; Thu, 15 Feb 2024 12:16:29 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4C1F9121198 for ; Thu, 15 Feb 2024 17:16:29 +0000 (UTC) X-FDA: 81794692098.05.C9E0FE3 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf24.hostedemail.com (Postfix) with ESMTP id 14B07180021 for ; Thu, 15 Feb 2024 17:16:25 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=crXxaNt4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=tw5zFj2V; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3aZQNKOD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="rqsige/G"; dmarc=none; spf=pass (imf24.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708017386; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mN7N6sR+6YLENx+tkwEFlJDkjcUq22eMFFhbhlDssyE=; b=jibbsUzy5BiuddU2BuzPrq6mLlI/bP2VFxOR4ZqLUucLdMs65fFRQ4gsnTxI6V/6WLb0HW kwWsFtP4DFyq5ltGwcueZea7Fg9L5vYmhFx/DuScBP8qibcvlnkI61wUTOsEIxJCwwKMRy /BNVXLndflUKNWJidASE31dAvanSayM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=crXxaNt4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=tw5zFj2V; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3aZQNKOD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="rqsige/G"; dmarc=none; spf=pass (imf24.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708017386; a=rsa-sha256; cv=none; b=Y7Den4jQElG2qAp4brRIse+TNz5v6dp6Brb+9xIVcmuFMkh+Xy+PT3qCillkNU6l8dlaTJ XQBoOTBc9RsHB/q3awlLxEv1EdbSGBk1SdRvJ/tGnCA8IFnN2faYS9g3Jm6qMnzGPH392a OHRNLwffxuBVko/O0wQqqkF3gmFeJvY= Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 53CFF1FD72; Thu, 15 Feb 2024 17:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708017384; 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=mN7N6sR+6YLENx+tkwEFlJDkjcUq22eMFFhbhlDssyE=; b=crXxaNt4lz+6l+N1R7/8qInOvrZc42YDVwOgn7kmGjjKgGPBh08qU9C2tVz6gWWL/1c5/8 GXr08GIve9b2Kij0ykGJdztHaTEXbZu8crqH377qaY63BT+dkl/QFxO7obovljjRvA00mQ GzdFHnUlI/7KlOtp/r6bz78eVOy4rwg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708017384; 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=mN7N6sR+6YLENx+tkwEFlJDkjcUq22eMFFhbhlDssyE=; b=tw5zFj2V2oD3MPiFJMvYDH/qkPCwX9pSObaRuCoL8AaH2cSC6HH/onlR9PsN6KPIrxL/Lc nOL9N5eUyK2R/GCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708017383; 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=mN7N6sR+6YLENx+tkwEFlJDkjcUq22eMFFhbhlDssyE=; b=3aZQNKODUKOoV8JVnld6mFSn3VKkr/j1RwTX53xoftbrWHoE1SUX720mKlEsfM99xJlQ8q /EX2kXq8WzII6GZaWu9tXxubeDE9aAieAYOc8XVDKsfgX7KhsKSM2pKcoIhbSrm9Ebr25Z 1Z8vsp9Wp0YXiMQqdoR0nZYgz6QnML0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708017383; 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=mN7N6sR+6YLENx+tkwEFlJDkjcUq22eMFFhbhlDssyE=; b=rqsige/GL0a+boAWmMzPwVHF8fyiQZ1F3UuvQ19UTSuX1g1/q7hrGjDdVIZ4UljyUXWR1b tfJI2RMdF+bSFvDA== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 4087F139D0; Thu, 15 Feb 2024 17:16:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id sym6D+dGzmVzTAAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 17:16:23 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id A7C03A0809; Thu, 15 Feb 2024 18:16:22 +0100 (CET) Date: Thu, 15 Feb 2024 18:16:22 +0100 From: Jan Kara To: "Liam R. Howlett" Cc: Jan Kara , Chuck Lever , viro@zeniv.linux.org.uk, brauner@kernel.org, hughd@google.com, akpm@linux-foundation.org, oliver.sang@intel.com, feng.tang@intel.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Subject: Re: [PATCH RFC 7/7] libfs: Re-arrange locking in offset_iterate_dir() Message-ID: <20240215171622.gsbjbjz6vau3emkh@quack3> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> <170786028847.11135.14775608389430603086.stgit@91.116.238.104.host.secureserver.net> <20240215131638.cxipaxanhidb3pev@quack3> <20240215170008.22eisfyzumn5pw3f@revolver> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240215170008.22eisfyzumn5pw3f@revolver> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 14B07180021 X-Stat-Signature: bedqyy3h8payzu13jbkuzy5ynjk8qebc X-HE-Tag: 1708017385-587057 X-HE-Meta: U2FsdGVkX1+MPqv9a5bO6a6RuGSb6SjN6N35zVQG8eATDmpAaQiXagab9fypiZGeA92EHLr7EnxRiEd6mZqP5XybjmPI5LCLsOejcg47QYmSmnvFVwC5U7b1VjljiWK0mLW2tnHlDx4qxjIzEw7EM6g3z7tSNIUsTLAjQuUGSVHVLXQrcsn1dqBjaPAHoVjfqwlaJQV4lEQqzP+T6hrwKHlGstgh12KEZ7PG8MuryatH2tOhcVsQtxkOyptbYE+wHOEIeebPKANTQDxAFU7PPSnBEKfzHTy2HBog5s9OjX3Y8jye144zRllRpnnnu7IdW22SAtq0vtueYTZHAlC3vnxLPpke1QuImBWKsmGU4ky8aOSHY0Im3mWiwI1wqU3CvFLybS+vpHqJKPw4DwHtjJMdFOJe3mUZHCwnPfaMDSrq9zX8Dfjx7D2TejRo73vKi5WeE/apPIy8CXfPJul3ORCWmZO5q/7urcREeFcKfTd6dQid5KceTGNg6VsBxu/uB7GQBQiNhnqq+X0Np7V7W/IfVWLGHgjkrWyyDfuhF7Q8JV82e51vdTwEcc75u468V9iqiAfbasYE5UhgGdUfkneM85aRkP321ANVvsBrpEBrxiiA/AFeneeq9DZDENBRD5Lbrozo3/GrkcAtV3HEFpssz3dtusprjKRhWGNaD+HAhduDSpohFNiOVPDFjdCuCm87GyUmnD1L6hkaooKCCyvQ5QcvJriqYpH8pRv3JDhxrCLh56KSYqc5lGySqOA2LWFdB+xc+BpFnZcuAtZKSQCpKHm7N0jlj9AcagJh8KQ4c3FvDmEsc8CjImkrQXMOY/My4ZyiRE5zhTuxyBtfDbbgQwGUk/aPJXIUPrCZE9rJa48sON2HOmKrLJxJCnbyGs5//YbdbP9nI/ZPEcEN2quXkoed9YdeGyW/R94nkMljz9fGP0io4cUJkGzsnGLO X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu 15-02-24 12:00:08, Liam R. Howlett wrote: > * Jan Kara [240215 08:16]: > > On Tue 13-02-24 16:38:08, Chuck Lever wrote: > > > From: Chuck Lever > > > > > > Liam says that, unlike with xarray, once the RCU read lock is > > > released ma_state is not safe to re-use for the next mas_find() call. > > > But the RCU read lock has to be released on each loop iteration so > > > that dput() can be called safely. > > > > > > Thus we are forced to walk the offset tree with fresh state for each > > > directory entry. mt_find() can do this for us, though it might be a > > > little less efficient than maintaining ma_state locally. > > > > > > Since offset_iterate_dir() doesn't build ma_state locally any more, > > > there's no longer a strong need for offset_find_next(). Clean up by > > > rolling these two helpers together. > > > > > > Signed-off-by: Chuck Lever > > > > Well, in general I think even xas_next_entry() is not safe to use how > > offset_find_next() was using it. Once you drop rcu_read_lock(), > > xas->xa_node could go stale. But since you're holding inode->i_rwsem when > > using offset_find_next() you should be protected from concurrent > > modifications of the mapping (whatever the underlying data structure is) - > > that's what makes xas_next_entry() safe AFAIU. Isn't that enough for the > > maple tree? Am I missing something? > > If you are stopping, you should be pausing the iteration. Although this > works today, it's not how it should be used because if we make changes > (ie: compaction requires movement of data), then you may end up with a > UAF issue. We'd have no way of knowing you are depending on the tree > structure to remain consistent. I see. But we have versions of these structures that have locking external to the structure itself, don't we? Then how do you imagine serializing the background operations like compaction? As much as I agree your argument is "theoretically clean", it seems a bit like a trap and there are definitely xarray users that are going to be broken by this (e.g. tag_pages_for_writeback())... Honza -- Jan Kara SUSE Labs, CR