From patchwork Fri Oct 27 03:38:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13438095 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 4A550C25B47 for ; Fri, 27 Oct 2023 03:39:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC3CE6B0388; Thu, 26 Oct 2023 23:39:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D73366B0389; Thu, 26 Oct 2023 23:39:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C142D6B038A; Thu, 26 Oct 2023 23:39:17 -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 AF86A6B0388 for ; Thu, 26 Oct 2023 23:39:17 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 94F52B6423 for ; Fri, 27 Oct 2023 03:39:17 +0000 (UTC) X-FDA: 81389835954.03.0FACCE6 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf06.hostedemail.com (Postfix) with ESMTP id C5471180007 for ; Fri, 27 Oct 2023 03:39:15 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=aKQAQVMU; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.216.54 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=1698377955; 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=W3VhzpPT4L+mg3QuUru0Nd/vnRDIbmeOsA1YFHm0EaI=; b=2VuLl69askqss3Sr4uTIxnRtFli0eDRvwFQuzOCmDic3hTowoAieDBv2xDi5AT0p5Ah7/2 g7HzUwcT5fimG/DDFTo+f9PgteZdRwiIxQI3GFuDrF7UJksESyzOVBAJGah5tBKcGml22p QDmXsTu4w9Mg9b4KiNHO+rnrPcG1q9w= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=aKQAQVMU; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698377955; a=rsa-sha256; cv=none; b=oTHuZMvItNzcCakUPk8K2jdzSfzY2F8RZOq6B2Utf64DLOZJ4SZ0Of83z7faHQWOZT7BDD xuoZYhA2r45cs8Aqj4QCl7dsV5z7wov5gaCl2SGTvOfJ2kh2NWu+8F7AVrEYsfiDdH2Gqs GjjyrAkDpKOifsA+IEMGet5gGWiuXuo= Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-27ff83feb29so1096994a91.3 for ; Thu, 26 Oct 2023 20:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698377954; x=1698982754; 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=W3VhzpPT4L+mg3QuUru0Nd/vnRDIbmeOsA1YFHm0EaI=; b=aKQAQVMUU1Gkwa/JjqnkQQiFqAjD/JNwurcoZIzsMbY4CcVTulZC5FC+4Dcn7JqD79 UtIKlHO44yMkEEPnmTAzazDaYAdmYUmo9qTKPvyH3IC9XVSD1d9aEkLNYlJ5SBRpYtCR q+26xd2f6yWS0R8LSYrIhlbxlFeVw5eL1px36RvVsj3ATRMSHObLOWn6Ok67GreW6s6K wvFY1iMEkDIQgzQcmtI8bsq7IxDnyt24hj3lBphctCgnLjDglEFE9CVqWFaNJqvD4lg3 yqfx1iuIDEoZk19xP2bJJPVpW08MP0Ix0msFCQ1j4/ZCtWJk23E3cL9rWF1/dOFcJdOr OAvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698377954; x=1698982754; 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=W3VhzpPT4L+mg3QuUru0Nd/vnRDIbmeOsA1YFHm0EaI=; b=DhKCxsozmfs+V90Lfp1lMWZbdOKrbPdLXFpGuG/F3H2pu320isx57Bz/KRGTdGyRlG uzpXF7/gzB8XmDPmXI5/cNuePixcm0gmmv3daV+AckVYFXrFZZicT5j+UC5t8NjKwvHM rUrQiBgtGXNRSeDkPS1mEUd4mpbl2VCG6S18aBGuH2Otwf1GJbGZ013GXd+W9FNqBuBS d+bTkPHu0yYdyNjFNmtKWPtEZsXdrywf14rzmRy6Mx5npPdGXSzWSeqVX8et0wroNIYK p/ZxQXQr0Yn9JqWp+eMsasUkOjfs1TBJ9FwP2CdLyan0+9mgLgVtkQI9baMUTXTjfSmU YfbQ== X-Gm-Message-State: AOJu0YxAdIsStA2uf/jCK6jGmOsNKdG9lHunZOCzgllEAu7+AljbV9f1 Vw2xsoAgs5hxwKMyC1NV44PsWQ== X-Google-Smtp-Source: AGHT+IErUxQpQyE6ZDI+WeBZM1BwVdK0VivW/g4FmIFgZocyNbqWFR+q60M1qzJpJ7pOns/5IgyeQA== X-Received: by 2002:a17:90a:bf04:b0:27f:f9e5:b8d6 with SMTP id c4-20020a17090abf0400b0027ff9e5b8d6mr1386794pjs.41.1698377954626; Thu, 26 Oct 2023 20:39:14 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([203.208.189.7]) by smtp.gmail.com with ESMTPSA id ms19-20020a17090b235300b00267d9f4d340sm2345676pjb.44.2023.10.26.20.39.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 26 Oct 2023 20:39:14 -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 v7 02/10] maple_tree: Introduce {mtree,mas}_lock_nested() Date: Fri, 27 Oct 2023 11:38:37 +0800 Message-Id: <20231027033845.90608-3-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231027033845.90608-1-zhangpeng.00@bytedance.com> References: <20231027033845.90608-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C5471180007 X-Stat-Signature: h71qxedodemspxijjo8ppq8gmk1spu65 X-HE-Tag: 1698377955-623030 X-HE-Meta: U2FsdGVkX1/mbyLq1XzUcgfyr4QICKu7M3wx1nd63vj+u9/3gXj0XnN485RgvsND7q7+F+toZVxZY+g9sFQtkuUYt+jHy19Zzr6f3SIXUigOFe/kJvgBpkEm+/JZF/t8HBg2Sr0csw3skoFQO1916Ma0ABcjw/tlXPXe5hpYz1zLYUHjbuv0F5lsJwXOI1eS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i3j8bzLC2uxZvstLft7vHqtxY3JRop387+G5uUI/Q69vJSTfY/DTGu1Q776tzcd2L9J8jFIGYkGZuU6MqBhxi+uiqLyY0Z0NTPm9bBtO0pxyDDPj6Q= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: Liam R. Howlett --- 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)