Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1082361rdb; Mon, 19 Feb 2024 03:55:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWoQxwbBvaTihBY/FaWPaNuzvwXJUzq9JhzLnYxSQx8VakjvNKqPRoO4bo32H9BdPukfEuEanRa/hJKfxZUfwut+ks53ts5n3oByPWRUA== X-Google-Smtp-Source: AGHT+IHh3oU66x02CNVplLTtU/rf7+63BblUgLJptjelIxTHjjptL7TjmGVsaOiV9zfwaS11ny2l X-Received: by 2002:a17:90a:be0d:b0:299:51bd:4f5e with SMTP id a13-20020a17090abe0d00b0029951bd4f5emr3559876pjs.2.1708343704192; Mon, 19 Feb 2024 03:55:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708343704; cv=pass; d=google.com; s=arc-20160816; b=LqNrVHHuhHZVaXhpTM4Wxo+Qz63PWCOxTpehYMA2abvE6AXrikdltllyA6O5BjjIW1 GaATl1ZLW6zpY1ooJ8rJ6tKXiv2J8ydqURz4x4azn90ehTbCPBNviluIW51gY9xj9u6w GZ5yKXLEvrDs3v6Bl71Kl/0nwH93TLOO0neMlZSkxkm1ktuP3RD3h8LBXDO8vvelaI4w 9onY4Yif0qoxQuHnMrgyxKTgWWK4aKzKqGjHllgWMciL7vUsvbepYbZTzcH1GliFGDHu 6IYtHfIETYn7kRB1k1QJqaE9E73U9wOwreEVsvnUiXbeewtI5cf4aUQ4VNP3ppCvEK86 Ka2g== 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=Zq3hIb/a7G7RDHkyPhkOMlDdykFo1mSw4GBQxXEi8tU=; fh=vlMMpqyFibvhUOoj3fgbjFyrAKtSBR3Gl5DpMqTTlxY=; b=O6mYUKI+aYZxykI4B1q7ySq8+JaNI0rdOaz8VFRbOQSBrGWOjupJJw9OSoLnCQMen3 54CE5S5J8ZJUBWsSf1oZBDyc7e3+lNIHMOmMtJHmf1kCTIf2IY3NuhzZRkZRfWRTS01h b5VKfUg71vtqr965p09OD8VW3e416MSlYy8C+ThYZiCLZ2SeHtITQkQ5x3SnEsJ4JivA pz0R2mYPWp9RxHg2VAjxyI5yA8zRSW9A3VBJ0ZE10KtfH1C2G7poQsluG1kQUsneO+iH qMAJQp3zIwpowNOppocMIsw6f24C/GaWdSYmq6h2qz4bZvUj6V57Z7VCNVlmFf0mzhxt hD8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oqk6Y6EN; 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-71240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id rj3-20020a17090b3e8300b00296041acecfsi4481633pjb.1.2024.02.19.03.55.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 03:55:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oqk6Y6EN; 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-71240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71240-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D3F8D284D79 for ; Mon, 19 Feb 2024 11:48:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF5C02375A; Mon, 19 Feb 2024 11:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oqk6Y6EN" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 6E5592C68E for ; Mon, 19 Feb 2024 11:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708343316; cv=none; b=AnuiemWU4FrZufXcH/wneTP+ZXQbz3kZ3S9J4QiUUIun5F8fqgtKdPeC64xAADfj8c7zPaiPZCV9NGWJi4VeGaxqxbYYlfXj7kEiOo+TItxS+f7Sx2TaPB4CCpeQDHPlANqpYmG+81IuzOloospsPjf7PAkMTc0hZdhWyrEMtAU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708343316; c=relaxed/simple; bh=0BgyreMqzz0PMtI4QUlHgDPJch1SnZJpj6ZUNM2eegA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=q7Ta6azk+LRZy1kRb0gLN9+89aTc7BowKPgfUXIohja06lZwBtK3xxLrTOztu8xHL6cM5jg/lihc7fi7prwM8B52f+QpPKtxqHdkxqHbWS1NEU/sRIsQbrsSJ/7LWcv99hxJhmytOA3QF5ZgiX7KQkpgjDbDbVHCgJRxmjJq4gg= 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=oqk6Y6EN; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc74ac7d015so5325860276.0 for ; Mon, 19 Feb 2024 03:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708343313; x=1708948113; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Zq3hIb/a7G7RDHkyPhkOMlDdykFo1mSw4GBQxXEi8tU=; b=oqk6Y6ENgoe+QN87VFoeCynR06gMK0PE9szXy93wj+qpKdCv/Ut+jWHL38P+q4KSCJ +isL9ifP+vUnGrjI7URyHTo0P/2R5wFkCgxUTyOJT1G3HMT4ZempChegdeW5REDR3IQc 2y8oZetCWnFiaFe9QvzzLdjpfZnbvGZBpC/ijeOJwKKuTIdKiZZhe2U9JAf+1Jxj0Dur GPIM9ceiLB9zfZOHGfq/vD0vnfQffbMFWEq3DJVkrquS2YvyVWFw/zqD654De1YqziG4 BuzH+TD7sHyhjuOAJEAWeuu6pRHNWehubdtbG1FEj2z0Qsy0uDz84AHn+uLis/NPkfWD OlDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708343313; x=1708948113; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Zq3hIb/a7G7RDHkyPhkOMlDdykFo1mSw4GBQxXEi8tU=; b=NuFCwZA6ohol2lCgcbt64+HqPiYk+ADXn0bb4FZZ91fu7BAK+62LLsJhb78IpAj0kF ICxfdgJd4Bp2fpP4cSiqaUfgj0bhRs/a8HedRmVfcnG7FBmPRv5/PiC664pGCqWPYlKx rer/qor9ISoLU8FuTzj9GTon6kfQqUqJwlT2EP8tSIWbYa5dUDsUnDOQ56C+xWhM7Xdp XT6zE8jxqZ7FCUYEDz31Y5gD9KxGUtKK6ZgHt3s8hh8TF2Eabs/n4KQVFSinEvJuiLS1 yPSM4p+zGVO4oGpLUXte4FLRh6G0yfZ/XrGILvD930Whs9BsknToCTNJa1dujo68Yquq ndiw== X-Forwarded-Encrypted: i=1; AJvYcCWfKDmPcKG/9bRV5ehkZZb4FiaFzoJs0+7/gPMIECeKNeil16UmRIr8EUhiV+UiAW1tw5UFNiY39RcZX/V/oGtufGNoRJL/qlqsGDM5 X-Gm-Message-State: AOJu0YzpJiU6D++TpbLuXo8BiBxHaMJZ9nZuvRhFcLdVSGrfE0pQe+F6 LZ5uwdv2p+uuyc5Ik3AoQ+KrqvX5j4jMM/XlPm30YoKbUPtBbaAI6mfV58GB5/Earbq+ivuPtmd nb6DSCGufreVbtjMo6OkYRnkD1A== X-Received: from mattgilbride.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2ac5]) (user=mattgilbride job=sendgmr) by 2002:a05:6902:1b85:b0:dc2:26f6:fbc8 with SMTP id ei5-20020a0569021b8500b00dc226f6fbc8mr479732ybb.7.1708343313437; Mon, 19 Feb 2024 03:48:33 -0800 (PST) Date: Mon, 19 Feb 2024 11:48:07 +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=H4sIAPc/02UC/1XMQQ7CIBCF4as0s3bMAK2xrryH6QJwSkm0NNAQT cPdpd25/F9evg0SR88Jbs0GkbNPPsw15KkBO+nZMfpnbZAklZDUoWkxmjUyozZGaBKXkTRB/S+ RR/85rMdQe/JpDfF70Fns66609K9kgYR937FiZnW1dHchuBefbXjDUEr5AbpTt/SjAAAA X-Mailer: b4 0.12.4 Message-ID: <20240219-b4-rbtree-v2-0-0b113aab330d@google.com> Subject: [PATCH v2 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 `RBTreeIterator`" [PATCH RFC 17/20] rust_binder: add oneway spam detection Users of "rust: rbtree: add `RBTreeIteratorMut`" [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 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` Matt Gilbride (1): rust: rbtree: add `RBTreeCursor` Wedson Almeida Filho (4): rust: add `container_of!` macro rust: rbtree: add red-black tree implementation backed by the C version rust: rbtree: add `RBTreeIterator` rust: rbtree: add `RBTreeIteratorMut` rust/helpers.c | 7 + rust/kernel/lib.rs | 33 ++ rust/kernel/rbtree.rs | 1214 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1254 insertions(+) --- base-commit: 41bccc98fb7931d63d03f326a746ac4d429c1dd3 change-id: 20231205-b4-rbtree-abb1a016f0a0 Best regards, -- Matt Gilbride