Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2816750iog; Mon, 20 Jun 2022 05:32:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhRSe0gvfglHdEN+DVvlRnsw25UQXUYDTdek/PmW3/Vsqe0a+jO/AYtQeOor/NkiO7iMSl X-Received: by 2002:a17:907:9715:b0:711:ca06:ca50 with SMTP id jg21-20020a170907971500b00711ca06ca50mr20371980ejc.192.1655728342325; Mon, 20 Jun 2022 05:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655728342; cv=none; d=google.com; s=arc-20160816; b=sZF7i2KshC4XGhILjh45gaIXP45fpvowkCALQzDm8XIjSb6f3yjhs0Jytw2cCIaAo7 0y1M/eKaVw38zJd7nxWEyOrfkrwpzh/BPibdvDqIsIwooR4VLZIhX4wfn+RTvNt7GcMR ma3FPm2J6XTgRsGCpOuC2CuIcuqSFw776nw5HR4Sgru+gjeDfWdVlPLqjH3xWuoNOoAh +jiUC4lz+EDmBj9WxP8oaSt9/l8h+KsBX2l+a7xRURhNM/9/QqpLnBalDkAXfAuGUb4z O5Pl0VgAuqSx6kShSP64l8IlIyw15bNQSicSvRxWcPuXpb3wWVW6UOf9Zv3sET2oIczA jvIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=84JNfelCkdxLToTDsvreDCjZT6RVwreOH7JGiyTrztY=; b=u2htc1TKSfuh2mR+kUCxxUsqFayg0FGIZbrro9za3DPbH/VadgM61sjJCGkOTdnYMp iItqD8QgopvpekQ8IStNbs16+LqQGvYk8cnXqDbt6riYP1RKxnGG+F8pXnhYjpTS481P h5GhBakb6FGs/X1hWNWaIosBhiYrVFQtUO2h+EWE6pvwa+ggXeJLevUonipqnLB0GOjE XNbsLg1oLeI939LOJjusMDKfnq/o/RzYygn7Y0QMi7N2W7gQ+dUzLpgK3L+El/Zq4puH jbfg5ARe+veqamaT6RI/T0/k4kCvK4odMmQ8lJ7RF2MY5HSFfRv3syWVnC5hKV5bHWT8 h2+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg10-20020a170907a40a00b0071216d32d82si12060152ejc.869.2022.06.20.05.31.52; Mon, 20 Jun 2022 05:32:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242585AbiFTMOV (ORCPT + 99 others); Mon, 20 Jun 2022 08:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242238AbiFTMOU (ORCPT ); Mon, 20 Jun 2022 08:14:20 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 949F514D1B; Mon, 20 Jun 2022 05:14:17 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LRT7N6YBKzkWZ0; Mon, 20 Jun 2022 20:13:04 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 20 Jun 2022 20:14:15 +0800 Subject: Re: [PATCH] filemap: obey mapping->invalidate_lock lock/unlock order To: Muchun Song CC: Matthew Wilcox , , , , References: <20220618083820.35626-1-linmiaohe@huawei.com> <364c8981-95c4-4bf8-cfbf-688c621db5b5@huawei.com> <72315fc0-eee9-13c8-2d94-43c8c7045a91@huawei.com> From: Miaohe Lin Message-ID: <385dcf89-da4c-d3ac-333a-7ab40ecbdf9f@huawei.com> Date: Mon, 20 Jun 2022 20:14:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/6/20 17:47, Muchun Song wrote: > 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. Yes, it seems the gain is not worth complicating the code. So I will drop the patch. Thanks. > >> 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! >>>> >>>>> >>>>> . >>>>> >>>> >>> >>> . >>> >> >> > . >