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 B447AC36017 for ; Tue, 1 Apr 2025 10:57:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4397C280002; Tue, 1 Apr 2025 06:57:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C2DC280001; Tue, 1 Apr 2025 06:57:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26292280002; Tue, 1 Apr 2025 06:57:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 04C58280001 for ; Tue, 1 Apr 2025 06:57:40 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2C123C0863 for ; Tue, 1 Apr 2025 10:57:42 +0000 (UTC) X-FDA: 83285174364.21.DFD418A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf13.hostedemail.com (Postfix) with ESMTP id D870720006 for ; Tue, 1 Apr 2025 10:57:39 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=L8P+rHYu; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Zu3GfSkV; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=L8P+rHYu; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Zu3GfSkV; dmarc=none; spf=pass (imf13.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=1743505060; a=rsa-sha256; cv=none; b=OTHks4Z9MYEkLz7bqxobDgu8zssXLhHZQrRClMivT2gW6ssiSaIum7fIf9ZkffZT5h8D2n VL+1A3rqnVOYpRdNSiyPaMUdk3Shxg9Nh4ZlJbe19bw65dsr1iVJ0NbJeUza2g0YfYmQ24 y4s5npiMEPnz6wdKmxQ3vQgNhcWdm38= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=L8P+rHYu; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Zu3GfSkV; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=L8P+rHYu; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Zu3GfSkV; dmarc=none; spf=pass (imf13.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=1743505060; 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=J5ks00aa614wqMqQeQ7qxtJzPV9hhH3xCwXQ795wViE=; b=aR/jz+6ZzRpmoppjTXvatk+kojn9P3C6QW6E7iBaj4JMl4SWyf5MUqx4nmVCaYs8ig5/cO 9u2x6qHAtDMKPpubmWQYh5VcjEfB6FC8GaPhSUd46GJS8l9lhKFzauZ05su0VgOivuQ7oi qVUrLuJd15Nx3kKn95gqUnUecffC+yE= Received: from imap1.dmz-prg2.suse.org (unknown [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 4B8121F38E; Tue, 1 Apr 2025 10:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1743505058; 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=J5ks00aa614wqMqQeQ7qxtJzPV9hhH3xCwXQ795wViE=; b=L8P+rHYuPSWVevuIOQ+uMRIuQqnbnQ6j/kw/cvnoq3qhGXJPMJNGYS+EFHOyUj2ts37lEq VhVqpHPUfQ6neX2U/smIsVexEn9Q2UhGhWQMvMjciQ5GK/LEPXN5vnadNxFoJ1FB9tRPeo /aG4bpXxcRV592m1pstYHo3A0bfjsQE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1743505058; 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=J5ks00aa614wqMqQeQ7qxtJzPV9hhH3xCwXQ795wViE=; b=Zu3GfSkVTh1ZSw7YNuHUhugCvDPA6n0OcaCvV90fRCiKAF54mbocG5V/Y7vrxzxj6ZbTOo Vrxjl1A/WaB4j7BQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1743505058; 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=J5ks00aa614wqMqQeQ7qxtJzPV9hhH3xCwXQ795wViE=; b=L8P+rHYuPSWVevuIOQ+uMRIuQqnbnQ6j/kw/cvnoq3qhGXJPMJNGYS+EFHOyUj2ts37lEq VhVqpHPUfQ6neX2U/smIsVexEn9Q2UhGhWQMvMjciQ5GK/LEPXN5vnadNxFoJ1FB9tRPeo /aG4bpXxcRV592m1pstYHo3A0bfjsQE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1743505058; 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=J5ks00aa614wqMqQeQ7qxtJzPV9hhH3xCwXQ795wViE=; b=Zu3GfSkVTh1ZSw7YNuHUhugCvDPA6n0OcaCvV90fRCiKAF54mbocG5V/Y7vrxzxj6ZbTOo Vrxjl1A/WaB4j7BQ== 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 340FD13691; Tue, 1 Apr 2025 10:57:38 +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 o3JuDKLG62cSHgAAD6G6ig (envelope-from ); Tue, 01 Apr 2025 10:57:38 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id AFC06A07E6; Tue, 1 Apr 2025 12:57:37 +0200 (CEST) Date: Tue, 1 Apr 2025 12:57:37 +0200 From: Jan Kara To: Luis Chamberlain Cc: brauner@kernel.org, jack@suse.cz, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, riel@surriel.com, willy@infradead.org, hannes@cmpxchg.org, oliver.sang@intel.com, dave@stgolabs.net, david@redhat.com, axboe@kernel.dk, hare@suse.de, david@fromorbit.com, djwong@kernel.org, ritesh.list@gmail.com, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com Subject: Re: [PATCH 2/3] fs/buffer: avoid races with folio migrations on __find_get_block_slow() Message-ID: References: <20250330064732.3781046-1-mcgrof@kernel.org> <20250330064732.3781046-3-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250330064732.3781046-3-mcgrof@kernel.org> X-Rspamd-Queue-Id: D870720006 X-Stat-Signature: 88edaktky4maisbn31i1bihepknihwow X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1743505059-202148 X-HE-Meta: U2FsdGVkX1/SrhsWFrIZj/OyEdaXUWce66Hc8wETWoC6BSC8fcU+7lSCUcjA/EsNai2fjws4eUjVa5jvuB07/S8uhHDMcfe7cexmqsoEksSygFHzYuRtxj4ikhaK/9g4ibQKd78/p3Zk+bG5Z+w5CRmL/tFDn6CobzwD2fw/ZsMv4OvSRQjYuWpBSt2SW1aZb6Djlrx0Vh1NExttINBCT/rRIH31ELIWGgcD6Hgwn3EYBSO8XwTkssdfmU8BoOgFwYufHSD7kjOIiSrhhqHwLL9FqlkHUBtNvWksc7l3iLC/esfPKaK9oEireI98oQJYPzhCoo0kTvsLK603qfe+NaBYXys25x3aEYwa6nLBGIaRAU38C/SR7t/AxtsWoJ9jqPGj4cEJ4yD55ZkZsRh5Hi8UWYd/MoeJJ7xjUQsN2tpvCy6MU2QUCZCkxt04pw8tokAEPmyviH/Zvl3TDBWjOz3JyUE/xaM2jo49ts3RQXMF4M3tSjnds41YOgwgSk60rNwAvn//Tu0bEB+OK0YywiFsFMuQ/b6B4DYjIC9X5VX7I6nnHb4KWFEV/etOPHOXEP3VPCSoD2BQk1uyo/BfInjM6U3q1TtG+cTYNKh5EbUIe1pavUQi7qocuYhCBvwKJXazcfzqUFuFYgWhq7cPQ+pKYR8Psq6SUwPizDvO1p5SAOPCZWh83xjhQdVrkAytPyyp1rAxbXb/l6TLKrKPseTezBeZ0GA3SdrojbmUThP3YgrNL6V8kwPBDNNiBlx/6XDs7K3TJAOroKURuThGrp2VWdj9C7GwCA92+MFd/aspe19121IBFoWJnzpxqY1JwnWg6ZHu4K8VbOvxEPlQ6PstukvDVRrDbPkVIX/eUiGrf9ENWr7z19Wb/LWANe53/zzKyT/KraJSGIWSyWdcVYb12TWH46rtAPbe1mufJyaHCnaWA7S+rmvoU0J4i6k6JrDL35K/JCREvXwel3d 9tPAo2+/ F4vJu8PXmSgA9vrUo55zXkVYqB9umPvntqPIUhgG6JOdvnBvLDYardPRVdgKtrf7U2V0xMTorXsYrvjQy21zPItLsXELXEsCf2it8d9QYZ3ys7tBZ8HGDxc91H1948vxJ8tc4C+SOYv8NasSd6mxBerNcJZvC8k10GAJbDJkREEsp5QLB3agUZgIzQgHicyDImATl2bhZ/B5DBi0NpEA36eJ6nY+7FJCBvWjKmf4BWgNrShr81MLzSDFQ/vFEtxcFtk3IIUUAFkMMulMTs+4FFVi0IT6fu7o1zeNuu5JgXZYNgpQpI4zsPRhodRyAR7fI0xyBvmgZttnrkjoHTUf4ZGhpTW6x59vQxUF17/dzPNBlGE9GKiVw4QdoqtCdr9ze2jyQ0/9PKICtDtoHyZqcD9Tm45EWMwwC+6eES68FJHAPa9VKA5b/ci3F2wq7EUiFn8sDLzFShD2O+Mo= 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 Sat 29-03-25 23:47:31, Luis Chamberlain wrote: > diff --git a/fs/buffer.c b/fs/buffer.c > index c7abb4a029dc..a4e4455a6ce2 100644 > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -208,6 +208,15 @@ __find_get_block_slow(struct block_device *bdev, sector_t block) > head = folio_buffers(folio); > if (!head) > goto out_unlock; > + > + if (folio->mapping->a_ops->migrate_folio && > + folio->mapping->a_ops->migrate_folio == buffer_migrate_folio_norefs) { This is always true for bdev mapping we have here, isn't it? > + if (folio_test_lru(folio) && Do you expect bdev page cache to contain non-LRU folios? I thought every pagecache folio is on LRU so this seems pointless as well? But I may be missing something here. > + folio_test_locked(folio) && > + !folio_test_writeback(folio)) > + goto out_unlock; I find this problematic. It fixes the race with migration, alright (although IMO we should have a comment very well explaining the interplay of folio lock and mapping->private_lock to make this work - probably in buffer_migrate_folio_norefs() - and reference it from here), but there are places which expect that if __find_get_block() doesn't return anything, this block is not cached in the buffer cache. And your change breaks this assumption. Look for example at write_boundary_block(), that will fail to write the block it should write if it races with someone locking the folio after your changes. Similarly the code tracking state of deleted metadata blocks in fs/jbd2/revoke.c will fail to properly update buffer's state if __find_get_block() suddently starts returning NULL although the buffer is present in cache. > + } > + > bh = head; > do { > if (!buffer_mapped(bh)) Honza -- Jan Kara SUSE Labs, CR