From patchwork Tue Mar 14 12:42:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13174288 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 A0964C74A5B for ; Tue, 14 Mar 2023 12:42:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DDE56B0074; Tue, 14 Mar 2023 08:42:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28DB58E0003; Tue, 14 Mar 2023 08:42:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 155F48E0002; Tue, 14 Mar 2023 08:42:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 003B36B0074 for ; Tue, 14 Mar 2023 08:42:21 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CC93C160C53 for ; Tue, 14 Mar 2023 12:42:21 +0000 (UTC) X-FDA: 80567466882.16.0B8730F Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 00627100012 for ; Tue, 14 Mar 2023 12:42:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Q0EWqbll; spf=pass (imf05.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678797740; 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=V3vWZFEyoFMtyU6NTTWlVAUK8MBUwQjg+G+jzZCDuAk=; b=2YoeB1Z49Cr0dgnxQeHo70e2qwvkuh8ClLb0f26vFvvazEHyT1HBp0e37QIK8tXwRocr3M BB0c0f91mPdTMW1qevx//7f/tGQtU9SWl1rruPs/YMyYxhzcGJsis1o5VYdvZ2rhuL3EUK 7E8i+LU+sqzGw2/mi8SSv4gtM6favfY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Q0EWqbll; spf=pass (imf05.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678797740; a=rsa-sha256; cv=none; b=4AGLx2/XGltPoPomkseeigu1q5gPjmHmSdGQcdhsyoXuqRUMQ9Xx8nZ4c0NEu+J9X2LsgS y8g7KcByVdDquYddGQUz8erkRFpCgErSEoezJvqrzz2rOXw271Rtt7Uh7XcNpD/hqqJkNI nm2jpO17jHw9zg+RX+7e8l07GkIIIOI= Received: by mail-pj1-f51.google.com with SMTP id gp15-20020a17090adf0f00b0023d1bbd9f9eso4805896pjb.0 for ; Tue, 14 Mar 2023 05:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678797738; 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=V3vWZFEyoFMtyU6NTTWlVAUK8MBUwQjg+G+jzZCDuAk=; b=Q0EWqbllJxrbZyB/Dz9VLiyjmY6OKzQ9ODkPXCtv1PHZFxEXHWUGy9j8P3QCubHPW6 laPUIMP5ae5R8SQ31VbcE0PP2Qxc0ZRZeq9ial6QzAMDElJuHuLPmKq8qz8iadur2NK2 Qc6llIatsVC/fIYVCuEaCkKpavYWo5xV0MCwYao4CrA7z5VX0new9FRvp3QEbxYXkyiI SLS6EiaBUB2md6d10HaQRcz8rW8OxSMc7iQFehdRbjLPyp5kXZppj44STkAZGKtyjsmc olYO/uynIoSxt0B+X/x9asOLPNhgHb9CaVT7qrMmAGPN7MuDUu025M1syzM8Q6iWO8yG UYOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678797738; 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=V3vWZFEyoFMtyU6NTTWlVAUK8MBUwQjg+G+jzZCDuAk=; b=dXCZsqEllk7RkIvWSzBYReumwyRng5z9ATsOhIaziN4hX6wHJIwswmYZ0Xt4x5pbjU Z1E5rsTT/Pf6JAS5QGooknffeokVo7LZKh7hgz/Mucf5OFZIyDoT6zHff0BaIuoVvlEd uqaigF91NAND4EJUr7KvgEO0PLq4aoAsJP4tJHAPqBXo9dpY1tlmAMpdjIz5kP7fIais C27xiik8tbLM+oUOcoaVYfcj/DDCiCBhAAZlOSkrrJODhnmdiyghlEHZuS8XmPVh4/cs A2bpG1sQSCUA5M+PVppUzbIZHZU/1ET2r4ot1nqcZu8oF5ZfiptoFx4FyMX7erYo74O1 Hdgg== X-Gm-Message-State: AO0yUKUzHVPcMXiMGIIcdNH5vvjHEmcvKSmE6q25ren2nn2o/RLoDmut 3OL05BasGjXuz50Uh/WS7NR9tQ== X-Google-Smtp-Source: AK7set9Ud5nZcxsuvhOGQRUujTT++2XEg590TsbcJ3Ds1UZrcs20nPDnaJZcfAnEuMlVPZqCfqCn0A== X-Received: by 2002:a05:6a20:bc97:b0:d5:74f:37a1 with SMTP id fx23-20020a056a20bc9700b000d5074f37a1mr3510720pzb.27.1678797738697; Tue, 14 Mar 2023 05:42:18 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id s11-20020aa7828b000000b005ded5d2d571sm1509385pfm.185.2023.03.14.05.42.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Mar 2023 05:42:18 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v2 1/3] maple_tree: Fix get wrong data_end in mtree_lookup_walk() Date: Tue, 14 Mar 2023 20:42:01 +0800 Message-Id: <20230314124203.91572-2-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230314124203.91572-1-zhangpeng.00@bytedance.com> References: <20230314124203.91572-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 00627100012 X-Rspam-User: X-Stat-Signature: bhzjg9k17zxodu1ipxs9neamcrhxrnnk X-HE-Tag: 1678797739-342419 X-HE-Meta: U2FsdGVkX1/waJn0Jotum19oQZM/lnqBau2BJnDUH5kgLgYJ5e9srSPNSERVeD5Cl0FptJ/fMCL9hhY2tuR1Y6zTLVMDaExt4F5EOxAeqJ/UUmkPL+iZ9yT1Kctm/G1oDh6HYHhKZJYtqBr2mnG1LCQsTwUakllmVfKxOz3aFlVF3SwHBPWGmTS4ml/zF20TyHwe3GNFDrIVasAOMmkgvRdwo8OW4hRTFIb4/Hf5Uc7qxQSlh86aWkKWufSPZaOtNKcXCyX/ghNm9suBVHwwvWmOmw95OYvpYhcOTRKaJXZ+EirEPdcW6pdDKVXfOdGDVY8PQpGVhlcEn6iSYTCB+92M/N3zg0Q8XXcygkYNs9u4aIlddeTRmi9ax1W0s6fb0TCWMzG+gTq9AQzaU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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: if (likely(offset > end)) max = pivots[offset]; The above code should be changed to if (likely(offset < end)), which is correct. This affects the correctness of ma_data_end(). Now it seems that the final result will not be wrong, but it is best to change it. This patch does not change the code as above, because it simplifies the code by the way. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 646297cae5d1..b3164266cfde 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3875,18 +3875,13 @@ static inline void *mtree_lookup_walk(struct ma_state *mas) end = ma_data_end(node, type, pivots, max); if (unlikely(ma_dead_node(node))) goto dead_node; - - if (pivots[offset] >= mas->index) - goto next; - do { - offset++; - } while ((offset < end) && (pivots[offset] < mas->index)); - - if (likely(offset > end)) - max = pivots[offset]; + if (pivots[offset] >= mas->index) { + max = pivots[offset]; + break; + } + } while (++offset < end); -next: slots = ma_slots(node, type); next = mt_slot(mas->tree, slots, offset); if (unlikely(ma_dead_node(node)))