From patchwork Mon Oct 16 03:22:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13422445 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 DCCBACDB465 for ; Mon, 16 Oct 2023 03:22:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 610328D0021; Sun, 15 Oct 2023 23:22:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BF418D0001; Sun, 15 Oct 2023 23:22:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4612C8D0021; Sun, 15 Oct 2023 23:22:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 31A7B8D0001 for ; Sun, 15 Oct 2023 23:22:58 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 07D1D1A0A67 for ; Mon, 16 Oct 2023 03:22:58 +0000 (UTC) X-FDA: 81349878036.02.1204F9F Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf29.hostedemail.com (Postfix) with ESMTP id 368CC12000B for ; Mon, 16 Oct 2023 03:22:55 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Qoxv3Unb; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697426576; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r3L72Q2C0A6XyhsC7UMGOLSZK5Azm/i+GpPRU3MZq4Q=; b=dWwc+qeFM/XtD39AqbDvvj7By7e0rtqINqELWr+HEhNVVT5w5s8NzTrDDSnDvoopER4MdM sCZpHITqUQzeU5AIzDX9ze+HXfiGHNC9WeTVIXLpaCDtWAbn/eGF65gaOm5d3JYO3yNq9I mNInPS66SJvvc7vK61moPitJhoYtcXM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Qoxv3Unb; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697426576; a=rsa-sha256; cv=none; b=OAcjwVntJHtGB0ktraJr5vbjvVTaKeE394teTambxR6bxCaWzDHkVynunBEZN96WCNSf2P TWfoNOpfhg9QqBCo3lgUP3T/225Nau9m+PELVV/Cfm830W+/8rbzPw63ryOUHa1tommbtW dDGNj+Pf9shInV38LVs11zwuypvvvu0= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6bce254ba56so715900b3a.1 for ; Sun, 15 Oct 2023 20:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1697426575; x=1698031375; darn=kvack.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=r3L72Q2C0A6XyhsC7UMGOLSZK5Azm/i+GpPRU3MZq4Q=; b=Qoxv3UnbcagXyW0U3BIqmMXqcGt+KStC+Kglx+tlUbUehJ+643E4vYkzXviCtI5cB3 tY9Ly6T5F9e51dBCb1SfCPWStY2KHA3yX14i/yq8ejGZQKZfvACH+hVQ/5BoXXf+2fqe A26LFd7OO1O/rO02j2vxfutzH3WJlAs4yJjdNI4N4FSJj2t6iWAMCuGNjkVUSpk2dmND QSNUoh1n/Yvwmx+M/dNX4LJ9s36hFJZno2Btaiz+HxDjv0IBH8734jXE6u8KEJjgH6i9 5ZgAO6YuGdyI8L2DiSX5NzjaRCTnrowBQUkTYlO+KP/PnVih1JFSs8qb9tjXSJbVfbWq Yr2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697426575; x=1698031375; 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=r3L72Q2C0A6XyhsC7UMGOLSZK5Azm/i+GpPRU3MZq4Q=; b=U+r9/nCpWt6IlvikX+jlGnlDn/aIH6wyMLoOUKoEf4EubO2NaI5wa7s8L5vSUWp9B6 CElWKorq0P5Dx8GUakJsQLJumIEdpgBOngM5ST1FUyY+fnloTCxQy1rk+u2CKhPYM68y Prfre0zlOeE+kcu0pwPw7M8XR/8wPXl0DSrjfSj8r/7JNhUeLfUz3g22auYH277o5vli xJelsMa4fZChQa6f5huQJycBuH9U/Iy782Pzaw0Db8I/TPdyMizpRc/1ODrZjIv12PUY NacGuCXbWMi1x95Ewo0pS+qfN0I2wPqBwEpGdazJLYSFcHc0pGmbc+HTqNj3RtBsXDEG 5Rxg== X-Gm-Message-State: AOJu0Yz08QLhhCkoj10t2uOoCnD0WpHN8VacIcaHfM4XLKSRbiAx7q9J DicHnu28FKLF8KoysR0Rfsk+GA== X-Google-Smtp-Source: AGHT+IF6N8e9Loe20mQNUBXUIhiXmTkb8m7FtzL5gkme8mgEaofINIog9sVAbKEQ8545hYi479/lHg== X-Received: by 2002:a05:6a20:1613:b0:15d:9ee7:180a with SMTP id l19-20020a056a20161300b0015d9ee7180amr33444332pzj.4.1697426575048; Sun, 15 Oct 2023 20:22:55 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id d8-20020a17090ae28800b0027758c7f585sm3452770pjz.52.2023.10.15.20.22.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 15 Oct 2023 20:22:54 -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, mst@redhat.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 v5 02/10] maple_tree: Introduce {mtree,mas}_lock_nested() Date: Mon, 16 Oct 2023 11:22:18 +0800 Message-Id: <20231016032226.59199-3-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231016032226.59199-1-zhangpeng.00@bytedance.com> References: <20231016032226.59199-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 368CC12000B X-Stat-Signature: pswxx7wxferq7gfw5f6ayqihi6u3oke6 X-Rspam-User: X-HE-Tag: 1697426575-628858 X-HE-Meta: U2FsdGVkX1+jpk5ROGs3CPd11eD4MOABTbHf84/THY5Mv8SeAJp4QQRrjI+aAfEGnq/hUiXujQw/pOZDdSDhWdL7HrGC27ZR469ghOKyUejCvDEC2mVD4l/XF7xo9ltGnmLiFOzHximx8JQM8BHjy3i64IGcO315SOA7vx0gzfkSZNw+xhfF02x2UB/AuAvVpNiwJgtFV7LSZCuHTkTkuN2gD5HV6mbj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jr1qIq+pdkMao9LmV1dA6/GtdIik7p4fk8ubfQ0X3agLXLLZIJIp1EnwRrNyYds2DXg1IZYgxxRTFlvklPwqzvXldUNXmI/RFBuZXDbfzv84u+SJOTgK1Tg3e78rzElkPGza0CRarEg0hu8KWdA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002101, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 d01e850b570f..f91dbc7fe091 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)