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 CC53FC369B1 for ; Wed, 16 Apr 2025 09:43:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3E896B0252; Wed, 16 Apr 2025 05:43:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEE266B0254; Wed, 16 Apr 2025 05:43:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8F416B0255; Wed, 16 Apr 2025 05:43:17 -0400 (EDT) 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 8BFF16B0252 for ; Wed, 16 Apr 2025 05:43:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A455FAD930 for ; Wed, 16 Apr 2025 09:43:17 +0000 (UTC) X-FDA: 83339418834.10.69E9AAE Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf07.hostedemail.com (Postfix) with ESMTP id 6317C40006 for ; Wed, 16 Apr 2025 09:43:15 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=HHhhJvJJ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=5tJ6Nxjh; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=nIYdAtjN; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=baEEojHK; dmarc=none; spf=pass (imf07.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=1744796595; a=rsa-sha256; cv=none; b=tBSKS+pjWBmlQOeShqp3rYVGWkuWLvg1SmfzMAX8TUCjbkxFDFEC7Qk63sEw6KvJmfRhmc +nm+smONZ6vpky9rt+J4FBn1vD5gCiN8jOoDrc2LbPY+Z+PHSLjNvKPvJWEJIrX4AGfaWq avgSt/Buv1N7xI1da147QrUhWb280CQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=HHhhJvJJ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=5tJ6Nxjh; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=nIYdAtjN; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=baEEojHK; dmarc=none; spf=pass (imf07.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=1744796595; 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=Ab9IcjuX6LQv/6sxl0cPtCD4BdqLZx1T92HH/x/n7jM=; b=phfw20ehzzxC6L4crmY9pEbq+i47bFnfsL7RdBhjFIUn6MUNrj4N3f77+20Dtkk70WHBwz XilmGOC1L+Pz2aqk99ud7QSLkOoQE5d9mv3O4XBY0Fy3XmVMEPcfsp0kza406FcbiyfxOZ GMZ8EBS75pfX9YrfKpMasYxFlgFUaig= 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 C79971F445; Wed, 16 Apr 2025 09:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1744796594; 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=Ab9IcjuX6LQv/6sxl0cPtCD4BdqLZx1T92HH/x/n7jM=; b=HHhhJvJJqTxUbE9sjUyrYS5d9OEMbtCLa4OTPN75dRyYGCFssYE+KE/3uVNmZpvupMJIhQ k1PV5AR/FsGTtX5S+T0fuzMnfuMw33JO777VklUaCrLi8Qt7xZJrH6s7D5731gkIJL6UvB L1nj+KRGfLPdtPnZW2C6uLFNFb8vqAc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1744796594; 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=Ab9IcjuX6LQv/6sxl0cPtCD4BdqLZx1T92HH/x/n7jM=; b=5tJ6NxjhqGpCK+QNFu1bPRJ/g/S1+8sMN+CnbK5kZyX9aXjO/KDPPkAcpItKxOsRZOM7nY HyoMF8uvcwyMJICw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1744796592; 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=Ab9IcjuX6LQv/6sxl0cPtCD4BdqLZx1T92HH/x/n7jM=; b=nIYdAtjNJheQ0w5+XR6ns5Ovifpb/Ij73acMwVLmIm47tqIPb53TfKosRjk5Ctir9G3WdG pSg3m0A3OmJsuMPXZ8fOqnFC2jiILvOfuOmxEpF+jGZHj+8ZnclSVfphBCLNRYIF5SqSi9 PKTTfSUkXmqPf1nnXWJEyzZqv1ZjYvg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1744796592; 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=Ab9IcjuX6LQv/6sxl0cPtCD4BdqLZx1T92HH/x/n7jM=; b=baEEojHKC3IGW9K/7OukHM+F5V5ZNNec7HQIDFEyJyQ4i3PQty1Rc8pAvgT9fAK3icsk1Q PZToT5ff6bd5hPBg== 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 BBF6713976; Wed, 16 Apr 2025 09:43:12 +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 M5DiLbB7/2eMdgAAD6G6ig (envelope-from ); Wed, 16 Apr 2025 09:43:12 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 5AE8CA0947; Wed, 16 Apr 2025 11:43:08 +0200 (CEST) Date: Wed, 16 Apr 2025 11:43:08 +0200 From: Jan Kara To: Davidlohr Bueso Cc: jack@suse.cz, tytso@mit.edu, adilger.kernel@dilger.ca, brauner@kernel.org, mcgrof@kernel.org, willy@infradead.org, hare@suse.de, djwong@kernel.org, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kernel test robot , syzbot+f3c6fda1297c748a7076@syzkaller.appspotmail.com Subject: Re: [PATCH 7/7] mm/migrate: fix sleep in atomic for large folios and buffer heads Message-ID: <4qdxc5vwmf3squ4yjpgarxdss3d7sacfwgupf4o3onbqxjzb23@4i4ubrmoi74r> References: <20250415231635.83960-1-dave@stgolabs.net> <20250415231635.83960-8-dave@stgolabs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250415231635.83960-8-dave@stgolabs.net> X-Rspamd-Server: rspam10 X-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wckuxyTpps7pAj5jqelzeKDQCtHkZAjuYzLd7AsfWKp2FGZELcwNv497Ya3UpEsewaDozMxIoSX1HyXO7lCDwcoZN1tHh/E81kASh2lLHqywo+TyIk3UIoWndmTzGBSy79cUaiChstQF5pXRtBkJxl1Ase9HIVSVS65bO4/qE3SZjDrMN3/pYG49MZfqyeF72j2KzfkqNOS55OViF+J2WI3CR8ejC/TNdUs9yorfCExJufItVaIhKHRXu0YtiV8Oy6ADzjRhG9FOB6V73brBZz0g/EtBpZWu0PXfWdxlOZa65tpeRUBzFb9EBak6K0rLvvbyvh9GQxC0XECXytkEUispj8eQGo8opoq+KKJtATZe2Zf1P7Pyn7NrrBXS/a15nO6D1ibvsStMIJfFqse0JxTE1Mi0PrJnbkhUYCEkL1haQCFUI4oz24lEARXGzL/7ThbCgVCkBKAxS+UXrF+MIrW1nyC5ew0vTGxPth4vW3ZzWyPS4FiRn/2nXJe0zCiwguXgtYV/PtFd1Mva89UDPgme334dZ1zyn4J1oiLKC1/9HU028FdUE9yJVKOWcdK+2uOkNqi2dwD+qPWjMX0aLhcqnUdctiRe3vXzM 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 Tue 15-04-25 16:16:35, Davidlohr Bueso wrote: > The large folio + buffer head noref migration scenarios are > being naughty and blocking while holding a spinlock. > > As a consequence of the pagecache lookup path taking the > folio lock this serializes against migration paths, so > they can wait for each other. For the private_lock > atomic case, a new BH_Migrate flag is introduced which > enables the lookup to bail. > > This allows the critical region of the private_lock on > the migration path to be reduced to the way it was before > ebdf4de5642fb6 ("mm: migrate: fix reference check race > between __find_get_block() and migration"), that is covering > the count checks. > > The scope is always noref migration. > > Reported-by: kernel test robot > Reported-by: syzbot+f3c6fda1297c748a7076@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/oe-lkp/202503101536.27099c77-lkp@intel.com > Fixes: 3c20917120ce61 ("block/bdev: enable large folio support for large logical block sizes") > Co-developed-by: Luis Chamberlain > Signed-off-by: Davidlohr Bueso Looks good! Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/buffer.c | 12 +++++++++++- > fs/ext4/ialloc.c | 3 ++- > include/linux/buffer_head.h | 1 + > mm/migrate.c | 8 +++++--- > 4 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/fs/buffer.c b/fs/buffer.c > index f8e63885604b..b8e1e6e325cd 100644 > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -207,6 +207,15 @@ __find_get_block_slow(struct block_device *bdev, sector_t block, bool atomic) > head = folio_buffers(folio); > if (!head) > goto out_unlock; > + /* > + * Upon a noref migration, the folio lock serializes here; > + * otherwise bail. > + */ > + if (test_bit_acquire(BH_Migrate, &head->b_state)) { > + WARN_ON(!atomic); > + goto out_unlock; > + } > + > bh = head; > do { > if (!buffer_mapped(bh)) > @@ -1390,7 +1399,8 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) > /* > * Perform a pagecache lookup for the matching buffer. If it's there, refresh > * it in the LRU and mark it as accessed. If it is not present then return > - * NULL > + * NULL. Atomic context callers may also return NULL if the buffer is being > + * migrated; similarly the page is not marked accessed either. > */ > static struct buffer_head * > find_get_block_common(struct block_device *bdev, sector_t block, > diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c > index 38bc8d74f4cc..e7ecc7c8a729 100644 > --- a/fs/ext4/ialloc.c > +++ b/fs/ext4/ialloc.c > @@ -691,7 +691,8 @@ static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino) > if (!bh || !buffer_uptodate(bh)) > /* > * If the block is not in the buffer cache, then it > - * must have been written out. > + * must have been written out, or, most unlikely, is > + * being migrated - false failure should be OK here. > */ > goto out; > > diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h > index c791aa9a08da..0029ff880e27 100644 > --- a/include/linux/buffer_head.h > +++ b/include/linux/buffer_head.h > @@ -34,6 +34,7 @@ enum bh_state_bits { > BH_Meta, /* Buffer contains metadata */ > BH_Prio, /* Buffer should be submitted with REQ_PRIO */ > BH_Defer_Completion, /* Defer AIO completion to workqueue */ > + BH_Migrate, /* Buffer is being migrated (norefs) */ > > BH_PrivateStart,/* not a state bit, but the first bit available > * for private allocation by other entities > diff --git a/mm/migrate.c b/mm/migrate.c > index 6e2488e5dbe4..c80591514e66 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -845,9 +845,11 @@ static int __buffer_migrate_folio(struct address_space *mapping, > return -EAGAIN; > > if (check_refs) { > - bool busy; > + bool busy, migrating; > bool invalidated = false; > > + migrating = test_and_set_bit_lock(BH_Migrate, &head->b_state); > + VM_WARN_ON_ONCE(migrating); > recheck_buffers: > busy = false; > spin_lock(&mapping->i_private_lock); > @@ -859,12 +861,12 @@ static int __buffer_migrate_folio(struct address_space *mapping, > } > bh = bh->b_this_page; > } while (bh != head); > + spin_unlock(&mapping->i_private_lock); > if (busy) { > if (invalidated) { > rc = -EAGAIN; > goto unlock_buffers; > } > - spin_unlock(&mapping->i_private_lock); > invalidate_bh_lrus(); > invalidated = true; > goto recheck_buffers; > @@ -883,8 +885,7 @@ static int __buffer_migrate_folio(struct address_space *mapping, > > unlock_buffers: > if (check_refs) > - spin_unlock(&mapping->i_private_lock); > + clear_bit_unlock(BH_Migrate, &head->b_state); > bh = head; > do { > unlock_buffer(bh); > -- > 2.39.5 > -- Jan Kara SUSE Labs, CR