Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp446582lqt; Thu, 6 Jun 2024 08:10:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIiRs3wHaytTa7TM2iImCnsrfd7ghRJXTRuGOCM7LnI00utIlNiLwNl6T4Ii30owz9FoSExi+B5S48jE/HFTv9itvPWPFDb6fjA3Yqqw== X-Google-Smtp-Source: AGHT+IHXHXZUOrbOHSfoO/fgmXUWVxpOfS6gspUqQ1/seq+6wJK+IqMgi+DKVKTB2gUqQJj1zwgc X-Received: by 2002:a05:6870:e6d3:b0:22e:8408:a98f with SMTP id 586e51a60fabf-251228b3aedmr6113708fac.36.1717686632834; Thu, 06 Jun 2024 08:10:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717686632; cv=pass; d=google.com; s=arc-20160816; b=b01Fp4tVXqZI1nEe5jKMD6OMIWFm0Jy1efbDQC+iJ7MfvrretShICV0HsGUrM+HgFs +1NsPu4YemfxKjb919PToT4SJIfBBvZR/KwcPcJLUDTIKIxE2iw63nyuunDVH+p9eZhL dPj8msT4OqGys0xEoWsknVAr8P1/gAf8O6JTLvQCfzicMeYoZFzGg44VMUiZWJD4FAjg 4tHwoQGWMpEoZwngKT8tWNsF1xMCgfC3xDB6LPjfBrJv0NytH+0Pj3biIcdklbJqmHcY bkap6rJhwuo3CyH/38wKzF3PGpNL13BuspCi2AiSoBibllEvI7RmJAdZd48ztv3+raCo QH1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=YbF+MHEIuz2j4yWwye2pV8E1rRND1f3g4pzJjU/SQzI=; fh=PrEnAYKGSmpcZ8/KKr0HSQ25+MWaGoegJLQibkaLdYc=; b=hXM9x2ff1R6iUxgvyo5ipDhWm1Af6vDtjRtarK9ETBWusI0A81XA08kDP22Vmfo7dB pVtFUzlAVgS9un98CSpIlRJ1f2+qPSlvoCxiegKmNTruXMUjgfmXf+pe9ysPKf52HzPQ 8M6T4rHfKH8dLIV4k6nL3VRq1BIb9kovBIdBMWAhn81SOKX/hTKkTB0G+d4tC2/f2JdU EIE5FGjGYZkVxwll/7rqv+zeBGcE7tUS3wuIR3ZGqQEwmkTOEXFAuTCA/Qye9LlXKlWC pAg+SAaie/hXCa/BgEAX6iZx8JbXvPfPPlQSDTaDDSvDPDnrsTAp97jaJxrBlYduEPxA OJUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="gESt/CPi"; arc=pass (i=1 spf=pass spfdomain=flex--mattgilbride.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204520-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204520-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 71dfb90a1353d-4eb4ad68142si321506e0c.249.2024.06.06.08.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 08:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204520-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="gESt/CPi"; arc=pass (i=1 spf=pass spfdomain=flex--mattgilbride.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204520-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204520-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 763E41C20C22 for ; Thu, 6 Jun 2024 15:10:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C697B19FA68; Thu, 6 Jun 2024 14:50:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gESt/CPi" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21F30196D86 for ; Thu, 6 Jun 2024 14:50:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717685422; cv=none; b=dAZ2fJlurnsRqR3Fl6GMXRHArDtGFxYDiqyxh+kPgoET/nQufgS0AgQS6wjpOamu4RadOF5T7Kjg1fBipSa8T3Bo8o3MGtaCrPi5JmNt7tjxbgd5Yn6gWQ6Sn6mjmGLJh40fOCBGrIdzzz0qtnAK7wCOpBQG/YPlPNAGjXBzE0U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717685422; c=relaxed/simple; bh=nNzkTpZJ7qh9/otKbRVfsT4Y09H0DA5UH+VJfpL9/2g=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=mXmCn0p0wDolueMnbW3qvrzLvfaNQJZ5GcrGM9ZQKdWJD6QWDnV1WqO+zgxTDQR5jMFgpj6AGakb62HsbduVEJfhdb4/7G5ui0sEav/6/Evpb16flZSHWknOHaQhJwbWc1s0ktHHxGwWTuE/PsAGkwR0CcVtrl2TBxekLrDgPR8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mattgilbride.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gESt/CPi; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mattgilbride.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62a3dec382eso11317387b3.1 for ; Thu, 06 Jun 2024 07:50:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717685420; x=1718290220; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=YbF+MHEIuz2j4yWwye2pV8E1rRND1f3g4pzJjU/SQzI=; b=gESt/CPiSNgWGF3RSKgF7XALR+pxtQilhZF6qaS8nrTOd2GKLlNrircD+2H6czun8b Cvuv76X5ITAkQBUVy9YoGuCc0k4AzaAXnBDHyZxXAMBUpwI+GnDycpX7eQ/Q06t5wk7p 99tJwwnyQfGDcSwVDIZp8xMVSZlUYGtPDjJXUeaCAqKt2cGuQjIVv1O17zmIWTdhFBx4 Q8VhbaqrlFpXcFaL3QiTfIuFL/LmHJRpqo+MMlp6efKIHrU/QNtW/n03e6Ye6ru+5JcW P7GQ4MH2pkHVEVBAkqt3NZlm96gB3+wnsRpg3I3lOKtMyBAB6nVQmF41lVAxayK/Cvja SiGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717685420; x=1718290220; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YbF+MHEIuz2j4yWwye2pV8E1rRND1f3g4pzJjU/SQzI=; b=DHaLG6J8sT8mi3F/ugnH0JZTEd4uwKR5Quuy4QQss+K1d28F2+8ot11xsa2MfMeOwE Rg/AcVyQLrefs5ZVrxxAu++TC/z0u9xqTqdXdTMM0whGo9bamfNzpeaUopr4WlMXPEBD C9PTS8Q7JeXr0E1qcFNR6ZxjhYJwIKpjQwp8o8S8651C8HrTsh0VoYDWdnDJifXoKnnc WcDfZIp0cRvgJh0CiJfVUQ/ITPuqNoj0k3xxTxmovQexMRryteuBm6SropyFv9b2m5Fx /Y9ix/mUYrVtro38t5ZJJ55GSzxZNF7XcAr53jYaii/TwYYbs4yJS8Ni/FgJ+VZx4mgt GsoQ== X-Forwarded-Encrypted: i=1; AJvYcCUHWuwi9txcXjhtcG9nexTdmVOHj61yHuEtlp+PUH8wL6AIUV42anvaX2sdeXwnOY4akEbU6ns20sPAPvI98h8Gog/BSbF/OEGMBjR1 X-Gm-Message-State: AOJu0YwKllryimR6uW02g0t8PIHS64Cfw/YEl+VxL3mCcXMa903GjJuO N+4UZTsAisW+Yx7zYBAAPNpXPlVTULozmAC7Ll9mG2eKZVTiCAstWk0XNlYpoR7myx8KhmdKzTY q4fSJTRDE90/dY9jqO5pEVp3zwQ== X-Received: from mattgilbride.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2ac5]) (user=mattgilbride job=sendgmr) by 2002:a05:690c:dcf:b0:61b:e53e:c7ae with SMTP id 00721157ae682-62cc709c399mr8543147b3.2.1717685420049; Thu, 06 Jun 2024 07:50:20 -0700 (PDT) Date: Thu, 06 Jun 2024 14:50:03 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAJvMYWYC/2XMQQ6CMBCF4auQrq2Z6RQCrryHcdGWAZooNYUQD eHuFjZiWL7JfP8sBo6eB3HJZhF58oMPfRr5KROuM33L0tdpCwWKUEEurZbRjpFZGmvRABYNGBD p/xW58e+tdbun3flhDPGzpSdcr2tFw39lQgmyqnImZqbSwbUNoX3w2YWnWDOT2lGs9lQlChaRj LFEUB8o/ajGck8pUVLESJoqcHyg+kcLoD3VK4WSNdWFsY37o8uyfAHCHDrdVAEAAA== X-Mailer: b4 0.12.4 Message-ID: <20240606-b4-rbtree-v5-0-96fe1a0e97c0@google.com> Subject: [PATCH v5 0/6] Red-black tree abstraction needed by Rust Binder From: Matt Gilbride To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Greg Kroah-Hartman , "=?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Christian Brauner Cc: Rob Landley , Davidlohr Bueso , Michel Lespinasse , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Matt Gilbride Content-Type: text/plain; charset="utf-8" This patchset contains the red-black tree abstractions needed by the Rust implementation of the Binder driver. Binder driver benefits from O(log n) search/insertion/deletion of key/value mappings in various places, including `process.rs` and `range_alloc.rs`. In `range_alloc.rs`, the ability to store and search by a generic key type is also useful. Please see the Rust Binder RFC for usage examples [1]. Note that the `container_of` macro is currently used only by `rbtree` itself. Users of "rust: rbtree: add red-black tree implementation backed by the C version" [PATCH RFC 03/20] rust_binder: add threading support [PATCH RFC 05/20] rust_binder: add nodes and context managers [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: rbtree: add iterator" [PATCH RFC 17/20] rust_binder: add oneway spam detection Users of "rust: rbtree: add mutable iterator" [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: rbtree: add `RBTreeCursor`" [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: rbtree: add RBTree::entry" Not used in the original RFC, but introduced after further code review. See: https://r.android.com/2849906 The Rust Binder RFC addresses the upstream deprecation of red-black tree. Quoted here for convenience: "This RFC uses the kernel's red-black tree for key/value mappings, but we are aware that the red-black tree is deprecated. We did this to make the performance comparison more fair, since C binder also uses rbtree for this. We intend to replace these with XArrays instead. That said, we don't think that XArray is a good fit for the range allocator, and we propose to continue using the red-black tree for the range allocator." Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/ [1] Signed-off-by: Matt Gilbride --- Changes in v5: - Used `Box::write` in `RBTreeNodeReservation::into_node`, removing unnecessary `unsafe` blocks. - Updated `RBTreeCursor::remove_current` to return the removed node. - Link to v4: https://lore.kernel.org/r/20240603-b4-rbtree-v4-0-308e43d6abfc@google.com Changes in v4: - rebased onto the tip of rust-for-linux/rust-next (97ab3e8eec0ce79d9e265e6c9e4c480492180409) - addressed comments from draft PR on GitHub: https://github.com/Rust-for-Linux/linux/pull/1081 - Link to v3: https://lore.kernel.org/r/20240418-b4-rbtree-v3-0-323e134390ce@google.com Changes in v3: - Address various feedback re: SAFETY and INVARIANT comments from v2. - Update variable naming and add detailed comments for the `RBTree::insert` (later moved to `RBTree::raw_entry`) implementation. - Link to v2: https://lore.kernel.org/r/20240219-b4-rbtree-v2-0-0b113aab330d@google.com Changes in v2: - Update documentation link to the C header file - Use `core::convert::Infallible` in try_reserve_node - Link to v1: https://lore.kernel.org/r/20240205-b4-rbtree-v1-0-995e3eee38c0@google.com --- Alice Ryhl (1): rust: rbtree: add `RBTree::entry` Benno Lossin (1): rust: kernel: add `drop_contents` to `BoxExt` Matt Gilbride (1): rust: rbtree: add `RBTreeCursor` Wedson Almeida Filho (3): rust: rbtree: add red-black tree implementation backed by the C version rust: rbtree: add iterator rust: rbtree: add mutable iterator rust/helpers.c | 7 + rust/kernel/alloc/box_ext.rs | 24 +- rust/kernel/lib.rs | 1 + rust/kernel/rbtree.rs | 1279 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1310 insertions(+), 1 deletion(-) --- base-commit: 97ab3e8eec0ce79d9e265e6c9e4c480492180409 change-id: 20231205-b4-rbtree-abb1a016f0a0 Best regards, -- Matt Gilbride