From patchwork Fri Oct 11 21:44:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidhartha Kumar X-Patchwork-Id: 13833200 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 85E8DD0EE3F for ; Fri, 11 Oct 2024 21:45:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EE676B009F; Fri, 11 Oct 2024 17:45:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79CCF6B00A1; Fri, 11 Oct 2024 17:45:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63CF76B00A2; Fri, 11 Oct 2024 17:45:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3C0DC6B00A1 for ; Fri, 11 Oct 2024 17:45:07 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 698001A19C0 for ; Fri, 11 Oct 2024 21:44:58 +0000 (UTC) X-FDA: 82662652212.29.E347F33 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf18.hostedemail.com (Postfix) with ESMTP id D30A41C0009 for ; Fri, 11 Oct 2024 21:45:03 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=djD9E7VD; spf=pass (imf18.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728682966; 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:references:dkim-signature; bh=ZqnDF4NJzZ0S7p0y6Jm6lFyensH2WrRmhFzYfRLv1UI=; b=1V1rHYyeeaE/H5P5xdnlkO8cDwUBoIn7f/8wM+DgdbgT4quMeXKVGp+PIBkpvykuk82We7 zgs6ER3sEHNnxicd/1uMAWq/MJFz9Big0MqMGbPYtqwiXWbU+TtLLJOp2KBAqnqRnF2oMB nHd7yStJ698bwIRBp0AA52TVRwJAqKM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728682966; a=rsa-sha256; cv=none; b=ANWqNywlqV4qmwW/LSZuoSns1n4pFkBPrwBVgRYnhLkhZHTmFcYO9gq7XK7026GUm4OdfP zb08yZsdYG0OFM3aJBegZFl2r5U3Hg91Yzipku6t4zGhDVTimwG00x+sy8KBGcCraUKlxo cggcMc72T7mRFF5faZl2bRTJ+ZyLhmc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=djD9E7VD; spf=pass (imf18.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49BJU7Em007071; Fri, 11 Oct 2024 21:44:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=corp-2023-11-20; bh=ZqnDF4NJzZ0S7p0y6Jm6lFyensH2W rRmhFzYfRLv1UI=; b=djD9E7VD6JF2c7WTLLYbLI70eIpssEjFQPzvmQvir9gOR /YtI6n/U1rqqi383p5hEPZZs9h673WkiTUfYULbXTlcUmw4SLMGjasS3rqZ41A5a PnzMZPeaIc40NeN6B5IEbE7UnFLZ3Pr3PhiLadLLAOBc/hxJ5850pAYrO9ru7fGU GZ7XJHhe+VOz2kX/yKfqUBX8sUoVIcNJ2uQQioQN7cYv90QhY97eNYTyVBLBMjtA MFbOYtDLe1lRpn0ofsqUVmkZWrwxCicB3grcat3Bc4pIRiez3IpmB9sVNrMi/E2x e9c2enqBefQoeSX0JNDzPwe2ahHDrxSCM/apbILew== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42303ynv68-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 21:44:56 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49BJssPW027931; Fri, 11 Oct 2024 21:44:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwj395s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 21:44:55 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 49BLisSm026877; Fri, 11 Oct 2024 21:44:54 GMT Received: from sidkumar-mac.us.oracle.com (dhcp-10-65-170-196.vpn.oracle.com [10.65.170.196]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 422uwj395e-1; Fri, 11 Oct 2024 21:44:54 +0000 From: Sidhartha Kumar To: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, liam.howlett@oracle.com, willy@infradead.org, richard.weiyang@gmail.com, Sidhartha Kumar Subject: [PATCH 1/2] maple_tree: check for MA_STATE_BULK on setting wr_rebalance Date: Fri, 11 Oct 2024 17:44:50 -0400 Message-ID: <20241011214451.7286-1-sidhartha.kumar@oracle.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-11_19,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110153 X-Proofpoint-ORIG-GUID: NOZrxeg1V9xh0fXmiHV9jw6tFqSzWPAE X-Proofpoint-GUID: NOZrxeg1V9xh0fXmiHV9jw6tFqSzWPAE X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D30A41C0009 X-Stat-Signature: k69y66awkm7nbam997aqu1d699osr6a8 X-HE-Tag: 1728683103-927983 X-HE-Meta: U2FsdGVkX18KE7H/bBc33UEkWUcPm7OAwracEvduEtvc4YyVMknzE8I+4pTKLHZZCgLmVLlThT0Q6/wbnVrlQZhxTwvZTUPCBmQfTRXrsMiqA+tUJZFbLN43H4sOX/feBY5ehoe1OB+vvph2iDJZ1tdwTvjh5EyOOHvOSPEExZPzsCm/NB2+bdx/+twuBawaazkd2SRazRfVjrwKQibcY2z5/PChFS3MT9MpR2NbO0Klthf0n1rBRCqKjBdkp/QpWlYQz8Ehmw7GQeCNH06IWKyR+56rQ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ests=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: It is possible for a bulk operation (MA_STATE_BULK is set) to enter the new_end < mt_min_slots[type] case and set wr_rebalance as a store type. This is incorrect as bulk stores do not rebalance per write, but rather after the all of the writes are done through the mas_bulk_rebalance() path. Therefore, add a check to make sure MA_STATE_BULK is not set before we return wr_rebalance as the store type. Also add a test to make sure wr_rebalance is never the store type when doing bulk operations via mas_expected_entries() Fixes: 5d659bbb52a2 ("maple_tree: introduce mas_wr_store_type()") Suggested-by: Liam Howlett Signed-off-by: Sidhartha Reviewed-by: Wei Yang Reviewed-by: Liam Howlett --- Hi Andrew, this commit is a hotfix for this rc however it has no userspace effects as there are no users of the bulk instertion mode. lib/maple_tree.c | 2 +- tools/testing/radix-tree/maple.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4b423330d83c..b3b1d4b8126b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4228,7 +4228,7 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) /* Potential spanning rebalance collapsing a node */ if (new_end < mt_min_slots[wr_mas->type]) { - if (!mte_is_root(mas->node)) { + if (!mte_is_root(mas->node) && !(mas->mas_flags & MA_STATE_BULK)) { mas->store_type = wr_rebalance; return; } diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 5fde09999be4..551ae6898c1d 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -36317,6 +36317,28 @@ static inline int check_vma_modification(struct maple_tree *mt) return 0; } +/* + * test to check that bulk stores do not use wr_rebalance as the store + * type. + */ +static inline void check_bulk_rebalance(struct maple_tree *mt) +{ + MA_STATE(mas, mt, ULONG_MAX, ULONG_MAX); + int max = 10; + + build_full_tree(mt, 0, 2); + + /* erase every entry in the tree */ + do { + /* set up bulk store mode */ + mas_expected_entries(&mas, max); + mas_erase(&mas); + MT_BUG_ON(mt, mas.store_type == wr_rebalance); + } while (mas_prev(&mas, 0) != NULL); + + mas_destroy(&mas); +} + void farmer_tests(void) { struct maple_node *node; @@ -36328,6 +36350,10 @@ void farmer_tests(void) check_vma_modification(&tree); mtree_destroy(&tree); + mt_init(&tree); + check_bulk_rebalance(&tree); + mtree_destroy(&tree); + tree.ma_root = xa_mk_value(0); mt_dump(&tree, mt_dump_dec);