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 2BEC9C433EF for ; Mon, 20 Jun 2022 09:47:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 915C98E0001; Mon, 20 Jun 2022 05:47:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C61C6B0073; Mon, 20 Jun 2022 05:47:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78D1D8E0001; Mon, 20 Jun 2022 05:47:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 68BCF6B0071 for ; Mon, 20 Jun 2022 05:47:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2FC0C20AEF for ; Mon, 20 Jun 2022 09:47:36 +0000 (UTC) X-FDA: 79598136912.01.1C71B63 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf17.hostedemail.com (Postfix) with ESMTP id 0222E400A6 for ; Mon, 20 Jun 2022 09:47:34 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id a17so7294493pls.6 for ; Mon, 20 Jun 2022 02:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=T/D9+9zuknnGmvNROM1Efleq7jN8Hw6RI6lzcGgc6IQ=; b=XX86aCfBgl3t0d/6RCMxP9LS53mtvlmGVVj8MUOMzwZv2yoQkTfT9LCJkIC6Lp+gHU m+e5CdHtVM8b6iCCiy61tWy5FNqsqjrvZ9P9OCMJZS23RoNDUX8jpAUqbk8bqfLdaHlQ hcQlKAWQJEatEqleQE8GFZEF9Ze7mlMvf9B3GIAStRMJbzkrSxhK2H447reigadjVitl /JwjkDuaqjcPmFcxjibJzglev8PC7plxSIvKK9/Y9YcCA6Ui433fVyJZv8xpg/kUv0UT mEc5R9P38hVJfaPdeiWtch1jDGuLGtTgkikd0GO0U4pkk1llVstOYgpBIzBhqcppCE/x S2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=T/D9+9zuknnGmvNROM1Efleq7jN8Hw6RI6lzcGgc6IQ=; b=fI6IM3x3qGYna6QMJ6NoGRti26bjDZT/Bk9k6Iv2WBE0/5ahutv9+nrS3wQlcMAvlT Ij4+I7f5iQuC7TSypRCuvwLW8l2qVMREU1BpNdCyIuhec1nY2UzULnfQAGN/zbitRlQz fdUub3yZwptyjo4nP1dGO8grr265TYX8R2xA1LF+RUAzp4GLLW9Dd+xJ+qvUWkYEFi++ mpQCVhefYCo3Jt68c7LLK2dfzr3KdLmlzr3LHK8nIaqF/ZuWmvU1nxbrC//gG6Jat51/ p9K4l0Bso5aG0fgOI9AyoR5uKdAIkDaxBSJMDWyxqghcF/TYOO1HvGg42WIAa3ZHGeBd hgxQ== X-Gm-Message-State: AJIora9uSRr2b7O+Yw8oFMrdV7ffaoDC2/O8XR4KAa6eXqDI39pcQ0M5 tVELOVushM7X9TG+8TquZM/VSw== X-Google-Smtp-Source: AGRyM1ubP3bXctHBXwws9ZgPXhQSsRzA67NQ6S79Bqf0qSAP2mXsbxcVc0OvELyVs9XZ4ypngOYt7A== X-Received: by 2002:a17:90a:eb05:b0:1ec:b85a:e1ac with SMTP id j5-20020a17090aeb0500b001ecb85ae1acmr1054643pjz.103.1655718453943; Mon, 20 Jun 2022 02:47:33 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id o1-20020a62f901000000b0052285857864sm8835329pfh.97.2022.06.20.02.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 02:47:33 -0700 (PDT) Date: Mon, 20 Jun 2022 17:47:28 +0800 From: Muchun Song To: Miaohe Lin Cc: Matthew Wilcox , akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] filemap: obey mapping->invalidate_lock lock/unlock order Message-ID: References: <20220618083820.35626-1-linmiaohe@huawei.com> <364c8981-95c4-4bf8-cfbf-688c621db5b5@huawei.com> <72315fc0-eee9-13c8-2d94-43c8c7045a91@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <72315fc0-eee9-13c8-2d94-43c8c7045a91@huawei.com> ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=XX86aCfB; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655718455; 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=T/D9+9zuknnGmvNROM1Efleq7jN8Hw6RI6lzcGgc6IQ=; b=FBhhANAutwHHMOKdj3zRcUwKZ4AY24F5qdEBcOKcdNUEERcnsHiMe7dzWc2PF9UoXYuuj5 Xrgi0LspGtJgW+I6HTzPJSzO7G9mi/GkeofGO9HmK5Wg90aqDfQSmwXOMOeyxWx7J8pm9Q yQn6GT4BbuazMkFugLQJFRCjDwx62vg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655718455; a=rsa-sha256; cv=none; b=4sT5r+9qgu2YWrNAbrtXiMwogXIqRcO8DaUe+JE7J6S5wNq2U3qXYzEmezikszOkGfUGAK xqwRPzUlLNbhz3f44FIVOpPNXtm/8rfyg2Wztbf6tO1El+lBtnmmQof5ffjJJa+WisR60y ThF87Y1osox6PbK3ph3ktRndQEhAWHY= X-Rspamd-Queue-Id: 0222E400A6 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=XX86aCfB; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5ow36zaawzw4xm8ok6z8j7cxd96o3zas X-HE-Tag: 1655718454-243241 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jun 20, 2022 at 02:35:30PM +0800, Miaohe Lin wrote: > On 2022/6/20 12:47, Matthew Wilcox wrote: > > On Mon, Jun 20, 2022 at 09:56:06AM +0800, Miaohe Lin wrote: > >> On 2022/6/18 18:34, Matthew Wilcox wrote: > >>> On Sat, Jun 18, 2022 at 04:38:20PM +0800, Miaohe Lin wrote: > >>>> The invalidate_locks of two mappings should be unlocked in reverse order > >>>> relative to the locking order in filemap_invalidate_lock_two(). Modifying > >>> > >>> Why? It's perfectly valid to lock(A) lock(B) unlock(A) unlock(B). > >>> If it weren't we'd have lockdep check it and complain. > > It seems I misunderstand your word. I thought you said it must be at lock(A) lock(B) unlock(A) unlock(B) > order... Sorry. > > >> > >> For spin_lock, they are lock(A) lock(B) unlock(B) unlock(A) e.g. in copy_huge_pud, > > > > I think you need to spend some time thinking about the semantics of > > locks and try to figure out why it would make any difference at all > > which order locks (of any type) are _unlocked_ in, > > IIUC, the lock orders are important to prevent possible deadlock. But unlock orders should be relaxed > because they won't result in problem indeed. And what I advocate here is that making it at lock(A) lock(B) > unlock(B) unlock(A) order should be a better program practice. Or unlock order shouldn't be obligatory > at practice? > lock(A) lock(B) unlock(A) unlock(B) is fine. So it is better not to complicate the code. > Thanks. > > > > >> copy_huge_pmd, move_huge_pmd and so on: > >> dst_ptl = pmd_lock(dst_mm, dst_pmd); > >> src_ptl = pmd_lockptr(src_mm, src_pmd); > >> spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); > >> ... > >> spin_unlock(src_ptl); > >> spin_unlock(dst_ptl); > >> > >> For rw_semaphore, they are also lock(A) lock(B) unlock(B) unlock(A) e.g. in dup_mmap(): > >> mmap_write_lock_killable(oldmm) > >> mmap_write_lock_nested(mm, SINGLE_DEPTH_NESTING); > >> ... > >> mmap_write_unlock(mm); > >> mmap_write_unlock(oldmm); > >> > >> and ntfs_extend_mft(): > >> down_write(&ni->file.run_lock); > >> down_write_nested(&sbi->used.bitmap.rw_lock, BITMAP_MUTEX_CLUSTERS); > >> ... > >> up_write(&sbi->used.bitmap.rw_lock); > >> up_write(&ni->file.run_lock); > >> > >> But I see some lock(A) lock(B) unlock(A) unlock(B) examples in some fs codes. Could you > >> please tell me the right lock/unlock order? I'm somewhat confused now... > >> > >> BTW: If lock(A) lock(B) unlock(A) unlock(B) is requested, filemap_invalidate_lock_two might > >> still need to be changed to respect that order? > >> > >> Thanks! > >> > >>> > >>> . > >>> > >> > > > > . > > > >