Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp999299rdh; Sun, 24 Sep 2023 23:10:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGC6mHWqg3p/7yiLwwJdaoPRu9e8ZrEfZncU/G1K6kKZyDAZXekQNVI8dkDe7XjJqYsmdPw X-Received: by 2002:a05:6a00:1a46:b0:68a:4103:9938 with SMTP id h6-20020a056a001a4600b0068a41039938mr4128609pfv.0.1695622239546; Sun, 24 Sep 2023 23:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695622239; cv=none; d=google.com; s=arc-20160816; b=r3ORnlIQtlryiBX8jVPjxenhu82yRFaw0bxI/18uSX2BNa69ODXq8PzZ/d4qG+4BmE 4DsvhGCVF2Avs5AXPTvxuYSz4J3cUo1vVcTwvFYfFWfLZSADJMEvLmRwXJIWUR7XB+NS IOwV38U+2B8GujRwfK88m97rh7qHYBCl6n8FLmZYxP3yIEFKFjFtY3rdHpXPfPn+1ON6 ixO3LoMyzLVvDYI2DomCfJD/a7q7mO8i3zcCuQXWTb/x/2RNZaccFs+wZ151PBbzHYaO L8HArsNUa4oy4nQNjISS9jHrjZbu5szncxP4bBMmHb/KV7W3Dl4Ea8Y/9rK8IYOYO/w/ wSkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KhsUxrKihKzaZBkbG2I3+KMiT6cOrZp7m1AFdT6cq6c=; fh=uq6KVc+CzZ80ucpwrp8f3d+Fe7Ue0w5J0Au2lk064nU=; b=u8ApPi1ZvdVHfymfYrerA+zExeSA6O9tu2o/YmmyuOl9hAjnod1wD6UbMXkt8Lye+0 PGDidxxNrMrMFGrfV0csDTbhYiFpElvbRUJSWlpc9xbYwDKdjfQ3E2I2MTvzpCcRGTQC 7Z6zEnkY4wP//pmRyzKnVSYQr53nkk3oThLtqoTrq9NjrKNfBZbd5yqIrvWmdp2VMTf3 OswADI2Sz81QV7KW/Rzqnta/D8UM0KG0oNhDDNdHUNZC30Pw0z04eArXZVCdYeAma0vv FSlx845+Mlm5AtAsCrpT/ABJIdlzuJTMG2esQhYeynCAfwAkswMdnm+8LQHRN1xZc6HT W8fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZPQmF96q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id dc8-20020a056a0035c800b0068a590d8043si9531331pfb.375.2023.09.24.23.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 23:10:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZPQmF96q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 30FA2816CB9B; Sun, 24 Sep 2023 20:58:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbjIYD6q (ORCPT + 99 others); Sun, 24 Sep 2023 23:58:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231717AbjIYD62 (ORCPT ); Sun, 24 Sep 2023 23:58:28 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E4ABFB for ; Sun, 24 Sep 2023 20:57:59 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6bdcbde9676so3825674a34.3 for ; Sun, 24 Sep 2023 20:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1695614279; x=1696219079; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KhsUxrKihKzaZBkbG2I3+KMiT6cOrZp7m1AFdT6cq6c=; b=ZPQmF96qpQll08vJTACYLiEM7GLH8jK+X1xhokrCi95QzjiE8lgpr5xme4gHjh2eTs J8L/qGV9laUgwmXS3fCTv7RttW//NZCB/ScJi771r7ZaV7pUxIfZ6f9bb5XfAeWNVDSx f7YuSyHvdjQ0PIgNW6V6Q/DYKaor7cxcafFoNUccBBnMgJhcM725BGWvxxwRCkrB/nVd 9ERQqSBYw0r6PXU/fAWuGzSN7zEORZ5qVI4Islu1tS/3cb0e2KpJ/S6FYa4IWprwIZU8 IOQ2fErQgHZlNBUgCja0V+z8sl/fAv6Q59w5pILdTZsOYMyhVNLJzS9ux1vFX/gZ54NX rFGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695614279; x=1696219079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KhsUxrKihKzaZBkbG2I3+KMiT6cOrZp7m1AFdT6cq6c=; b=gqg+E77xs2/700Jm//kQt98l0VfAdES5dqekTjlVelExkeL7cdnihrkLxpKXpTN35F gqknp71k+ZJA66czSHjpfFTUiBpuz/C1TfKmledELHnuV2HuvL6fJZtL8GQfrFTScbuh 2FyValJRTTpFGgnaT0c0ln7D8dD82TxcVEKhsrw0dQ8cPO0gB/6/TRre0/ikHY2T0KL8 84scB48JEyHybo3kHS+RxG2YbC5jlT0c/bCMLqqHT+yCMzPaxc0d3Ruh945uD9NayT7z trscqzMf+iV4ZKmLqb7KQalyZpJR0Ajw37wgu4YsRFYGJBjINVzicKEqfwqGMo3uBpJx 5KCg== X-Gm-Message-State: AOJu0YyYeZE4a9MH+DhOV4uSbB28UciA5+MO9Q9Hm9VkAabXLd+z8IC2 kuH9stBpo+LonOJJWvU0H0JutQ== X-Received: by 2002:a05:6830:2012:b0:6b9:c4b1:7a86 with SMTP id e18-20020a056830201200b006b9c4b17a86mr6335137otp.3.1695614278969; Sun, 24 Sep 2023 20:57:58 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id fm1-20020a056a002f8100b00679a4b56e41sm7025387pfb.43.2023.09.24.20.57.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 24 Sep 2023 20:57:58 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com, corbet@lwn.net, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, surenb@google.com, michael.christie@oracle.com, mjguzik@gmail.com, mathieu.desnoyers@efficios.com, npiggin@gmail.com, peterz@infradead.org, oliver.sang@intel.com Cc: zhangpeng.00@bytedance.com, maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 2/9] maple_tree: Introduce {mtree,mas}_lock_nested() Date: Mon, 25 Sep 2023 11:56:10 +0800 Message-Id: <20230925035617.84767-3-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230925035617.84767-1-zhangpeng.00@bytedance.com> References: <20230925035617.84767-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 24 Sep 2023 20:58:49 -0700 (PDT) In some cases, nested locks may be needed, so {mtree,mas}_lock_nested is introduced. For example, when duplicating maple tree, we need to hold the locks of two trees, in which case nested locks are needed. At the same time, add the definition of spin_lock_nested() in tools for testing. Signed-off-by: Peng Zhang --- include/linux/maple_tree.h | 4 ++++ tools/include/linux/spinlock.h | 1 + 2 files changed, 5 insertions(+) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index e41c70ac7744..666a3764ed89 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -256,6 +256,8 @@ struct maple_tree { struct maple_tree name = MTREE_INIT(name, 0) #define mtree_lock(mt) spin_lock((&(mt)->ma_lock)) +#define mtree_lock_nested(mas, subclass) \ + spin_lock_nested((&(mt)->ma_lock), subclass) #define mtree_unlock(mt) spin_unlock((&(mt)->ma_lock)) /* @@ -406,6 +408,8 @@ struct ma_wr_state { }; #define mas_lock(mas) spin_lock(&((mas)->tree->ma_lock)) +#define mas_lock_nested(mas, subclass) \ + spin_lock_nested(&((mas)->tree->ma_lock), subclass) #define mas_unlock(mas) spin_unlock(&((mas)->tree->ma_lock)) diff --git a/tools/include/linux/spinlock.h b/tools/include/linux/spinlock.h index 622266b197d0..a6cdf25b6b9d 100644 --- a/tools/include/linux/spinlock.h +++ b/tools/include/linux/spinlock.h @@ -11,6 +11,7 @@ #define spin_lock_init(x) pthread_mutex_init(x, NULL) #define spin_lock(x) pthread_mutex_lock(x) +#define spin_lock_nested(x, subclass) pthread_mutex_lock(x) #define spin_unlock(x) pthread_mutex_unlock(x) #define spin_lock_bh(x) pthread_mutex_lock(x) #define spin_unlock_bh(x) pthread_mutex_unlock(x) -- 2.20.1