Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBC58C4363A for ; Tue, 27 Oct 2020 10:45:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60CF520878 for ; Tue, 27 Oct 2020 10:45:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417709AbgJ0KpB (ORCPT ); Tue, 27 Oct 2020 06:45:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:58520 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417579AbgJ0Ko7 (ORCPT ); Tue, 27 Oct 2020 06:44:59 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B2202ACC2; Tue, 27 Oct 2020 10:44:58 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id DBA2ADA6E2; Tue, 27 Oct 2020 11:43:24 +0100 (CET) Date: Tue, 27 Oct 2020 11:43:24 +0100 From: David Sterba To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, Nikolay Borisov Subject: Re: [PATCH v4 16/68] btrfs: extent_io: add assert_spin_locked() for attach_extent_buffer_page() Message-ID: <20201027104324.GA6756@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , linux-btrfs@vger.kernel.org, Nikolay Borisov References: <20201021062554.68132-1-wqu@suse.com> <20201021062554.68132-17-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201021062554.68132-17-wqu@suse.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Wed, Oct 21, 2020 at 02:25:02PM +0800, Qu Wenruo wrote: > When calling attach_extent_buffer_page(), either we're attaching > anonymous pages, called from btrfs_clone_extent_buffer(). > > Or we're attaching btree_inode pages, called from alloc_extent_buffer(). > > For the later case, we should have page->mapping->private_lock hold to > avoid race modifying page->private. > > Add assert_spin_locked() if we're calling from alloc_extent_buffer(). > > Signed-off-by: Qu Wenruo > Reviewed-by: Nikolay Borisov > --- > fs/btrfs/extent_io.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index 5842d3522865..8bf38948bd37 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -3106,6 +3106,15 @@ static int submit_extent_page(unsigned int opf, > static void attach_extent_buffer_page(struct extent_buffer *eb, > struct page *page) > { > + /* > + * If the page is mapped to btree inode, we should hold the private > + * lock to prevent race. > + * For cloned or dummy extent buffers, their pages are not mapped and > + * will not race with any other ebs. > + */ > + if (page->mapping) > + assert_spin_locked(&page->mapping->private_lock); assert_spin_locked per documentation checks if the spinlock is lockded on any cpu, but from the comments above you want to assert that it's held by the caller. So for that you need lockdep_assert_held, I don't thing we'd ever want assert_spin_locked in our code. > + > if (!PagePrivate(page)) > attach_page_private(page, eb); > else > -- > 2.28.0