From nobody Mon Feb 9 20:09:33 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98F7EEB64DB for ; Thu, 15 Jun 2023 13:11:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244542AbjFONLI (ORCPT ); Thu, 15 Jun 2023 09:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343724AbjFONLC (ORCPT ); Thu, 15 Jun 2023 09:11:02 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA0626BA for ; Thu, 15 Jun 2023 06:10:37 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b3b3f67ad6so45418965ad.3 for ; Thu, 15 Jun 2023 06:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686834637; x=1689426637; 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=MG8wEkfZhYGC5aupLXEONPEpLbQPJyBuYKNQETRNYXQ=; b=JBdX1l1x+iSg2CpjvKE+gC3fQ5LWgXkFJ7O3qRqfSLsduXgNEEnfZyRZYD+aaDtn7N uSkoiI3TK2NJb/opjoa/il1l5jtgGuKT70/3p9YVeEph/4m8CwB62pWy40V19y6b3aBt T+3f4gBTnPVMNomBZwR+rHzM3IPEpaFZKEVHjpr3cDYsT085CBjG839Y0kDt0RG7zprr cs36S3Z9fzu8SZxcfDKFdL14UvqkXTGVFkmjRRMVFjUSG++ubc5+L0lc0JrsYkImHvD1 qPTGQOAli/Oa9AWBv0XxRDill+ZhjXzuiBCDJbggf+iwNECB11Vh4LZldV3czFsyeBDD w8IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686834637; x=1689426637; 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=MG8wEkfZhYGC5aupLXEONPEpLbQPJyBuYKNQETRNYXQ=; b=PTBuDcuCCjQGnNSP9tkcK1jvgAaGBGJ4B1OU/p88C/vN5B+q/nvnbCq8tn1qsBdTny nvnZAmiJeAGcs3p/eqmRB3PXnuK0zRiu2F+yHNrLILp1uqzEj8PkxuJ7gPL4QvUjNh4a +gbQCiKrFWuJVBiV3Td2g3CirOQDAlo6o6WO9E/g7qT4/vyYiJGVNyv/50BfsjNn7SKq hIaVHJnPnt8ymuxZujqAijC9+KGxETtiJHhntltbICpDUl9iMLy341amXwEsEXTtHEVE YmONHeSis+uW5V+47Q9OJZoVoZitneEJfNp6Qc8qRrYCOhstsg/Lc7JNnrVSuRgV/35C oVeQ== X-Gm-Message-State: AC+VfDxnSTTS6nIAe3TzGfBX6OSte7S4xHAbfVnwU2FmuMbtkNSohLQ+ mnDwPRa/pS42eNXcc4qsRjKa2A== X-Google-Smtp-Source: ACHHUZ7WKJVUJ+SDKFA9ptbKZMIDGFAgwrtvXxZ4yz/AJGuNYEZLYBZtCRPVCyj7PJ8FHVY00ecTSg== X-Received: by 2002:a17:903:1390:b0:1b2:28ca:d16 with SMTP id jx16-20020a170903139000b001b228ca0d16mr13196115plb.44.1686834637281; Thu, 15 Jun 2023 06:10:37 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id x1-20020a170902b40100b001a804b16e38sm14036019plr.150.2023.06.15.06.10.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 15 Jun 2023 06:10:36 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH 3/8] maple_tree: make mas_validate_gaps() to check metadata Date: Thu, 15 Jun 2023 21:08:54 +0800 Message-Id: <20230615130859.21858-4-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230615130859.21858-1-zhangpeng.00@bytedance.com> References: <20230615130859.21858-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make mas_validate_gaps() check whether the offset in the metadata points to the largest gap. By the way, simplify this function. Signed-off-by: Peng Zhang --- lib/maple_tree.c | 68 +++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 8aba9e419e08..799afd590cf3 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -6979,15 +6979,16 @@ EXPORT_SYMBOL_GPL(mt_dump); static void mas_validate_gaps(struct ma_state *mas) { struct maple_enode *mte =3D mas->node; - struct maple_node *p_mn; + struct maple_node *p_mn, *node =3D mte_to_node(mte); + enum maple_type mt =3D mte_node_type(mas->node); unsigned long gap =3D 0, max_gap =3D 0; unsigned long p_end, p_start =3D mas->min; - unsigned char p_slot; + unsigned char p_slot, offset; unsigned long *gaps =3D NULL; - unsigned long *pivots =3D ma_pivots(mte_to_node(mte), mte_node_type(mte)); + unsigned long *pivots =3D ma_pivots(node, mt); int i; =20 - if (ma_is_dense(mte_node_type(mte))) { + if (ma_is_dense(mt)) { for (i =3D 0; i < mt_slot_count(mte); i++) { if (mas_get_slot(mas, i)) { if (gap > max_gap) @@ -7000,52 +7001,51 @@ static void mas_validate_gaps(struct ma_state *mas) goto counted; } =20 - gaps =3D ma_gaps(mte_to_node(mte), mte_node_type(mte)); + gaps =3D ma_gaps(node, mt); for (i =3D 0; i < mt_slot_count(mte); i++) { - p_end =3D mas_logical_pivot(mas, pivots, i, mte_node_type(mte)); + p_end =3D mas_logical_pivot(mas, pivots, i, mt); =20 if (!gaps) { - if (mas_get_slot(mas, i)) { - gap =3D 0; - goto not_empty; - } - - gap +=3D p_end - p_start + 1; + if (!mas_get_slot(mas, i)) + gap =3D p_end - p_start + 1; } else { void *entry =3D mas_get_slot(mas, i); =20 gap =3D gaps[i]; - if (!entry) { - if (gap !=3D p_end - p_start + 1) { - pr_err("%p[%u] -> %p %lu !=3D %lu - %lu + 1\n", - mas_mn(mas), i, - mas_get_slot(mas, i), gap, - p_end, p_start); - mt_dump(mas->tree, mt_dump_hex); - - MT_BUG_ON(mas->tree, - gap !=3D p_end - p_start + 1); - } - } else { - if (gap > p_end - p_start + 1) { - pr_err("%p[%u] %lu >=3D %lu - %lu + 1 (%lu)\n", - mas_mn(mas), i, gap, p_end, p_start, - p_end - p_start + 1); - MT_BUG_ON(mas->tree, - gap > p_end - p_start + 1); - } + MT_BUG_ON(mas->tree, !entry); + + if (gap > p_end - p_start + 1) { + pr_err("%p[%u] %lu >=3D %lu - %lu + 1 (%lu)\n", + mas_mn(mas), i, gap, p_end, p_start, + p_end - p_start + 1); + MT_BUG_ON(mas->tree, + gap > p_end - p_start + 1); } } =20 if (gap > max_gap) max_gap =3D gap; -not_empty: + p_start =3D p_end + 1; if (p_end >=3D mas->max) break; } =20 counted: + if (mt =3D=3D maple_arange_64) { + offset =3D ma_meta_gap(node, mt); + if (offset > mt_slots[mt]) { + pr_err("gap offset %p[%u] is invalid\n", node, offset); + MT_BUG_ON(mas->tree, 1); + } + + if (gaps[offset] !=3D max_gap) { + pr_err("gap %p[%u] is not the largest gap %lu\n", + node, offset, max_gap); + MT_BUG_ON(mas->tree, 1); + } + } + if (mte_is_root(mte)) return; =20 @@ -7055,10 +7055,8 @@ static void mas_validate_gaps(struct ma_state *mas) if (ma_gaps(p_mn, mas_parent_type(mas, mte))[p_slot] !=3D max_gap) { pr_err("gap %p[%u] !=3D %lu\n", p_mn, p_slot, max_gap); mt_dump(mas->tree, mt_dump_hex); + MT_BUG_ON(mas->tree, 1); } - - MT_BUG_ON(mas->tree, - ma_gaps(p_mn, mas_parent_type(mas, mte))[p_slot] !=3D max_gap); } =20 static void mas_validate_parent_slot(struct ma_state *mas) --=20 2.20.1